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

feat(sync-call): [IC-1666] Endpoint for synchronous call requests #265

Merged
merged 50 commits into from
Sep 12, 2024
Merged
Changes from 8 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
38162d7
.
DSharifi Jan 11, 2024
8011384
First draft completed
DSharifi Jan 11, 2024
b87114c
.
DSharifi Jan 11, 2024
6fb43ff
.
DSharifi Jan 11, 2024
4fee649
.
DSharifi Jan 11, 2024
407f4bb
.
DSharifi Jan 11, 2024
e290147
.
DSharifi Jan 11, 2024
cfe5325
.
DSharifi Jan 11, 2024
4ff0235
Apply suggestions from code review
DSharifi Jan 12, 2024
a99ed43
Added need for polling for non happy path flows
DSharifi Jan 12, 2024
47b8478
Removed note
DSharifi Jan 12, 2024
4153579
Apply suggestions from code review
DSharifi Jan 16, 2024
89b2b9f
Apply suggestions from code review
DSharifi Jan 16, 2024
be5fd51
Removed enumeration of steps, and made reply/reject share `200` statu…
DSharifi Jan 16, 2024
ccf598d
Move back note to async call
DSharifi Jan 16, 2024
abd5688
.
DSharifi Jan 16, 2024
d8e3883
Added `status` field and updated where "/call" is found
DSharifi Jan 18, 2024
d0772ee
Moved request status to the reply section.
DSharifi Jan 18, 2024
07a4614
Removed "asynchronous" categorization for call requests
DSharifi Jan 23, 2024
d9df0eb
reformulate
mraszyk Jan 29, 2024
bdb833d
.
DSharifi Feb 8, 2024
34a9d45
Merge branch 'dsharifi/sync-update-call' of github.com:dfinity/interf…
DSharifi Feb 8, 2024
cd2e407
Changed deadline to 1 execution round
DSharifi Feb 29, 2024
816a366
.
DSharifi Feb 29, 2024
c9abb9e
Renamed to v3 for api path
DSharifi Apr 17, 2024
5f3ad3d
.
DSharifi Apr 17, 2024
af07a3a
.
DSharifi Apr 17, 2024
92db4e1
,
DSharifi Apr 17, 2024
89b2f9a
.
DSharifi Apr 17, 2024
930d29a
.
DSharifi Apr 17, 2024
6d09d85
.
DSharifi Apr 17, 2024
f1a7653
.
DSharifi Apr 18, 2024
81e96aa
.
DSharifi Apr 18, 2024
e62d423
Merge remote-tracking branch 'origin/master' into dsharifi/sync-updat…
DSharifi Apr 18, 2024
8e1c58e
.
DSharifi Apr 18, 2024
8e59368
.
DSharifi Apr 18, 2024
9ccb5cb
.
DSharifi Apr 18, 2024
1a9bb4e
.
DSharifi Apr 18, 2024
88fa8c2
.
DSharifi Apr 18, 2024
fa6c78e
.
DSharifi Apr 18, 2024
79b6f50
.
DSharifi Apr 18, 2024
a497bbc
Apply suggestions from code review
DSharifi Apr 22, 2024
53f8b13
Removed too specific status for pre-execution errors
DSharifi Apr 23, 2024
d0f7c04
Changed state to status for transition
DSharifi Apr 23, 2024
64507d0
202 empty body, and no certificate
DSharifi Apr 28, 2024
3190f34
Merge branch 'master' into dsharifi/sync-update-call
mraszyk Jun 23, 2024
d6edfe5
Merge branch 'master' into dsharifi/sync-update-call
mraszyk Jul 4, 2024
10d061b
clarify
mraszyk Sep 12, 2024
1841eda
Merge branch 'master' into dsharifi/sync-update-call
mraszyk Sep 12, 2024
9edd9de
changelog
mraszyk Sep 12, 2024
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
75 changes: 74 additions & 1 deletion spec/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ The concrete mechanism that users use to send requests to the Internet Computer

- At `/api/v2/canister/<effective_canister_id>/call` the user can submit (asynchronous, potentially state-changing) calls.

- At `/api/v2/canister/<effective_canister_id>/sync_call` the user can submit (synchronous, potentially state-changing) calls.

- At `/api/v2/canister/<effective_canister_id>/read_state` or `/api/v2/subnet/<subnet_id>/read_state` the user can read various information about the state of the Internet Computer. In particular, they can poll for the status of a call here.

- At `/api/v2/canister/<effective_canister_id>/query` the user can perform (synchronous, non-state-changing) query calls.
Expand All @@ -554,7 +556,13 @@ This document does not yet explain how to find the location and port of the Inte

### Overview of canister calling {#http-call-overview}

Users interact with the Internet Computer by calling canisters. By the very nature of a blockchain protocol, they cannot be acted upon immediately, but only with a delay. Moreover, the actual node that the user talks to may not be honest or, for other reasons, may fail to get the request on the way. This implies the following high-level workflow:
Users interact with the Internet Computer by calling canisters. By the very nature of a blockchain protocol, they cannot be acted upon immediately, but only with a delay. Moreover, the actual node that the user talks to may not be honest or, for other reasons, may fail to get the request on the way.

