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

Is MAX_LIMIT a bug? #625

Closed
Ruborcalor opened this issue Jan 6, 2022 · 2 comments
Closed

Is MAX_LIMIT a bug? #625

Ruborcalor opened this issue Jan 6, 2022 · 2 comments

Comments

@Ruborcalor
Copy link

Hello there!

I'm trying to understand why MAX_LIMIT is defined for limiting the querying of accounts: https://github.com/CosmWasm/cw-plus/blob/main/contracts/cw20-base/src/enumerable.rs#L8

There's basically two possibilities when you set MAX_LIMIT

  • You set MAX_LIMIT too low (meaning you could have set a higher limit without running out of gas) which means you are unnecessarily restricting the rate at which you can read data
  • You set MAX_LIMIT too high (meaning you run out of gas at the max limit) which means you might as well not set any MAX_LIMIT at all

There is technically a third option where you perfectly calibrate MAX_LIMIT but doesn't work in practice because the gas costs may fluctuate.

So what is the point of setting a MAX_LIMIT; why not let the querier decide the limit for themselves? Is it to intentionally throttle the data throughput? Thanks!

@hashedone
Copy link
Contributor

It is not to limit or optimize your gas usage. It is mostly to disallow any kind of overloading nodes performing such queries, and DOSing them. Remember that those queries are not run on google cloud or another AWS, they are calculated on validators machines, and we want make every single block reasonably small. Removing the limit of how much data you can query for means, that you can make single execution with bigger computation cost (indirectly represented by gas cost) that we expect the whole block to be. You can argue if 30 is fair limit, or it can be bigger - I don't know about that. But having a limit is just saving us from freezing the blockchain.

@Ruborcalor
Copy link
Author

Ruborcalor commented Jan 31, 2022

Hey thanks for your reply!

So what I understood is that you add MAX_LIMIT for queries in order to decrease their max gas consumption.

i.e. even though the gas limit for queries is 300_000, you want to further restrict certain queries to a smaller max amount of gas like 50_000.

My question now is why not lower the actual gas limit for queries? The current approach is not enforceable because people can clone the code and remove the MAX_LIMIT.

Is it that you want to leave the option for queries to consume 300_000 gas when necessary, while still building a culture around designing queries to consume less gas?

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

3 participants