-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
archive: Introduce archive_storageDiff for indexers #159
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5922d71
archive: Introduce archive_storageDiff
lexnv 6c8e970
archive: Stop the store diff subscription
lexnv 7e20f5f
archive: Add ability to continue storage diff
lexnv 70515bc
archive: Rename currentHash->hash and fromHash->previousHash
lexnv 9fe2b32
archive: Remove leftover comment
lexnv aeb19a0
archive: Remove `excludeKeyPrefixes` param
lexnv ee2a8c1
archive: Clarify hash parameter wrt storage diff calculation
lexnv 7aeb735
archive: Make previousHash ancestor of hash
lexnv 82d4245
archive: Make subscription into a method
lexnv c7921f6
archive: Support multiple childTrie queries
lexnv f059c18
archive: Add a bit more details
lexnv e40142b
archive: Extend error section
lexnv e1d08ad
archive: Remove prefixes array
lexnv 821093d
archive: Adjust return object fields
lexnv 1f8854b
archive: Remove concept of subscription
lexnv d87aa84
archive: Remove none return Type
lexnv 9390a22
archive: Remove null from childTrieKey
lexnv 1ed910f
archive: Remove trieType type from example
lexnv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# archive_unstable_storageDiff | ||
|
||
**Parameters**: | ||
|
||
- `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. | ||
|
||
```json | ||
"items": [ | ||
{ | ||
"key": "0x...", | ||
"returnType": "value" | "hash", | ||
"childTrieKey": "0x...", | ||
}, | ||
] | ||
``` | ||
|
||
If the `items` parameter is not provided, the storage difference is calculated for all keys of the main storage trie. | ||
|
||
Each element in `items` must be an object containing the following fields: | ||
|
||
- `key` (optional): String containing a hexadecimal-encoded key prefix. Only the storage entries whose key starts with the provided prefix are returned. If this field is not present, the storage difference is calculated for all keys of the trie. | ||
- `returnType`: String indicating the return type of the storage under the given `key`. The possible values are: | ||
- `value`: The result contains the hexadecimal-encoded value of the storage entry. | ||
- `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. | ||
|
||
The JSON object returned by this function has the following format: | ||
|
||
```json | ||
{ | ||
"result": [ | ||
{ | ||
"key": "0x...", | ||
"value": "0x...", | ||
"hash": "0x...", | ||
"type": "added" | "modified" | "deleted", | ||
"childTrieKey": "0x...", | ||
} | ||
], | ||
} | ||
``` | ||
|
||
The `result` field contains an array of objects, each containing a JSON object: | ||
|
||
- `key`: String containing the hexadecimal-encoded key of the storage entry. A prefix of this key may have been provided in the items input. | ||
|
||
- `value` (optional): String containing the hexadecimal-encoded value of the storage entry. This field is present when the `returnType` field in the `items` parameter is set to `value`. | ||
|
||
- `hash` (optional): String containing the hexadecimal-encoded hash of the storage entry. This field is present when the `returnType` field in the `items` parameter is set to `hash`. | ||
|
||
- `type`: String indicating the type of the storage difference. The possible values are: | ||
- `added`: The storage entry was added. | ||
- `modified`: The storage entry was modified. | ||
- `deleted`: The storage entry was deleted. | ||
|
||
- `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. | ||
|
||
## 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. | ||
|
||
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 | ||
lexnv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- 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). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we did the above, we'd also tweak this to be a single array whose entries contained a "childTrieKey" if one was provided in the input for that key ie
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see that "prefixes" is optional. If it's not provided, is the point that this method will provide all chanegs in the whole trie?
So either this suggestion wouldn't allow that, or one could set a key like "0x" (or not provide one) to indicate that we are searching for diffs under everything in that trie? (This would allow for the type to be specified I guess too, which isn't currently possible if no prefixes are given)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I think the API looks cleaner with this suggestion, I made the
key
optional instead of0x
🙏