feat: abstract over consumption of different RPC flavors#1177
feat: abstract over consumption of different RPC flavors#1177harrysolovay wants to merge 9 commits intomainfrom
Conversation
There was a problem hiding this comment.
TODO: get rid of this spec before merging
kratico
left a comment
There was a problem hiding this comment.
This is great!!!
When I try smoldot, I noticed that
- the first
chainHead_unstable_storagecalls yielded a fewinaccessiblebefore giving a successful value. chainHead_unstable_followstopcould happen at any time, and it will require to get a newfollowIdbefore attempting a newchainHead_unstable_storage
| nonce(ss58Address: string) { | ||
| return this.archiveConsumer.nonce(ss58Address) | ||
| } |
There was a problem hiding this comment.
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.
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.
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.
there are other events that we need to think how to handle
waiting-for-continue, tricky because.valuesPendingcan be resolved only onceinaccessible, retry a few times and reject?error, rejectdisjoint, reject

Heavily WIP
Introduces
Consumers, 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 theConnectitself. 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
ExperimentalRpcAPI 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.