Inter-canister query calls
Ulan Degenbaev, Scalability and Performance WG, 2022-10-20
Background: concepts
?
6
6
6
6
6
9
9
6
?
9
Background: concepts
Query | Update |
Read-only | Modifies state |
Isolated from other queries | Sees changes of other updates |
Supports all execution modes | Replicated execution only |
No calls | Cross- and same-subnet calls |
Background: calls
update
update
query
call
call
query
Goal: allow a query to call another query
update
update
query
call
call
query
call
Consider ICQC as a new type of query
update
update
query
call
query
ICQC
ICQC
ICQC: properties and requirements
| Query | Update | ICQC |
1. | Read-only | Modifies state | Modifies and then discards state |
2. | Isolated from other queries | Sees changes of other updates | Isolated from other queries |
3. | Supports all execution modes | Replicated execution only | Supports all execution modes |
4. | No calls | Cross- and same-subnet calls | Cross- and same-subnet calls |
async fn foo(input: Input) -> Output {
let data = pre_process(input);
let result = call(bar, "query", data).await;
post_process(input, data, result)
}
Query message
Future/task/env
Response callback
6
?
?
?
?
Step 1)
Step 2)
1
2
3
Step 3)
Step 4)
?
behaves like update
behaves like query
!
?
?
?
!
!
!
2. Query isolation
async fn foo(input: Input) -> Output {
destroy_all_global_state()
// No problem for other queries.
}
2. Query isolation
2. Query isolation
2. Query isolation
3. Replicated execution
4. Cross-subnet calls
?
!
?
!
caller_id =
Experimental prototype implementation
The prototype implementation is available on verified application subnets. It is missing:
Implementing (A) is a large engineering effort (1-2 years).
(A) breaks the contract of existing queries: “Every query can be executed in replicated mode.”
Proposal: release the prototype implementation now with a new query type for backwards compatibility
Proposal: Composite Queries
| Query | Update | Composite Query |
1. | Read-only | Modifies state | Modifies and then discards state |
2. | Isolated from other queries | Sees changes of other updates | Isolated from other queries |
3. | Supports all execution modes | Replicated execution only | Non-replicated execution only |
4. | No calls | Cross- and same-subnet calls | Same-subnet calls only |
Proposal: Composite Queries
update
update
query
call
query
composite query
composite query
Proposal: Composite Queries
// Wasm export:
canister_composite_query foo
// Motoko:
public composite_query func foo() : … { … }
// Rust:
#[composite_query]
fn foo() -> … { … }
// Candid:
foo: () -> (…) composite_query;
Next Steps