Skip to content

Commit 97ad916

Browse files
authored
chore: new fields for uninstalling code while taking canister snapshot (#7855)
This PR adds two extra fields to the input type of the `take_canister_snapshot` method of the management canister: - `uninstall_code`: allows to atomically uninstall the canister after taking its snapshot; in particular, the canister memory usage is updated atomically and thus it does not grow significantly (ignoring some potential constant overhead for certified variables which are not accounted for by canister memory usage, but are accounted for in canister snapshot memory usage), - `sender_canister_version`: needed to record the sender canister version in the code uninstallation entry in canister history. Warning! The actual functionality will only be implemented in follow-up PRs.
1 parent f66f0b6 commit 97ad916

File tree

13 files changed

+205
-82
lines changed

13 files changed

+205
-82
lines changed

rs/execution_environment/benches/management_canister/canister_snapshots.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn env_and_canister(canister_size: u64) -> (StateMachine, CanisterId) {
4848
fn env_and_canister_snapshot(canister_size: u64) -> (StateMachine, CanisterId, SnapshotId) {
4949
let (env, canister_id) = env_and_canister(canister_size);
5050
let snapshot_id = env
51-
.take_canister_snapshot(TakeCanisterSnapshotArgs::new(canister_id, None))
51+
.take_canister_snapshot(TakeCanisterSnapshotArgs::new(canister_id, None, None, None))
5252
.expect("Error taking canister snapshot")
5353
.snapshot_id();
5454
(env, canister_id, snapshot_id)
@@ -124,8 +124,13 @@ fn take_canister_snapshot_bench<M: criterion::measurement::Measurement>(
124124
b.iter_batched(
125125
|| env_and_canister(canister_size),
126126
|(env, canister_id)| {
127-
env.take_canister_snapshot(TakeCanisterSnapshotArgs::new(canister_id, None))
128-
.expect("Error taking canister snapshot");
127+
env.take_canister_snapshot(TakeCanisterSnapshotArgs::new(
128+
canister_id,
129+
None,
130+
None,
131+
None,
132+
))
133+
.expect("Error taking canister snapshot");
129134
env
130135
},
131136
BatchSize::SmallInput,
@@ -135,8 +140,13 @@ fn take_canister_snapshot_bench<M: criterion::measurement::Measurement>(
135140
b.iter_batched(
136141
|| env_and_canister(canister_size),
137142
|(env, canister_id)| {
138-
env.take_canister_snapshot(TakeCanisterSnapshotArgs::new(canister_id, None))
139-
.expect("Error taking canister snapshot");
143+
env.take_canister_snapshot(TakeCanisterSnapshotArgs::new(
144+
canister_id,
145+
None,
146+
None,
147+
None,
148+
))
149+
.expect("Error taking canister snapshot");
140150
env.checkpointed_tick();
141151
env
142152
},
@@ -157,6 +167,8 @@ fn replace_canister_snapshot_bench<M: criterion::measurement::Measurement>(
157167
env.take_canister_snapshot(TakeCanisterSnapshotArgs::new(
158168
canister_id,
159169
Some(snapshot_id),
170+
None,
171+
None,
160172
))
161173
.expect("Error replacing canister snapshot");
162174
env
@@ -171,6 +183,8 @@ fn replace_canister_snapshot_bench<M: criterion::measurement::Measurement>(
171183
env.take_canister_snapshot(TakeCanisterSnapshotArgs::new(
172184
canister_id,
173185
Some(snapshot_id),
186+
None,
187+
None,
174188
))
175189
.expect("Error replacing canister snapshot");
176190
env.checkpointed_tick();

rs/execution_environment/src/canister_manager/tests.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ fn delete_canister_updates_subnet_available_memory_for_memory_allocation(memory_
19091909
.unwrap();
19101910

19111911
// Take canister snapshot => ~1 GiB of snapshot memory.
1912-
let take_canister_snapshot_args = TakeCanisterSnapshotArgs::new(canister_id, None);
1912+
let take_canister_snapshot_args = TakeCanisterSnapshotArgs::new(canister_id, None, None, None);
19131913
test.subnet_message(
19141914
Method::TakeCanisterSnapshot,
19151915
take_canister_snapshot_args.encode(),
@@ -6724,6 +6724,8 @@ fn cannot_rename_with_snapshots() {
67246724
env2.take_canister_snapshot(TakeCanisterSnapshotArgs {
67256725
canister_id: canister_id2.into(),
67266726
replace_snapshot: None,
6727+
uninstall_code: None,
6728+
sender_canister_version: None,
67276729
})
67286730
.unwrap();
67296731

rs/execution_environment/src/execution_environment/tests.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,8 @@ fn get_canister_status_memory_metrics_snapshots_size() {
10491049
TakeCanisterSnapshotArgs {
10501050
canister_id: canister_id.into(),
10511051
replace_snapshot: None,
1052+
uninstall_code: None,
1053+
sender_canister_version: None,
10521054
}
10531055
.encode(),
10541056
)
@@ -1699,15 +1701,17 @@ fn canister_snapshots_after_split() {
16991701
);
17001702

17011703
// Take canister snapshot for each canister.
1702-
let args: TakeCanisterSnapshotArgs = TakeCanisterSnapshotArgs::new(canister_id_1, None);
1704+
let args: TakeCanisterSnapshotArgs =
1705+
TakeCanisterSnapshotArgs::new(canister_id_1, None, None, None);
17031706
test.inject_call_to_ic00(
17041707
Method::TakeCanisterSnapshot,
17051708
Encode!(&args).unwrap(),
17061709
Cycles::new(1_000_000_000),
17071710
);
17081711
test.execute_subnet_message();
17091712

1710-
let args: TakeCanisterSnapshotArgs = TakeCanisterSnapshotArgs::new(canister_id_2, None);
1713+
let args: TakeCanisterSnapshotArgs =
1714+
TakeCanisterSnapshotArgs::new(canister_id_2, None, None, None);
17111715
test.inject_call_to_ic00(
17121716
Method::TakeCanisterSnapshot,
17131717
Encode!(&args).unwrap(),

0 commit comments

Comments
 (0)