refactor: Consolidate how system state modifications are extracted from the System API #3706
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.
Currently, there are two similar functions in the
SystemApiImpl
to extract system state modifications. One of themtake_system_state_modifications
is used in the sandbox when preparing the state changes to be transmitted back to the replica. Then, the replica after deserializing the result that it receives from the sandbox callsinto_system_state_changes
on the reconstructedsystem_api
to extract the changes again.In a recent PR,
into_system_state_modifications
was changed (to make it more clear which changes are relevant per message type) buttake_system_state_modifications
wasn't. This works correctly becauseinto_system_state_modifications
is the last one that's called before applying the state changes back to the canister state. However, it's also a very clear example of how the code can easily diverge and go unnoticed, potentially with more severe implications in the future.This PR proposes to use one function which seems to provide the usual benefits of consistent way of applying the changes and "having one way" of doing the same task. We keep
take_system_state_modifications
(this allows us to get rid of someclone
s but more importantly it's needed in the sandbox, see comment in the existing code) and change the call sites respectively.