refactor: Harden the code around consumed cycles in system api#9656
Merged
mraszyk merged 3 commits intodfinity:masterfrom Mar 30, 2026
Merged
refactor: Harden the code around consumed cycles in system api#9656mraszyk merged 3 commits intodfinity:masterfrom
mraszyk merged 3 commits intodfinity:masterfrom
Conversation
Contributor
mraszyk
reviewed
Mar 30, 2026
Contributor
mraszyk
left a comment
There was a problem hiding this comment.
Thanks a lot for the cleanup!
I only left a few code style suggestions (and I'm not approving now since my approval would be dismissed anyway).
rs/embedders/src/wasmtime_embedder/system_api/sandbox_safe_system_state.rs
Outdated
Show resolved
Hide resolved
rs/embedders/src/wasmtime_embedder/system_api/sandbox_safe_system_state.rs
Outdated
Show resolved
Hide resolved
rs/embedders/src/wasmtime_embedder/system_api/sandbox_safe_system_state.rs
Outdated
Show resolved
Hide resolved
rs/embedders/src/wasmtime_embedder/system_api/sandbox_safe_system_state.rs
Show resolved
Hide resolved
dsarlis
commented
Mar 30, 2026
rs/embedders/src/wasmtime_embedder/system_api/sandbox_safe_system_state.rs
Show resolved
Hide resolved
Contributor
Contributor
mraszyk
approved these changes
Mar 30, 2026
Contributor
Author
|
@mraszyk Thanks for the approval. I see CI is green, can you add to the queue please? |
Contributor
Author
Actually it seems an interface owner needs to approve as well. This view that I have is really confusing some times... |
schneiderstefan
approved these changes
Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a follow up to #9520 where
CompoundCycleswere introduced. In the system API there can only be 3 cases of consumed cycles, specificallyBurnedCycles,InstructionsandRequestAndResponseTransmission. Currently, there's an awkwardpanicto deal with the possibility that the currentBTreeMapwhere consumed cycles are stored cannot contain other variants. While this is easy to verify that is the case now (code inspection + type imports), it is unideal as it's error prone and we can do better with the stricter types introduced viaCompoundCycles.The solution is to define a struct which captures exactly the possible cases that can be produced via the system API calls and use that throughout. There's some little extra boilerplate but this ensures that no unexpected cases can happen and removes the need to handle such cases. An alternative would have been to add a check in
validate_cycle_changeto raise a critical error instead but it's better if we can eliminate the possibility of errors altogether.