Skip to content

Commit b2cba40

Browse files
committed
archive: Use subscriptions for storageDiff
Signed-off-by: Alexandru Vasile <[email protected]>
1 parent 9491d90 commit b2cba40

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

src/api/archive_unstable_storageDiff.md

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,41 @@
2828
- `hash`: The result contains the hexadecimal-encoded hash of the storage entry.
2929
- `childTrieKey` (optional): String containing the hexadecimal-encoded key of the child trie of the "default" namespace. If this field is not present, the storage difference is calculated for the main storage trie.
3030

31-
**Return value**: A JSON object.
31+
**Return value**: String containing an opaque value representing the operation.
32+
33+
## Notifications format
34+
35+
This function will later generate one or more notifications in the following format:
36+
37+
```json
38+
{
39+
"jsonrpc": "2.0",
40+
"method": "archive_unstable_storageDiffEvent",
41+
"params": {
42+
"subscription": "...",
43+
"result": ...
44+
}
45+
}
46+
```
47+
48+
Where `subscription` is the value returned by this function, and `result` can be one of:
49+
50+
### storageDiff
3251

3352
The JSON object returned by this function has the following format:
3453

3554
```json
3655
{
37-
"result": [
38-
{
39-
"key": "0x...",
40-
"value": "0x...",
41-
"hash": "0x...",
42-
"type": "added" | "modified" | "deleted",
43-
"childTrieKey": "0x...",
44-
}
45-
],
56+
"event": "storageDiff",
57+
"key": "0x...",
58+
"value": "0x...",
59+
"hash": "0x...",
60+
"type": "added" | "modified" | "deleted",
61+
"childTrieKey": "0x...",
4662
}
4763
```
4864

49-
The `result` field contains an array of objects, each containing a JSON object:
65+
The `storageDiff` event is generated for each storage difference between the two blocks.
5066

5167
- `key`: String containing the hexadecimal-encoded key of the storage entry. A prefix of this key may have been provided in the items input.
5268

@@ -61,11 +77,23 @@ The `result` field contains an array of objects, each containing a JSON object:
6177

6278
- `childTrieKey` (optional): String containing the hexadecimal-encoded key of the child trie of the "default" namespace if the storage entry is part of a child trie. If the storage entry is part of the main trie, this field is not present.
6379

80+
### storageDiffDone
81+
82+
The JSON object returned by this function has the following format:
83+
84+
```json
85+
{
86+
"event": "storageDiffDone",
87+
}
88+
```
89+
90+
This event is always generated after all `storageDiff` events have been generated.
91+
6492
## Overview
6593

6694
This function calculates the storage difference between two blocks. The storage difference is calculated by comparing the storage of the `previousHash` block with the storage of the `hash` block. If the `previousHash` parameter is not provided, the storage difference is calculated between the parent of the `hash` block and the `hash` block.
6795

68-
The JSON-RPC server is encouraged to accept at least one `archive_unstable_storageDiff` method per JSON-RPC client. Trying to make more calls might lead to a JSON-RPC error when calling `archive_unstable_storageDiff`. The JSON-RPC server must return an error code if the server is overloaded and cannot accept new method call.
96+
The JSON-RPC server is encouraged to accept at least one `archive_unstable_storageDiff` subscription per JSON-RPC client. Trying to make more calls might lead to a JSON-RPC error when calling `archive_unstable_storageDiff`. The JSON-RPC server must return an error code if the server is overloaded and cannot accept new subscription call.
6997

7098
Users that want to obtain the storage difference between two blocks should use this function instead of calling `archive_unstable_storage` for each block and comparing the results.
7199
When users are interested in the main trie storage differences, as well as in a child storage difference, they can call this function with `items: [ { "returnType": "value" }, { "returnType": "value", "childTrieKey": "0x..." } ]`.

0 commit comments

Comments
 (0)