Skip to content

feat: certification version V30 with monotonic consumed cycles in subnet metrics - #11777

Merged
mraszyk merged 3 commits into
masterfrom
mraszyk/certification-version-v30-monotonic-cycles
Oct 7, 2026
Merged

mraszyk merged 3 commits into
masterfrom
mraszyk/certification-version-v30-monotonic-cycles

Conversation

@mraszyk

@mraszyk mraszyk commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Add certification version V30 as the new maximum supported version; the current certification version stays at V29 (it can only be bumped once V30 is supported by all replicas).

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

  • up to and including V28: legacy consumed_cycles_total_v28 (unchanged);
  • V29: SubnetMetrics::consumed_cycles_total_including_canisters (unchanged);
  • from V30: the new SubnetMetrics::consumed_cycles_total_including_canisters_monotonic.

Implementation:

  • ColdStats additionally aggregates consumed_cycles_monotonic over cold canisters, so the new CanisterStates::total_consumed_cycles_monotonic is O(|hot canisters|).
  • SubnetMetrics stores a second derived (non-persisted) total; refresh_consumed_cycles now 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.
  • The management canister subnet_metrics endpoint and the replicated_state_consumed_cycles_since_replica_started gauge are unchanged (they keep reading the gauge-based total).

Tests:

  • tree_hash.rs backward-compatibility test: new V30 hash, distinct from V29 (hashes for V19–V29 unchanged).
  • CBOR compatibility, traversal, ColdStats, restart-consistency, and gauge tests extended to cover the monotonic total.

🤖 Generated with Claude Code

…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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@mraszyk
mraszyk marked this pull request as ready for review October 7, 2026 12:22
@mraszyk
mraszyk requested a review from a team as a code owner October 7, 2026 12:22
@zeropath-ai

zeropath-ai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to 4612213.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/canonical_state/certification_version/src/lib.rs
    Add V30 certification version and update MAX_SUPPORTED_CERTIFICATION_VERSION
► rs/canonical_state/src/encoding/types.rs
    Support V30 monotonic consumed_cycles_total_including_canisters
► rs/canonical_state/src/encoding/tests/compatibility.rs
    Adjust expected encoding for V30 monotonic total cycles
► rs/canonical_state/src/lazy_tree_conversion.rs
    Handle V30 in canister expander selection and metrics blob encoding
► rs/canonical_state/src/traversal.rs
    Update tests for V30 subnet metrics inclusion
► rs/execution_environment/src/execution_environment.rs
    Document metric reading behavior across V29/V30
► rs/replicated_state/src/metadata_state.rs
    Add monotonic consumed cycles fields and refresh logic
► rs/replicated_state/src/metadata_state/proto.rs
    Initialize monotonic field in protobuf conversion
► rs/replicated_state/src/replicated_state.rs
    Refresh metrics using both gauge and monotonic totals
► rs/replicated_state/src/metrics.rs
    Update comment regarding V29 drift and V30 monotonic handling
► rs/replicated_state/src/canister_states.rs
    Add total_consumed_cycles_monotonic method and fields
► rs/replicated_state/src/canister_states/tests.rs
    Update tests to account for monotonic consumption and new total
► rs/replicated_state/src/metadata_state/tests.rs
    Adjust tests to refresh both gauge and monotonic totals
► rs/execution_environment/tests/execution_test.rs
    Update restart/consumption tests to consider monotonic totals
► rs/state_manager/src/tree_hash.rs
    Exercise monotonic consumption in tests for V30 compatibility

Comment thread rs/state_manager/src/tree_hash.rs Resolved
mraszyk and others added 2 commits October 7, 2026 17:22
…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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Consensus-certified state changes and cycle-accounting transitions warrant final human validation despite comprehensive coverage.

0 open findings

🧠 Review effort: Balanced

@mraszyk
mraszyk enabled auto-merge October 7, 2026 17:33
@mraszyk
mraszyk added this pull request to the merge queue Oct 7, 2026
Merged via the queue into master with commit 5291ec8 Oct 7, 2026
41 checks passed
@mraszyk
mraszyk deleted the mraszyk/certification-version-v30-monotonic-cycles branch October 7, 2026 18:15
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants