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

Initial spec changes for query stats feature #183

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
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
6 changes: 6 additions & 0 deletions spec/_attachments/ic.did
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ service ic : {
memory_size: nat;
cycles: nat;
idle_cycles_burned_per_day: nat;
query_stats: vec record {
mraszyk marked this conversation as resolved.
Show resolved Hide resolved
num_calls: nat;
num_instructions: nat;
num_request_payload_bytes: nat;
num_response_payload_bytes: nat;
};
});
canister_info : (record {
canister_id : canister_id;
Expand Down
46 changes: 46 additions & 0 deletions spec/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,16 @@ Indicates various information about the canister. It contains:

- The cycle balance of the canister.

- Statistics regarding the query execution of the canister, i.e., a record containing the following fields:

* `num_queries`: the total number of query calls evaluated on the canister,

* `num_instructions`: the total number of WebAssembly instructions executed during the evaluation of query calls on the canister,

* `num_request_payload_bytes`: the total number of query call request payload (query argument) bytes, and

* `num_response_payload_bytes`: the total number of query call response payload (reply data or reject message) bytes.

Only the controllers of the canister or the canister itself can request its status.

### IC method `canister_info` {#ic-canister-info}
Expand Down Expand Up @@ -2908,6 +2918,12 @@ Finally, we can describe the state of the IC as a record having the following fi
total_num_changes : Nat;
recent_changes : [Change];
}
QueryStats = {
timestamp : Timestamp;
num_instructions : Nat;
num_request_payload_bytes : Nat;
num_response_payload_bytes : Nat;
}
Subnet = {
subnet_id : Principal;
subnet_size : Nat;
Expand All @@ -2927,6 +2943,7 @@ Finally, we can describe the state of the IC as a record having the following fi
balances: CanisterId ↦ Nat;
certified_data: CanisterId ↦ Blob;
canister_history: CanisterId ↦ CanisterHistory;
query_stats: CanisterId ↦ [QueryStats];
system_time : Timestamp
call_contexts : CallId ↦ CallCtxt;
messages : List Message; // ordered!
Expand Down Expand Up @@ -2972,6 +2989,7 @@ The initial state of the IC is
balances = ();
certified_data = ();
canister_history = ();
query_stats = ();
system_time = T;
call_contexts = ();
messages = [];
Expand Down Expand Up @@ -3728,6 +3746,7 @@ S with
freezing_threshold[CanisterId] = New_freezing_threshold
balances[CanisterId] = M.transferred_cycles
certified_data[CanisterId] = ""
query_stats[CanisterId] = []
canister_history[CanisterId] = New_canister_history
messages = Older_messages · Younger_messages ·
ResponseMessage {
Expand Down Expand Up @@ -3893,12 +3912,18 @@ S with
S.freezing_threshold[A.canister_id],
S.canister_subnet[A.canister_id].subnet_size,
);
query_stats = noise(SUM {(1, num_instructions, num_request_payload_bytes, num_response_payload_bytes) |
(t, num_instructions, num_request_payload_bytes, num_response_payload_bytes) <- S.query_stats[A.canister_id]
t <= S.time[A.canister_id] - T})
})
refunded_cycles = M.transferred_cycles
}

```

where `T` is an unspecified time delay of query statistics and `noise` is an unspecified probabilistic function
modelling information loss due to aggregating query statistics in a distributed system.

#### IC Management Canister: Canister information

Every canister can retrieve the canister history, current module hash, and current controllers of every other canister (including itself).
Expand Down Expand Up @@ -4605,6 +4630,7 @@ S with
balances[A.canister_id] = (deleted)
certified_data[A.canister_id] = (deleted)
canister_history[A.canister_id] = (deleted)
query_stats[A.canister_id] = (deleted)
messages = Older_messages · Younger_messages ·
ResponseMessage {
origin = M.origin
Expand Down Expand Up @@ -4757,6 +4783,7 @@ S with
balances[Canister_id] = New_balance
certified_data[Canister_id] = ""
canister_history[Canister_id] = New_canister_history
query_stats[CanisterId] = []
messages = Older_messages · Younger_messages ·
ResponseMessage {
origin = M.origin
Expand Down Expand Up @@ -5226,6 +5253,25 @@ verify_response(Q, R, Cert') ∧ lookup(["time"], Cert') = Found S.system_time /

```

State after

```html

S with
query_stats[Q.receiver] = S.query_stats[Q.receiver] · {
timestamp = S.time[Q.receiver]
num_instructions = NumInstructions
num_request_payload_bytes = |Q.Arg|
num_response_payload_bytes =
if composite_query_helper(S, MAX_CYCLES_PER_QUERY, 0, Q.canister_id, Q.sender, Q.canister_id, Q.method_name, Q.arg) = (Reject (RejectCode, RejectMsg), _) then |RejectMsg|
else if composite_query_helper(S, MAX_CYCLES_PER_QUERY, 0, Q.canister_id, Q.sender, Q.canister_id, Q.method_name, Q.arg) = (Reply Res, _) then |Res|
}

```

where `NumInstructions` is the unspecified number of WebAssembly instructions executed during the evaluation of the query call,
i.e., the value of `ic0.performance_counter(0)` at the end of the query method execution.
mraszyk marked this conversation as resolved.
Show resolved Hide resolved

#### Certified state reads

:::note
Expand Down