-
Notifications
You must be signed in to change notification settings - Fork 9
feat: abstract over consumption of different RPC flavors #1177
base: main
Are you sure you want to change the base?
Conversation
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.
TODO: get rid of this spec before merging
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.
This is great!!!
When I try smoldot, I noticed that
- the first
chainHead_unstable_storage
calls yielded a fewinaccessible
before giving a successful value. chainHead_unstable_follow
stop
could happen at any time, and it will require to get a newfollowId
before attempting a newchainHead_unstable_storage
nonce(ss58Address: string) { | ||
return this.archiveConsumer.nonce(ss58Address) | ||
} |
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.
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.
There a note in the docs for chainHead_unstable_call
Note: This can be used as a replacement for the legacy state_getMetadata, system_accountNextIndex, and payment_queryInfo functions.
https://paritytech.github.io/json-rpc-interface-spec/api/chainHead_unstable_call.html
this.subscription<{ event: "items"; items: { key: string; value: string }[] }>( | ||
"chainHead_unstable_storage", | ||
"chainHead_unstable_stopStorage", | ||
[followId, blockHash, items, null], |
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.
I'm not sure if the docs are outdated or if the polkadot
/substrate
API implementation is not complete.
Passing a single hex encoded key works.
Something like
this.subscription<{ event: "items"; items: { key: string; value: string }[] }>(
"chainHead_unstable_storage",
"chainHead_unstable_stopStorage",
[followId, blockHash, items[0]?.key[0], null],
(message) => {
And the response is something like
<<< {
message: {
jsonrpc: "2.0",
method: "chainHead_unstable_storage",
params: {
subscription: "x1sMLqhwCWeg7QBJ",
result: {
event: "done",
result: "0x000000000000000001000000000000004035323d3400000000000000000000000000000000000000000000000000000000"... 62 more characters
}
}
}
}
It seems that the chainHead_unstable_storage
is working for single key reads
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.
Investigated this API spec updates and the multiple item support was documented 3 weeks ago
See paritytech/json-rpc-interface-spec@bea1a60
Smoldot hasn't been updated as it supports a single item request
See https://github.com/paritytech/smoldot/blob/938055a638ec201c022f680c8e8cbd0349e70ed1/bin/light-base/src/json_rpc_service/chain_head.rs#L874
And I guess substrate
is in the same state
if (keys.length) { | ||
const items = keys.map((key) => ({ key, type: "value" })) | ||
const controller = new AbortController() | ||
this.subscription<{ event: "items"; items: { key: string; value: string }[] }>( |
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.
there are other events that we need to think how to handle
waiting-for-continue
, tricky because.valuesPending
can be resolved only onceinaccessible
, retry a few times and reject?error
, rejectdisjoint
, reject
Heavily WIP
Introduces
Consumer
s, which provide a standard layer on top of different RPC APIs (the current and the experimental). This will allow us to decouple the fluent API from RPC specifics (and therefore ease the transition to Smoldot). The end DX may look as follows.The
ExperimentalRpc
(aConsumer
) wraps theConnect
itself. The consumer is then passed into the chain rune factory, so that the chain rune can operate with an RPC-unspecific API.For now, the
ExperimentalRpc
API accepts an additional argument: a non-smoldotConnect
. This is necessary for retrieving historical block info. It seems thearchive
-prefixed methods of the new JSON RPC spec are yet to be implemented for any chains (?). Seems a bit far-fetched... but a GitHub-wide search revealed no such clues.