diff --git a/client/rpc-api/src/chain/mod.rs b/client/rpc-api/src/chain/mod.rs index f5f9524264e34..c7cc97463983d 100644 --- a/client/rpc-api/src/chain/mod.rs +++ b/client/rpc-api/src/chain/mod.rs @@ -26,24 +26,24 @@ pub mod error; #[rpc(client, server)] pub trait ChainApi { /// Get header. - #[method(name = "chain_getHeader")] - async fn header(&self, hash: Option) -> RpcResult>; + #[method(name = "chain_getHeader", blocking)] + fn header(&self, hash: Option) -> RpcResult>; /// Get header and body of a relay chain block. - #[method(name = "chain_getBlock")] - async fn block(&self, hash: Option) -> RpcResult>; + #[method(name = "chain_getBlock", blocking)] + fn block(&self, hash: Option) -> RpcResult>; /// Get hash of the n-th block in the canon chain. /// /// By default returns latest block hash. - #[method(name = "chain_getBlockHash", aliases = ["chain_getHead"])] + #[method(name = "chain_getBlockHash", aliases = ["chain_getHead"], blocking)] fn block_hash( &self, hash: Option>, ) -> RpcResult>>; /// Get hash of the last finalized block in the canon chain. - #[method(name = "chain_getFinalizedHead", aliases = ["chain_getFinalisedHead"])] + #[method(name = "chain_getFinalizedHead", aliases = ["chain_getFinalisedHead"], blocking)] fn finalized_head(&self) -> RpcResult; /// All head subscription. diff --git a/client/rpc-api/src/child_state/mod.rs b/client/rpc-api/src/child_state/mod.rs index a15b1a0e7ee05..be279a97463b0 100644 --- a/client/rpc-api/src/child_state/mod.rs +++ b/client/rpc-api/src/child_state/mod.rs @@ -28,9 +28,9 @@ use sp_core::storage::{PrefixedStorageKey, StorageData, StorageKey}; #[rpc(client, server)] pub trait ChildStateApi { /// Returns the keys with prefix from a child storage, leave empty to get all the keys - #[method(name = "childstate_getKeys")] + #[method(name = "childstate_getKeys", blocking)] #[deprecated(since = "2.0.0", note = "Please use `getKeysPaged` with proper paging support")] - async fn storage_keys( + fn storage_keys( &self, child_storage_key: PrefixedStorageKey, prefix: StorageKey, @@ -40,8 +40,8 @@ pub trait ChildStateApi { /// Returns the keys with prefix from a child storage with pagination support. /// Up to `count` keys will be returned. /// If `start_key` is passed, return next keys in storage in lexicographic order. - #[method(name = "childstate_getKeysPaged", aliases = ["childstate_getKeysPagedAt"])] - async fn storage_keys_paged( + #[method(name = "childstate_getKeysPaged", aliases = ["childstate_getKeysPagedAt"], blocking)] + fn storage_keys_paged( &self, child_storage_key: PrefixedStorageKey, prefix: Option, @@ -51,8 +51,8 @@ pub trait ChildStateApi { ) -> RpcResult>; /// Returns a child storage entry at a specific block's state. - #[method(name = "childstate_getStorage")] - async fn storage( + #[method(name = "childstate_getStorage", blocking)] + fn storage( &self, child_storage_key: PrefixedStorageKey, key: StorageKey, @@ -60,8 +60,8 @@ pub trait ChildStateApi { ) -> RpcResult>; /// Returns child storage entries for multiple keys at a specific block's state. - #[method(name = "childstate_getStorageEntries")] - async fn storage_entries( + #[method(name = "childstate_getStorageEntries", blocking)] + fn storage_entries( &self, child_storage_key: PrefixedStorageKey, keys: Vec, @@ -69,8 +69,8 @@ pub trait ChildStateApi { ) -> RpcResult>>; /// Returns the hash of a child storage entry at a block's state. - #[method(name = "childstate_getStorageHash")] - async fn storage_hash( + #[method(name = "childstate_getStorageHash", blocking)] + fn storage_hash( &self, child_storage_key: PrefixedStorageKey, key: StorageKey, @@ -78,8 +78,8 @@ pub trait ChildStateApi { ) -> RpcResult>; /// Returns the size of a child storage entry at a block's state. - #[method(name = "childstate_getStorageSize")] - async fn storage_size( + #[method(name = "childstate_getStorageSize", blocking)] + fn storage_size( &self, child_storage_key: PrefixedStorageKey, key: StorageKey, @@ -87,8 +87,8 @@ pub trait ChildStateApi { ) -> RpcResult>; /// Returns proof of storage for child key entries at a specific block's state. - #[method(name = "state_getChildReadProof")] - async fn read_child_proof( + #[method(name = "state_getChildReadProof", blocking)] + fn read_child_proof( &self, child_storage_key: PrefixedStorageKey, keys: Vec, diff --git a/client/rpc-api/src/state/mod.rs b/client/rpc-api/src/state/mod.rs index fba023e830262..54bf21674a8bd 100644 --- a/client/rpc-api/src/state/mod.rs +++ b/client/rpc-api/src/state/mod.rs @@ -34,21 +34,17 @@ pub use self::helpers::ReadProof; #[rpc(client, server)] pub trait StateApi { /// Call a contract at a block's state. - #[method(name = "state_call", aliases = ["state_callAt"])] - async fn call(&self, name: String, bytes: Bytes, hash: Option) -> RpcResult; + #[method(name = "state_call", aliases = ["state_callAt"], blocking)] + fn call(&self, name: String, bytes: Bytes, hash: Option) -> RpcResult; /// Returns the keys with prefix, leave empty to get all the keys. - #[method(name = "state_getKeys")] + #[method(name = "state_getKeys", blocking)] #[deprecated(since = "2.0.0", note = "Please use `getKeysPaged` with proper paging support")] - async fn storage_keys( - &self, - prefix: StorageKey, - hash: Option, - ) -> RpcResult>; + fn storage_keys(&self, prefix: StorageKey, hash: Option) -> RpcResult>; /// Returns the keys with prefix, leave empty to get all the keys - #[method(name = "state_getPairs")] - async fn storage_pairs( + #[method(name = "state_getPairs", blocking)] + fn storage_pairs( &self, prefix: StorageKey, hash: Option, @@ -57,8 +53,8 @@ pub trait StateApi { /// Returns the keys with prefix with pagination support. /// Up to `count` keys will be returned. /// If `start_key` is passed, return next keys in storage in lexicographic order. - #[method(name = "state_getKeysPaged", aliases = ["state_getKeysPagedAt"])] - async fn storage_keys_paged( + #[method(name = "state_getKeysPaged", aliases = ["state_getKeysPagedAt"], blocking)] + fn storage_keys_paged( &self, prefix: Option, count: u32, @@ -67,32 +63,32 @@ pub trait StateApi { ) -> RpcResult>; /// Returns a storage entry at a specific block's state. - #[method(name = "state_getStorage", aliases = ["state_getStorageAt"])] - async fn storage(&self, key: StorageKey, hash: Option) -> RpcResult>; + #[method(name = "state_getStorage", aliases = ["state_getStorageAt"], blocking)] + fn storage(&self, key: StorageKey, hash: Option) -> RpcResult>; /// Returns the hash of a storage entry at a block's state. - #[method(name = "state_getStorageHash", aliases = ["state_getStorageHashAt"])] - async fn storage_hash(&self, key: StorageKey, hash: Option) -> RpcResult>; + #[method(name = "state_getStorageHash", aliases = ["state_getStorageHashAt"], blocking)] + fn storage_hash(&self, key: StorageKey, hash: Option) -> RpcResult>; /// Returns the size of a storage entry at a block's state. - #[method(name = "state_getStorageSize", aliases = ["state_getStorageSizeAt"])] - async fn storage_size(&self, key: StorageKey, hash: Option) -> RpcResult>; + #[method(name = "state_getStorageSize", aliases = ["state_getStorageSizeAt"], blocking)] + fn storage_size(&self, key: StorageKey, hash: Option) -> RpcResult>; /// Returns the runtime metadata as an opaque blob. - #[method(name = "state_getMetadata")] - async fn metadata(&self, hash: Option) -> RpcResult; + #[method(name = "state_getMetadata", blocking)] + fn metadata(&self, hash: Option) -> RpcResult; /// Get the runtime version. - #[method(name = "state_getRuntimeVersion", aliases = ["chain_getRuntimeVersion"])] - async fn runtime_version(&self, hash: Option) -> RpcResult; + #[method(name = "state_getRuntimeVersion", aliases = ["chain_getRuntimeVersion"], blocking)] + fn runtime_version(&self, hash: Option) -> RpcResult; /// Query historical storage entries (by key) starting from a block given as the second /// parameter. /// /// NOTE This first returned result contains the initial state of storage for all keys. /// Subsequent values in the vector represent changes to the previous state (diffs). - #[method(name = "state_queryStorage")] - async fn query_storage( + #[method(name = "state_queryStorage", blocking)] + fn query_storage( &self, keys: Vec, block: Hash, @@ -100,20 +96,16 @@ pub trait StateApi { ) -> RpcResult>>; /// Query storage entries (by key) starting at block hash given as the second parameter. - #[method(name = "state_queryStorageAt")] - async fn query_storage_at( + #[method(name = "state_queryStorageAt", blocking)] + fn query_storage_at( &self, keys: Vec, at: Option, ) -> RpcResult>>; /// Returns proof of storage entries at a specific block's state. - #[method(name = "state_getReadProof")] - async fn read_proof( - &self, - keys: Vec, - hash: Option, - ) -> RpcResult>; + #[method(name = "state_getReadProof", blocking)] + fn read_proof(&self, keys: Vec, hash: Option) -> RpcResult>; /// New runtime version subscription #[subscription( @@ -285,8 +277,8 @@ pub trait StateApi { /// /// If you are having issues with maximum payload size you can use the flag /// `-ltracing=trace` to get some logging during tracing. - #[method(name = "state_traceBlock")] - async fn trace_block( + #[method(name = "state_traceBlock", blocking)] + fn trace_block( &self, block: Hash, targets: Option, diff --git a/client/rpc/src/chain/chain_full.rs b/client/rpc/src/chain/chain_full.rs index 2d507f7b9b684..c00c6e5875d94 100644 --- a/client/rpc/src/chain/chain_full.rs +++ b/client/rpc/src/chain/chain_full.rs @@ -26,7 +26,7 @@ use futures::{ future::{self, FutureExt}, stream::{self, Stream, StreamExt}, }; -use jsonrpsee::{core::async_trait, PendingSubscription}; +use jsonrpsee::PendingSubscription; use sc_client_api::{BlockBackend, BlockchainEvents}; use sp_blockchain::HeaderBackend; use sp_runtime::{ @@ -51,7 +51,6 @@ impl FullChain { } } -#[async_trait] impl ChainBackend for FullChain where Block: BlockT + 'static, @@ -62,11 +61,11 @@ where &self.client } - async fn header(&self, hash: Option) -> Result, Error> { + fn header(&self, hash: Option) -> Result, Error> { self.client.header(BlockId::Hash(self.unwrap_or_best(hash))).map_err(client_err) } - async fn block(&self, hash: Option) -> Result>, Error> { + fn block(&self, hash: Option) -> Result>, Error> { self.client.block(&BlockId::Hash(self.unwrap_or_best(hash))).map_err(client_err) } diff --git a/client/rpc/src/chain/mod.rs b/client/rpc/src/chain/mod.rs index a79c66e0a18f6..a300c80271fd1 100644 --- a/client/rpc/src/chain/mod.rs +++ b/client/rpc/src/chain/mod.rs @@ -27,10 +27,7 @@ use std::sync::Arc; use crate::SubscriptionTaskExecutor; -use jsonrpsee::{ - core::{async_trait, RpcResult}, - PendingSubscription, -}; +use jsonrpsee::{core::RpcResult, PendingSubscription}; use sc_client_api::BlockchainEvents; use sp_rpc::{list::ListOrValue, number::NumberOrHex}; use sp_runtime::{ @@ -45,7 +42,6 @@ pub use sc_rpc_api::chain::*; use sp_blockchain::HeaderBackend; /// Blockchain backend API -#[async_trait] trait ChainBackend: Send + Sync + 'static where Block: BlockT + 'static, @@ -64,10 +60,10 @@ where } /// Get header of a relay chain block. - async fn header(&self, hash: Option) -> Result, Error>; + fn header(&self, hash: Option) -> Result, Error>; /// Get header and body of a relay chain block. - async fn block(&self, hash: Option) -> Result>, Error>; + fn block(&self, hash: Option) -> Result>, Error>; /// Get hash of the n-th block in the canon chain. /// @@ -126,7 +122,6 @@ pub struct Chain { backend: Box>, } -#[async_trait] impl ChainApiServer, Block::Hash, Block::Header, SignedBlock> for Chain where @@ -134,12 +129,12 @@ where Block::Header: Unpin, Client: HeaderBackend + BlockchainEvents + 'static, { - async fn header(&self, hash: Option) -> RpcResult> { - self.backend.header(hash).await.map_err(Into::into) + fn header(&self, hash: Option) -> RpcResult> { + self.backend.header(hash).map_err(Into::into) } - async fn block(&self, hash: Option) -> RpcResult>> { - self.backend.block(hash).await.map_err(Into::into) + fn block(&self, hash: Option) -> RpcResult>> { + self.backend.block(hash).map_err(Into::into) } fn block_hash( diff --git a/client/rpc/src/state/mod.rs b/client/rpc/src/state/mod.rs index a45651c5e7990..4b5b74950a486 100644 --- a/client/rpc/src/state/mod.rs +++ b/client/rpc/src/state/mod.rs @@ -28,7 +28,7 @@ use std::sync::Arc; use crate::SubscriptionTaskExecutor; use jsonrpsee::{ - core::{async_trait, Error as JsonRpseeError, RpcResult}, + core::{Error as JsonRpseeError, RpcResult}, ws_server::PendingSubscription, }; @@ -53,14 +53,13 @@ use sp_blockchain::{HeaderBackend, HeaderMetadata}; const STORAGE_KEYS_PAGED_MAX_COUNT: u32 = 1000; /// State backend API. -#[async_trait] pub trait StateBackend: Send + Sync + 'static where Block: BlockT + 'static, Client: Send + Sync + 'static, { /// Call runtime method at given block. - async fn call( + fn call( &self, block: Option, method: String, @@ -68,21 +67,21 @@ where ) -> Result; /// Returns the keys with prefix, leave empty to get all the keys. - async fn storage_keys( + fn storage_keys( &self, block: Option, prefix: StorageKey, ) -> Result, Error>; /// Returns the keys with prefix along with their values, leave empty to get all the pairs. - async fn storage_pairs( + fn storage_pairs( &self, block: Option, prefix: StorageKey, ) -> Result, Error>; /// Returns the keys with prefix with pagination support. - async fn storage_keys_paged( + fn storage_keys_paged( &self, block: Option, prefix: Option, @@ -91,14 +90,14 @@ where ) -> Result, Error>; /// Returns a storage entry at a specific block's state. - async fn storage( + fn storage( &self, block: Option, key: StorageKey, ) -> Result, Error>; /// Returns the hash of a storage entry at a block's state. - async fn storage_hash( + fn storage_hash( &self, block: Option, key: StorageKey, @@ -108,24 +107,24 @@ where /// /// If data is available at `key`, it is returned. Else, the sum of values who's key has `key` /// prefix is returned, i.e. all the storage (double) maps that have this prefix. - async fn storage_size( + fn storage_size( &self, block: Option, key: StorageKey, ) -> Result, Error>; /// Returns the runtime metadata as an opaque blob. - async fn metadata(&self, block: Option) -> Result; + fn metadata(&self, block: Option) -> Result; /// Get the runtime version. - async fn runtime_version(&self, block: Option) -> Result; + fn runtime_version(&self, block: Option) -> Result; /// Query historical storage entries (by key) starting from a block given as the second /// parameter. /// /// NOTE This first returned result contains the initial state of storage for all keys. /// Subsequent values in the vector represent changes to the previous state (diffs). - async fn query_storage( + fn query_storage( &self, from: Block::Hash, to: Option, @@ -133,21 +132,21 @@ where ) -> Result>, Error>; /// Query storage entries (by key) starting at block hash given as the second parameter. - async fn query_storage_at( + fn query_storage_at( &self, keys: Vec, at: Option, ) -> Result>, Error>; /// Returns proof of storage entries at a specific block's state. - async fn read_proof( + fn read_proof( &self, block: Option, keys: Vec, ) -> Result, Error>; /// Trace storage changes for block - async fn trace_block( + fn trace_block( &self, block: Block::Hash, targets: Option, @@ -203,39 +202,33 @@ pub struct StateApi { deny_unsafe: DenyUnsafe, } -#[async_trait] impl StateApiServer for StateApi where Block: BlockT + 'static, Client: Send + Sync + 'static, { - async fn call( - &self, - method: String, - data: Bytes, - block: Option, - ) -> RpcResult { - self.backend.call(block, method, data).await.map_err(Into::into) + fn call(&self, method: String, data: Bytes, block: Option) -> RpcResult { + self.backend.call(block, method, data).map_err(Into::into) } - async fn storage_keys( + fn storage_keys( &self, key_prefix: StorageKey, block: Option, ) -> RpcResult> { - self.backend.storage_keys(block, key_prefix).await.map_err(Into::into) + self.backend.storage_keys(block, key_prefix).map_err(Into::into) } - async fn storage_pairs( + fn storage_pairs( &self, key_prefix: StorageKey, block: Option, ) -> RpcResult> { self.deny_unsafe.check_if_safe()?; - self.backend.storage_pairs(block, key_prefix).await.map_err(Into::into) + self.backend.storage_pairs(block, key_prefix).map_err(Into::into) } - async fn storage_keys_paged( + fn storage_keys_paged( &self, prefix: Option, count: u32, @@ -250,66 +243,61 @@ where } self.backend .storage_keys_paged(block, prefix, count, start_key) - .await .map_err(Into::into) } - async fn storage( + fn storage( &self, key: StorageKey, block: Option, ) -> RpcResult> { - self.backend.storage(block, key).await.map_err(Into::into) + self.backend.storage(block, key).map_err(Into::into) } - async fn storage_hash( + fn storage_hash( &self, key: StorageKey, block: Option, ) -> RpcResult> { - self.backend.storage_hash(block, key).await.map_err(Into::into) + self.backend.storage_hash(block, key).map_err(Into::into) } - async fn storage_size( - &self, - key: StorageKey, - block: Option, - ) -> RpcResult> { - self.backend.storage_size(block, key).await.map_err(Into::into) + fn storage_size(&self, key: StorageKey, block: Option) -> RpcResult> { + self.backend.storage_size(block, key).map_err(Into::into) } - async fn metadata(&self, block: Option) -> RpcResult { - self.backend.metadata(block).await.map_err(Into::into) + fn metadata(&self, block: Option) -> RpcResult { + self.backend.metadata(block).map_err(Into::into) } - async fn runtime_version(&self, at: Option) -> RpcResult { - self.backend.runtime_version(at).await.map_err(Into::into) + fn runtime_version(&self, at: Option) -> RpcResult { + self.backend.runtime_version(at).map_err(Into::into) } - async fn query_storage( + fn query_storage( &self, keys: Vec, from: Block::Hash, to: Option, ) -> RpcResult>> { self.deny_unsafe.check_if_safe()?; - self.backend.query_storage(from, to, keys).await.map_err(Into::into) + self.backend.query_storage(from, to, keys).map_err(Into::into) } - async fn query_storage_at( + fn query_storage_at( &self, keys: Vec, at: Option, ) -> RpcResult>> { - self.backend.query_storage_at(keys, at).await.map_err(Into::into) + self.backend.query_storage_at(keys, at).map_err(Into::into) } - async fn read_proof( + fn read_proof( &self, keys: Vec, block: Option, ) -> RpcResult> { - self.backend.read_proof(block, keys).await.map_err(Into::into) + self.backend.read_proof(block, keys).map_err(Into::into) } /// Re-execute the given block with the tracing targets given in `targets` @@ -317,7 +305,7 @@ where /// /// Note: requires the node to run with `--rpc-methods=Unsafe`. /// Note: requires runtimes compiled with wasm tracing support, `--features with-tracing`. - async fn trace_block( + fn trace_block( &self, block: Block::Hash, targets: Option, @@ -327,7 +315,6 @@ where self.deny_unsafe.check_if_safe()?; self.backend .trace_block(block, targets, storage_keys, methods) - .await .map_err(Into::into) } @@ -348,14 +335,13 @@ where } /// Child state backend API. -#[async_trait] pub trait ChildStateBackend: Send + Sync + 'static where Block: BlockT + 'static, Client: Send + Sync + 'static, { /// Returns proof of storage for a child key entries at a specific block's state. - async fn read_child_proof( + fn read_child_proof( &self, block: Option, storage_key: PrefixedStorageKey, @@ -364,7 +350,7 @@ where /// Returns the keys with prefix from a child storage, /// leave prefix empty to get all the keys. - async fn storage_keys( + fn storage_keys( &self, block: Option, storage_key: PrefixedStorageKey, @@ -372,7 +358,7 @@ where ) -> Result, Error>; /// Returns the keys with prefix from a child storage with pagination support. - async fn storage_keys_paged( + fn storage_keys_paged( &self, block: Option, storage_key: PrefixedStorageKey, @@ -382,7 +368,7 @@ where ) -> Result, Error>; /// Returns a child storage entry at a specific block's state. - async fn storage( + fn storage( &self, block: Option, storage_key: PrefixedStorageKey, @@ -390,7 +376,7 @@ where ) -> Result, Error>; /// Returns child storage entries at a specific block's state. - async fn storage_entries( + fn storage_entries( &self, block: Option, storage_key: PrefixedStorageKey, @@ -398,7 +384,7 @@ where ) -> Result>, Error>; /// Returns the hash of a child storage entry at a block's state. - async fn storage_hash( + fn storage_hash( &self, block: Option, storage_key: PrefixedStorageKey, @@ -406,13 +392,13 @@ where ) -> Result, Error>; /// Returns the size of a child storage entry at a block's state. - async fn storage_size( + fn storage_size( &self, block: Option, storage_key: PrefixedStorageKey, key: StorageKey, ) -> Result, Error> { - self.storage(block, storage_key, key).await.map(|x| x.map(|x| x.0.len() as u64)) + self.storage(block, storage_key, key).map(|x| x.map(|x| x.0.len() as u64)) } } @@ -421,25 +407,21 @@ pub struct ChildState { backend: Box>, } -#[async_trait] impl ChildStateApiServer for ChildState where Block: BlockT + 'static, Client: Send + Sync + 'static, { - async fn storage_keys( + fn storage_keys( &self, storage_key: PrefixedStorageKey, key_prefix: StorageKey, block: Option, ) -> RpcResult> { - self.backend - .storage_keys(block, storage_key, key_prefix) - .await - .map_err(Into::into) + self.backend.storage_keys(block, storage_key, key_prefix).map_err(Into::into) } - async fn storage_keys_paged( + fn storage_keys_paged( &self, storage_key: PrefixedStorageKey, prefix: Option, @@ -449,47 +431,46 @@ where ) -> RpcResult> { self.backend .storage_keys_paged(block, storage_key, prefix, count, start_key) - .await .map_err(Into::into) } - async fn storage( + fn storage( &self, storage_key: PrefixedStorageKey, key: StorageKey, block: Option, ) -> RpcResult> { - self.backend.storage(block, storage_key, key).await.map_err(Into::into) + self.backend.storage(block, storage_key, key).map_err(Into::into) } - async fn storage_entries( + fn storage_entries( &self, storage_key: PrefixedStorageKey, keys: Vec, block: Option, ) -> RpcResult>> { - self.backend.storage_entries(block, storage_key, keys).await.map_err(Into::into) + self.backend.storage_entries(block, storage_key, keys).map_err(Into::into) } - async fn storage_hash( + fn storage_hash( &self, storage_key: PrefixedStorageKey, key: StorageKey, block: Option, ) -> RpcResult> { - self.backend.storage_hash(block, storage_key, key).await.map_err(Into::into) + self.backend.storage_hash(block, storage_key, key).map_err(Into::into) } - async fn storage_size( + fn storage_size( &self, storage_key: PrefixedStorageKey, key: StorageKey, block: Option, ) -> RpcResult> { - self.backend.storage_size(block, storage_key, key).await.map_err(Into::into) + self.backend.storage_size(block, storage_key, key).map_err(Into::into) } - async fn read_child_proof( + fn read_child_proof( &self, child_storage_key: PrefixedStorageKey, keys: Vec, @@ -497,7 +478,6 @@ where ) -> RpcResult> { self.backend .read_child_proof(block, child_storage_key, keys) - .await .map_err(Into::into) } } diff --git a/client/rpc/src/state/state_full.rs b/client/rpc/src/state/state_full.rs index 0e20832b30508..c58638c870ab3 100644 --- a/client/rpc/src/state/state_full.rs +++ b/client/rpc/src/state/state_full.rs @@ -28,10 +28,7 @@ use super::{ use crate::SubscriptionTaskExecutor; use futures::{future, stream, FutureExt, StreamExt}; -use jsonrpsee::{ - core::{async_trait, Error as JsonRpseeError}, - PendingSubscription, -}; +use jsonrpsee::{core::Error as JsonRpseeError, PendingSubscription}; use sc_client_api::{ Backend, BlockBackend, BlockchainEvents, CallExecutor, ExecutorProvider, ProofProvider, StorageProvider, @@ -170,7 +167,6 @@ where } } -#[async_trait] impl StateBackend for FullState where Block: BlockT + 'static, @@ -190,7 +186,7 @@ where + 'static, Client::Api: Metadata, { - async fn call( + fn call( &self, block: Option, method: String, @@ -212,7 +208,7 @@ where .map_err(client_err) } - async fn storage_keys( + fn storage_keys( &self, block: Option, prefix: StorageKey, @@ -222,7 +218,7 @@ where .map_err(client_err) } - async fn storage_pairs( + fn storage_pairs( &self, block: Option, prefix: StorageKey, @@ -232,7 +228,7 @@ where .map_err(client_err) } - async fn storage_keys_paged( + fn storage_keys_paged( &self, block: Option, prefix: Option, @@ -251,7 +247,7 @@ where .map_err(client_err) } - async fn storage( + fn storage( &self, block: Option, key: StorageKey, @@ -261,7 +257,7 @@ where .map_err(client_err) } - async fn storage_size( + fn storage_size( &self, block: Option, key: StorageKey, @@ -290,7 +286,7 @@ where .map_err(client_err) } - async fn storage_hash( + fn storage_hash( &self, block: Option, key: StorageKey, @@ -300,7 +296,7 @@ where .map_err(client_err) } - async fn metadata(&self, block: Option) -> std::result::Result { + fn metadata(&self, block: Option) -> std::result::Result { self.block_or_best(block).map_err(client_err).and_then(|block| { self.client .runtime_api() @@ -310,7 +306,7 @@ where }) } - async fn runtime_version( + fn runtime_version( &self, block: Option, ) -> std::result::Result { @@ -321,7 +317,7 @@ where }) } - async fn query_storage( + fn query_storage( &self, from: Block::Hash, to: Option, @@ -337,16 +333,16 @@ where call_fn() } - async fn query_storage_at( + fn query_storage_at( &self, keys: Vec, at: Option, ) -> std::result::Result>, Error> { let at = at.unwrap_or_else(|| self.client.info().best_hash); - self.query_storage(at, Some(at), keys).await + self.query_storage(at, Some(at), keys) } - async fn read_proof( + fn read_proof( &self, block: Option, keys: Vec, @@ -454,7 +450,7 @@ where self.executor.spawn("substrate-rpc-subscription", Some("rpc"), fut.boxed()); } - async fn trace_block( + fn trace_block( &self, block: Block::Hash, targets: Option, @@ -474,7 +470,6 @@ where } } -#[async_trait] impl ChildStateBackend for FullState where Block: BlockT + 'static, @@ -493,7 +488,7 @@ where + 'static, Client::Api: Metadata, { - async fn read_child_proof( + fn read_child_proof( &self, block: Option, storage_key: PrefixedStorageKey, @@ -518,7 +513,7 @@ where .map_err(client_err) } - async fn storage_keys( + fn storage_keys( &self, block: Option, storage_key: PrefixedStorageKey, @@ -536,7 +531,7 @@ where .map_err(client_err) } - async fn storage_keys_paged( + fn storage_keys_paged( &self, block: Option, storage_key: PrefixedStorageKey, @@ -562,7 +557,7 @@ where .map_err(client_err) } - async fn storage( + fn storage( &self, block: Option, storage_key: PrefixedStorageKey, @@ -580,7 +575,7 @@ where .map_err(client_err) } - async fn storage_entries( + fn storage_entries( &self, block: Option, storage_key: PrefixedStorageKey, @@ -595,18 +590,18 @@ where }; let block = self.block_or_best(block).map_err(client_err)?; let client = self.client.clone(); - future::try_join_all(keys.into_iter().map(move |key| { - let res = client - .clone() - .child_storage(&BlockId::Hash(block), &child_info, &key) - .map_err(client_err); - - async move { res } - })) - .await + + keys.into_iter() + .map(move |key| { + client + .clone() + .child_storage(&BlockId::Hash(block), &child_info, &key) + .map_err(client_err) + }) + .collect() } - async fn storage_hash( + fn storage_hash( &self, block: Option, storage_key: PrefixedStorageKey, diff --git a/client/rpc/src/state/tests.rs b/client/rpc/src/state/tests.rs index a375a30d2c1a2..53dd8ebf50499 100644 --- a/client/rpc/src/state/tests.rs +++ b/client/rpc/src/state/tests.rs @@ -61,31 +61,23 @@ async fn should_return_storage() { assert_eq!( client .storage(key.clone(), Some(genesis_hash).into()) - .await .map(|x| x.map(|x| x.0.len())) .unwrap() .unwrap() as usize, VALUE.len(), ); assert_matches!( - client - .storage_hash(key.clone(), Some(genesis_hash).into()) - .await - .map(|x| x.is_some()), + client.storage_hash(key.clone(), Some(genesis_hash).into()).map(|x| x.is_some()), Ok(true) ); + assert_eq!(client.storage_size(key.clone(), None).unwrap().unwrap() as usize, VALUE.len(),); assert_eq!( - client.storage_size(key.clone(), None).await.unwrap().unwrap() as usize, - VALUE.len(), - ); - assert_eq!( - client.storage_size(StorageKey(b":map".to_vec()), None).await.unwrap().unwrap() as usize, + client.storage_size(StorageKey(b":map".to_vec()), None).unwrap().unwrap() as usize, 2 + 3, ); assert_eq!( child .storage(prefixed_storage_key(), key, Some(genesis_hash).into()) - .await .map(|x| x.map(|x| x.0.len())) .unwrap() .unwrap() as usize, @@ -114,7 +106,6 @@ async fn should_return_storage_entries() { assert_eq!( child .storage_entries(prefixed_storage_key(), keys.to_vec(), Some(genesis_hash).into()) - .await .map(|x| x.into_iter().map(|x| x.map(|x| x.0.len()).unwrap()).sum::()) .unwrap(), CHILD_VALUE1.len() + CHILD_VALUE2.len() @@ -126,7 +117,6 @@ async fn should_return_storage_entries() { assert_matches!( child .storage_entries(prefixed_storage_key(), failing_keys, Some(genesis_hash).into()) - .await .map(|x| x.iter().all(|x| x.is_some())), Ok(false) ); @@ -150,17 +140,16 @@ async fn should_return_child_storage() { child_key.clone(), key.clone(), Some(genesis_hash).into(), - ).await, + ), Ok(Some(StorageData(ref d))) if d[0] == 42 && d.len() == 1 ); assert_matches!( child .storage_hash(child_key.clone(), key.clone(), Some(genesis_hash).into(),) - .await .map(|x| x.is_some()), Ok(true) ); - assert_matches!(child.storage_size(child_key.clone(), key.clone(), None).await, Ok(Some(1))); + assert_matches!(child.storage_size(child_key.clone(), key.clone(), None), Ok(Some(1))); } #[tokio::test] @@ -179,7 +168,6 @@ async fn should_return_child_storage_entries() { let res = child .storage_entries(child_key.clone(), keys.clone(), Some(genesis_hash).into()) - .await .unwrap(); assert_matches!( @@ -193,18 +181,12 @@ async fn should_return_child_storage_entries() { if d[0] == 43 && d[1] == 44 && d.len() == 2 ); assert_matches!( - executor::block_on(child.storage_hash( - child_key.clone(), - keys[0].clone(), - Some(genesis_hash).into() - )) - .map(|x| x.is_some()), + child + .storage_hash(child_key.clone(), keys[0].clone(), Some(genesis_hash).into()) + .map(|x| x.is_some()), Ok(true) ); - assert_matches!( - child.storage_size(child_key.clone(), keys[0].clone(), None).await, - Ok(Some(1)) - ); + assert_matches!(child.storage_size(child_key.clone(), keys[0].clone(), None), Ok(Some(1))); } #[tokio::test] @@ -216,9 +198,7 @@ async fn should_call_contract() { use jsonrpsee::{core::Error, types::error::CallError}; assert_matches!( - client - .call("balanceOf".into(), Bytes(vec![1, 2, 3]), Some(genesis_hash).into()) - .await, + client.call("balanceOf".into(), Bytes(vec![1, 2, 3]), Some(genesis_hash).into()), Err(Error::Call(CallError::Failed(_))) ) } @@ -347,7 +327,7 @@ async fn should_query_storage() { let keys = (1..6).map(|k| StorageKey(vec![k])).collect::>(); let result = api.query_storage(keys.clone(), genesis_hash, Some(block1_hash).into()); - assert_eq!(result.await.unwrap(), expected); + assert_eq!(result.unwrap(), expected); // Query all changes let result = api.query_storage(keys.clone(), genesis_hash, None.into()); @@ -360,18 +340,18 @@ async fn should_query_storage() { (StorageKey(vec![5]), Some(StorageData(vec![1]))), ], }); - assert_eq!(result.await.unwrap(), expected); + assert_eq!(result.unwrap(), expected); // Query changes up to block2. let result = api.query_storage(keys.clone(), genesis_hash, Some(block2_hash)); - assert_eq!(result.await.unwrap(), expected); + assert_eq!(result.unwrap(), expected); // Inverted range. let result = api.query_storage(keys.clone(), block1_hash, Some(genesis_hash)); assert_eq!( - result.await.map_err(|e| e.to_string()), + result.map_err(|e| e.to_string()), Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned( 4001, Error::InvalidBlockRange { @@ -392,7 +372,7 @@ async fn should_query_storage() { let result = api.query_storage(keys.clone(), genesis_hash, Some(random_hash1)); assert_eq!( - result.await.map_err(|e| e.to_string()), + result.map_err(|e| e.to_string()), Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned( 4001, Error::InvalidBlockRange { @@ -413,7 +393,7 @@ async fn should_query_storage() { let result = api.query_storage(keys.clone(), random_hash1, Some(genesis_hash)); assert_eq!( - result.await.map_err(|e| e.to_string()), + result.map_err(|e| e.to_string()), Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned( 4001, Error::InvalidBlockRange { @@ -434,7 +414,7 @@ async fn should_query_storage() { let result = api.query_storage(keys.clone(), random_hash1, None); assert_eq!( - result.await.map_err(|e| e.to_string()), + result.map_err(|e| e.to_string()), Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned( 4001, Error::InvalidBlockRange { @@ -455,7 +435,7 @@ async fn should_query_storage() { let result = api.query_storage(keys.clone(), random_hash1, Some(random_hash2)); assert_eq!( - result.await.map_err(|e| e.to_string()), + result.map_err(|e| e.to_string()), Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned( 4001, Error::InvalidBlockRange { @@ -476,7 +456,7 @@ async fn should_query_storage() { let result = api.query_storage_at(keys.clone(), Some(block1_hash)); assert_eq!( - result.await.unwrap(), + result.unwrap(), vec![StorageChangeSet { block: block1_hash, changes: vec![ @@ -506,7 +486,7 @@ async fn should_return_runtime_version() { [\"0xf78b278be53f454c\",2],[\"0xab3c0572291feb8b\",1],[\"0xbc9d89904f5b923f\",1]],\ \"transactionVersion\":1,\"stateVersion\":1}"; - let runtime_version = api.runtime_version(None.into()).await.unwrap(); + let runtime_version = api.runtime_version(None.into()).unwrap(); let serialized = serde_json::to_string(&runtime_version).unwrap(); assert_eq!(serialized, result);