Skip to content
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

feat: new System API ic0.subnet_self #3790

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/references/ic-interface-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -7229,6 +7244,11 @@ ic0.canister_self_copy<es>(dst : I, offset : I, size : I) =
if es.context = s then Trap {cycles_used = es.cycles_used;}
copy_to_canister<es>(dst, offset, size, es.wasm_state.self_id)

I ∈ {i32, i64}
ic0.subnet_self_copy<es>(dst : I, offset : I, size : I) =
if es.context = s then Trap {cycles_used = es.cycles_used;}
copy_to_canister<es>(dst, offset, size, es.wasm_state.self_id)
mraszyk marked this conversation as resolved.
Show resolved Hide resolved

ic0.canister_cycle_balance<es>() : i64 =
if es.context = s then Trap {cycles_used = es.cycles_used;}
if es.balance >= 2^64 then Trap {cycles_used = es.cycles_used;}
Expand Down
Loading