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

Add example of execution limits using fuel consumption #2869

Merged
merged 6 commits into from
May 4, 2021

Conversation

ryanpbrewster
Copy link
Contributor

This is a quick example of using the "fuel consumption" logic introduced in #2611.

It computes larger and larger Fibonacci numbers (using the expensive recursive algorithm) until the computation requires more than 10k fuel.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

examples/fuel.wat Show resolved Hide resolved
@alexcrichton
Copy link
Member

Ah it looks like CI is failing when it's running the examples, as it expects that all examples pass successfully. Could the example be updated to not return a failure code? (e.g. catch the error)

Also I think our CI verifies that all examples are available in both C and Rust, so I think that at least a stub program will be needed for a C example?

@ryanpbrewster
Copy link
Contributor Author

ryanpbrewster commented May 3, 2021

Ah, that could be it. Thanks for the pointer, adding a C stub now.

EDIT: This may take a bit, figuring out how to build and run the C examples on a mac now.

@ryanpbrewster
Copy link
Contributor Author

ryanpbrewster commented May 3, 2021

Added a C example. I'm not particularly confident in the error handling and cleanup code there. I think I handle the error codes from wasm_store_add_fuel (I manually checked that if the config does not enable fuel consumption that those calls fail and exit).

I'm not sure about the semantics of the bool that wasm_store_fuel_consumed returns, so I just ignored it. Should I be asserting that it's true?

@alexcrichton
Copy link
Member

That all looks great to me, thanks!

@alexcrichton alexcrichton merged commit 2145855 into bytecodealliance:main May 4, 2021
@ryanpbrewster ryanpbrewster deleted the rpb/fuel-example branch May 4, 2021 16:14
mchesser pushed a commit to mchesser/wasmtime that referenced this pull request May 24, 2021
…nce#2869)

* Add example of execution limits using fuel consumption

* run rustfmt

* Use a more naive WAT implementation

* Catch error and return cleanly

* Add a C example to demonstrate fuel consumption

* Add error handling for add_fuel
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

Successfully merging this pull request may close these issues.

2 participants