The Internet Computer has two HTTPS APIs for canister calling:
- [*Asynchronous*](#http-async-call) canister calling, where the user must poll the Internet Computer for the status of the request.
- [*Synchronous*](#http-sync-call) canister calling, where the user waits for a certified response from the Internet Computer for the initial call.
DSharifi marked this conversation as resolved.
Show resolved Hide resolved

#### Asynchronous canister calling {#http-async-call}

1. A user submits a call via the [HTTPS Interface](#http-interface). No useful information is returned in the immediate response (as such information cannot be trustworthy anyways).

Expand Down Expand Up @@ -613,6 +621,27 @@ Calls must stay in `replied` or `rejected` long enough for polling users to catc

When asking the IC about the state or call of a request, the user uses the request id (see [Request ids](#request-id)) to read the request status (see [Request status](#state-tree-request-status)) from the state tree (see [Request: Read state](#http-read-state)).

#### Synchronous canister calling {#http-sync-call}
mraszyk marked this conversation as resolved.
Show resolved Hide resolved

Unlike asynchronous canister calling, synchronous canister calling does not require the user to poll the Internet Computer for the status of the request. Instead, the user waits for a certified response from the Internet Computer for the initial call. However, The state transitions and semantics of the call are the same as for asynchronous canister calling.
DSharifi marked this conversation as resolved.
Show resolved Hide resolved

1. A user submits a synchronous call via the [HTTPS Interface](#http-interface).

2. The IC asks the targeted canister if it is willing to accept this message and be charged for the expense of processing it. This uses the [Ingress message inspection](#system-api-inspect-message) API for normal calls. For calls to the management canister, the rules in [The IC management canister](#ic-management-canister) apply.
DSharifi marked this conversation as resolved.
Show resolved Hide resolved

3. At some point, the IC may accept the call for processing and set its status to `received`. This indicates that the IC as a whole has received the call and plans on processing it (although it may still not get processed if the IC is under high load).
DSharifi marked this conversation as resolved.
Show resolved Hide resolved

4. If the call is processed (sufficient resources, call not yet expired), it will be executed, for some calls this may be atomic, for others this involves multiple internal steps.
DSharifi marked this conversation as resolved.
Show resolved Hide resolved

5. Eventually, a response will be produced which will be replied the user. The response can be a `reply`, indicating success, a `reject`, indicating some form of error.
DSharifi marked this conversation as resolved.
Show resolved Hide resolved

6. In the case that the call has been retained for long enough before a response is generated, but the request has not expired yet, the IC can forget the response data and only remember the call as `done`, to prevent a replay attack.
mraszyk marked this conversation as resolved.
Show resolved Hide resolved

7. The user can also afterwards retrieve the state of the request via the [HTTPS Interface](#http-interface) for a certain amount of time.

8. Once the expiry time is past, the IC can prune the call and its response, and completely forget about it.


### Request: Call {#http-call}

In order to call a canister, the user makes a POST request to `/api/v2/canister/<effective_canister_id>/call`. The request body consists of an authentication envelope with a `content` map with the following fields:
Expand Down Expand Up @@ -651,6 +680,50 @@ The functionality exposed via the [The IC management canister](#ic-management-ca

:::

### Request: Sync Call {#http-sync-call}
A synchronous update call, or "call and await", is a type of update [call](#http-call) where the replica will wait with replying to the user until the call has been processed and the result has been added to the replicated state. This means the user will receive a certified result of the call, and thus __do not need to poll__ [`read_state`](#http-read-state) to determine the status of the call.
DSharifi marked this conversation as resolved.
Show resolved Hide resolved
In order to make a synchronous update call to a canister, the user makes a POST request to `/api/v2/canister/<effective_canister_id>/sync_call`. The request body consists of an authentication envelope with a `content` map with the following fields:

- `request_type` (`text`): Always `sync-call`
DSharifi marked this conversation as resolved.
Show resolved Hide resolved

- `sender`, `nonce`, `ingress_expiry`: See [Authentication](#authentication)

- `canister_id` (`blob`): The principal of the canister to call.

- `method_name` (`text`): Name of the canister method to call

- `arg` (`blob`): Argument to pass to the canister method

The HTTP response to this request can have the following responses:

- 202 HTTP status with a non-empty body. Implying the request was processed.
DSharifi marked this conversation as resolved.
Show resolved Hide resolved
- `response` (`blob`): A certificate (see [Certification](#certification)).

The returned certificate includes the subtree at `/request_status/<request_id>` and `/time`.
DSharifi marked this conversation as resolved.
Show resolved Hide resolved

- 200 HTTP status with a non-empty body. Implying an execution pre-processing error occurred. The body of the response contains more information about the IC specific error encountered. The body is a CBOR map with the following fields:

- `reject_code` (`nat`): The reject code (see [Reject codes](#reject-codes)).

- `reject_message` (`text`): a textual diagnostic message.

- `error_code` (`text`): an optional implementation-specific textual error code (see [Error codes](#error-codes)).

- 4xx HTTP status for client errors (e.g. malformed request). Except for 429 HTTP status, retrying the request will likely have the same outcome.

- 5xx HTTP status when the server has encountered an error or is otherwise incapable of performing the request. The request might succeed if retried at a later time.

This request type can *also* be used to call a query method (but not a composite query method). A user may choose to go this way, instead of via the faster and cheaper [Request: Query call](#http-query) below, if they want to get a *certified* response. Note that the canister state will not be changed by sending a call request type for a query method (except for cycle balance change due to message execution).

:::note

The functionality exposed via the [The IC management canister](#ic-management-canister) can be used this way.
mraszyk marked this conversation as resolved.
Show resolved Hide resolved

:::

See [The system state tree](#state-tree) for details on the state tree.
DSharifi marked this conversation as resolved.
Show resolved Hide resolved


### Request: Read state {#http-read-state}

:::note
Expand Down
Loading