Repository navigation
refactor: read HTTP/ECDSA outcall cycles from the per-use-case map - #11202
Conversation
The cycles consumed by HTTP and ECDSA outcalls are tracked both in the legacy scalar fields consumed_cycles_http_outcalls / consumed_cycles_ecdsa_outcalls of SubnetMetrics and in the consumed_cycles_by_use_case map, which a migration introduced in #10844 keeps in lockstep with those fields. This switches all readers over to the map: - get_consumed_cycles_http_outcalls / get_consumed_cycles_ecdsa_outcalls now read the HTTPOutcalls / ECDSAOutcalls entries of consumed_cycles_by_use_case, via a new helper that also backs the existing Schnorr / VetKd / dropped messages getters. - consumed_cycles_total and consumed_cycles_total_v28 add those entries instead of the scalar fields. The scalar fields are still observed and serialized, so that downgrading to an earlier replica version keeps observing the correct totals; only their reads are gone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
✅ No security or compliance issues detected. Reviewed everything up to 18dfede. Security Overview
Detected Code Changes
|
…ls-cycles-from-use-cases # Conflicts: # rs/replicated_state/src/metadata_state.rs # rs/replicated_state/src/metrics.rs
There was a problem hiding this comment.
🟡 Changes recommended
Existing canonical encoding and state-hash fixtures remain scalar-only and will fail after the totals switch to map entries.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Switches HTTP/ECDSA cycle reporting from legacy scalar fields to per-use-case metrics.
Changes:
- Adds a shared subnet use-case getter.
- Updates cycle totals and tests to use map entries.
File summaries
| File | Description |
|---|---|
rs/replicated_state/src/metadata_state.rs |
Reads outcall metrics from the use-case map. |
rs/replicated_state/src/metadata_state/tests.rs |
Updates migration and total assertions. |
Review details
Suppressed comments (1)
rs/replicated_state/src/metadata_state.rs:710
- The V28 compatibility fixture still records HTTP/ECDSA cycles only through the scalar observers (
canonical_state/src/encoding/tests/compatibility.rs:320-351). This branch now omits both values and encodes 100B rather than its expected 250B, so the compatibility test will fail. Populate or migrate the corresponding use-case entries in that fixture before encoding so the established V28 bytes remain unchanged.
CyclesUseCase::ECDSAOutcalls
| CyclesUseCase::HTTPOutcalls
| CyclesUseCase::Memory
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…elds The canonical-encoding and state-hash fixtures, as well as the restart test, populate only the legacy scalar outcall fields, which no longer contribute to any total now that the readers go through consumed_cycles_by_use_case. Fold them into the map first, the way the scheduler does once per round, keeping the scalar fields in place as they are in production. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The readers consistently use migrated map entries, and affected totals and compatibility fixtures are updated accordingly.
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Move the explanation of which `consumed_cycles_by_use_case` entries the scalar already accounts for from the match in `consumed_cycles_total` to the field's own doc comment, where it documents the field rather than one of its readers. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… map The scalar may be strictly larger than the sum of the `consumed_cycles_by_use_case` entries it accounts for, as deletions from before use-case tracking are recorded in it alone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Name the `CyclesUseCase` variant in each subnet-level getter's doc comment instead of pointing at `get_consumed_cycles_subnet_use_case`, and drop the explanations of where the HTTP / ECDSA outcall cycles used to be read from, which go stale once the legacy scalar fields are removed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The cycles consumed by HTTP and ECDSA outcalls are tracked both in the legacy scalar fields consumed_cycles_http_outcalls / consumed_cycles_ecdsa_outcalls of SubnetMetrics and in the consumed_cycles_by_use_case map, which a migration introduced in #10844 keeps in lockstep with those fields. #11219 fixed that migration to run once per round from the scheduler's
finish_round, i.e. regardless of subnet activity, so the map entries can no longer go stale on a subnet that performs no outcalls.I could now successfully confirm that the migration completed on all subnets with a DFINITY-owned node.
This switches all readers over to the map:
The scalar fields are still observed and serialized, so that downgrading to an earlier replica version keeps observing the correct totals; only their reads are gone.
The fixtures that populate only the scalar fields (
canonical_encoding_subnet_metrics, thestate_managertree hash fixture andconsumed_cycles_total_is_the_same_across_a_restart) now run the migration first, the way the scheduler does once per round. The expected canonical encodings and state hashes are unchanged.