Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #231 from dfinity/bogwar/in_replicated_execution
Browse files Browse the repository at this point in the history
feat: System API method in_replicated_execution
  • Loading branch information
bogwar authored Oct 10, 2023
2 parents d780e54 + 2701491 commit e9cf725
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion spec/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -1338,6 +1339,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
Expand Down Expand Up @@ -1789,6 +1791,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.
Expand Down Expand Up @@ -6146,6 +6156,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<es>() : 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<es>(src : i32, size : i32) =
return

Expand Down

0 comments on commit e9cf725

Please sign in to comment.