Skip to content

Commit

Permalink
feat: RUN-914: Bump canister version on start/stop
Browse files Browse the repository at this point in the history
  • Loading branch information
dfinity-berestovskyy committed Feb 12, 2024
1 parent 76a6f96 commit c991c99
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions rs/execution_environment/src/canister_manager.rs
Expand Up @@ -1116,6 +1116,7 @@ impl CanisterManager {
}
}
};
canister.system_state.canister_version += 1;
state.put_canister_state(canister);
result
}
Expand Down Expand Up @@ -1159,6 +1160,7 @@ impl CanisterManager {
CanisterStatus::Stopped => CanisterStatus::new_running(),
};
canister.system_state.status = status;
canister.system_state.canister_version += 1;

Ok(stop_contexts)
}
Expand Down
1 change: 1 addition & 0 deletions rs/execution_environment/src/execution_environment.rs
Expand Up @@ -2956,6 +2956,7 @@ impl ExecutionEnvironment {
&mut canister.system_state.status,
CanisterStatus::Stopped,
);
canister.system_state.canister_version += 1;

// Reply to all pending stop_canister requests.
if let CanisterStatus::Stopping { stop_contexts, .. } = stopping_status {
Expand Down
27 changes: 22 additions & 5 deletions rs/execution_environment/src/hypervisor/tests.rs
Expand Up @@ -1068,20 +1068,37 @@ fn ic0_canister_version_returns_correct_value() {
WasmResult::Reply(expected_ctr.to_le_bytes().to_vec())
);

// This internally transitioning to stopping and then stopped,
// i.e. it adds 2 to canister version.
test.stop_canister(canister_id);
test.process_stopping_canisters();
test.ingress(canister_id, "update", ctr.clone())
.expect_err("The update should fail on the stopped canister.");
test.start_canister(canister_id)
.expect("The start canister should not fail.");
let result = test.ingress(canister_id, "update", ctr.clone()).unwrap();
// Plus 8 for the previous (successful) ingress messages.
let expected_ctr: u64 = 12 + 8;
assert_eq!(
result,
WasmResult::Reply(expected_ctr.to_le_bytes().to_vec())
);

test.set_controller(canister_id, canister_id.into())
.unwrap();
let result = test.ingress(canister_id, "update", ctr.clone()).unwrap();
// Plus 8 for the previous ingress messages.
let expected_ctr: u64 = 10 + 8;
// Plus 9 for the previous ingress messages.
let expected_ctr: u64 = 13 + 9;
assert_eq!(
result,
WasmResult::Reply(expected_ctr.to_le_bytes().to_vec())
);

test.uninstall_code(canister_id).unwrap_err();
test.uninstall_code(canister_id)
.expect_err("Uninstall code should fail as the controller has changed.");
let result = test.ingress(canister_id, "update", ctr).unwrap();
// Plus 9 for the previous ingress messages.
let expected_ctr: u64 = 10 + 9;
// Plus 10 for the previous ingress messages.
let expected_ctr: u64 = 13 + 10;
assert_eq!(
result,
WasmResult::Reply(expected_ctr.to_le_bytes().to_vec())
Expand Down

0 comments on commit c991c99

Please sign in to comment.