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

Limit resource usage of state_call #1628

Open
xlc opened this issue Sep 19, 2023 · 5 comments
Open

Limit resource usage of state_call #1628

xlc opened this issue Sep 19, 2023 · 5 comments
Labels
D2-substantial Can be fixed by an experienced coder with a working knowledge of the codebase. I5-enhancement An additional feature request. T0-node This PR/Issue is related to the topic “node”. T4-runtime_API This PR/Issue is related to runtime APIs.

Comments

@xlc
Copy link
Contributor

xlc commented Sep 19, 2023

Previous issue: paritytech/substrate#12698

Do we have any resource limits of making runtime API calls via state_call RPC?

For Ethereum nodes, we can submit RPC call to ask it to arbitrary EVM computation but up to some hard coded gas limit, which could be like 10x of the block gas limit. This ensures a single RPC call cannot consume too much CPU on the node.

I think we need a similar mechanism for state_call. Make it accept an optional Weight which capped to like 10x block weight limit and interrupt the wasm function call when it is taking too long.

@pepyakin
Copy link
Contributor

Related: paritytech/substrate#10648

@bkchr bkchr added the I5-enhancement An additional feature request. label Sep 25, 2023
@bkchr bkchr added this to SDK Node Sep 25, 2023
@github-project-automation github-project-automation bot moved this to backlog in SDK Node Sep 25, 2023
@bkchr
Copy link
Member

bkchr commented Sep 25, 2023

Yeah, I think we should use the fuel mechanism and not weight. weight would require that we also start benchmarking the runtime apis.

@ggwpez
Copy link
Member

ggwpez commented Mar 13, 2024

Make it accept an optional Weight which capped to like 10x block weight limit and interrupt the wasm function call when it is taking too long.

We can just use a tokio timeout and kill the WASM instance? It is not deterministic, but should already prevent DoS vector.

@ggwpez ggwpez added D2-substantial Can be fixed by an experienced coder with a working knowledge of the codebase. T0-node This PR/Issue is related to the topic “node”. T4-runtime_API This PR/Issue is related to runtime APIs. labels Mar 13, 2024
@xlc
Copy link
Contributor Author

xlc commented Mar 14, 2024

That will be a simple starting point

@pepyakin
Copy link
Contributor

I am not sure how that would work. Imagine that a thread enters in wasm and that wasm just loops indefinitely. When the timeout triggers it drops the future.

If you execute wasm, it is a blocking operation. That means that even if you armed a timeout, it won't ever trigger. It will elapse, but the future cannot be polled while it is blocked in the wasm code!

You can use epochs but that would be pretty involved. fuel seems the most simple option here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D2-substantial Can be fixed by an experienced coder with a working knowledge of the codebase. I5-enhancement An additional feature request. T0-node This PR/Issue is related to the topic “node”. T4-runtime_API This PR/Issue is related to runtime APIs.
Projects
Status: backlog
Development

No branches or pull requests

4 participants