Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default token mints subscriptions, killer for public rpc and private pools #27

Closed
Arrowana opened this issue Jul 22, 2021 · 4 comments
Closed

Comments

@Arrowana
Copy link
Contributor

Every single token mint in spl-token-registry is added to the cache

const [tokenMap, setTokenMap] = useState<Map<string, TokenInfo>>(new Map());
useEffect(() => {
cache.clear();
// fetch token files
(async () => {
const res = await new TokenListProvider().resolve();
const list = res
.filterByChainId(chain.chainID)
.excludeByTag("nft")
.getList();
const knownMints = list.reduce((map, item) => {
map.set(item.address, item);
return map;
}, new Map<string, TokenInfo>());
const accounts = await getMultipleAccounts(connection, [...knownMints.keys()], 'single');
accounts.keys.forEach((key, index) => {
const account = accounts.array[index];
if(!account) {
return;
}
cache.add(new PublicKey(key), account, MintParser);
})
setTokenMap(knownMints);
setTokens(list);
})();
}, [connection, chain]);

Adding to the cache has a side effect, creating a subscription to the added account:

useEffect(() => {
const subs: number[] = [];
cache.emitter.onCache((args) => {
if (args.isNew) {
let id = args.id;
let deserialize = args.parser;
connection.onAccountChange(new PublicKey(id), (info) => {
cache.add(id, info, deserialize);
});
}
});

This problem is invisible on devnet as the token list is small, but once plugged to mainnet this is a node/rpcpool killer as the code will open a great number of account subscriptions through onAccountChange

In most cases an up to date token mint is not required, only in rare cases it is useful (LP token supply...).

This should be reworked so the dapp-scaffold boilerplate is not a trap.

Here is a screenshot of the swarm of accountSubscribe in the websocket, it can't even fit on the screen
Screenshot from 2021-07-22 18-39-12

Some of which are essential tokens to be monitored
Screenshot from 2021-07-22 17-54-47

@Arrowana Arrowana changed the title Many token mints subscriptions potential killer for public rpc and private pools Default token mints subscriptions potential killer for public rpc and private pools Jul 22, 2021
@Arrowana Arrowana changed the title Default token mints subscriptions potential killer for public rpc and private pools Default token mints subscriptions, killer for public rpc and private pools Jul 22, 2021
@brianlong
Copy link

I'll upvote the importance of this issue. We have now seen multiple cases where developers started with this scaffold and later saw disastrous results on their mainnet launch. Blindly opening this many subscriptions is an anti-pattern to be avoided.

A safer approach might be for the developer to explicitly state the subscriptions they require.

// @bartosz-lipinski @rmshea

@joeaba
Copy link

joeaba commented Jul 23, 2021

'+ @bhgames

@aaronovz1
Copy link

Can confirm this is a node killer. It's better to get rid of subscriptions altogether and just poll at reasonable frequencies using getMultipleAccounts to batch as much as you can.

@kevinrodriguez-io
Copy link
Contributor

I'll take a look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants