Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
chainHead: Produce method responses on chainHead_follow (#14692)
Browse files Browse the repository at this point in the history
* chainHead/api: Make storage/body/call pure RPC methods

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Add mpsc channel between RPC methods

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/subscriptions: Extract mpsc::Sender via BlockGuard

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/subscriptions: Generate and provide the method operation ID

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Generate `chainHead_body` response

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Generate `chainHead_call` response

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Generate `chainHead_storage` responses

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Propagate responses of methods to chainHead_follow

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Adjust `chainHead_body` responses

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Adjust `chainHead_call` responses

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Adjust `chainHead_call` responses

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Ensure unique operation IDs across methods

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/events: Remove old method events

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Return `InvalidBlock` error if pinning fails

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Wrap subscription IDs

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Ensure separate operation IDs across subscriptions

Signed-off-by: Alexandru Vasile <[email protected]>

---------

Signed-off-by: Alexandru Vasile <[email protected]>
Co-authored-by: parity-processbot <>
  • Loading branch information
lexnv authored Aug 8, 2023
1 parent c0ee512 commit 25993e8
Show file tree
Hide file tree
Showing 10 changed files with 664 additions and 495 deletions.
2 changes: 1 addition & 1 deletion client/rpc-spec-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sp-api = { version = "4.0.0-dev", path = "../../primitives/api" }
sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" }
sp-version = { version = "22.0.0", path = "../../primitives/version" }
sc-client-api = { version = "4.0.0-dev", path = "../api" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }
codec = { package = "parity-scale-codec", version = "3.6.1" }
thiserror = "1.0"
serde = "1.0"
Expand All @@ -44,6 +45,5 @@ sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/comm
sp-maybe-compressed-blob = { version = "4.1.0-dev", path = "../../primitives/maybe-compressed-blob" }
sc-block-builder = { version = "0.10.0-dev", path = "../block-builder" }
sc-service = { version = "0.10.0-dev", features = ["test-helpers"], path = "../service" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }
assert_matches = "1.3.0"
pretty_assertions = "1.2.1"
30 changes: 11 additions & 19 deletions client/rpc-spec-v2/src/chain_head/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![allow(non_snake_case)]

//! API trait of the chain head.
use crate::chain_head::event::{ChainHeadEvent, FollowEvent, StorageQuery};
use crate::chain_head::event::{FollowEvent, MethodResponse, StorageQuery};
use jsonrpsee::{core::RpcResult, proc_macros::rpc};

#[rpc(client, server)]
Expand Down Expand Up @@ -47,12 +47,12 @@ pub trait ChainHeadApi<Hash> {
/// # Unstable
///
/// This method is unstable and subject to change in the future.
#[subscription(
name = "chainHead_unstable_body",
unsubscribe = "chainHead_unstable_stopBody",
item = ChainHeadEvent<String>,
)]
fn chain_head_unstable_body(&self, follow_subscription: String, hash: Hash);
#[method(name = "chainHead_unstable_body", blocking)]
fn chain_head_unstable_body(
&self,
follow_subscription: String,
hash: Hash,
) -> RpcResult<MethodResponse>;

/// Retrieves the header of a pinned block.
///
Expand Down Expand Up @@ -86,36 +86,28 @@ pub trait ChainHeadApi<Hash> {
/// # Unstable
///
/// This method is unstable and subject to change in the future.
#[subscription(
name = "chainHead_unstable_storage",
unsubscribe = "chainHead_unstable_stopStorage",
item = ChainHeadEvent<String>,
)]
#[method(name = "chainHead_unstable_storage", blocking)]
fn chain_head_unstable_storage(
&self,
follow_subscription: String,
hash: Hash,
items: Vec<StorageQuery<String>>,
child_trie: Option<String>,
);
) -> RpcResult<MethodResponse>;

/// Call into the Runtime API at a specified block's state.
///
/// # Unstable
///
/// This method is unstable and subject to change in the future.
#[subscription(
name = "chainHead_unstable_call",
unsubscribe = "chainHead_unstable_stopCall",
item = ChainHeadEvent<String>,
)]
#[method(name = "chainHead_unstable_call", blocking)]
fn chain_head_unstable_call(
&self,
follow_subscription: String,
hash: Hash,
function: String,
call_parameters: String,
);
) -> RpcResult<MethodResponse>;

/// Unpin a block reported by the `follow` method.
///
Expand Down
Loading

0 comments on commit 25993e8

Please sign in to comment.