Skip to content

Commit f66f0b6

Browse files
authored
refactor: drop AddCanisterChangeToHistory enum (#7860)
This PR drops the `AddCanisterChangeToHistory` enum by inlining the canister history update to `CanisterManager::uninstall_code`. The motivation for this change is to decouple `RoundLimits` update due to uninstalling code and due to updating canister history: those steps will be performed separately (in a follow-up PR) when taking a canister snapshot and uninstalling its code atomically (and thus setting `RoundLimits` to `None` would conveniently skip the `RoundLimits` update in the helper function `uninstall_canister`).
1 parent e5e0d13 commit f66f0b6

File tree

4 files changed

+17
-33
lines changed

4 files changed

+17
-33
lines changed

rs/execution_environment/src/canister_manager.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -966,16 +966,26 @@ impl CanisterManager {
966966
canister,
967967
Some(round_limits),
968968
time,
969-
AddCanisterChangeToHistory::Yes(origin),
970969
Arc::clone(&self.fd_factory),
971970
);
971+
972+
let available_execution_memory_change = canister.add_canister_change(
973+
time,
974+
origin,
975+
CanisterChangeDetails::CanisterCodeUninstall,
976+
);
977+
round_limits
978+
.subnet_available_memory
979+
.update_execution_memory_unchecked(available_execution_memory_change);
980+
972981
crate::util::process_responses(
973982
rejects,
974983
state,
975984
Arc::clone(&self.ingress_history_writer),
976985
self.log.clone(),
977986
canister_not_found_error,
978987
);
988+
979989
Ok(())
980990
}
981991

@@ -3109,9 +3119,8 @@ fn get_response_size(kind: &CanisterSnapshotDataKind) -> Result<u64, CanisterMan
31093119
pub fn uninstall_canister(
31103120
log: &ReplicaLogger,
31113121
canister: &mut CanisterState,
3112-
mut round_limits: Option<&mut RoundLimits>,
3122+
round_limits: Option<&mut RoundLimits>,
31133123
time: Time,
3114-
add_canister_change: AddCanisterChangeToHistory,
31153124
fd_factory: Arc<dyn PageAllocatorFileDescriptor>,
31163125
) -> Vec<Response> {
31173126
let old_allocated_bytes = canister.memory_allocated_bytes();
@@ -3136,7 +3145,7 @@ pub fn uninstall_canister(
31363145
let new_allocated_bytes = canister.memory_allocated_bytes();
31373146
debug_assert!(new_allocated_bytes <= old_allocated_bytes);
31383147

3139-
if let Some(round_limits) = round_limits.as_deref_mut() {
3148+
if let Some(round_limits) = round_limits {
31403149
let deallocated_bytes = old_allocated_bytes.saturating_sub(&new_allocated_bytes);
31413150
round_limits.subnet_available_memory.increment(
31423151
deallocated_bytes,
@@ -3145,22 +3154,6 @@ pub fn uninstall_canister(
31453154
);
31463155
}
31473156

3148-
match add_canister_change {
3149-
AddCanisterChangeToHistory::Yes(origin) => {
3150-
let available_execution_memory_change = canister.add_canister_change(
3151-
time,
3152-
origin,
3153-
CanisterChangeDetails::CanisterCodeUninstall,
3154-
);
3155-
if let Some(round_limits) = round_limits {
3156-
round_limits
3157-
.subnet_available_memory
3158-
.update_execution_memory_unchecked(available_execution_memory_change);
3159-
}
3160-
}
3161-
AddCanisterChangeToHistory::No => {}
3162-
};
3163-
31643157
let canister_id = canister.canister_id();
31653158

31663159
canister

rs/execution_environment/src/canister_manager/tests.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::{
22
IngressHistoryWriterImpl, RoundLimits, as_num_instructions,
33
canister_manager::{
4-
AddCanisterChangeToHistory, CanisterManager, CanisterManagerError, CanisterMgrConfig,
5-
DtsInstallCodeResult, InstallCodeContext, MAX_SLICE_SIZE_BYTES, StopCanisterResult,
6-
WasmSource, uninstall_canister,
4+
CanisterManager, CanisterManagerError, CanisterMgrConfig, DtsInstallCodeResult,
5+
InstallCodeContext, MAX_SLICE_SIZE_BYTES, StopCanisterResult, WasmSource,
6+
uninstall_canister,
77
},
88
canister_settings::CanisterSettings,
99
execution_environment::{CompilationCostHandling, RoundCounters, as_round_instructions},
@@ -2286,7 +2286,6 @@ fn uninstall_canister_doesnt_respond_to_responded_call_contexts() {
22862286
.build(),
22872287
None,
22882288
UNIX_EPOCH,
2289-
AddCanisterChangeToHistory::No,
22902289
Arc::new(TestPageAllocatorFileDescriptorImpl),
22912290
),
22922291
Vec::new()
@@ -2313,7 +2312,6 @@ fn uninstall_canister_responds_to_unresponded_call_contexts() {
23132312
.build(),
23142313
None,
23152314
UNIX_EPOCH,
2316-
AddCanisterChangeToHistory::No,
23172315
Arc::new(TestPageAllocatorFileDescriptorImpl),
23182316
)[0],
23192317
Response::Ingress(IngressResponse {

rs/execution_environment/src/canister_manager/types.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,6 @@ impl TryFrom<(CanisterChangeOrigin, InstallCodeArgsV2)> for InstallCodeContext {
316316
}
317317
}
318318

319-
/// Indicates whether `uninstall_canister` should push a canister change (with a given change origin) to canister history.
320-
pub enum AddCanisterChangeToHistory {
321-
Yes(CanisterChangeOrigin),
322-
No,
323-
}
324-
325319
pub(crate) struct UploadChunkResult {
326320
pub(crate) reply: UploadChunkReply,
327321
pub(crate) heap_delta_increase: NumBytes,

rs/execution_environment/src/scheduler.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
canister_manager::{types::AddCanisterChangeToHistory, uninstall_canister},
2+
canister_manager::uninstall_canister,
33
execution_environment::{
44
ExecuteCanisterResult, ExecutionEnvironment, RoundInstructions, RoundLimits,
55
as_num_instructions, as_round_instructions, execute_canister,
@@ -934,7 +934,6 @@ impl SchedulerImpl {
934934
canister,
935935
None, /* we're at the end of a round so no need to update round limits */
936936
state_time,
937-
AddCanisterChangeToHistory::No,
938937
Arc::clone(&self.fd_factory),
939938
));
940939
canister.scheduler_state.compute_allocation = ComputeAllocation::zero();

0 commit comments

Comments
 (0)