Skip to content

feat: Store prepayment for call transmission#9859

Merged
schneiderstefan merged 5 commits intodfinity:masterfrom
dsarlis:dimitris/store-prepayment-call-transmission
Apr 17, 2026
Merged

feat: Store prepayment for call transmission#9859
schneiderstefan merged 5 commits intodfinity:masterfrom
dsarlis:dimitris/store-prepayment-call-transmission

Conversation

@dsarlis
Copy link
Copy Markdown
Contributor

@dsarlis dsarlis commented Apr 14, 2026

Store the prepayment for call transmission so that it can be used to properly calculate the consumed amount for an inter-canister call when updating the metrics during the refund phase.

Problem

In the current state of the code, only the prepayment for response transmission is stored so that the refund can be calculated when the actual response is received. This is enough for now when wanting to credit the refund back to the canister's balance or updating the current metrics which act like gauges. However, if we want to have new metrics that will act as counters (which will happen in a follow-up) we cannot rely only on that amount for the consumed part as we would miss the parts that are not refunded -- specifically the base fee and request transmission parts.

Solution

The proposed solution here is to additionally store the total call transmission fee so that it can be passed into the function that refunds cycles to the canister -- the refund part to the balance remains the same but based on prepayment and refund one can calculate the amount to update the metrics with only at refund step.

The changes include the following parts:

  1. Storing the new field in the callback in a checkpoint and updating any code needed because of that.
  2. Some logic to handle the case that this field could be empty for callbacks that are outstanding. Since no updates are happening to metrics yet, we can hope that by the time after this code is deployed and the update to metrics will be, there won't be empty values there.
  3. A small refactoring in CyclesAccountManager that felt reasonable given that we have the total transmission fee computed and we don't need to recompute stuff.

@dsarlis dsarlis force-pushed the dimitris/store-prepayment-call-transmission branch from 338adb5 to dd37c1d Compare April 14, 2026 12:43
@dsarlis dsarlis marked this pull request as ready for review April 14, 2026 12:43
@dsarlis dsarlis requested review from a team as code owners April 14, 2026 12:43
@basvandijk basvandijk added the security-review-passed IDX or InfraSec have concluded it's safe to run CI on the external PR. label Apr 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

@dsarlis
Copy link
Copy Markdown
Contributor Author

dsarlis commented Apr 14, 2026

Run on dd37c1d URL: https://github.com/dfinity/ic/actions/runs/24399827516

I see some test failures that I missed, I'll push a fix in a bit.

Comment thread rs/embedders/tests/sandbox_safe_system_state.rs Outdated
Comment thread rs/embedders/tests/sandbox_safe_system_state.rs
Comment thread rs/embedders/tests/sandbox_safe_system_state.rs
@dsarlis
Copy link
Copy Markdown
Contributor Author

dsarlis commented Apr 14, 2026

Run on dd37c1d URL: https://github.com/dfinity/ic/actions/runs/24399827516

I see some test failures that I missed, I'll push a fix in a bit.

Pushed a fix.

@github-actions
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends callback bookkeeping to persist the total call transmission prepayment (request + response transmission) so refund-time accounting can compute “consumed” transmission cycles (including non-refunded portions like base fee + request bytes), enabling future counter-style metrics.

Changes:

  • Add prepayment_for_call_transmission to Callback + protobuf, with backward-compatible decoding default.
  • Thread the new prepayment through request charging and response refund paths (including sandbox-safe system state).
  • Minor refactor: compute/consume call transmission fees via xnet_total_transmission_fee and add CompoundCycles::is_zero().

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
rs/types/types/src/methods.rs Adds new callback field + protobuf (de)serialization for call transmission prepayment.
rs/types/cycles/src/compound_cycles.rs Adds CompoundCycles::is_zero() helper used for backward-compat handling.
rs/test_utilities/state/src/lib.rs Updates callback construction in test utilities to include new field.
rs/state_layout/src/state_layout/tests.rs Updates encode/decode tests to include new callback field (compat coverage).
rs/replicated_state/src/canister_state/tests.rs Updates callback round-trip tests for the new field.
rs/replicated_state/src/canister_state/system_state/call_context_manager/tests.rs Updates CCM tests for new callback constructor parameter.
rs/replicated_state/src/canister_state/system_state.rs Updates internal test helpers to include new callback field.
rs/protobuf/src/gen/state/state.canister_state_bits.v1.rs Regenerated prost output adding the new callback field + comment tweaks.
rs/protobuf/def/state/canister_state_bits/v1/canister_state_bits.proto Adds protobuf field prepayment_for_call_transmission (tag 13).
rs/execution_environment/src/scheduler/test_utilities.rs Updates scheduler test utilities to populate new callback field.
rs/execution_environment/src/execution/response.rs Uses call-transmission prepayment during refund to enable correct “consumed” computation.
rs/execution_environment/benches/lib/src/common.rs Updates benchmark setup callback initialization for new field.
rs/embedders/tests/system_api.rs Updates embedders system API tests to include new callback field.
rs/embedders/tests/sandbox_safe_system_state.rs Refactors tests to use total transmission fee and updated refund semantics.
rs/embedders/src/wasmtime_embedder/system_api/sandbox_safe_system_state.rs Updates request charging to accept call-transmission prepayment and records it as consumed.
rs/embedders/src/wasmtime_embedder/system_api/request_in_prep.rs Computes/stores call-transmission prepayment when building outgoing requests/callbacks.
rs/embedders/src/wasmtime_embedder/system_api.rs Threads new prepayment through push_output_request plumbing.
rs/cycles_account_manager/src/cycles_account_manager.rs Refactors withdraw_request_cycles to take total call-transmission prepayment and simplifies fee calculation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rs/types/types/src/methods.rs
Comment thread rs/types/types/src/methods.rs Outdated
Comment thread rs/embedders/tests/sandbox_safe_system_state.rs Outdated
Comment thread rs/types/types/src/methods.rs Outdated
Comment thread rs/execution_environment/src/execution/response.rs
Comment thread rs/execution_environment/src/scheduler/test_utilities.rs Outdated
Comment thread rs/embedders/tests/sandbox_safe_system_state.rs Outdated
Comment thread rs/embedders/tests/sandbox_safe_system_state.rs
Comment thread rs/embedders/tests/sandbox_safe_system_state.rs
Comment thread rs/embedders/tests/sandbox_safe_system_state.rs Outdated
Comment thread rs/types/types/src/methods.rs
@dsarlis dsarlis requested a review from mraszyk April 16, 2026 15:11
mraszyk
mraszyk previously approved these changes Apr 16, 2026
@github-actions github-actions bot dismissed mraszyk’s stale review April 16, 2026 16:51

Review dismissed by automation script.

@dsarlis dsarlis requested a review from mraszyk April 16, 2026 16:51
@github-actions
Copy link
Copy Markdown
Contributor

@schneiderstefan schneiderstefan added this pull request to the merge queue Apr 17, 2026
Merged via the queue into dfinity:master with commit c297176 Apr 17, 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 feat @ic-interface-owners security-review-passed IDX or InfraSec have concluded it's safe to run CI on the external PR. @team-dsm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants