feat: Store prepayment for call transmission#9859
feat: Store prepayment for call transmission#9859schneiderstefan merged 5 commits intodfinity:masterfrom
Conversation
338adb5 to
dd37c1d
Compare
I see some test failures that I missed, I'll push a fix in a bit. |
Pushed a fix. |
There was a problem hiding this comment.
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_transmissiontoCallback+ 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_feeand addCompoundCycles::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.
Review dismissed by automation script.
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:
CyclesAccountManagerthat felt reasonable given that we have the total transmission fee computed and we don't need to recompute stuff.