From e0f228a9a9ebd0ffe454f97704b37f47159411ad Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Tue, 16 Jun 2026 20:03:47 +0200 Subject: [PATCH] chore: migrate rust/canister-snapshot-download to icp-cli Co-Authored-By: Claude Sonnet 4.6 --- .../workflows/canister-snapshot-download.yml | 28 ++ ...st-canister-snapshot-download-example.yaml | 44 -- rust/canister-snapshot-download/.gitignore | 9 +- rust/canister-snapshot-download/Cargo.lock | 401 +++++++++++------- rust/canister-snapshot-download/Cargo.toml | 4 +- rust/canister-snapshot-download/Makefile | 31 ++ rust/canister-snapshot-download/README.md | 129 ++---- .../{src/quotes => backend}/Cargo.toml | 6 +- .../{src/quotes => backend}/src/lib.rs | 0 rust/canister-snapshot-download/dfx.json | 17 - rust/canister-snapshot-download/icp.yaml | 8 + rust/canister-snapshot-download/run.sh | 29 -- .../src/quotes/quotes.did | 4 - 13 files changed, 361 insertions(+), 349 deletions(-) create mode 100644 .github/workflows/canister-snapshot-download.yml delete mode 100644 .github/workflows/rust-canister-snapshot-download-example.yaml create mode 100644 rust/canister-snapshot-download/Makefile rename rust/canister-snapshot-download/{src/quotes => backend}/Cargo.toml (76%) rename rust/canister-snapshot-download/{src/quotes => backend}/src/lib.rs (100%) delete mode 100644 rust/canister-snapshot-download/dfx.json create mode 100644 rust/canister-snapshot-download/icp.yaml delete mode 100755 rust/canister-snapshot-download/run.sh delete mode 100644 rust/canister-snapshot-download/src/quotes/quotes.did diff --git a/.github/workflows/canister-snapshot-download.yml b/.github/workflows/canister-snapshot-download.yml new file mode 100644 index 0000000000..7b6c015fcf --- /dev/null +++ b/.github/workflows/canister-snapshot-download.yml @@ -0,0 +1,28 @@ +name: canister-snapshot-download + +on: + push: + branches: [master] + pull_request: + paths: + - rust/canister-snapshot-download/** + - .github/workflows/canister-snapshot-download.yml + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rust-canister-snapshot-download: + runs-on: ubuntu-24.04 + container: ghcr.io/dfinity/icp-dev-env-rust:1.0.0 + env: + ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + - name: Deploy and test + working-directory: rust/canister-snapshot-download + run: | + icp network start -d + icp deploy + make test diff --git a/.github/workflows/rust-canister-snapshot-download-example.yaml b/.github/workflows/rust-canister-snapshot-download-example.yaml deleted file mode 100644 index 290be932e7..0000000000 --- a/.github/workflows/rust-canister-snapshot-download-example.yaml +++ /dev/null @@ -1,44 +0,0 @@ -name: rust-canister-snapshot-download -on: - push: - branches: - - master - pull_request: - paths: - - rust/canister-snapshot-download/** - - .github/workflows/provision-darwin.sh - - .github/workflows/provision-linux.sh - - .github/workflows/rust-canister-snapshot-download-example.yaml - - .ic-commit -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true -jobs: - rust-canister-snapshot-download-example-darwin: - runs-on: macos-15 - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # v1.2.0 - - name: Provision Darwin - run: bash .github/workflows/provision-darwin.sh - - name: Remove networks.json - run: rm -f ~/.config/dfx/networks.json - - name: Rust Canister Snapshots Darwin - run: | - dfx start --background - pushd rust/canister-snapshot-download - # ./run.sh # enable when download feature is out of beta - popd - rust-canister-snapshot-download-example-linux: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # v1.2.0 - - name: Provision Linux - run: bash .github/workflows/provision-linux.sh - - name: Remove networks.json - run: rm -f ~/.config/dfx/networks.json - - name: Rust Canister Snapshots Linux - run: | - dfx start --background - pushd rust/canister-snapshot-download - # ./run.sh # enable when download feature is out of beta - popd diff --git a/rust/canister-snapshot-download/.gitignore b/rust/canister-snapshot-download/.gitignore index ef5c64bb90..4baaedfa04 100644 --- a/rust/canister-snapshot-download/.gitignore +++ b/rust/canister-snapshot-download/.gitignore @@ -7,9 +7,6 @@ .DS_Store **/.DS_Store -# dfx temporary files -.dfx/ - # generated files **/declarations/ @@ -21,7 +18,5 @@ node_modules/ dist/ .svelte-kit/ -# environment variables -.env - -snapshots/ \ No newline at end of file +# snapshot download directory +snapshots/ diff --git a/rust/canister-snapshot-download/Cargo.lock b/rust/canister-snapshot-download/Cargo.lock index 57bc82b3b9..db51eb374b 100644 --- a/rust/canister-snapshot-download/Cargo.lock +++ b/rust/canister-snapshot-download/Cargo.lock @@ -4,9 +4,18 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.99" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "ar_archive_writer" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4087686b4b0a3427190bae57a1d9a478dbb2d40c5dc1bd6e2b6d797913bdd348" +dependencies = [ + "object", +] [[package]] name = "arrayvec" @@ -16,9 +25,17 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "autocfg" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "backend" +version = "0.1.0" +dependencies = [ + "candid", + "ic-cdk", +] [[package]] name = "binread" @@ -60,9 +77,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "candid" -version = "0.10.17" +version = "0.10.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaac522d18020d5fbc8320ecb12a9b13b2137ae31133da2d42fa256a825507c4" +checksum = "f8f781afa4a1303e3eab4ada0720a874942bcfa936ce01b816ac6378945c43a9" dependencies = [ "anyhow", "binread", @@ -78,35 +95,36 @@ dependencies = [ "serde", "serde_bytes", "stacker", - "thiserror", + "thiserror 1.0.69", ] [[package]] name = "candid_derive" -version = "0.10.17" +version = "0.10.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a1b4fddbd462182050989068d53604a91a3d0f117c3c8316c6818023df00add" +checksum = "ad6ae8e7944dd0035651bc0e7b3a3e4cb16f5fc43f8ae4fd76b36ff2cd52759f" dependencies = [ "lazy_static", "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.118", ] [[package]] name = "cc" -version = "1.2.32" +version = "1.2.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2352e5597e9c544d5e6d9c95190d5d27738ade584fa8db0a16e130e5c2b5296e" +checksum = "dad887fd958be91b5098c0248def011f4523ab786cd411be668777e55063501f" dependencies = [ + "find-msvc-tools", "shlex", ] [[package]] name = "cfg-if" -version = "1.0.1" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cpufeatures" @@ -128,19 +146,53 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" dependencies = [ "generic-array", "typenum", ] +[[package]] +name = "darling" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9865a50f7c335f53564bb694ef660825eb8610e0a53d3e11bf1b0d3df31e03b0" +dependencies = [ + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.118", +] + +[[package]] +name = "darling_macro" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.118", +] + [[package]] name = "data-encoding" -version = "2.9.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" +checksum = "a4ae5f15dda3c708c0ade84bfee31ccab44a3da4f88015ed22f63732abe300c8" [[package]] name = "digest" @@ -154,9 +206,15 @@ dependencies = [ [[package]] name = "either" -version = "1.15.0" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "generic-array" @@ -168,6 +226,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hex" version = "0.4.3" @@ -176,57 +240,80 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "ic-cdk" -version = "0.16.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a50afd39a4c2022ca6cbdf15dbd653b33eeaae9010748b74006bbd717aa7c51a" +checksum = "6a7971f4983db147afbbc4e7f87f60b09fcd60ac707af37ff3d2468dcddbf551" dependencies = [ "candid", "ic-cdk-executor", "ic-cdk-macros", + "ic-error-types", "ic0", + "pin-project-lite", "serde", - "serde_bytes", + "thiserror 2.0.18", ] [[package]] name = "ic-cdk-executor" -version = "0.1.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "903057edd3d4ff4b3fe44a64eaee1ceb73f579ba29e3ded372b63d291d7c16c2" +checksum = "33716b730ded33690b8a704bff3533fda87d229e58046823647d28816e9bcee7" +dependencies = [ + "ic0", + "slotmap", + "smallvec", +] [[package]] name = "ic-cdk-macros" -version = "0.16.0" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d4d857135deef20cc7ea8f3869a30cd9cfeb1392b3a81043790b2cd82adc3e0" +checksum = "a7c20c002200c720958f321bb78b4d4987fc2c380bf9ef69ed4404730810f45f" dependencies = [ "candid", + "darling", "proc-macro2", "quote", + "syn 2.0.118", +] + +[[package]] +name = "ic-error-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbeeb3d91aa179d6496d7293becdacedfc413c825cac79fd54ea1906f003ee55" +dependencies = [ "serde", - "serde_tokenstream", - "syn 2.0.105", + "strum", + "strum_macros", ] [[package]] name = "ic0" -version = "0.23.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de254dd67bbd58073e23dc1c8553ba12fa1dc610a19de94ad2bbcd0460c067f" +checksum = "c77c8932bff1f09502d0d8c079d5a206a06afe523e35e816162cf4d30b5bf80d" [[package]] name = "ic_principal" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1762deb6f7c8d8c2bdee4b6c5a47b60195b74e9b5280faa5ba29692f8e17429c" +checksum = "1aea751965eaf92990be8c79c64b4f3174ff22dd3604e6696a06a494afbaba2a" dependencies = [ "crc32fast", "data-encoding", "serde", "sha2", - "thiserror", + "thiserror 1.0.69", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "lazy_static" version = "1.5.0" @@ -235,15 +322,21 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "leb128" -version = "0.2.5" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" +checksum = "c83bff1d572d6b9aeef67ddfc8448e4a3737909cb28e81f97c791b9018703e52" [[package]] name = "libc" -version = "0.2.175" +version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "memchr" +version = "2.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" [[package]] name = "num-bigint" @@ -274,17 +367,32 @@ dependencies = [ "autocfg", ] +[[package]] +name = "object" +version = "0.37.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" +dependencies = [ + "memchr", +] + [[package]] name = "paste" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + [[package]] name = "pretty" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac98773b7109bc75f475ab5a134c9b64b87e59d776d31098d8f346922396a477" +checksum = "0d22152487193190344590e4f30e219cf3fe140d9e7a3fdb683d82aa2c5f4156" dependencies = [ "arrayvec", "typed-arena", @@ -293,39 +401,32 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.97" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61789d7719defeb74ea5fe81f2fdfdbd28a803847077cecce2ff14e1472f6f1" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] [[package]] name = "psm" -version = "0.1.26" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e944464ec8536cd1beb0bbfd96987eb5e3b72f2ecdafdc5c769a37f1fa2ae1f" +checksum = "645dbe486e346d9b5de3ef16ede18c26e6c70ad97418f4874b8b1889d6e761ea" dependencies = [ + "ar_archive_writer", "cc", ] [[package]] name = "quote" -version = "1.0.40" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] -[[package]] -name = "quotes" -version = "0.1.0" -dependencies = [ - "candid", - "ic-cdk", -] - [[package]] name = "rustversion" version = "1.0.22" @@ -334,43 +435,42 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "serde" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ + "serde_core", "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.17" +version = "0.11.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8437fd221bde2d4ca316d61b90e337e9e702b3820b87d63caa9ba6c02bd06d96" +checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8" dependencies = [ "serde", + "serde_core", ] [[package]] -name = "serde_derive" -version = "1.0.219" +name = "serde_core" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.105", + "serde_derive", ] [[package]] -name = "serde_tokenstream" -version = "0.2.2" +name = "serde_derive" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64060d864397305347a78851c51588fd283767e7e7589829e8121d65512340f1" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "serde", - "syn 2.0.105", + "syn 2.0.118", ] [[package]] @@ -386,15 +486,30 @@ dependencies = [ [[package]] name = "shlex" -version = "1.3.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "slotmap" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdd58c3c93c3d278ca835519292445cb4b0d4dc59ccfdf7ceadaab3f8aeb4038" +dependencies = [ + "version_check", +] + +[[package]] +name = "smallvec" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" [[package]] name = "stacker" -version = "0.1.21" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cddb07e32ddb770749da91081d8d0ac3a16f1a569a18b20348cd371f5dead06b" +checksum = "640c8cdd92b6b12f5bcb1803ca3bbf5ab96e5e6b6b96b9ab77dabe9e880b3190" dependencies = [ "cc", "cfg-if", @@ -403,6 +518,34 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.118", +] + [[package]] name = "syn" version = "1.0.109" @@ -416,9 +559,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.105" +version = "2.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bc3fcb250e53458e712715cf74285c1f889686520d79294a9ef3bd7aa1fc619" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" dependencies = [ "proc-macro2", "quote", @@ -431,7 +574,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", ] [[package]] @@ -442,7 +594,18 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.118", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.118", ] [[package]] @@ -453,21 +616,21 @@ checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" [[package]] name = "typenum" -version = "1.18.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "unicode-width" -version = "0.1.14" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" [[package]] name = "version_check" @@ -476,74 +639,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] -name = "windows-sys" -version = "0.59.0" +name = "windows-link" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] -name = "windows-targets" -version = "0.52.6" +name = "windows-sys" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-link", ] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/rust/canister-snapshot-download/Cargo.toml b/rust/canister-snapshot-download/Cargo.toml index 06399e21c7..d1e49e317a 100644 --- a/rust/canister-snapshot-download/Cargo.toml +++ b/rust/canister-snapshot-download/Cargo.toml @@ -1,5 +1,3 @@ [workspace] -members = [ - "src/quotes" -] +members = ["backend"] resolver = "2" diff --git a/rust/canister-snapshot-download/Makefile b/rust/canister-snapshot-download/Makefile new file mode 100644 index 0000000000..3334ba94bc --- /dev/null +++ b/rust/canister-snapshot-download/Makefile @@ -0,0 +1,31 @@ +.PHONY: test + +test: + @echo "=== Test 1: setup stable memory with initial data ===" + @result=$$(icp canister call backend setup '()') && \ + echo "$$result" && \ + echo "$$result" | grep -q '()' && \ + echo "PASS" || (echo "FAIL" && exit 1) + + @echo "=== Test 2: print returns the initial quote ===" + @result=$$(icp canister call --query backend print '()') && \ + echo "$$result" && \ + echo "$$result" | grep -q 'Colourless' && \ + echo "PASS" || (echo "FAIL" && exit 1) + + @echo "=== Test 3: snapshot create/download/upload/load workflow ===" + @mkdir -p ./snapshots + @icp canister stop backend + @snapshot_id=$$(icp canister snapshot create backend | grep -oE '[0-9a-f]{36}'); \ + echo "Snapshot ID: $$snapshot_id" && \ + icp canister snapshot download --dir ./snapshots backend "$$snapshot_id" + @sed -i 's/Colour/Color/g' ./snapshots/stable_memory.bin + @new_id=$$(icp canister snapshot upload --dir ./snapshots backend | grep -oE '[0-9a-f]{36}'); \ + echo "New Snapshot ID: $$new_id" && \ + icp canister snapshot load backend "$$new_id" + @icp canister start backend + @result=$$(icp canister call --query backend print '()') && \ + echo "$$result" && \ + echo "$$result" | grep -q 'Colorless' && \ + echo "PASS" || (echo "FAIL" && exit 1) + @rm -rf ./snapshots diff --git a/rust/canister-snapshot-download/README.md b/rust/canister-snapshot-download/README.md index 64beb7f05a..0e381f2b5a 100644 --- a/rust/canister-snapshot-download/README.md +++ b/rust/canister-snapshot-download/README.md @@ -1,111 +1,52 @@ # Canister snapshot download and upload -This example demonstrates the process of downloading and uploading canister snapshots. It features a canister called `quotes` which has some faulty data in its stable memory. You may think of it as data corrupted during a data migration or something similar. For the purposes of this example, it's simply a quote with a typo. +This example demonstrates the process of downloading and uploading canister snapshots. +It features a canister called `backend` which stores some data in stable memory. +The example walks through downloading a snapshot, manipulating the binary stable memory +off-chain, uploading the fixed snapshot, and restoring the canister from it. -The steps in this readme can be run all in sequence by invoking the `run.sh` script in bash. +## Build and deploy from the command line -## Prerequisites - -This example requires an installation of: - -- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). Note: the Canister Snapshots feature requires `dfx` version `0.23.0-beta.3` or later. -- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples` - -Begin by opening a terminal window. - -## Step 1: Setup the project environment - -Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the commands: +### Prerequisites +- Node.js +- icp-cli: `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm` +### Install ```bash +git clone https://github.com/dfinity/examples cd examples/rust/canister-snapshot-download -dfx start --clean --background -``` - -## Step 2: Compile and deploy `quotes` canister - -```bash -dfx deploy -``` - -Also setup its initial state: - -```bash -dfx canister call quotes "setup" -``` - -And check what the `print` endpoint returns: - -```bash -dfx canister call quotes "print" -``` - -Output: -```bash -Colourless green ideas sleep furiously. -``` - -Clearly, this British spelling is not correct, as the author of the quote is American. Let's fix it by downloading the canister state, fixing the stable memory and loading the fixed version. - -## Step 3: Create and download snapshot - -```bash -dfx canister stop quotes -dfx canister snapshot create quotes -``` - -This returns a snapshot id, similar to -```bash -0000000000000000ffffffffff9000010101 -``` - -Create a local directory and download the new snapshot: -```bash -mkdir ./snapshots -dfx canister snapshot download --dir ./snapshots quotes 0000000000000000ffffffffff9000010101 -``` - -## Step 4: Manipulate and upload the snapshot -View the file in ./snapshot/stable_memory.bin. This is a binary file, but the first few bytes are ASCII characters. - -Fix the spelling by running: -```bash -sed -i -e 's/Colour/Color/g' ./snapshots/stable_memory.bin -``` - -Upload the fixed snapshot. -```bash -dfx canister snapshot upload --dir ./snapshots quotes -``` - -This will return a new snapshot id, similar to -```bash -0000000000000001ffffffffff9000010101 ``` -## Step 5: Load the snapshot and verify - +### Deploy and test ```bash -dfx canister snapshot load quotes 0000000000000001ffffffffff9000010101 -dfx canister start quotes -dfx canister call quotes "print" +icp network start -d +icp deploy +make test +icp network stop ``` -Output: -```bash -Colorless green ideas sleep furiously. -``` +## How it works -Clean up. -```bash -rm -rf ./snapshots -dfx stop -``` +The backend canister stores a quote in stable memory using the low-level stable memory API. +The initial quote contains a British spelling ("Colourless") that can be fixed off-chain: -## Conclusion +1. **Setup**: call `setup` to write the initial data into stable memory. +2. **Snapshot**: stop the canister, create a snapshot, then start it again. +3. **Download**: `icp canister snapshot download --dir ./snapshots backend ` saves + `stable_memory.bin` and other files to the local directory. +4. **Manipulate**: edit the binary file directly (e.g. `sed -i 's/Colour/Color/g' ./snapshots/stable_memory.bin`). +5. **Upload**: `icp canister snapshot upload --dir ./snapshots backend` returns a new snapshot ID. +6. **Load**: stop the canister, load the new snapshot, then start it again. +7. **Verify**: call `print` to confirm the spelling fix is live. -The ability to download and upload snapshots enables various new use cases: +This workflow enables several use cases: - Keeping canister backups on disk rather than on-chain. - Cloning canister state into another canister. -- Migrating canister state to a different subnet. -- Fixing faulty state or performing data migrations that would be prohibitive on-chain. \ No newline at end of file +- Migrating canister state to a different subnet. +- Fixing faulty state or performing data migrations that would be prohibitive on-chain. + +## Security considerations and best practices + +If you base your application on this example, we recommend you familiarize +yourself with and adhere to the [security best practices](https://docs.internetcomputer.org/guides/security/overview) +for developing on the Internet Computer. This example may not implement all the best practices. diff --git a/rust/canister-snapshot-download/src/quotes/Cargo.toml b/rust/canister-snapshot-download/backend/Cargo.toml similarity index 76% rename from rust/canister-snapshot-download/src/quotes/Cargo.toml rename to rust/canister-snapshot-download/backend/Cargo.toml index 58674419dc..669a663902 100644 --- a/rust/canister-snapshot-download/src/quotes/Cargo.toml +++ b/rust/canister-snapshot-download/backend/Cargo.toml @@ -1,11 +1,11 @@ [package] -edition = "2021" -name = "quotes" +name = "backend" version = "0.1.0" +edition = "2021" [lib] crate-type = ["cdylib"] [dependencies] candid = "0.10" -ic-cdk = "0.16" +ic-cdk = "0.20" diff --git a/rust/canister-snapshot-download/src/quotes/src/lib.rs b/rust/canister-snapshot-download/backend/src/lib.rs similarity index 100% rename from rust/canister-snapshot-download/src/quotes/src/lib.rs rename to rust/canister-snapshot-download/backend/src/lib.rs diff --git a/rust/canister-snapshot-download/dfx.json b/rust/canister-snapshot-download/dfx.json deleted file mode 100644 index 9378936fbe..0000000000 --- a/rust/canister-snapshot-download/dfx.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "canisters": { - "quotes": { - "candid": "src/quotes/quotes.did", - "package": "quotes", - "type": "rust" - } - }, - "defaults": { - "build": { - "args": "", - "packtool": "" - } - }, - "output_env_file": ".env", - "version": 1 -} \ No newline at end of file diff --git a/rust/canister-snapshot-download/icp.yaml b/rust/canister-snapshot-download/icp.yaml new file mode 100644 index 0000000000..df5c7edaaf --- /dev/null +++ b/rust/canister-snapshot-download/icp.yaml @@ -0,0 +1,8 @@ +networks: + - name: local + mode: managed + +canisters: + - name: backend + recipe: + type: "@dfinity/rust@v3.3.0" diff --git a/rust/canister-snapshot-download/run.sh b/rust/canister-snapshot-download/run.sh deleted file mode 100755 index fb7cf49463..0000000000 --- a/rust/canister-snapshot-download/run.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash -set -eo pipefail - -rm -rf ./snapshots -mkdir ./snapshots - -dfx stop -dfx start --clean --background -dfx deploy - -dfx canister call quotes "setup" -dfx canister call quotes "print" - -dfx canister stop quotes -dfx canister snapshot create quotes -# snapshot id 0000000000000000ffffffffff9000010101 - -dfx canister snapshot download --dir ./snapshots quotes 0000000000000000ffffffffff9000010101 - -# manipulate file -sed -i -e 's/Colour/Color/g' ./snapshots/stable_memory.bin - -dfx canister snapshot upload --dir ./snapshots quotes - -dfx canister snapshot load quotes 0000000000000001ffffffffff9000010101 -dfx canister start quotes -dfx canister call quotes "print" - - diff --git a/rust/canister-snapshot-download/src/quotes/quotes.did b/rust/canister-snapshot-download/src/quotes/quotes.did deleted file mode 100644 index 51ecf68241..0000000000 --- a/rust/canister-snapshot-download/src/quotes/quotes.did +++ /dev/null @@ -1,4 +0,0 @@ -service : { - "setup": () -> (); - "print": () -> (text); -}