Skip to content

Commit

Permalink
Merge branch 'roman-ledger-compressed-archive' into 'master'
Browse files Browse the repository at this point in the history
chore(icrc1): compress embedded archive canister Wasm

This change ensures that the ledger canister embeds a gzip-compressed
version of the archive canister. 

See merge request dfinity-lab/public/ic!10559
  • Loading branch information
levsha committed Feb 7, 2023
2 parents 5376a14 + 33b1259 commit f9136d1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 23 deletions.
24 changes: 16 additions & 8 deletions publish/canisters/BUILD.bazel
Expand Up @@ -13,15 +13,13 @@ CANISTERS = {
"http_counter.wasm": "//rs/tests/test_canisters/http_counter",
"ic-ckbtc-minter.wasm": "//rs/bitcoin/ckbtc/minter:ckbtc_minter",
"ic-ckbtc-minter_debug.wasm": "//rs/bitcoin/ckbtc/minter:ckbtc_minter_debug",
"ic-icrc1-archive.wasm": "//rs/rosetta-api/icrc1/archive:archive_canister",
"ic-icrc1-index.wasm": "//rs/rosetta-api/icrc1/index:index_canister",
"ic-icrc1-ledger.wasm": "//rs/rosetta-api/icrc1/ledger:ledger_canister",
"ic-nervous-system-common-test-canister.wasm": "//rs/nervous_system/common/test_canister",
"identity-canister.wasm": "//rs/nns/identity:identity-canister",
"inter_canister_error_handling.wasm": "//rs/rust_canisters/tests:inter_canister_error_handling",
"kv_store.wasm": "//rs/tests/test_canisters/kv_store",
"json.wasm": "//rs/rust_canisters/tests:json",
"ledger-archive-node-canister.wasm": "//rs/rosetta-api/icp_ledger/archive:ledger-archive-node-canister-wasm",
"ledger-canister.wasm": "//rs/rosetta-api/icp_ledger/ledger:ledger-canister-wasm",
"ledger-canister_notify-method.wasm": "//rs/rosetta-api/icp_ledger/ledger:ledger-canister-wasm-notify-method",
"lifeline.wasm": "//rs/nns/handlers/lifeline:lifeline_actor",
Expand Down Expand Up @@ -96,16 +94,26 @@ CANISTERS_MAX_SIZE_IN_BYTES = {
for (name, target) in CANISTERS.items()
]

COMPRESSED_CANISTERS = {
"ic-btc-canister.wasm.gz": "@btc_canister//file",
"ic-icrc1-archive.wasm.gz": "//rs/rosetta-api/icrc1/archive:archive_canister.wasm.gz",
"ledger-archive-node-canister.wasm.gz": "//rs/rosetta-api/icp_ledger/archive:ledger_archive_node_canister.wasm.gz",
}

# `bazel cquery --output=files` that is used by build-ic script does not show external sources of `filegroup` targets.
copy_file(
name = "copy_ic-btc-canister.wasm.gz",
src = "@btc_canister//file",
out = "ic-btc-canister.wasm.gz",
)
[
copy_file(
name = "copy_" + compressed_file_name,
src = target,
out = compressed_file_name,
)
for (compressed_file_name, target) in COMPRESSED_CANISTERS.items()
]

filegroup(
name = "canisters",
srcs = [name + ".gz" for name in CANISTERS] + [":ic-btc-canister.wasm.gz"],
srcs = [name + ".gz" for name in CANISTERS] +
[name for name in COMPRESSED_CANISTERS],
visibility = ["//visibility:public"],
)

Expand Down
9 changes: 2 additions & 7 deletions rs/nns/sns-wasm/tests/upgrade_sns_instance.rs
Expand Up @@ -878,17 +878,12 @@ fn test_out_of_sync_version_still_allows_upgrade_to_succeed() {

let deployed_version = version_response.deployed_version.unwrap();
assert_eq!(deployed_version, old_version_plus_governance);
// Ensure the recorded archive_wasm_hash is not the same as the one contained in ledger
let ledgers_archive_wasm_hash = build_archive_sns_wasm().sha256_hash().to_vec();
assert_ne!(
deployed_version.archive_wasm_hash,
ledgers_archive_wasm_hash
);

// Ensure we are still mismatched between running archive version and deployed_version.archive_wasm_hash
let running_archive_statuses = get_canister_statuses(SnsCanisterType::Archive, &machine, root);
assert!(running_archive_statuses
.iter()
.all(|s| { s.module_hash().unwrap() == ledgers_archive_wasm_hash }));
.all(|s| { s.module_hash().unwrap() != deployed_version.archive_wasm_hash }));

// After checking version stuff, ensure proposal executed (not failed)
state_test_helpers::sns_wait_for_proposal_execution(&machine, governance, proposal_id);
Expand Down
6 changes: 6 additions & 0 deletions rs/rosetta-api/icp_ledger/archive/BUILD.bazel
@@ -1,5 +1,6 @@
load("@rules_rust//rust:defs.bzl", "rust_test")
load("//bazel:canisters.bzl", "rust_canister")
load("//bazel:defs.bzl", "gzip_compress")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -33,6 +34,11 @@ rust_canister(
],
)

