Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions src/api/archive_unstable_stopStorageDiff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# archive_unstable_stopStorageDiff

**Parameters**:

- An opaque string that was returned by `archive_unstable_storageDiff`.

**Return value**: *null*

Stops a subscription started with `archive_unstable_storageDiff`. Has no effect if the opaque string is invalid or refers to a subscription that has already emitted a `{"event": "storageDiffDone"}` event.

JSON-RPC client implementations must be aware that, due to the asynchronous nature of JSON-RPC client <-> server communication, they might still receive chain updates notifications, for example because these notifications were already in the process of being sent back by the JSON-RPC server.
73 changes: 55 additions & 18 deletions src/api/archive_unstable_storageDiff.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

- `hash`: String containing a hexadecimal-encoded hash of the header of the block whose storage difference will be retrieved.

- `previousHash` (optional): String containing a hexadecimal-encoded hash of the header of the block from which the storage difference will be calculated. The `previousHash` must be an ancestor of the provided `hash`. When this parameter is provided, the storage difference is calculated between the `hash` block and the `previousHash` block. If this parameter is not provided, the storage difference is calculated between the `hash` block and the parent of the `hash` block.

- `items` (optional): Array of objects. The structure of these objects is found below.
- `items`: Array of objects. The structure of these objects is found below.

```json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description of items is now indented and below the previousHash bullet point. Should it be below the items bullet point instead?

(Perhaps move previousHash above items to achieve this, though it makes a bit less sense to me having a "less important" field first!)

"items": [
Expand All @@ -28,25 +26,41 @@
- `hash`: The result contains the hexadecimal-encoded hash of the storage entry.
- `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.

**Return value**: A JSON object.
- `previousHash` (optional): String containing a hexadecimal-encoded hash of the header of the block from which the storage difference will be calculated. The `previousHash` must be an ancestor of the provided `hash`. When this parameter is provided, the storage difference is calculated between the `hash` block and the `previousHash` block. If this parameter is not provided, the storage difference is calculated between the `hash` block and the parent of the `hash` block.

**Return value**: String containing an opaque value representing the operation.

The JSON object returned by this function has the following format:
## Notifications format

This function will later generate one or more notifications in the following format:

```json
{
"result": [
{
"key": "0x...",
"value": "0x...",
"hash": "0x...",
"type": "added" | "modified" | "deleted",
"childTrieKey": "0x...",
}
],
"jsonrpc": "2.0",
"method": "archive_unstable_storageDiffEvent",
"params": {
"subscription": "...",
"result": ...
}
}
```

The `result` field contains an array of objects, each containing a JSON object:
Where `subscription` is the value returned by this function, and `result` can be one of:

### storageDiff
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps just remove this line, since this object is no longer returned by this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the The JSON object returned by this function has the following format. Dq: is that the line mentioned? 🤔


```json
{
"event": "storageDiff",
"key": "0x...",
"value": "0x...",
"hash": "0x...",
"type": "added" | "modified" | "deleted",
"childTrieKey": "0x...",
}
```

The `storageDiff` event is generated for each storage difference between the two blocks.

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

Expand All @@ -61,18 +75,41 @@ The `result` field contains an array of objects, each containing a JSON object:

- `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.

### storageDiffDone

```json
{
"event": "storageDiffDone",
}
```

This event is always generated after all `storageDiff` events have been generated.

No more events will be generated after a `storageDiffDone` event.

### storageDiffError

```json
{
"event": "storageDiffError",
"error": "...",
}
```

`error` is a human-readable error message indicating why the call has failed. This string isn't meant to be shown to end users, but is for developers to understand the problem.

No more events will be generated after a `storageDiffError` event.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at chainHead_v1_storage, and this mentions that operationError notificaitons can be generated, but doesn't actually say anything else about them (nor does it say anything about operationStorageDone: it doesn't appear to promise anything about when it will finish ie will it always end with operationStorageDone or will it also end when operationError is encountered).

We might want to allow multiple storageDiffError events to be emitted (in case some keys are inaccessible or something.) and always end with a storageDiffDone event. One way to work out whether to do this would be opening an issue re what the semantics are supposed to be on chainhead_v1_storage since they are unclear (to me at least): maybe we can reach a consensus that multiple errors can be emitted or maybe this isn't necessary / can't happen!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aahh, I was wrong: operationError and operationDone are explained in the chainHead_v1_follow docs actually! And indeed, in those, operationError signals completion and nothing else will be generated after this.

For now we could be consistent with this then as we are here. We might want to revisit this and allow multiple errors to be emitted htough if errors accessing storage values can happen in practise! (Alternately we could skip any such values in the implementation if they are inaccessible..)


## Overview

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.

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.
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.

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.
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..." } ]`.

## Possible errors

- A JSON-RPC error can be generated if the JSON-RPC client has to many active calls to `archive_unstable_storageDiff`.
- A JSON-RPC error can be generated if the `previousHash` parameter is provided, but the `previousHash` block is not an ancestor of the `hash` block.
- A JSON-RPC error can be generated if one of the hashes provided does not correspond to a known block header hash.
- A JSON-RPC error with error code `-32602` is generated if one of the parameters doesn't correspond to the expected type (similarly to a missing parameter or an invalid parameter type).