-
Notifications
You must be signed in to change notification settings - Fork 372
feat(governance): Stop the target canister before taking or loading a snapshot... #8359
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
Open
daniel-wong-dfinity-org
wants to merge
12
commits into
master
Choose a base branch
from
stop-before-and-start-after-snapshot-ops-daniel-wong
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
12 commits
Select commit
Hold shift + click to select a range
7ee45d6
Moved LoadCanisterSnapshot* types from rs/handlers/root/interface to …
daniel-wong-dfinity-org 96f3614
Analogous to the previous commit, except this time, we are dealing wi…
daniel-wong-dfinity-org ecfbfbe
Move implementation of load_canister_snapshot from rs/handlers/root/i…
daniel-wong-dfinity-org 2e8b85d
Moved implementation of take_canister_snapshot from rs/nns/handlers/r…
daniel-wong-dfinity-org 4acc1b3
Clean up some imports that are no longer needed due to previous two c…
daniel-wong-dfinity-org f972cfe
Added exclusively_stop_and_start_canister to rs/nervous_system/root. …
daniel-wong-dfinity-org 266b4be
The `load_canister_snapshot` function (in rs/nervous_system/root) now…
daniel-wong-dfinity-org bb594cb
Do some extra safety stuff within take_canister_snapshot (like the pr…
daniel-wong-dfinity-org 2ed3469
Stop letting callers choose between DfnRuntime and CdkRuntime when ca…
daniel-wong-dfinity-org ae6e2ac
More or less a refactoring of change_canister (in rs/nervous_system/r…
daniel-wong-dfinity-org 545518b
lint
daniel-wong-dfinity-org a058b35
Fix test. Problem was that I removed a generic parameter. This unlock…
daniel-wong-dfinity-org 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| pub mod change_canister; | ||
| pub mod load_canister_snapshot; | ||
| pub mod take_canister_snapshot; | ||
|
|
||
| pub(crate) mod private; | ||
|
|
||
| pub const LOG_PREFIX: &str = "[Root Canister] "; |
This file contains hidden or 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,96 @@ | ||
| use crate::private::exclusively_stop_and_start_canister; | ||
| use candid::CandidType; | ||
| use ic_base_types::{CanisterId, PrincipalId, SnapshotId}; | ||
| use ic_management_canister_types_private::LoadCanisterSnapshotArgs; | ||
| use ic_nervous_system_clients::management_canister_client::ManagementCanisterClient; | ||
| use serde::Deserialize; | ||
|
|
||
| #[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize)] | ||
| pub struct LoadCanisterSnapshotRequest { | ||
| pub canister_id: PrincipalId, | ||
| pub snapshot_id: Vec<u8>, | ||
| } | ||
|
|
||
| #[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize)] | ||
| pub enum LoadCanisterSnapshotResponse { | ||
| Ok(LoadCanisterSnapshotOk), | ||
| Err(LoadCanisterSnapshotError), | ||
| } | ||
|
|
||
| #[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize)] | ||
| pub struct LoadCanisterSnapshotOk {} | ||
|
|
||
| #[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize)] | ||
| pub struct LoadCanisterSnapshotError { | ||
| pub code: Option<i32>, | ||
| pub description: String, | ||
| } | ||
|
|
||
| pub async fn load_canister_snapshot( | ||
| load_canister_snapshot_request: LoadCanisterSnapshotRequest, | ||
| management_canister_client: &mut impl ManagementCanisterClient, | ||
| ) -> LoadCanisterSnapshotResponse { | ||
| let operation_description = format!("{:?}", load_canister_snapshot_request); | ||
|
|
||
| let LoadCanisterSnapshotRequest { | ||
| canister_id, | ||
| snapshot_id, | ||
| } = load_canister_snapshot_request; | ||
|
|
||
| let snapshot_id = match SnapshotId::try_from(snapshot_id) { | ||
| Ok(ok) => ok, | ||
| Err(err) => { | ||
| return LoadCanisterSnapshotResponse::Err(LoadCanisterSnapshotError { | ||
| code: None, | ||
| description: format!("Invalid snapshot ID: {err}"), | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| let canister_id = match CanisterId::try_from(canister_id) { | ||
| Ok(ok) => ok, | ||
| Err(err) => { | ||
| return LoadCanisterSnapshotResponse::Err(LoadCanisterSnapshotError { | ||
| code: None, | ||
| description: format!("Invalid canister ID: {err}"), | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| let result = exclusively_stop_and_start_canister::<_, _, _>( | ||
| canister_id, | ||
| &operation_description, | ||
| true, // stop_before | ||
| || async { | ||
| let load_canister_snapshot_args = LoadCanisterSnapshotArgs::new( | ||
| canister_id, | ||
| snapshot_id, | ||
| management_canister_client.canister_version(), | ||
| ); | ||
|
|
||
| management_canister_client | ||
| .load_canister_snapshot(load_canister_snapshot_args) | ||
| .await | ||
| }, | ||
| ) | ||
| .await; | ||
|
|
||
| let result = match result { | ||
| Ok(ok) => ok, | ||
| Err(err) => { | ||
| let description = format!("{err}"); | ||
| return LoadCanisterSnapshotResponse::Err(LoadCanisterSnapshotError { | ||
| code: None, | ||
| description, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| match result { | ||
| Ok(()) => LoadCanisterSnapshotResponse::Ok(LoadCanisterSnapshotOk {}), | ||
| Err((code, description)) => LoadCanisterSnapshotResponse::Err(LoadCanisterSnapshotError { | ||
| code: Some(code), | ||
| description, | ||
| }), | ||
| } | ||
| } |
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.
Usually I don't like comments just stating what the code does, but here, since the
resultabove is aResult<Result<_, _>, _>, it's probably good to comment on what each error handling does.