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

chainHead: Sync events with spec #14654

Merged
merged 6 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 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, NetworkConfig, StorageQuery};
use crate::chain_head::event::{ChainHeadEvent, FollowEvent, StorageQuery};
use jsonrpsee::{core::RpcResult, proc_macros::rpc};

#[rpc(client, server)]
Expand Down Expand Up @@ -52,12 +52,7 @@ pub trait ChainHeadApi<Hash> {
unsubscribe = "chainHead_unstable_stopBody",
item = ChainHeadEvent<String>,
)]
fn chain_head_unstable_body(
&self,
follow_subscription: String,
hash: Hash,
network_config: Option<NetworkConfig>,
);
fn chain_head_unstable_body(&self, follow_subscription: String, hash: Hash);

/// Retrieves the header of a pinned block.
///
Expand Down Expand Up @@ -102,7 +97,6 @@ pub trait ChainHeadApi<Hash> {
hash: Hash,
items: Vec<StorageQuery<String>>,
child_trie: Option<String>,
network_config: Option<NetworkConfig>,
);

/// Call into the Runtime API at a specified block's state.
Expand All @@ -121,7 +115,6 @@ pub trait ChainHeadApi<Hash> {
hash: Hash,
function: String,
call_parameters: String,
network_config: Option<NetworkConfig>,
);

/// Unpin a block reported by the `follow` method.
Expand Down
12 changes: 4 additions & 8 deletions client/rpc-spec-v2/src/chain_head/chain_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
api::ChainHeadApiServer,
chain_head_follow::ChainHeadFollower,
error::Error as ChainHeadRpcError,
event::{ChainHeadEvent, ChainHeadResult, ErrorEvent, FollowEvent, NetworkConfig},
event::{ChainHeadEvent, ChainHeadResult, ErrorEvent, FollowEvent},
hex_string,
subscription::{SubscriptionManagement, SubscriptionManagementError},
},
Expand Down Expand Up @@ -205,7 +205,6 @@ where
mut sink: SubscriptionSink,
follow_subscription: String,
hash: Block::Hash,
_network_config: Option<NetworkConfig>,
) -> SubscriptionResult {
let client = self.client.clone();
let subscriptions = self.subscriptions.clone();
Expand Down Expand Up @@ -294,7 +293,6 @@ where
hash: Block::Hash,
items: Vec<StorageQuery<String>>,
child_trie: Option<String>,
_network_config: Option<NetworkConfig>,
) -> SubscriptionResult {
// Gain control over parameter parsing and returned error.
let items = items
Expand Down Expand Up @@ -327,7 +325,7 @@ where
Ok(block) => block,
Err(SubscriptionManagementError::SubscriptionAbsent) => {
// Invalid invalid subscription ID.
let _ = sink.send(&ChainHeadStorageEvent::<String>::Disjoint);
let _ = sink.send(&ChainHeadStorageEvent::Disjoint);
return Ok(())
},
Err(SubscriptionManagementError::BlockHashAbsent) => {
Expand All @@ -336,9 +334,8 @@ where
return Ok(())
},
Err(error) => {
let _ = sink.send(&ChainHeadStorageEvent::<String>::Error(ErrorEvent {
error: error.to_string(),
}));
let _ = sink
.send(&ChainHeadStorageEvent::Error(ErrorEvent { error: error.to_string() }));
return Ok(())
},
};
Expand All @@ -362,7 +359,6 @@ where
hash: Block::Hash,
function: String,
call_parameters: String,
_network_config: Option<NetworkConfig>,
) -> SubscriptionResult {
let call_parameters = Bytes::from(parse_hex_param(&mut sink, call_parameters)?);

Expand Down
20 changes: 9 additions & 11 deletions client/rpc-spec-v2/src/chain_head/chain_head_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ fn is_key_queryable(key: &[u8]) -> bool {
}

/// The result of making a query call.
type QueryResult = Result<Option<StorageResult<String>>, ChainHeadStorageEvent<String>>;
type QueryResult = Result<Option<StorageResult>, ChainHeadStorageEvent>;

/// The result of iterating over keys.
type QueryIterResult = Result<Vec<StorageResult<String>>, ChainHeadStorageEvent<String>>;
type QueryIterResult = Result<Vec<StorageResult>, ChainHeadStorageEvent>;

impl<Client, Block, BE> ChainHeadStorage<Client, Block, BE>
where
Expand All @@ -96,13 +96,13 @@ where

result
.map(|opt| {
QueryResult::Ok(opt.map(|storage_data| StorageResult::<String> {
QueryResult::Ok(opt.map(|storage_data| StorageResult {
key: hex_string(&key.0),
result: StorageResultType::Value(hex_string(&storage_data.0)),
}))
})
.unwrap_or_else(|err| {
QueryResult::Err(ChainHeadStorageEvent::<String>::Error(ErrorEvent {
QueryResult::Err(ChainHeadStorageEvent::Error(ErrorEvent {
error: err.to_string(),
}))
})
Expand All @@ -123,13 +123,13 @@ where

result
.map(|opt| {
QueryResult::Ok(opt.map(|storage_data| StorageResult::<String> {
QueryResult::Ok(opt.map(|storage_data| StorageResult {
key: hex_string(&key.0),
result: StorageResultType::Hash(hex_string(&storage_data.as_ref())),
}))
})
.unwrap_or_else(|err| {
QueryResult::Err(ChainHeadStorageEvent::<String>::Error(ErrorEvent {
QueryResult::Err(ChainHeadStorageEvent::Error(ErrorEvent {
error: err.to_string(),
}))
})
Expand All @@ -148,9 +148,7 @@ where
} else {
self.client.storage_keys(hash, Some(key), None)
}
.map_err(|err| {
ChainHeadStorageEvent::<String>::Error(ErrorEvent { error: err.to_string() })
})?;
.map_err(|err| ChainHeadStorageEvent::Error(ErrorEvent { error: err.to_string() }))?;

let mut ret = Vec::with_capacity(MAX_ITER_ITEMS);
let mut keys_iter = keys_iter.take(MAX_ITER_ITEMS);
Expand Down Expand Up @@ -178,7 +176,7 @@ where
) {
if let Some(child_key) = child_key.as_ref() {
if !is_key_queryable(child_key.storage_key()) {
let _ = sink.send(&ChainHeadStorageEvent::<String>::Done);
let _ = sink.send(&ChainHeadStorageEvent::Done);
return
}
}
Expand Down Expand Up @@ -242,6 +240,6 @@ where
let _ = sink.send(&event);
}

let _ = sink.send(&ChainHeadStorageEvent::<String>::Done);
let _ = sink.send(&ChainHeadStorageEvent::Done);
}
}
Loading