Skip to content
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: Use subscriptions for storageDiff #161

Merged
merged 9 commits into from
Nov 15, 2024
Merged

archive: Use subscriptions for storageDiff #161

merged 9 commits into from
Nov 15, 2024

Conversation

lexnv
Copy link
Contributor

@lexnv lexnv commented Nov 4, 2024

This PR modifies the archive_unstable_storageDiff as a subscription instead of a method.

The change mainly leverages subscriptions' backpressure without implementing a low-level API by the RPC crates.

This is a followup from:

cc @paritytech/subxt-team

pkhry
pkhry previously approved these changes Nov 5, 2024

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? 🤔

jsdw
jsdw previously approved these changes Nov 5, 2024
Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

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

LGTM, just a small wording tweak suggestion.

I would still like to see whether @tomaka has any further thoughts, but my general feeling is that this change is worth doing.

I also wonder how consistent this should be with archive_storage. That call contains a paginationStartKey param which I don't fully understand (given it appears to return everything at once). Should it also be a subscription so that it's able to stream the possibly large set of values found from a users request (again, rather than building up such a set in memory and then sending the whole thing)?

@lexnv lexnv dismissed stale reviews from jsdw and pkhry via c2112e3 November 5, 2024 16:13
niklasad1
niklasad1 previously approved these changes Nov 7, 2024

- `items` (optional): Array of objects. The structure of these objects is found below.
- `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.

```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!)


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

jsdw
jsdw previously approved these changes Nov 15, 2024
Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

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

This LGTM modulo moving the itesm description back under the items bulelt point (#161 (comment)) :)

@lexnv lexnv dismissed stale reviews from jsdw and niklasad1 via c87d0c7 November 15, 2024 16:02
@lexnv lexnv merged commit e3d9dd3 into main Nov 15, 2024
3 checks passed
@lexnv lexnv deleted the lexnv/archive-sub branch November 15, 2024 16:03
github-merge-queue bot pushed a commit to paritytech/polkadot-sdk that referenced this pull request Nov 27, 2024
This PR implements the `archive_unstable_storageDiff`.

The implementation follows the rpc-v2 spec from:
-  paritytech/json-rpc-interface-spec#159.
- builds on top of
paritytech/json-rpc-interface-spec#161

cc @paritytech/subxt-team

---------

Signed-off-by: Alexandru Vasile <[email protected]>
Co-authored-by: James Wilson <[email protected]>
lexnv added a commit to paritytech/polkadot-sdk that referenced this pull request Nov 29, 2024
This PR implements the `archive_unstable_storageDiff`.

The implementation follows the rpc-v2 spec from:
-  paritytech/json-rpc-interface-spec#159.
- builds on top of
paritytech/json-rpc-interface-spec#161

cc @paritytech/subxt-team

---------

Signed-off-by: Alexandru Vasile <[email protected]>
Co-authored-by: James Wilson <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants