Skip to content

Commit 5993fe2

Browse files
authored
refactor: Rename SystemStateChanges to SystemStateModifications for consistency (dfinity#3555)
All the other structs that maintain modifications of different parts of the canister state use `*Modifications` in their name, so change `SystemStateChanges` to use it as well for consistency.
1 parent 6d3c488 commit 5993fe2

File tree

16 files changed

+120
-110
lines changed

16 files changed

+120
-110
lines changed

rs/canister_sandbox/src/protocol/ctlsvc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ mod tests {
6767
InstanceStats, SystemApiCallCounters, WasmExecutionOutput,
6868
};
6969
use ic_replicated_state::{Global, NumWasmPages, PageMap};
70-
use ic_system_api::sandbox_safe_system_state::SystemStateChanges;
70+
use ic_system_api::sandbox_safe_system_state::SystemStateModifications;
7171
use ic_types::{ingress::WasmResult, CanisterLog, NumBytes, NumInstructions};
7272

7373
use crate::protocol::{
@@ -125,7 +125,7 @@ mod tests {
125125
size: NumWasmPages::new(42),
126126
},
127127
}),
128-
system_state_changes: SystemStateChanges::default(),
128+
system_state_modifications: SystemStateModifications::default(),
129129
},
130130
execute_total_duration: Duration::from_secs(10),
131131
execute_run_duration: Duration::from_secs(1),

rs/canister_sandbox/src/protocol/structs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ic_replicated_state::{
44
page_map::PageDeltaSerialization, Global, Memory, NumWasmPages, PageIndex,
55
};
66
use ic_system_api::{
7-
sandbox_safe_system_state::{SandboxSafeSystemState, SystemStateChanges},
7+
sandbox_safe_system_state::{SandboxSafeSystemState, SystemStateModifications},
88
ApiType, ExecutionParameters,
99
};
1010
use ic_types::{methods::FuncRef, NumBytes};
@@ -67,7 +67,7 @@ pub struct StateModifications {
6767
/// The system state changes contain parts that are always applied
6868
/// and parts that are only applied depending on the method executed
6969
/// (similarly to `execution_state_modifications`).
70-
pub system_state_changes: SystemStateChanges,
70+
pub system_state_modifications: SystemStateModifications,
7171
}
7272

7373
#[derive(Serialize, Debug, Deserialize, Clone, PartialEq)]

rs/canister_sandbox/src/replica_controller/sandboxed_execution_controller.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,13 +1587,13 @@ impl SandboxedExecutionController {
15871587

15881588
let StateModifications {
15891589
execution_state_modifications,
1590-
system_state_changes,
1590+
system_state_modifications,
15911591
} = exec_output.take_state_modifications();
15921592

15931593
match execution_state_modifications {
15941594
None => CanisterStateChanges {
15951595
execution_state_changes: None,
1596-
system_state_changes,
1596+
system_state_modifications,
15971597
},
15981598
Some(execution_state_modifications) => {
15991599
// TODO: If a canister has broken out of wasm then it might have allocated more
@@ -1647,7 +1647,7 @@ impl SandboxedExecutionController {
16471647
wasm_memory,
16481648
stable_memory,
16491649
}),
1650-
system_state_changes,
1650+
system_state_modifications,
16511651
}
16521652
}
16531653
}

