fix: Cap ingress induction debit for cleanup callback #1777
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes an edge case where in a cleanup callback that has produced some cycles balance change and when there's an accumulated ingress induction debit (due to ingress messages inducted while the cleanup callback was running DTS), the canister's balance might end up with an amount that wouldn't respect the canister's freezing threshold.
Typically, for other message executions, the DTS execution would fail if there were concurrent cycles changes that could not be applied. The cleanup callback is a bit different and failing it is not a good option; canisters depend on it running successfully to perform critical tasks (such as releasing locks or reverting state changes in case something goes wrong). Therefore, we should ensure that the cleanup callback can still complete successfully.
The solution (which the PR implements) is to cap the ingress induction debit by the amount removed from the cycles balance during execution. This way we can ensure completion of the cleanup callback at the expense of some cycles debit that is applied partially in some cases.