Skip to content

fix: check the cycles balance and charge executed instructions on DTS resume - #11039

Draft
mraszyk wants to merge 1 commit into
masterfrom
mraszyk/dts-resume-cycles-accounting
Draft

fix: check the cycles balance and charge executed instructions on DTS resume#11039
mraszyk wants to merge 1 commit into
masterfrom
mraszyk/dts-resume-cycles-accounting

Conversation

@mraszyk

@mraszyk mraszyk commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

InstallCodeHelper records the cycles balance of the clean canister state it was built from and compares it when resuming a paused install_code execution, analogously to ResponseHelper and CallOrTaskHelper.

Moreover, if resuming a paused execution fails, then the instructions already executed by the paused Wasm execution are charged now: those instructions consumed round instructions, but the instruction limits are only updated when the Wasm execution finishes and hence such instructions used to be free. For install_code, only the instructions of the steps preceding the paused Wasm execution (e.g., compilation) used to be charged; for update calls, replicated queries, canister tasks, and response callbacks, no instructions used to be charged at all; for cleanup callbacks, the instructions of the preceding response callback used to be charged, but not those of the cleanup callback itself.

Finally, dts_replicated_execution_resume_fails_due_to_cycles_change moves to the general execution tests as dts_resume_fails_due_to_cycles_decrease, decreases the cycles balance using remove_cycles, and covers response and cleanup callbacks and the heartbeat in addition to update calls and replicated queries; the new test dts_install_code_resume_fails_due_to_cycles_decrease covers install_code. The tests assert that the instructions reported by the failed execution match the round instructions consumed by its slices and that the canister is charged exactly the cost of those instructions, for which ExecutionTest tracks the round instructions consumed per canister.

… resume

`InstallCodeHelper` records the cycles balance of the clean canister state it
was built from and compares it when resuming a paused `install_code` execution,
analogously to `ResponseHelper` and `CallOrTaskHelper`.

Moreover, if resuming a paused execution fails, then the instructions already
executed by the paused Wasm execution are charged now: those instructions
consumed round instructions, but the instruction limits are only updated when
the Wasm execution finishes and hence such instructions used to be free.
For `install_code`, only the instructions of the steps preceding the paused Wasm
execution (e.g., compilation) used to be charged; for update calls, replicated
queries, canister tasks, and response callbacks, no instructions used to be
charged at all; for cleanup callbacks, the instructions of the preceding
response callback used to be charged, but not those of the cleanup callback
itself.

Finally, `dts_replicated_execution_resume_fails_due_to_cycles_change` moves to
the general execution tests as `dts_resume_fails_due_to_cycles_decrease`,
decreases the cycles balance using `remove_cycles`, and covers response and
cleanup callbacks and the heartbeat in addition to update calls and replicated
queries; the new test `dts_install_code_resume_fails_due_to_cycles_decrease`
covers `install_code`. The tests assert that the instructions reported by the
failed execution match the round instructions consumed by its slices and that
the canister is charged exactly the cost of those instructions, for which
`ExecutionTest` tracks the round instructions consumed per canister.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the fix label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant