From a83730a46fd2c723dd3d0b784cb897afd3835fde Mon Sep 17 00:00:00 2001 From: Martin Raszyk Date: Wed, 20 Nov 2024 17:59:18 +0100 Subject: [PATCH 1/4] feat: new System API ic0.subnet_self --- docs/references/ic-interface-spec.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index e22d82385f..8b49c11638 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -1455,6 +1455,9 @@ defaulting to `I = i32` if the canister declares no memory. ic0.canister_status : () -> i32; // * ic0.canister_version : () -> i64; // * + ic0.subnet_self_size : () -> I; // * + ic0.subnet_self_copy : (dst : I, offset : I, size : I) -> (); // * + ic0.msg_method_name_size : () -> I; // F ic0.msg_method_name_copy : (dst : I, offset : I, size : I) -> (); // F ic0.accept_message : () -> (); // F @@ -1656,6 +1659,12 @@ A canister can learn about its own identity: These functions allow the canister to query its own canister id (as a blob). +A canister can learn about the subnet it is running on: + +- `ic0.subnet_self_size : () → I` and `ic0.subnet_self_copy: (dst : I, offset : I, size : I) → ()`; `I ∈ {i32, i64}` + + These functions allow the canister to query the subnet id (as a blob) of the subnet on which the canister is running. + ### Canister status {#system-api-canister-status} This function allows a canister to find out if it is running, stopping or stopped (see [IC method](#ic-canister_status) and [IC method](#ic-stop_canister) for context). @@ -3177,6 +3186,7 @@ The [WebAssembly System API](#system-api) is relatively low-level, and some of i memory_usage_chunk_store : Nat; memory_usage_snapshot : Nat; freezing_threshold : Nat; + subnet_id : Principal; subnet_size : Nat; certificate : NoCertificate | Blob; status : Running | Stopping | Stopped; @@ -3756,6 +3766,7 @@ is_effective_canister_id(E.content, ECID) memory_usage_chunk_store = memory_usage_chunk_store(S.chunk_store[E.content.canister_id]); memory_usage_snapshot = memory_usage_snapshot(S.snapshots[E.content.canister_id]); freezing_threshold = S.freezing_threshold[E.content.canister_id]; + subnet_id = S.canister_subnet[E.content.canister_id].subnet_id; subnet_size = S.canister_subnet[E.content.canister_id].subnet_size; certificate = NoCertificate; status = simple_status(S.canister_status[E.content.canister_id]); @@ -4060,6 +4071,7 @@ Env = { memory_usage_chunk_store = memory_usage_chunk_store(S.chunk_store[M.receiver]); memory_usage_snapshot = memory_usage_snapshot(S.snapshots[M.receiver]); freezing_threshold = S.freezing_threshold[M.receiver]; + subnet_id = S.canister_subnet[M.receiver].subnet_id; subnet_size = S.canister_subnet[M.receiver].subnet_size; certificate = NoCertificate; status = simple_status(S.canister_status[M.receiver]); @@ -4801,6 +4813,7 @@ Env = { memory_usage_chunk_store = memory_usage_chunk_store(New_chunk_store); memory_usage_snapshot = memory_usage_snapshot(S.snapshots[A.canister_id]); freezing_threshold = S.freezing_threshold[A.canister_id]; + subnet_id = S.canister_subnet[A.canister_id].subnet_id; subnet_size = S.canister_subnet[A.canister_id].subnet_size; certificate = NoCertificate; status = simple_status(S.canister_status[A.canister_id]); @@ -4920,6 +4933,7 @@ Env = { memory_usage_chunk_store = memory_usage_chunk_store(S.chunk_store[A.canister_id]); memory_usage_snapshot = memory_usage_snapshot(S.snapshots[A.canister_id]); freezing_threshold = S.freezing_threshold[A.canister_id]; + subnet_id = S.canister_subnet[A.canister_id].subnet_id; subnet_size = S.canister_subnet[A.canister_id].subnet_size; certificate = NoCertificate; status = simple_status(S.canister_status[A.canister_id]); @@ -6313,6 +6327,7 @@ composite_query_helper(S, Cycles, Depth, Root_canister_id, Caller, Canister_id, memory_usage_chunk_store = memory_usage_chunk_store(S.chunk_store[Canister_id]); memory_usage_snapshot = memory_usage_snapshot(S.snapshots[Canister_id]); freezing_threshold = S.freezing_threshold[Canister_id]; + subnet_id = S.canister_subnet[Canister_id].subnet_id; subnet_size = S.canister_subnet[Canister_id].subnet_size; certificate = Cert; status = simple_status(S.canister_status[Canister_id]); @@ -7229,6 +7244,11 @@ ic0.canister_self_copy(dst : I, offset : I, size : I) = if es.context = s then Trap {cycles_used = es.cycles_used;} copy_to_canister(dst, offset, size, es.wasm_state.self_id) +I ∈ {i32, i64} +ic0.subnet_self_copy(dst : I, offset : I, size : I) = + if es.context = s then Trap {cycles_used = es.cycles_used;} + copy_to_canister(dst, offset, size, es.wasm_state.self_id) + ic0.canister_cycle_balance() : i64 = if es.context = s then Trap {cycles_used = es.cycles_used;} if es.balance >= 2^64 then Trap {cycles_used = es.cycles_used;} From 180f8f027f48fdeabea3c4ace210d189b975a33e Mon Sep 17 00:00:00 2001 From: mraszyk <31483726+mraszyk@users.noreply.github.com> Date: Wed, 29 Jan 2025 11:17:31 +0100 Subject: [PATCH 2/4] Update docs/references/ic-interface-spec.md --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 8b49c11638..4204b19f27 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -7247,7 +7247,7 @@ ic0.canister_self_copy(dst : I, offset : I, size : I) = I ∈ {i32, i64} ic0.subnet_self_copy(dst : I, offset : I, size : I) = if es.context = s then Trap {cycles_used = es.cycles_used;} - copy_to_canister(dst, offset, size, es.wasm_state.self_id) + copy_to_canister(dst, offset, size, es.params.sysenv.subnet_id) ic0.canister_cycle_balance() : i64 = if es.context = s then Trap {cycles_used = es.cycles_used;} From 25fd0915e782a70f8ac60dc70e618d5fcf6bd876 Mon Sep 17 00:00:00 2001 From: Martin Raszyk Date: Tue, 4 Feb 2025 20:48:38 +0100 Subject: [PATCH 3/4] ic0.subnet_self_size --- docs/references/ic-interface-spec.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 4204b19f27..57929f7d98 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -7244,6 +7244,11 @@ ic0.canister_self_copy(dst : I, offset : I, size : I) = if es.context = s then Trap {cycles_used = es.cycles_used;} copy_to_canister(dst, offset, size, es.wasm_state.self_id) +I ∈ {i32, i64} +ic0.subnet_self_size() : I = + if es.context = s then Trap {cycles_used = es.cycles_used;} + return |es.params.sysenv.subnet_id| + I ∈ {i32, i64} ic0.subnet_self_copy(dst : I, offset : I, size : I) = if es.context = s then Trap {cycles_used = es.cycles_used;} From 596bccd267e6f85bad18b0473e5eb4ae1270c0c0 Mon Sep 17 00:00:00 2001 From: Martin Raszyk Date: Fri, 7 Feb 2025 08:23:47 +0100 Subject: [PATCH 4/4] changelog --- docs/references/_attachments/interface-spec-changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/references/_attachments/interface-spec-changelog.md b/docs/references/_attachments/interface-spec-changelog.md index 2d3c0fc653..ab8c9ed910 100644 --- a/docs/references/_attachments/interface-spec-changelog.md +++ b/docs/references/_attachments/interface-spec-changelog.md @@ -1,5 +1,8 @@ ## Changelog {#changelog} +### 0.33.0 (2025-02-12) {#0_33_0} +* New system API `ic0.subnet_self_size` and `ic0.subnet_self_copy`. + ### 0.32.0 (2025-01-23) {#0_32_0} * Allow accepting and burning cycles in replicated queries.