-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(nervous-system): Enable Root to upgrade canisters using chunked Wasms #3300
Open
aterga
wants to merge
6
commits into
master
Choose a base branch
from
arshavir/change-canister-with-chunked-wasm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
610068c
first
aterga cb7fd64
second
aterga ae144c3
remove unwanted changes
aterga 8f489d7
Update rs/nervous_system/root/src/change_canister.rs
aterga f24e60a
third
aterga ae69b03
Add integration test for Root.change_canister with chunked_canister_wasm
aterga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
rs/nervous_system/integration_tests/tests/upgrade_sns_controlled_canister_with_large_wasm.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
use canister_test::Wasm; | ||
use ic_base_types::PrincipalId; | ||
use ic_management_canister_types::CanisterInstallMode; | ||
use ic_nervous_system_integration_tests::pocket_ic_helpers::{ | ||
await_with_timeout, install_canister_on_subnet, nns, sns, | ||
}; | ||
use ic_nervous_system_integration_tests::{ | ||
create_service_nervous_system_builder::CreateServiceNervousSystemBuilder, | ||
pocket_ic_helpers::{add_wasms_to_sns_wasm, install_nns_canisters}, | ||
}; | ||
use ic_nns_constants::ROOT_CANISTER_ID; | ||
use ic_nns_test_utils::common::modify_wasm_bytes; | ||
use ic_sns_swap::pb::v1::Lifecycle; | ||
use ic_test_utilities::universal_canister::UNIVERSAL_CANISTER_WASM; | ||
use pocket_ic::PocketIcBuilder; | ||
|
||
use ic_nervous_system_root::change_canister::ChangeCanisterRequest; | ||
use ic_nervous_system_root::change_canister::ChunkedCanisterWasm; | ||
|
||
const MIN_INSTALL_CHUNKED_CODE_TIME_SECONDS: u64 = 20; | ||
const MAX_INSTALL_CHUNKED_CODE_TIME_SECONDS: u64 = 5 * 60; | ||
|
||
#[tokio::test] | ||
async fn test_store_same_as_target() { | ||
let store_same_as_target = true; | ||
run_test(store_same_as_target).await; | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_store_different_from_target() { | ||
let store_same_as_target = false; | ||
run_test(store_same_as_target).await; | ||
} | ||
|
||
mod interim_sns_helpers { | ||
use super::*; | ||
|
||
use candid::{Decode, Encode}; | ||
use pocket_ic::nonblocking::PocketIc; | ||
use pocket_ic::WasmResult; | ||
|
||
/// Interim test function for calling Root.change_canister. | ||
/// | ||
/// This function is not in src/pocket_ic_helpers.rs because it's going to be replaced with | ||
/// a proposal with the same effect. It should not be used in any other tests. | ||
pub async fn change_canister( | ||
pocket_ic: &PocketIc, | ||
canister_id: PrincipalId, | ||
sender: PrincipalId, | ||
request: ChangeCanisterRequest, | ||
) { | ||
let result = pocket_ic | ||
.update_call( | ||
canister_id.into(), | ||
sender.into(), | ||
"change_canister", | ||
Encode!(&request).unwrap(), | ||
) | ||
.await | ||
.unwrap(); | ||
let result = match result { | ||
WasmResult::Reply(result) => result, | ||
WasmResult::Reject(s) => panic!("Call to change_canister failed: {:#?}", s), | ||
}; | ||
Decode!(&result, ()).unwrap() | ||
} | ||
} | ||
|
||
async fn run_test(store_same_as_target: bool) { | ||
// 1. Prepare the world | ||
let pocket_ic = PocketIcBuilder::new() | ||
.with_nns_subnet() | ||
.with_sns_subnet() | ||
.with_application_subnet() | ||
.build_async() | ||
.await; | ||
|
||
// Install the NNS canisters. | ||
{ | ||
let with_mainnet_nns_canisters = false; | ||
install_nns_canisters(&pocket_ic, vec![], with_mainnet_nns_canisters, None, vec![]).await; | ||
} | ||
|
||
// Publish SNS Wasms to SNS-W. | ||
{ | ||
let with_mainnet_sns_canisters = false; | ||
add_wasms_to_sns_wasm(&pocket_ic, with_mainnet_sns_canisters) | ||
.await | ||
.unwrap(); | ||
}; | ||
|
||
// Install a dapp canister. | ||
let original_wasm = Wasm::from_bytes(UNIVERSAL_CANISTER_WASM.to_vec()); | ||
let original_wasm_hash = original_wasm.sha256_hash(); | ||
|
||
let app_subnet = pocket_ic.topology().await.get_app_subnets()[0]; | ||
|
||
let target_canister_id = install_canister_on_subnet( | ||
&pocket_ic, | ||
app_subnet, | ||
vec![], | ||
Some(original_wasm.clone()), | ||
vec![ROOT_CANISTER_ID.into()], | ||
) | ||
.await; | ||
|
||
let sns = { | ||
let create_service_nervous_system = CreateServiceNervousSystemBuilder::default() | ||
.with_dapp_canisters(vec![target_canister_id]) | ||
.build(); | ||
|
||
let swap_parameters = create_service_nervous_system | ||
.swap_parameters | ||
.clone() | ||
.unwrap(); | ||
|
||
let sns_instance_label = "1"; | ||
let (sns, _) = nns::governance::propose_to_deploy_sns_and_wait( | ||
&pocket_ic, | ||
create_service_nervous_system, | ||
sns_instance_label, | ||
) | ||
.await; | ||
|
||
sns::swap::await_swap_lifecycle(&pocket_ic, sns.swap.canister_id, Lifecycle::Open) | ||
.await | ||
.unwrap(); | ||
sns::swap::smoke_test_participate_and_finalize( | ||
&pocket_ic, | ||
sns.swap.canister_id, | ||
swap_parameters, | ||
) | ||
.await; | ||
|
||
sns | ||
}; | ||
|
||
let store_canister_id = if store_same_as_target { | ||
target_canister_id | ||
} else { | ||
install_canister_on_subnet( | ||
&pocket_ic, | ||
app_subnet, | ||
vec![], | ||
None, | ||
vec![sns.root.canister_id], | ||
) | ||
.await | ||
}; | ||
|
||
// TODO: Make the new WASM bigger than 2 MiB so that it does not fit into an ingress message. | ||
let new_wasm = modify_wasm_bytes(&original_wasm.bytes(), 123); | ||
let new_wasm = Wasm::from_bytes(new_wasm.to_vec()); | ||
let new_wasm_hash = new_wasm.sha256_hash(); | ||
|
||
// Smoke test | ||
assert_ne!(new_wasm_hash, original_wasm_hash); | ||
|
||
let chunk_hashes_list = { | ||
pocket_ic | ||
.upload_chunk( | ||
store_canister_id.into(), | ||
// This is a simplification; for now, we assume the Root itself decides to upload | ||
// some WASM chunks, but eventually this should be triggered via proposal. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it doesn't matter how the chunks get there so long as 1) root is a co-controller and 2) the wasm hash is correct (which is part of the proposal and should be verified). I think that means that you don't need root to upload the chunks necessarily. |
||
Some(sns.root.canister_id.into()), | ||
new_wasm.bytes(), | ||
) | ||
.await | ||
.unwrap(); | ||
let chunk_hashes_list = pocket_ic | ||
.stored_chunks(store_canister_id.into(), Some(sns.root.canister_id.into())) | ||
.await | ||
.unwrap(); | ||
assert_eq!(chunk_hashes_list[0], new_wasm_hash); | ||
chunk_hashes_list | ||
}; | ||
|
||
// 2. Run code under test. | ||
interim_sns_helpers::change_canister( | ||
&pocket_ic, | ||
sns.root.canister_id, | ||
sns.governance.canister_id, | ||
ChangeCanisterRequest { | ||
stop_before_installing: true, | ||
mode: CanisterInstallMode::Upgrade, | ||
canister_id: target_canister_id, | ||
// This is the old field being generalized. | ||
wasm_module: vec![], | ||
// This is the new field we want to test. | ||
chunked_canister_wasm: Some(ChunkedCanisterWasm { | ||
wasm_module_hash: new_wasm_hash.clone().to_vec(), | ||
store_canister_id, | ||
chunk_hashes_list, | ||
}), | ||
arg: vec![], | ||
compute_allocation: None, | ||
memory_allocation: None, | ||
}, | ||
) | ||
.await; | ||
|
||
// 3. Inspect the resulting state. | ||
await_with_timeout( | ||
&pocket_ic, | ||
MIN_INSTALL_CHUNKED_CODE_TIME_SECONDS..MAX_INSTALL_CHUNKED_CODE_TIME_SECONDS, | ||
|pocket_ic| async { | ||
let status = pocket_ic | ||
.canister_status(target_canister_id.into(), Some(sns.root.canister_id.into())) | ||
.await; | ||
status | ||
.expect("canister status must be available") | ||
.module_hash | ||
}, | ||
&Some(new_wasm_hash.to_vec()), | ||
) | ||
.await | ||
.unwrap(); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to not have all our tests do this. This was originally created for the sake of final release qualification and is the slowest part of most tests.
PocketIC tests seem to be a bit slower for some reason