Repository navigation
feat(pic): support canister snapshots #310
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
71bcd43
feat(pic): support canister snapshots
marc0olo 09e63fa
docs: add a canister snapshots guide
marc0olo 007b9a9
fix(pic): document that snapshot viewers can list and download snapshots
marc0olo 59df3ac
test(pic): cover replacing a snapshot on upload, fix snapshot content…
marc0olo 5299b2d
Merge remote-tracking branch 'origin/main' into feat/canister-snapshots
marc0olo 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 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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --- | ||
| title: Canister snapshots | ||
| sidebar: | ||
| order: 7 | ||
| --- | ||
|
|
||
| A [canister snapshot](https://docs.internetcomputer.org/guides/canister-management/snapshots/) captures a canister's state: its Wasm module, heap and stable memory, and chunk store. All snapshot methods must be called by a controller of the canister. | ||
|
|
||
| ## Restoring state | ||
|
|
||
| Take a snapshot, change the canister's state, and load the snapshot to go back, for example to roll back a failed upgrade: | ||
|
|
||
| ```ts | ||
| const snapshot = await pic.takeCanisterSnapshot({ canisterId, sender }); | ||
|
|
||
| await pic.upgradeCanister({ canisterId, wasm, sender }); | ||
| // assert on the upgraded canister... | ||
|
|
||
| await pic.loadCanisterSnapshot({ | ||
| canisterId, | ||
| snapshotId: snapshot.id, | ||
| sender, | ||
| }); | ||
| ``` | ||
|
|
||
| Snapshots can also be listed with `listCanisterSnapshots` and deleted with `deleteCanisterSnapshot`. Pass `replaceSnapshot` to `takeCanisterSnapshot` to replace an existing snapshot instead of adding one. | ||
|
|
||
| ## Testing against real state | ||
|
|
||
| Snapshots are not tied to a network, so a snapshot downloaded from mainnet or a local network can be uploaded into PocketIC to test against real state. Download it with [icp-cli](https://cli.internetcomputer.org): | ||
|
|
||
| ```shell | ||
| icp canister snapshot create <canister> -n ic | ||
| icp canister snapshot download <canister> <snapshot-id> -n ic -o ./snapshot | ||
| ``` | ||
|
|
||
| Then upload it to a canister in PocketIC and load it: | ||
|
|
||
| ```ts | ||
| const canisterId = await pic.createCanister({ sender }); | ||
|
|
||
| const snapshotId = await pic.uploadCanisterSnapshot({ | ||
| canisterId, | ||
| snapshotDir: path.resolve('./snapshot'), | ||
| sender, | ||
| }); | ||
| await pic.loadCanisterSnapshot({ canisterId, snapshotId, sender }); | ||
| ``` | ||
|
|
||
| `downloadCanisterSnapshot` writes a snapshot in the same format, which `icp canister snapshot upload` accepts. | ||
|
|
||
| `snapshotDir` is a path on the machine running the PocketIC server, and should be absolute. | ||
|
|
||
| The snapshot carries state that may depend on where it was taken: | ||
|
|
||
| - The canister ID changes, so state that stores the canister's own ID refers to the original canister. | ||
| - Other canisters the state refers to may not exist on PocketIC under the same IDs. | ||
| - Public keys derived from threshold keys (ECDSA, Schnorr, vetKD) differ between networks. | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.