Repository navigation
feat: certification version V30 with monotonic consumed cycles in subnet metrics - #11777
Merged
mraszyk merged 3 commits intoOct 7, 2026
Merged
Conversation
…net metrics Add certification version `V30` as the new maximum supported version; the current certification version stays at `V29`. Starting with `V30`, `/subnet/<subnet_id>/metrics` accounts for the cycles consumed by non-deleted canisters as the sum of their monotonic `CanisterMetrics::consumed_cycles_monotonic` instead of their `CanisterMetrics::consumed_cycles` gauges (which also include outstanding prepayments). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes consensus-critical certified-state encoding and cycle accounting, warranting final human review despite comprehensive compatibility coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Adds certification version V30 support for monotonic canister cycle accounting while retaining V29 as the active version.
Changes:
- Adds V30 as the maximum supported certification version.
- Maintains gauge-based and monotonic subnet cycle totals.
- Adds compatibility, traversal, aggregation, and restart tests.
| File | Description |
|---|---|
rs/state_manager/src/tree_hash.rs |
Adds the expected V30 state hash. |
rs/replicated_state/tests/replicated_state.rs |
Tests both totals across restart. |
rs/replicated_state/src/replicated_state.rs |
Refreshes both derived totals. |
rs/replicated_state/src/metrics.rs |
Clarifies gauge behavior. |
rs/replicated_state/src/metadata_state/tests.rs |
Tests monotonic subnet totals. |
rs/replicated_state/src/metadata_state/proto.rs |
Initializes the derived monotonic field. |
rs/replicated_state/src/metadata_state.rs |
Stores and computes both totals. |
rs/replicated_state/src/canister_states/tests.rs |
Tests hot/cold monotonic aggregation. |
rs/replicated_state/src/canister_states.rs |
Aggregates monotonic cycles efficiently. |
rs/execution_environment/tests/execution_test.rs |
Updates certification test documentation. |
rs/execution_environment/src/execution_environment.rs |
Clarifies endpoint accounting behavior. |
rs/canonical_state/src/traversal.rs |
Tests version-specific traversal output. |
rs/canonical_state/src/lazy_tree_conversion.rs |
Adds V30 tree expansion support. |
rs/canonical_state/src/encoding/types.rs |
Selects monotonic totals for V30. |
rs/canonical_state/src/encoding/tests/compatibility.rs |
Adds V30 CBOR compatibility coverage. |
rs/canonical_state/certification_version/src/lib.rs |
Defines V30 as the supported maximum. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
✅ No security or compliance issues detected. Reviewed everything up to 4612213. Security Overview
Detected Code Changes
|
eichhorl
approved these changes
Oct 7, 2026
…on-version-v30-monotonic-cycles # Conflicts: # rs/canonical_state/src/encoding/tests/compatibility.rs # rs/state_manager/src/tree_hash.rs
- tree_hash: set the monotonic canisters' part unconditionally, as earlier certification versions never read it. - execution_test: rewrap a doc comment line exceeding 100 columns. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
mraszyk
enabled auto-merge
October 7, 2026 17:33
AleDema
pushed a commit
to AleDema/ic
that referenced
this pull request
Oct 11, 2026
…ion and install_code (dfinity#11776) Switches the remaining production readers of the `CanisterMetrics::consumed_cycles_by_use_cases` gauges to `consumed_cycles_by_use_cases_monotonic`: - `rs/replicated_state/src/metrics.rs`: the canister part of the per-use-case consumed cycles gauge exported to Prometheus now comes from the monotonic map, with `HTTPOutcalls` removed, just like the counter's. The gauge (`replicated_state_consumed_cycles_from_replica_start`) and the counter (`..._as_counters`) are therefore built from exactly the same inputs, so `observe()` builds a single per-use-case map and feeds it to both, instead of building an identical second map over every canister after each round. - `rs/execution_environment/src/canister_manager.rs`: on canister deletion, the canister's per-use-case consumption is moved into `SubnetMetrics` from the monotonic map. - `rs/execution_environment/src/execution/install_code.rs`: the burned cycles delta in `finish` reads `BurnedCycles` from the monotonic map. Burned cycles are charged directly without a prepayment, so both maps move together and the balance `debug_assert` is unaffected. The monotonic map has an `HTTPOutcalls` entry, which the gauge map lacks because HTTPS outcalls are recorded at the subnet level when they are charged. The metrics and deletion paths skip it. Without the skip, deletion would double count outcall cycles in the subnet-level `HTTPOutcalls` entry, and through it in `SubnetMetrics::consumed_cycles_total()`. That subnet-level part goes into the certified `/subnet/<subnet_id>/metrics` total from V29 on (`consumed_cycles_total_including_canisters`) and also into the V30 total (`consumed_cycles_total_including_canisters_monotonic`, dfinity#11777). For the other use cases, the deletion path should behave as before once the monotonic amounts have been backfilled (which is the case in production by now). A stopped canister has no outstanding prepayments, so its gauges equal their monotonic counterparts. Tests: - New `http_outcalls_consumed_cycles_are_not_double_counted_on_canister_deletion`: deleting a canister that made an HTTPS outcall leaves the subnet-level `HTTPOutcalls` entry, the subnet total (beyond the leftover balance), and the exported gauge and counter unchanged. It fails without the skip (subnet `HTTPOutcalls` entry 2,000,000 instead of 1,000,000). - `consumed_cycles_for_instructions_are_updated_from_valid_canisters` first observes the metrics while the instruction prepayment is outstanding and expects `0.0` (it fails with `1000.0` if `metrics.rs` reads the gauges again), then settles the prepayment with a zero refund, as finishing an execution would, and expects the full amount. - `consumed_cycles_are_updated_from_deleted_canisters` settles the prepayment the same way before deleting the canister, so the cycles count as consumed in the monotonic map. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.
Add certification version
V30as the new maximum supported version; the current certification version stays atV29(it can only be bumped onceV30is supported by all replicas).Starting with
V30,/subnet/<subnet_id>/metricsaccounts for the cycles consumed by non-deleted canisters as the sum of their monotonicCanisterMetrics::consumed_cycles_monotonicinstead of theirCanisterMetrics::consumed_cyclesgauges (which also include outstanding prepayments):V28: legacyconsumed_cycles_total_v28(unchanged);V29:SubnetMetrics::consumed_cycles_total_including_canisters(unchanged);V30: the newSubnetMetrics::consumed_cycles_total_including_canisters_monotonic.Implementation:
ColdStatsadditionally aggregatesconsumed_cycles_monotonicover cold canisters, so the newCanisterStates::total_consumed_cycles_monotonicisO(|hot canisters|).SubnetMetricsstores a second derived (non-persisted) total;refresh_consumed_cyclesnow takes both the gauge and the monotonic canisters' parts and adds the same subnet-level part to each. It is refreshed on every commit and on checkpoint load, as before.subnet_metricsendpoint and thereplicated_state_consumed_cycles_since_replica_startedgauge are unchanged (they keep reading the gauge-based total).Tests:
tree_hash.rsbackward-compatibility test: newV30hash, distinct fromV29(hashes forV19–V29unchanged).ColdStats, restart-consistency, and gauge tests extended to cover the monotonic total.🤖 Generated with Claude Code