Skip to content

refactor: Harden the code around consumed cycles in system api#9656

Merged
mraszyk merged 3 commits intodfinity:masterfrom
dsarlis:dimitris/harden-checks
Mar 30, 2026
Merged

refactor: Harden the code around consumed cycles in system api#9656
mraszyk merged 3 commits intodfinity:masterfrom
dsarlis:dimitris/harden-checks

Conversation

@dsarlis
Copy link
Copy Markdown
Contributor

@dsarlis dsarlis commented Mar 30, 2026

This is a follow up to #9520 where CompoundCycles were introduced. In the system API there can only be 3 cases of consumed cycles, specifically BurnedCycles, Instructions and RequestAndResponseTransmission. Currently, there's an awkward panic to deal with the possibility that the current BTreeMap where 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 via CompoundCycles.

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_change to raise a critical error instead but it's better if we can eliminate the possibility of errors altogether.

@dsarlis dsarlis requested review from a team as code owners March 30, 2026 08:46
@cgundy cgundy added the security-review-passed IDX or InfraSec have concluded it's safe to run CI on the external PR. label Mar 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

@dfinity dfinity deleted a comment from github-actions bot Mar 30, 2026
Copy link
Copy Markdown
Contributor

@mraszyk mraszyk left a comment

Choose a reason for hiding this comment

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

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).

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown
Contributor

@dsarlis
Copy link
Copy Markdown
Contributor Author

dsarlis commented Mar 30, 2026

@mraszyk Thanks for the approval. I see CI is green, can you add to the queue please?

@dsarlis
Copy link
Copy Markdown
Contributor Author

dsarlis commented Mar 30, 2026

@mraszyk Thanks for the approval. I see CI is green, can you add to the queue please?

Actually it seems an interface owner needs to approve as well. This view that I have is really confusing some times...

@mraszyk mraszyk added this pull request to the merge queue Mar 30, 2026
Merged via the queue into dfinity:master with commit b68e839 Mar 30, 2026
13 of 14 checks passed
@dsarlis dsarlis deleted the dimitris/harden-checks branch March 31, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor @ic-interface-owners refactor security-review-passed IDX or InfraSec have concluded it's safe to run CI on the external PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants