From efdf401c70965cbefc683b0c39c63f90e96dd983 Mon Sep 17 00:00:00 2001 From: bogwar <51327868+bogwar@users.noreply.github.com> Date: Wed, 27 Sep 2023 19:58:00 +0200 Subject: [PATCH 1/2] System API method in_replicated_execution --- spec/index.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/index.md b/spec/index.md index 52e693c71..82773907c 100644 --- a/spec/index.md +++ b/spec/index.md @@ -1308,6 +1308,7 @@ The following sections describe various System API functions, also referred to a ic0.global_timer_set : (timestamp : i64) -> i64; // I G U Ry Rt C T ic0.performance_counter : (counter_type : i32) -> (counter : i64); // * s ic0.is_controller: (src: i32, size: i32) -> ( result: i32); // * s + ic0.in_replicated_execution: () -> (result: i32); // * ic0.debug_print : (src : i32, size : i32) -> (); // * s ic0.trap : (src : i32, size : i32) -> (); // * s @@ -1757,6 +1758,14 @@ The system resets the counter at the beginning of each [Entry points](#entry-poi The main purpose of this counter is to facilitate in-canister performance profiling. +### Replicated execution check {#system-api-replicated-execution-check} + +The canister can check whether it is currently running in replicated or non replicated execution. + +`ic0.in_replicated_execution : () -> (result: i32)` + +Returns 1 if the canister is being run in replicated mode and 0 otherwise. + ### Controller check {#system-api-controller-check} The canister can check whether a given principal is one of its controllers. @@ -5921,6 +5930,12 @@ The pseudo-code below does *not* explicitly enforce the restrictions of which im else Trap {cycles_used = es.cycles_used;} + ic0.in_replicated_execution() : i32 = + if es.context = s then Trap {cycles_used = es.cycles_used;} + if es.params.sysenv.certificate = NoCertificate + then return 1 + else return 0 + ic0.debug_print(src : i32, size : i32) = return From 59c8eebc8a4f050f06226b6915c36a7e38d231c1 Mon Sep 17 00:00:00 2001 From: bogwar <51327868+bogwar@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:31:18 +0200 Subject: [PATCH 2/2] introduce replicated/non-replicated mode in the Nomenclature section --- spec/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/index.md b/spec/index.md index 82773907c..7035c4f7e 100644 --- a/spec/index.md +++ b/spec/index.md @@ -76,7 +76,8 @@ The public entry points of canisters are called *methods*. Methods can be declar Methods can be *called*, from *caller* to *callee*, and will eventually incur a *response* which is either a *reply* or a *reject*. A method may have *parameters*, which are provided with concrete *arguments* in a method call. -External calls can be update calls, which can *only* call update and query methods, and query calls, which can *only* call query and composite query methods. Inter-canister calls issued while evaluating an update call can call update and query methods (just like update calls). Inter-canister calls issued while evaluating a query call (to a composite query method) can call query and composite query methods (just like query calls). Note that calls from a canister to itself also count as "inter-canister". +External calls can be update calls, which can *only* call update and query methods, and query calls, which can *only* call query and composite query methods. Inter-canister calls issued while evaluating an update call can call update and query methods (just like update calls). Inter-canister calls issued while evaluating a query call (to a composite query method) can call query and composite query methods (just like query calls). Note that calls from a canister to itself also count as "inter-canister". Update and query call offer a security/efficiency trade-off. +Update calls are executed in *replicated* mode, i.e. execution takes place in parallel on multiple replicas who need to arrive at a consensus on what the result of the call is. Query calls are fast but offer less guarantees since they are executed in *non-replicated* mode, by a single replica. Internally, a call or a response is transmitted as a *message* from a *sender* to a *receiver*. Messages do not have a response.