From 670a00ef579279f76a95c9b21ad95333785084c0 Mon Sep 17 00:00:00 2001 From: Ulan Degenbaev Date: Wed, 17 Apr 2024 09:16:49 +0000 Subject: [PATCH] feat: Add `wasm_memory_limit` to the management canister This adds `wasm_memory_limit` to `CanisterSettings` and `DefiniteCanisterSettings`. The corresponding spec change: - https://github.com/dfinity/interface-spec/pull/278 --- e2e-tests/canisters/canister_info.rs | 1 + e2e-tests/canisters/management_caller.rs | 2 ++ src/ic-cdk/CHANGELOG.md | 6 ++++++ src/ic-cdk/src/api/management_canister/main/types.rs | 8 ++++++++ 4 files changed, 17 insertions(+) diff --git a/e2e-tests/canisters/canister_info.rs b/e2e-tests/canisters/canister_info.rs index b04d38a34..33a108b22 100644 --- a/e2e-tests/canisters/canister_info.rs +++ b/e2e-tests/canisters/canister_info.rs @@ -72,6 +72,7 @@ async fn canister_lifecycle() -> Principal { memory_allocation: None, freezing_threshold: None, reserved_cycles_limit: None, + wasm_memory_limit: None, }, canister_id: canister_id.canister_id, }) diff --git a/e2e-tests/canisters/management_caller.rs b/e2e-tests/canisters/management_caller.rs index ecadb4b6b..d9cc7669b 100644 --- a/e2e-tests/canisters/management_caller.rs +++ b/e2e-tests/canisters/management_caller.rs @@ -12,6 +12,7 @@ mod main { memory_allocation: Some(10000u16.into()), freezing_threshold: Some(10000u16.into()), reserved_cycles_limit: Some(10000u16.into()), + wasm_memory_limit: Some(10000u16.into()), }), }; let canister_id = create_canister(arg, 100_000_000_000u128 / 13) @@ -61,6 +62,7 @@ mod provisional { memory_allocation: Some(10000u16.into()), freezing_threshold: Some(10000u16.into()), reserved_cycles_limit: Some(10000u16.into()), + wasm_memory_limit: Some(10000u16.into()), }; let arg = ProvisionalCreateCanisterWithCyclesArgument { amount: Some(1_000_000_000u64.into()), diff --git a/src/ic-cdk/CHANGELOG.md b/src/ic-cdk/CHANGELOG.md index 0532d2f13..31baa54d5 100644 --- a/src/ic-cdk/CHANGELOG.md +++ b/src/ic-cdk/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +### Added + +- Add `wasm_memory_limit` to the management canister API types: + * `CanisterSettings` + * `DefiniteCanisterSettings`. + ## [0.13.2] - 2024-04-08 ### Added diff --git a/src/ic-cdk/src/api/management_canister/main/types.rs b/src/ic-cdk/src/api/management_canister/main/types.rs index 5499c5087..f0bc38e0f 100644 --- a/src/ic-cdk/src/api/management_canister/main/types.rs +++ b/src/ic-cdk/src/api/management_canister/main/types.rs @@ -22,6 +22,12 @@ pub struct CanisterSettings { /// Must be a number between 0 and 2^128^-1, inclusively, and indicates the /// upper limit on cycles in the `reserved_cycles` balance of the canister. pub reserved_cycles_limit: Option, + /// A soft limit on the Wasm memory usage of the canister. Update calls, + /// timers, heartbeats, install, and post-upgrade fail if the Wasm memory + /// usage exceeds this limit. The main purpose of this field is to protect + /// against the case when the canister reaches the hard 4GiB limit. + /// Must be a number between 0 and 2^48^ (i.e 256TB), inclusively. + pub wasm_memory_limit: Option, } /// Argument type of [create_canister](super::create_canister). @@ -281,6 +287,8 @@ pub struct DefiniteCanisterSettings { pub freezing_threshold: Nat, /// Reserved cycles limit. pub reserved_cycles_limit: Nat, + /// The Wasm memory limit. + pub wasm_memory_limit: Nat, } /// Query statistics, returned by [canister_status](super::canister_status).