rs/canister_sandbox/src/sandbox_manager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl Execution {
160160
match wasm_result {
161161
Ok(_) => {
162162
let state_modifications = {
163-
let system_state_changes = match instance_or_system_api {
163+
let system_state_modifications = match instance_or_system_api {
164164
// Here we use `store_data_mut` instead of
165165
// `into_store_data` because the later will drop the
166166
// wasmtime Instance which can be an expensive
@@ -172,8 +172,8 @@ impl Execution {
172172
.store_data_mut()
173173
.system_api_mut()
174174
.expect("System api not present in the wasmtime instance")
175-
.take_system_state_changes(),
176-
Err(system_api) => system_api.into_system_state_changes(),
175+
.take_system_state_modifications(),
176+
Err(system_api) => system_api.into_system_state_modifications(),
177177
};
178178

179179
let execution_state_modifications = deltas.map(
@@ -193,7 +193,7 @@ impl Execution {
193193

194194
StateModifications {
195195
execution_state_modifications,
196-
system_state_changes,
196+
system_state_modifications,
197197
}
198198
};
199199
if state_modifications.execution_state_modifications.is_some() {

rs/embedders/src/wasm_executor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::Arc;
55
use ic_replicated_state::canister_state::execution_state::WasmBinary;
66
use ic_replicated_state::page_map::PageAllocatorFileDescriptor;
77
use ic_replicated_state::{ExportedFunctions, Global, Memory, NumWasmPages, PageMap};
8-
use ic_system_api::sandbox_safe_system_state::{SandboxSafeSystemState, SystemStateChanges};
8+
use ic_system_api::sandbox_safe_system_state::{SandboxSafeSystemState, SystemStateModifications};
99
use ic_system_api::{ApiType, DefaultOutOfInstructionsHandler};
1010
use ic_types::methods::{FuncRef, WasmMethod};
1111
use ic_types::NumOsPages;
@@ -146,7 +146,7 @@ pub struct ExecutionStateChanges {
146146
pub struct CanisterStateChanges {
147147
pub execution_state_changes: Option<ExecutionStateChanges>,
148148

149-
pub system_state_changes: SystemStateChanges,
149+
pub system_state_modifications: SystemStateModifications,
150150
}
151151

152152
/// The result of WebAssembly execution with deterministic time slicing.
@@ -260,7 +260,7 @@ impl WasmExecutor for WasmExecutorImpl {
260260
Ok(instance) => instance.into_store_data().system_api.unwrap(),
261261
Err(system_api) => system_api,
262262
};
263-
let system_state_changes = system_api.into_system_state_changes();
263+
let system_state_modifications = system_api.into_system_state_modifications();
264264

265265
(
266266
compilation_result,
@@ -269,7 +269,7 @@ impl WasmExecutor for WasmExecutorImpl {
269269
wasm_execution_output,
270270
CanisterStateChanges {
271271
execution_state_changes,
272-
system_state_changes,
272+
system_state_modifications,
273273
},
274274
),
275275
)
@@ -497,7 +497,7 @@ pub fn wasm_execution_error(
497497
},
498498
CanisterStateChanges {
499499
execution_state_changes: None,
500-
system_state_changes: SystemStateChanges::default(),
500+
system_state_modifications: SystemStateModifications::default(),
501501
},
502502
)
503503
}

rs/embedders/tests/wasmtime_embedder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,14 +3118,14 @@ fn wasm64_saturate_fun_index() {
31183118
.build();
31193119
let _res = instance.run(FuncRef::Method(WasmMethod::Update("test".to_string())));
31203120

3121-
let system_state_changes = instance
3121+
let system_state_modifications = instance
31223122
.store_data_mut()
31233123
.system_api_mut()
31243124
.unwrap()
3125-
.take_system_state_changes();
3125+
.take_system_state_modifications();
31263126

31273127
// call_perform should trigger one callback update
3128-
let callback_update = system_state_changes
3128+
let callback_update = system_state_modifications
31293129
.callback_updates
31303130
.first()
31313131
.unwrap()

rs/execution_environment/src/execution/common.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use ic_replicated_state::{
1818
CallContext, CallContextAction, CallOrigin, CanisterState, ExecutionState, NetworkTopology,
1919
SystemState,
2020
};
21-
use ic_system_api::sandbox_safe_system_state::{RequestMetadataStats, SystemStateChanges};
21+
use ic_system_api::sandbox_safe_system_state::{RequestMetadataStats, SystemStateModifications};
2222
use ic_types::ingress::{IngressState, IngressStatus, WasmResult};
2323
use ic_types::messages::{
2424
CallContextId, CallbackId, CanisterCall, CanisterCallOrTask, MessageId, Payload, RejectContext,
@@ -410,7 +410,7 @@ pub fn update_round_limits(round_limits: &mut RoundLimits, slice: &SliceExecutio
410410
/// subnet available memory. In case of an error, the partially applied changes
411411
/// are not undone.
412412
fn try_apply_canister_state_changes(
413-
system_state_changes: SystemStateChanges,
413+
system_state_modifications: SystemStateModifications,
414414
output: &WasmExecutionOutput,
415415
system_state: &mut SystemState,
416416
subnet_available_memory: &mut SubnetAvailableMemory,
@@ -427,7 +427,7 @@ fn try_apply_canister_state_changes(
427427
)
428428
.map_err(|_| HypervisorError::OutOfMemory)?;
429429

430-
system_state_changes.apply_changes(time, system_state, network_topology, subnet_id, log)
430+
system_state_modifications.apply_changes(time, system_state, network_topology, subnet_id, log)
431431
}
432432

433433
/// Applies canister state change after Wasm execution if possible.
@@ -457,17 +457,17 @@ pub fn apply_canister_state_changes(
457457
) {
458458
let CanisterStateChanges {
459459
execution_state_changes,
460-
system_state_changes,
460+
system_state_modifications,
461461
} = canister_state_changes;
462462

463463
let clean_system_state = system_state.clone();
464464
let clean_subnet_available_memory = round_limits.subnet_available_memory;
465-
let callbacks_created = system_state_changes.callbacks_created();
465+
let callbacks_created = system_state_modifications.callbacks_created();
466466
if output.wasm_result.is_ok() {
467467
// Everything that is passed via a mutable reference in this function
468468
// should be cloned and restored in case of an error.
469469
match try_apply_canister_state_changes(
470-
system_state_changes,
470+
system_state_modifications,
471471
output,
472472
system_state,
473473
&mut round_limits.subnet_available_memory,

rs/execution_environment/src/execution/install_code.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,10 @@ impl InstallCodeHelper {
743743

744744
let CanisterStateChanges {
745745
execution_state_changes,
746-
system_state_changes,
746+
system_state_modifications,
747747
} = canister_state_changes;
748748

749-
if let Err(err) = system_state_changes.apply_changes(
749+
if let Err(err) = system_state_modifications.apply_changes(
750750
original.time,
751751
&mut self.canister.system_state,
752752
round.network_topology,

rs/execution_environment/src/execution/response.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ impl ResponseHelper {
374374
// Check that the cycles balance does not go below zero after applying
375375
// the Wasm execution state changes.
376376
let old_balance = self.canister.system_state.balance();
377-
let requested = canister_state_changes.system_state_changes.removed_cycles();
377+
let requested = canister_state_changes
378+
.system_state_modifications
379+
.removed_cycles();
378380
// Note that we ignore the freezing threshold as required by the spec.
379381
if old_balance < requested {
380382
let reveal_top_up = self
@@ -462,7 +464,9 @@ impl ResponseHelper {
462464
// like releasing locks or undoing other state changes.
463465
let ingress_induction_cycles_debit =
464466
self.canister.system_state.ingress_induction_cycles_debit();
465-
let removed_cycles = canister_state_changes.system_state_changes.removed_cycles();
467+
let removed_cycles = canister_state_changes
468+
.system_state_modifications
469+
.removed_cycles();
466470
if self.canister.system_state.balance() < ingress_induction_cycles_debit + removed_cycles {
467471
self.canister
468472
.system_state

rs/execution_environment/src/execution/update.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,9 @@ impl UpdateHelper {
448448
// Check that the cycles balance does not go below the freezing
449449
// threshold after applying the Wasm execution state changes.
450450
let old_balance = self.canister.system_state.balance();
451-
let requested = canister_state_changes.system_state_changes.removed_cycles();
451+
let requested = canister_state_changes
452+
.system_state_modifications
453+
.removed_cycles();
452454
let reveal_top_up = self
453455
.canister
454456
.controllers()

0 commit comments

Comments
 (0)