Skip to content

refactor: Better separation between Cycles and NominalCycles#9264

Merged
alin-at-dfinity merged 8 commits intodfinity:masterfrom
dsarlis:dimitris/refactor-private-metrics
Mar 11, 2026
Merged

refactor: Better separation between Cycles and NominalCycles#9264
alin-at-dfinity merged 8 commits intodfinity:masterfrom
dsarlis:dimitris/refactor-private-metrics

Conversation

@dsarlis
Copy link
Contributor

@dsarlis dsarlis commented Mar 9, 2026

This PR is a first step towards implementing what's sketched out in #9063.

Specifically, in this PR we make some cycles metrics private to ReplicatedState so that we force callers to always use APIs that require specific types to be passed in as well as convert some other APIs to accept NominalCycles instead of simply Cycles. This allows the removal of the functions that allow direct conversion from Cycles to NominalCycles and wherever this is needed we can convert from the raw amount (this is mostly tests and one case in CyclesAccountManager which will be further improved in a follow-up).

Follow-up PR(s) will implement the remaining parts of the solution, namely a new type that captures both the real amount and the one to update metrics and further locking down access patterns via public APIs with explicit types on them.

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

github-actions bot commented Mar 9, 2026

@dsarlis
Copy link
Contributor Author

dsarlis commented Mar 9, 2026

@basvandijk Seems there were some Java exceptions when running all tests, can you restart the job?

@basvandijk
Copy link
Collaborator

basvandijk commented Mar 9, 2026

Seems bazel-test-all failed because of a clippy error: (sorry about color codes, I had to copy/paste this via my phone since I'm on the run)

�[1m�[91merror�[0m�[1m: unused import: `Cycles`�[0m
  �[1m�[94m--> �[0mrs/replicated_state/src/replicated_state.rs:29:38
   �[1m�[94m|�[0m
�[1m�[94m29�[0m �[1m�[94m|�[0m     AccumulatedPriority, CanisterId, Cycles, NumBytes, SubnetId, Time,
   �[1m�[94m|�[0m                                      �[1m�[91m^^^^^^�[0m
   �[1m�[94m|�[0m
   �[1m�[94m= �[0m�[1mnote�[0m: `-D unused-imports` implied by `-D warnings`
   �[1m�[94m= �[0m�[1mhelp�[0m: to override `-D warnings` add `#[allow(unused_imports)]`

�[1m�[91merror�[0m�[1m: aborting due to 1 previous error�[0m

But strange the cargo clippyjob didn't fail with the same error.

@dsarlis
Copy link
Contributor Author

dsarlis commented Mar 9, 2026

Seems bazel-test-all failed because of a clippy error: (sorry about color codes, I had to copy/paste this via my phone since I'm on the run)

�[1m�[91merror�[0m�[1m: unused import: `Cycles`�[0m
  �[1m�[94m--> �[0mrs/replicated_state/src/replicated_state.rs:29:38
   �[1m�[94m|�[0m
�[1m�[94m29�[0m �[1m�[94m|�[0m     AccumulatedPriority, CanisterId, Cycles, NumBytes, SubnetId, Time,
   �[1m�[94m|�[0m                                      �[1m�[91m^^^^^^�[0m
   �[1m�[94m|�[0m
   �[1m�[94m= �[0m�[1mnote�[0m: `-D unused-imports` implied by `-D warnings`
   �[1m�[94m= �[0m�[1mhelp�[0m: to override `-D warnings` add `#[allow(unused_imports)]`

�[1m�[91merror�[0m�[1m: aborting due to 1 previous error�[0m

But strange the cargo clippyjob didn't fail with the same error.

Hmm, it seems that Cycles are only used with [#cfg(debug_assertions)] after my changes so it rightfully complains. Perhaps, the conditional usage is what confused things with cargo clippy? But it shouldn't have been the case.

Btw, I am not sure how to easily fish out the actual error messages from the usually quite long output. There were indeed about 50 or so java exceptions that seemed to be what the issue was about (also given that I saw nothing else fail).

@basvandijk
Copy link
Collaborator

Btw, I am not sure how to easily fish out the actual error messages from the usually quite long output. There were indeed about 50 or so java exceptions that seemed to be what the issue was about (also given that I saw nothing else fail).

Yeah good point. It would be great if we could make BuildBuddy public. I'll bring it up in our next IDX meeting.

Copy link
Contributor

@alin-at-dfinity alin-at-dfinity left a comment

Choose a reason for hiding this comment

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

Just some nitpicks / questions, otherwise LGTM.

@github-actions github-actions bot dismissed alin-at-dfinity’s stale review March 10, 2026 13:20

Review dismissed by automation script.

@dsarlis
Copy link
Contributor Author

dsarlis commented Mar 10, 2026

@alin-at-dfinity Assuming the approval meant that there are no other concerns. Since I merged master and fixed some stuff after merging, your approval is required again. Please also kickstart CI and add the PR to the merge queue if no more concerns.

@alin-at-dfinity
Copy link
Contributor

Apologies for the late response, got carried away with other stuff. Triggered presubmit tests and auto-merge, let's see if it just works. I'll check back later.

@github-actions github-actions bot dismissed alin-at-dfinity’s stale review March 10, 2026 16:16

Review dismissed by automation script.

@dsarlis
Copy link
Contributor Author

dsarlis commented Mar 10, 2026

@alin-at-dfinity I am not sure CI was started properly. You should see a message like this one if it's properly triggered.

@github-actions
Copy link
Contributor

1 similar comment
@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@alin-at-dfinity
Copy link
Contributor

Sorry about all that, I believe I got it all figured out now (with a lot of handholding).

@dsarlis
Copy link
Contributor Author

dsarlis commented Mar 11, 2026

No worries. I see you started 3 of them -- at least we'll have some fault tolerance in case we hit some flaky tests :)

@alin-at-dfinity
Copy link
Contributor

Problem is, for the first couple of them I used the GitHub commit URL instead of just the commit SHA. And couldn't understand why they kept failing.

@alin-at-dfinity alin-at-dfinity added this pull request to the merge queue Mar 11, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 11, 2026
@github-actions github-actions bot dismissed alin-at-dfinity’s stale review March 11, 2026 11:02

Review dismissed by automation script.

@dsarlis dsarlis requested a review from alin-at-dfinity March 11, 2026 11:02
@dsarlis
Copy link
Contributor Author

dsarlis commented Mar 11, 2026

@alin-at-dfinity I had to fix some things after merging master which contained some latest changes. Please restart things when you get a chance.

@github-actions
Copy link
Contributor

@alin-at-dfinity alin-at-dfinity added this pull request to the merge queue Mar 11, 2026
Merged via the queue into dfinity:master with commit a78d8ee Mar 11, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor 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.

3 participants