Skip to content

Commit c237e6d

Browse files
feat: EXC-1422: Canister install mode v2 with skip pre-upgrade flag This MR is the first step that follows dfinity/interface-spec#135. Closes EXC-1422. Closes EXC-1422 See merge request dfinity-lab/public/ic!13842
2 parents f588aea + 6c22f40 commit c237e6d

File tree

11 files changed

+456
-61
lines changed

11 files changed

+456
-61
lines changed

rs/execution_environment/src/canister_manager.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use ic_config::flag_status::FlagStatus;
1313
use ic_cycles_account_manager::CyclesAccountManager;
1414
use ic_error_types::{ErrorCode, RejectCode, UserError};
1515
use ic_ic00_types::{
16-
CanisterChangeDetails, CanisterChangeOrigin, CanisterInstallMode, CanisterStatusResultV2,
17-
CanisterStatusType, InstallCodeArgs, Method as Ic00Method,
16+
CanisterChangeDetails, CanisterChangeOrigin, CanisterInstallModeV2, CanisterStatusResultV2,
17+
CanisterStatusType, InstallCodeArgsV2, Method as Ic00Method,
1818
};
1919
use ic_interfaces::execution_environment::{
2020
CanisterOutOfCyclesError, HypervisorError, IngressHistoryWriter, SubnetAvailableMemory,
@@ -134,7 +134,7 @@ impl CanisterMgrConfig {
134134
#[derive(Clone, Debug)]
135135
pub struct InstallCodeContext {
136136
pub origin: CanisterChangeOrigin,
137-
pub mode: CanisterInstallMode,
137+
pub mode: CanisterInstallModeV2,
138138
pub canister_id: CanisterId,
139139
pub wasm_module: CanisterModule,
140140
pub arg: Vec<u8>,
@@ -149,7 +149,7 @@ impl InstallCodeContext {
149149
}
150150
}
151151

152-
/// Errors that can occur when converting from (sender, [`InstallCodeArgs`]) to
152+
/// Errors that can occur when converting from (sender, [`InstallCodeArgsV2`]) to
153153
/// an [`InstallCodeContext`].
154154
#[derive(Debug)]
155155
pub enum InstallCodeContextError {
@@ -214,10 +214,10 @@ impl From<InvalidMemoryAllocationError> for InstallCodeContextError {
214214
}
215215
}
216216

217-
impl TryFrom<(CanisterChangeOrigin, InstallCodeArgs)> for InstallCodeContext {
217+
impl TryFrom<(CanisterChangeOrigin, InstallCodeArgsV2)> for InstallCodeContext {
218218
type Error = InstallCodeContextError;
219219

220-
fn try_from(input: (CanisterChangeOrigin, InstallCodeArgs)) -> Result<Self, Self::Error> {
220+
fn try_from(input: (CanisterChangeOrigin, InstallCodeArgsV2)) -> Result<Self, Self::Error> {
221221
let (origin, args) = input;
222222
let canister_id = CanisterId::new(args.canister_id).map_err(|err| {
223223
InstallCodeContextError::InvalidCanisterId(format!(
@@ -775,10 +775,11 @@ impl CanisterManager {
775775
};
776776

777777
match context.mode {
778-
CanisterInstallMode::Install | CanisterInstallMode::Reinstall => {
778+
CanisterInstallModeV2::Install | CanisterInstallModeV2::Reinstall => {
779779
execute_install(context, canister, original, round.clone(), round_limits)
780780
}
781-
CanisterInstallMode::Upgrade => {
781+
// SkipPreUpgrade field will be used in the follow up.
782+
CanisterInstallModeV2::Upgrade(..) => {
782783
execute_upgrade(context, canister, original, round.clone(), round_limits)
783784
}
784785
}

rs/execution_environment/src/canister_manager/tests.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use ic_cycles_account_manager::{CyclesAccountManager, ResourceSaturation};
2121
use ic_error_types::{ErrorCode, UserError};
2222
use ic_ic00_types::{
2323
CanisterChange, CanisterChangeDetails, CanisterChangeOrigin, CanisterIdRecord,
24-
CanisterInstallMode, CanisterSettingsArgsBuilder, CanisterStatusType, CreateCanisterArgs,
25-
EmptyBlob, InstallCodeArgs, Method, Payload, UpdateSettingsArgs,
24+
CanisterInstallMode, CanisterInstallModeV2, CanisterSettingsArgsBuilder, CanisterStatusType,
25+
CreateCanisterArgs, EmptyBlob, InstallCodeArgsV2, Method, Payload, UpdateSettingsArgs,
2626
};
2727
use ic_interfaces::execution_environment::{
2828
ExecutionComplexity, ExecutionMode, HypervisorError, SubnetAvailableMemory,
@@ -167,7 +167,7 @@ impl InstallCodeContextBuilder {
167167
self
168168
}
169169

170-
pub fn mode(mut self, mode: CanisterInstallMode) -> Self {
170+
pub fn mode(mut self, mode: CanisterInstallModeV2) -> Self {
171171
self.ctx.mode = mode;
172172
self
173173
}
@@ -187,7 +187,7 @@ impl Default for InstallCodeContextBuilder {
187187
arg: vec![],
188188
compute_allocation: None,
189189
memory_allocation: None,
190-
mode: CanisterInstallMode::Install,
190+
mode: CanisterInstallModeV2::Install,
191191
query_allocation: QueryAllocation::default(),
192192
},
193193
}
@@ -316,7 +316,7 @@ fn install_code(
316316
..EXECUTION_PARAMETERS.clone()
317317
};
318318

319-
let args = InstallCodeArgs::new(
319+
let args = InstallCodeArgsV2::new(
320320
context.mode,
321321
context.canister_id,
322322
context.wasm_module.as_slice().into(),
@@ -487,7 +487,7 @@ fn upgrade_non_existing_canister_fails() {
487487
install_code(
488488
&canister_manager,
489489
InstallCodeContextBuilder::default()
490-
.mode(CanisterInstallMode::Upgrade)
490+
.mode(CanisterInstallModeV2::Upgrade(None))
491491
.wasm_module(
492492
ic_test_utilities::universal_canister::UNIVERSAL_CANISTER_WASM.to_vec(),
493493
)
@@ -533,7 +533,7 @@ fn upgrade_canister_with_no_wasm_fails() {
533533
&canister_manager,
534534
InstallCodeContextBuilder::default()
535535
.sender(sender)
536-
.mode(CanisterInstallMode::Upgrade)
536+
.mode(CanisterInstallModeV2::Upgrade(None))
537537
.wasm_module(
538538
ic_test_utilities::universal_canister::UNIVERSAL_CANISTER_WASM.to_vec(),
539539
)
@@ -612,7 +612,7 @@ fn can_update_compute_allocation_during_upgrade() {
612612
.sender(sender)
613613
.canister_id(canister_id1)
614614
.compute_allocation(ComputeAllocation::try_from(80).unwrap())
615-
.mode(CanisterInstallMode::Upgrade)
615+
.mode(CanisterInstallModeV2::Upgrade(None))
616616
.build(),
617617
&mut state,
618618
&mut round_limits,
@@ -738,7 +738,7 @@ fn upgrading_canister_makes_subnet_oversubscribed() {
738738
ic_test_utilities::universal_canister::UNIVERSAL_CANISTER_WASM.to_vec(),
739739
)
740740
.compute_allocation(ComputeAllocation::try_from(30).unwrap())
741-
.mode(CanisterInstallMode::Upgrade)
741+
.mode(CanisterInstallModeV2::Upgrade(None))
742742
.build(),
743743
&mut state,
744744
&mut round_limits,
@@ -911,7 +911,7 @@ fn can_update_memory_allocation_during_upgrade() {
911911
.sender(sender)
912912
.canister_id(canister_id)
913913
.memory_allocation(final_memory_allocation)
914-
.mode(CanisterInstallMode::Upgrade)
914+
.mode(CanisterInstallModeV2::Upgrade(None))
915915
.build(),
916916
&mut state,
917917
&mut round_limits,
@@ -1198,7 +1198,7 @@ fn install_code_with_wrong_controller_fails() {
11981198
.0
11991199
.unwrap();
12001200

1201-
for mode in CanisterInstallMode::iter() {
1201+
for mode in CanisterInstallModeV2::iter() {
12021202
// Try to install_code with canister_test_id 2. Should fail.
12031203
let res = install_code(
12041204
&canister_manager,
@@ -1395,7 +1395,7 @@ fn reinstall_on_empty_canister_succeeds() {
13951395
InstallCodeContextBuilder::default()
13961396
.sender(sender)
13971397
.canister_id(canister_id)
1398-
.mode(CanisterInstallMode::Reinstall)
1398+
.mode(CanisterInstallModeV2::Reinstall)
13991399
.build(),
14001400
&mut state,
14011401
&mut round_limits,
@@ -1603,7 +1603,7 @@ fn reinstall_clears_stable_memory() {
16031603
InstallCodeContextBuilder::default()
16041604
.sender(sender)
16051605
.canister_id(canister_id)
1606-
.mode(CanisterInstallMode::Reinstall)
1606+
.mode(CanisterInstallModeV2::Reinstall)
16071607
.build(),
16081608
&mut state,
16091609
&mut round_limits,
@@ -2716,7 +2716,7 @@ fn installing_a_canister_with_not_enough_memory_allocation_fails() {
27162716
InstallCodeContextBuilder::default()
27172717
.sender(sender)
27182718
.canister_id(canister_id)
2719-
.mode(CanisterInstallMode::Reinstall)
2719+
.mode(CanisterInstallModeV2::Reinstall)
27202720
.wasm_module(
27212721
ic_test_utilities::universal_canister::UNIVERSAL_CANISTER_WASM.to_vec(),
27222722
)
@@ -2785,7 +2785,7 @@ fn upgrading_canister_with_not_enough_memory_allocation_fails() {
27852785
ic_test_utilities::universal_canister::UNIVERSAL_CANISTER_WASM.to_vec()
27862786
)
27872787
.memory_allocation(memory_allocation)
2788-
.mode(CanisterInstallMode::Upgrade)
2788+
.mode(CanisterInstallModeV2::Upgrade(None))
27892789
.build(),
27902790
&mut state,
27912791
&mut round_limits,
@@ -3013,7 +3013,7 @@ fn failed_upgrade_hooks_consume_instructions() {
30133013
arg: vec![],
30143014
compute_allocation: None,
30153015
memory_allocation: None,
3016-
mode: CanisterInstallMode::Install,
3016+
mode: CanisterInstallModeV2::Install,
30173017
query_allocation: QueryAllocation::default(),
30183018
},
30193019
&mut state,
@@ -3039,7 +3039,7 @@ fn failed_upgrade_hooks_consume_instructions() {
30393039
arg: vec![],
30403040
compute_allocation: None,
30413041
memory_allocation: None,
3042-
mode: CanisterInstallMode::Upgrade,
3042+
mode: CanisterInstallModeV2::Upgrade(None),
30433043
query_allocation: QueryAllocation::default(),
30443044
},
30453045
&mut state,
@@ -3158,7 +3158,7 @@ fn failed_install_hooks_consume_instructions() {
31583158
arg: vec![],
31593159
compute_allocation: None,
31603160
memory_allocation: None,
3161-
mode: CanisterInstallMode::Install,
3161+
mode: CanisterInstallModeV2::Install,
31623162
query_allocation: QueryAllocation::default(),
31633163
},
31643164
&mut state,
@@ -3276,7 +3276,7 @@ fn install_code_respects_instruction_limit() {
32763276
arg: vec![],
32773277
compute_allocation: None,
32783278
memory_allocation: None,
3279-
mode: CanisterInstallMode::Install,
3279+
mode: CanisterInstallModeV2::Install,
32803280
query_allocation: QueryAllocation::default(),
32813281
},
32823282
&mut state,
@@ -3308,7 +3308,7 @@ fn install_code_respects_instruction_limit() {
33083308
arg: vec![],
33093309
compute_allocation: None,
33103310
memory_allocation: None,
3311-
mode: CanisterInstallMode::Install,
3311+
mode: CanisterInstallModeV2::Install,
33123312
query_allocation: QueryAllocation::default(),
33133313
},
33143314
&mut state,
@@ -3334,7 +3334,7 @@ fn install_code_respects_instruction_limit() {
33343334
arg: vec![],
33353335
compute_allocation: None,
33363336
memory_allocation: None,
3337-
mode: CanisterInstallMode::Upgrade,
3337+
mode: CanisterInstallModeV2::Upgrade(None),
33383338
query_allocation: QueryAllocation::default(),
33393339
},
33403340
&mut state,
@@ -3366,7 +3366,7 @@ fn install_code_respects_instruction_limit() {
33663366
arg: vec![],
33673367
compute_allocation: None,
33683368
memory_allocation: None,
3369-
mode: CanisterInstallMode::Upgrade,
3369+
mode: CanisterInstallModeV2::Upgrade(None),
33703370
query_allocation: QueryAllocation::default(),
33713371
},
33723372
&mut state,
@@ -3420,14 +3420,14 @@ fn install_code_preserves_system_state_and_scheduler_state() {
34203420

34213421
// 1. INSTALL
34223422
let install_code_context = InstallCodeContextBuilder::default()
3423-
.mode(CanisterInstallMode::Install)
3423+
.mode(CanisterInstallModeV2::Install)
34243424
.sender(controller.into())
34253425
.canister_id(canister_id)
34263426
.build();
34273427
let compilation_cost = wasm_compilation_cost(install_code_context.wasm_module.as_slice());
34283428

34293429
let ctxt = InstallCodeContextBuilder::default()
3430-
.mode(CanisterInstallMode::Install)
3430+
.mode(CanisterInstallModeV2::Install)
34313431
.sender(controller.into())
34323432
.canister_id(canister_id)
34333433
.build();
@@ -3469,7 +3469,7 @@ fn install_code_preserves_system_state_and_scheduler_state() {
34693469

34703470
let instructions_before_reinstall = as_num_instructions(round_limits.instructions);
34713471
let ctxt = InstallCodeContextBuilder::default()
3472-
.mode(CanisterInstallMode::Reinstall)
3472+
.mode(CanisterInstallModeV2::Reinstall)
34733473
.sender(controller.into())
34743474
.canister_id(canister_id)
34753475
.build();
@@ -3520,7 +3520,7 @@ fn install_code_preserves_system_state_and_scheduler_state() {
35203520
.certified_data = certified_data;
35213521
let instructions_before_upgrade = as_num_instructions(round_limits.instructions);
35223522
let ctxt = InstallCodeContextBuilder::default()
3523-
.mode(CanisterInstallMode::Upgrade)
3523+
.mode(CanisterInstallModeV2::Upgrade(None))
35243524
.sender(controller.into())
35253525
.canister_id(canister_id)
35263526
.build();
@@ -3600,7 +3600,7 @@ fn lower_memory_allocation_than_usage_fails() {
36003600
arg: vec![],
36013601
compute_allocation: None,
36023602
memory_allocation: None,
3603-
mode: CanisterInstallMode::Install,
3603+
mode: CanisterInstallModeV2::Install,
36043604
query_allocation: QueryAllocation::default(),
36053605
},
36063606
&mut state,
@@ -3668,7 +3668,7 @@ fn test_install_when_updating_memory_allocation_via_canister_settings() {
36683668
arg: vec![],
36693669
compute_allocation: None,
36703670
memory_allocation: None,
3671-
mode: CanisterInstallMode::Install,
3671+
mode: CanisterInstallModeV2::Install,
36723672
query_allocation: QueryAllocation::default(),
36733673
},
36743674
&mut state,
@@ -3710,7 +3710,7 @@ fn test_install_when_updating_memory_allocation_via_canister_settings() {
37103710
arg: vec![],
37113711
compute_allocation: None,
37123712
memory_allocation: None,
3713-
mode: CanisterInstallMode::Install,
3713+
mode: CanisterInstallModeV2::Install,
37143714
query_allocation: QueryAllocation::default(),
37153715
},
37163716
&mut state,
@@ -3769,7 +3769,7 @@ fn test_upgrade_when_updating_memory_allocation_via_canister_settings() {
37693769
arg: vec![],
37703770
compute_allocation: None,
37713771
memory_allocation: None,
3772-
mode: CanisterInstallMode::Install,
3772+
mode: CanisterInstallModeV2::Install,
37733773
query_allocation: QueryAllocation::default(),
37743774
},
37753775
&mut state,
@@ -3795,7 +3795,7 @@ fn test_upgrade_when_updating_memory_allocation_via_canister_settings() {
37953795
arg: vec![],
37963796
compute_allocation: None,
37973797
memory_allocation: None,
3798-
mode: CanisterInstallMode::Upgrade,
3798+
mode: CanisterInstallModeV2::Upgrade(None),
37993799
query_allocation: QueryAllocation::default(),
38003800
},
38013801
&mut state,
@@ -3842,7 +3842,7 @@ fn test_upgrade_when_updating_memory_allocation_via_canister_settings() {
38423842
arg: vec![],
38433843
compute_allocation: None,
38443844
memory_allocation: None,
3845-
mode: CanisterInstallMode::Upgrade,
3845+
mode: CanisterInstallModeV2::Upgrade(None),
38463846
query_allocation: QueryAllocation::default(),
38473847
},
38483848
&mut state,
@@ -3947,7 +3947,7 @@ fn test_install_when_setting_memory_allocation_to_zero() {
39473947
arg: vec![],
39483948
compute_allocation: None,
39493949
memory_allocation: None,
3950-
mode: CanisterInstallMode::Install,
3950+
mode: CanisterInstallModeV2::Install,
39513951
query_allocation: QueryAllocation::default(),
39523952
},
39533953
&mut state,
@@ -3998,7 +3998,7 @@ fn test_upgrade_when_setting_memory_allocation_to_zero() {
39983998
arg: vec![],
39993999
compute_allocation: None,
40004000
memory_allocation: None,
4001-
mode: CanisterInstallMode::Install,
4001+
mode: CanisterInstallModeV2::Install,
40024002
query_allocation: QueryAllocation::default(),
40034003
},
40044004
&mut state,
@@ -4034,7 +4034,7 @@ fn test_upgrade_when_setting_memory_allocation_to_zero() {
40344034
arg: vec![],
40354035
compute_allocation: None,
40364036
memory_allocation: None,
4037-
mode: CanisterInstallMode::Upgrade,
4037+
mode: CanisterInstallModeV2::Upgrade(None),
40384038
query_allocation: QueryAllocation::default(),
40394039
},
40404040
&mut state,
@@ -4306,8 +4306,8 @@ fn test_install_code_rate_limiting_disabled() {
43064306

43074307
#[test]
43084308
fn install_code_context_conversion_u128() {
4309-
let install_args = InstallCodeArgs {
4310-
mode: CanisterInstallMode::Install,
4309+
let install_args = InstallCodeArgsV2 {
4310+
mode: CanisterInstallModeV2::Install,
43114311
canister_id: PrincipalId::try_from([1, 2, 3].as_ref()).unwrap(),
43124312
wasm_module: vec![],
43134313
arg: vec![],

0 commit comments

Comments
 (0)