gzip_compress(
name = "ledger_archive_node_canister.wasm.gz",
srcs = [":ledger-archive-node-canister-wasm"],
)

rust_test(
name = "ledger_archive_node_test",
crate = "_wasm_ledger-archive-node-canister-wasm",
Expand Down
8 changes: 4 additions & 4 deletions rs/rosetta-api/icp_ledger/ledger/BUILD.bazel
Expand Up @@ -11,14 +11,14 @@ rust_library(
"src/tests.rs",
],
compile_data = [
"//rs/rosetta-api/icp_ledger/archive:ledger-archive-node-canister-wasm",
"//rs/rosetta-api/icp_ledger/archive:ledger_archive_node_canister.wasm.gz",
],
crate_name = "ledger_canister",
proc_macro_deps = [
"@crate_index//:async-trait",
],
rustc_env = {
"LEDGER_ARCHIVE_NODE_CANISTER_WASM_PATH": "$(execpath //rs/rosetta-api/icp_ledger/archive:ledger-archive-node-canister-wasm)",
"LEDGER_ARCHIVE_NODE_CANISTER_WASM_PATH": "$(execpath //rs/rosetta-api/icp_ledger/archive:ledger_archive_node_canister.wasm.gz)",
},
version = "0.8.0",
deps = [
Expand All @@ -44,11 +44,11 @@ rust_library(
rust_test(
name = "ledger_test",
compile_data = [
"//rs/rosetta-api/icp_ledger/archive:ledger-archive-node-canister-wasm",
"//rs/rosetta-api/icp_ledger/archive:ledger_archive_node_canister.wasm.gz",
],
crate = ":ledger",
rustc_env = {
"LEDGER_ARCHIVE_NODE_CANISTER_WASM_PATH": "$(execpath //rs/rosetta-api/icp_ledger/archive:ledger-archive-node-canister-wasm)",
"LEDGER_ARCHIVE_NODE_CANISTER_WASM_PATH": "$(execpath //rs/rosetta-api/icp_ledger/archive:ledger_archive_node_canister.wasm.gz)",
},
)

Expand Down
6 changes: 6 additions & 0 deletions rs/rosetta-api/icrc1/archive/BUILD.bazel
@@ -1,5 +1,6 @@
load("@rules_rust//rust:defs.bzl", "rust_test")
load("//bazel:canisters.bzl", "rust_canister")
load("//bazel:defs.bzl", "gzip_compress")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -30,6 +31,11 @@ rust_canister(
],
)

gzip_compress(
name = "archive_canister.wasm.gz",
srcs = [":archive_canister"],
)

rust_test(
name = "archive_test",
crate = ":_wasm_archive_canister",
Expand Down
8 changes: 4 additions & 4 deletions rs/rosetta-api/icrc1/ledger/BUILD.bazel
Expand Up @@ -10,14 +10,14 @@ rust_library(
"src/lib.rs",
],
compile_data = [
"//rs/rosetta-api/icrc1/archive:archive_canister.wasm",
"//rs/rosetta-api/icrc1/archive:archive_canister.wasm.gz",
],
crate_name = "ic_icrc1_ledger",
proc_macro_deps = [
"@crate_index//:async-trait",
],
rustc_env = {
"IC_ICRC1_ARCHIVE_WASM_PATH": "$(execpath //rs/rosetta-api/icrc1/archive:archive_canister.wasm)",
"IC_ICRC1_ARCHIVE_WASM_PATH": "$(execpath //rs/rosetta-api/icrc1/archive:archive_canister.wasm.gz)",
},
version = "0.8.0",
deps = [
Expand Down Expand Up @@ -81,12 +81,12 @@ rust_test(
":ledger_canister.wasm",
"//rs/canister_sandbox",
"//rs/canister_sandbox/sandbox_launcher",
"//rs/rosetta-api/icrc1/archive:archive_canister.wasm",
"//rs/rosetta-api/icrc1/archive:archive_canister.wasm.gz",
],
env = {
"CARGO_MANIFEST_DIR": "rs/rosetta-api/icrc1/ledger",
"IC_ICRC1_LEDGER_WASM_PATH": "$(rootpath :ledger_canister.wasm)",
"IC_ICRC1_ARCHIVE_WASM_PATH": "$(rootpath //rs/rosetta-api/icrc1/archive:archive_canister.wasm)",
"IC_ICRC1_ARCHIVE_WASM_PATH": "$(rootpath //rs/rosetta-api/icrc1/archive:archive_canister.wasm.gz)",
"LAUNCHER_BINARY": "$(rootpath //rs/canister_sandbox/sandbox_launcher)",
"SANDBOX_BINARY": "$(rootpath //rs/canister_sandbox)",
},
Expand Down

0 comments on commit f9136d1

Please sign in to comment.