-
Notifications
You must be signed in to change notification settings - Fork 2.6k
frame/utils: introduce substrate-rpc-client
crate for RPC utils
#12212
Conversation
utils/frame/rpc-utils/src/lib.rs
Outdated
use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; | ||
use std::collections::VecDeque; | ||
|
||
pub use jsonrpsee::{ |
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.
is there actually any logic change here as well?
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 have increased connection timeout
and request timeout
but nothing else.
In addition I removed this keep connection
stuff completely instead if one wants make a request then a client needs instantiated otherwise it's not possible to get access the RPC trait stuff from the macros.
utils/frame/rpc-utils/src/lib.rs
Outdated
} | ||
|
||
#[async_trait] | ||
impl<Block: BlockT> HeaderSubscription<Block> for Subscription<Block::Header> |
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.
Don't you want this abstraction available do all jsonrpsee users?
although it would make sense to have it here in substrate as well. Better than nothing and better than being ONLY on try-runtime.
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 think it makes most sense to have this one in substrate and not in jsonrpsee but maybe we could have a shared crate where because we need it subxt and perhaps somewhere else :P
We could probably implement it for T
instead of Block::Header
to work
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 looks good to me, just reshuffling things around for better usability.
What I really want to explore someday, and if it doesn't have an issue you should make one for it, are a set of extension traits that bridge the gap between a frame storage item tyoe and jsonrpsee.
Imagine you import the EMP
pallet, and from it you fetch the #[pallet::storage] type CurrentPhase = ...
. Imagine you had some extension trait that allowed you to do CurrentPhase::get_remote(...)
and it would get this value for you from a remove node.
The nice thing here is that the storage item itself knows how to build its key, which is all we need from it, and then we directly pass that key to jsonrpsee
under the hood to fetch.
Although, now that I have uttered this out, I think the future of Rust tooling for substrate is less and less importing pallets directly and using pallet types from subxt.
I had this idea almost 2 years ago. I think things have changed too much in the meantime :D
TBH I don't think the |
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
The annoying thing is that |
@niklasad1 I was about to start working on cleaning up |
rpc-utils
cratesubstrate-rpc-client
crate with shared RPC stuff
Yeah, it should cover both step 2 and 3. |
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.
generally, for me, it looks quite well, surely it is a step into right direction
regarding these long type specifiers, I'm afraid that some macro is the only easy way of removing such opaque calls; or we could provide some type shortcuts for common Block
types
impl<B: BlockT> Builder<B> | ||
where | ||
B::Hash: DeserializeOwned, | ||
B::Header: DeserializeOwned, |
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.
it might be helpful to create a DeserializableBlock
trait with all such constraints
The reason why these type params are needed is because the |
Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions. |
substrate-rpc-client
crate with shared RPC stuffsubstrate-rpc-client
crate for RPC utils
yes |
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.
approving this, looks broadly good. If we need some further modifications - we could make them within sub-du PR.
bot merge |
@niklasad1 you are no longer using |
Yeah because one must create client to make a request and the client has just to kept just somewhere to maintain the connection. |
I am not into the details of the networking here, but either the logic related to this flag was removed by mistake, or the flag should have been removed too. Having the flag do nothing is wrong. |
Ok, the flag should be removed too then I thought I did that. |
This pull request has been mentioned on Polkadot Forum. There might be relevant details there: https://forum.polkadot.network/t/polkadot-release-analysis/1026/2 |
…ritytech#12212) * hack together a PoC * Update utils/frame/rpc-utils/Cargo.toml Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update utils/frame/rpc-utils/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * rpc_utils -> substrate_rpc_client * try runtime: remove keep connection * make CI happy * cargo fmt * fix ci * update lock file * fix * fix Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: kianenigma <kian@parity.io>
Close #8988
So in general I like this approach of using the
sc-rpc-api
instead of re-defining this stuff all over the place however it requires some super ugly type annotations because the trait itself insc-rpc-api
takes a bunch a trait type params.So for example:
In that cause we only care about
Header
but because the trait itself has 3 other type params that are unused in that call and we don't care about makes the code almost unreadable.I tried this trick:
but it doesn't work because the jsonrpsee traits are not object-safe.
polkadot companion: paritytech/polkadot#6162