Skip to content

refactor: read HTTP/ECDSA outcall cycles from the per-use-case map - #11202

Merged
mraszyk merged 6 commits into
masterfrom
mraszyk/read-outcalls-cycles-from-use-cases
Sep 22, 2026
Merged

mraszyk merged 6 commits into
masterfrom
mraszyk/read-outcalls-cycles-from-use-cases

Conversation

@mraszyk

@mraszyk mraszyk commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

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:

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

The fixtures that populate only the scalar fields (canonical_encoding_subnet_metrics, the state_manager tree hash fixture and consumed_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.

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]>
@mraszyk
mraszyk marked this pull request as ready for review August 18, 2026 16:16
@mraszyk
mraszyk requested a review from a team as a code owner August 18, 2026 16:16
@zeropath-ai

zeropath-ai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

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

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/canonical_state/src/encoding/tests/compatibility.rs
    Fold outcall scalar fields into use-case totals via migrate_outcalls_cycles_to_use_cases()
Enhancement ► rs/replicated_state/src/metadata_state.rs
    Add documentation and new methods for subnet use-case consumption retrieval and migration notes; introduce get_consumed_cycles_subnet_use_case and related getters; adjust comments around migration and totals
Enhancement ► rs/replicated_state/src/metadata_state.rs
    Add migrate_outcalls_cycles_to_use_cases() behavior adjustments and related doc/comments
Enhancement ► rs/replicated_state/src/metadata_state.rs
    Update consumed_cycles_total calculations and related logic to account for migrated use cases; adjust total aggregation logic and matching comments
Enhancement ► rs/replicated_state/src/metadata_state/tests.rs
    Update tests to reflect migration of outcall scalars into use-case entries and updated total calculations; adjust expected totals and comments
Enhancement ► rs/replicated_state/tests/replicated_state.rs
    Call migrate_outcalls_cycles_to_use_cases() in test to align with new aggregation behavior
Enhancement ► rs/state_manager/src/tree_hash.rs
    Call migrate_outcalls_cycles_to_use_cases() during test setup to align with new aggregation behavior

@mraszyk
mraszyk marked this pull request as draft August 19, 2026 15:04
…ls-cycles-from-use-cases

# Conflicts:
#	rs/replicated_state/src/metadata_state.rs
#	rs/replicated_state/src/metrics.rs

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.

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

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.

🟢 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

@mraszyk
mraszyk marked this pull request as ready for review September 11, 2026 12:02
mraszyk and others added 3 commits September 22, 2026 10:33
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]>
@mraszyk
mraszyk added this pull request to the merge queue Sep 22, 2026
Merged via the queue into master with commit 0e30071 Sep 22, 2026
38 checks passed
@mraszyk
mraszyk deleted the mraszyk/read-outcalls-cycles-from-use-cases branch September 22, 2026 12:44
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