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

RPC: Mark storage methods as blocking #11459

Merged
merged 12 commits into from
May 20, 2022
4 changes: 2 additions & 2 deletions client/rpc-api/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ pub mod error;
pub trait ChainApi<Number, Hash, Header, SignedBlock> {
/// Get header.
#[method(name = "chain_getHeader")]
async fn header(&self, hash: Option<Hash>) -> RpcResult<Option<Header>>;
fn header(&self, hash: Option<Hash>) -> RpcResult<Option<Header>>;

/// Get header and body of a relay chain block.
#[method(name = "chain_getBlock")]
async fn block(&self, hash: Option<Hash>) -> RpcResult<Option<SignedBlock>>;
fn block(&self, hash: Option<Hash>) -> RpcResult<Option<SignedBlock>>;
lexnv marked this conversation as resolved.
Show resolved Hide resolved

/// Get hash of the n-th block in the canon chain.
///
Expand Down
28 changes: 14 additions & 14 deletions client/rpc-api/src/child_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use sp_core::storage::{PrefixedStorageKey, StorageData, StorageKey};
#[rpc(client, server)]
pub trait ChildStateApi<Hash> {
/// 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,
Expand All @@ -40,8 +40,8 @@ pub trait ChildStateApi<Hash> {
/// 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<StorageKey>,
Expand All @@ -51,44 +51,44 @@ pub trait ChildStateApi<Hash> {
) -> RpcResult<Vec<StorageKey>>;

/// 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,
hash: Option<Hash>,
) -> RpcResult<Option<StorageData>>;

/// 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<StorageKey>,
hash: Option<Hash>,
) -> RpcResult<Vec<Option<StorageData>>>;

/// 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,
hash: Option<Hash>,
) -> RpcResult<Option<Hash>>;

/// 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,
hash: Option<Hash>,
) -> RpcResult<Option<u64>>;

/// 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<StorageKey>,
Expand Down
58 changes: 25 additions & 33 deletions client/rpc-api/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,17 @@ pub use self::helpers::ReadProof;
#[rpc(client, server)]
pub trait StateApi<Hash> {
/// 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<Hash>) -> RpcResult<Bytes>;
#[method(name = "state_call", aliases = ["state_callAt"], blocking)]
fn call(&self, name: String, bytes: Bytes, hash: Option<Hash>) -> RpcResult<Bytes>;

/// 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<Hash>,
) -> RpcResult<Vec<StorageKey>>;
fn storage_keys(&self, prefix: StorageKey, hash: Option<Hash>) -> RpcResult<Vec<StorageKey>>;

/// 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<Hash>,
Expand All @@ -58,7 +54,7 @@ pub trait StateApi<Hash> {
/// 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(
fn storage_keys_paged(
&self,
prefix: Option<StorageKey>,
count: u32,
Expand All @@ -67,53 +63,49 @@ pub trait StateApi<Hash> {
) -> RpcResult<Vec<StorageKey>>;

/// 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<Hash>) -> RpcResult<Option<StorageData>>;
#[method(name = "state_getStorage", aliases = ["state_getStorageAt"], blocking)]
fn storage(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<StorageData>>;

/// 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<Hash>) -> RpcResult<Option<Hash>>;
#[method(name = "state_getStorageHash", aliases = ["state_getStorageHashAt"], blocking)]
fn storage_hash(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<Hash>>;

/// 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<Hash>) -> RpcResult<Option<u64>>;
#[method(name = "state_getStorageSize", aliases = ["state_getStorageSizeAt"], blocking)]
fn storage_size(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<u64>>;

/// Returns the runtime metadata as an opaque blob.
#[method(name = "state_getMetadata")]
async fn metadata(&self, hash: Option<Hash>) -> RpcResult<Bytes>;
#[method(name = "state_getMetadata", blocking)]
fn metadata(&self, hash: Option<Hash>) -> RpcResult<Bytes>;

/// Get the runtime version.
#[method(name = "state_getRuntimeVersion", aliases = ["chain_getRuntimeVersion"])]
async fn runtime_version(&self, hash: Option<Hash>) -> RpcResult<RuntimeVersion>;
#[method(name = "state_getRuntimeVersion", aliases = ["chain_getRuntimeVersion"], blocking)]
fn runtime_version(&self, hash: Option<Hash>) -> RpcResult<RuntimeVersion>;

/// 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<StorageKey>,
block: Hash,
hash: Option<Hash>,
) -> RpcResult<Vec<StorageChangeSet<Hash>>>;

/// 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<StorageKey>,
at: Option<Hash>,
) -> RpcResult<Vec<StorageChangeSet<Hash>>>;

/// Returns proof of storage entries at a specific block's state.
#[method(name = "state_getReadProof")]
async fn read_proof(
&self,
keys: Vec<StorageKey>,
hash: Option<Hash>,
) -> RpcResult<ReadProof<Hash>>;
#[method(name = "state_getReadProof", blocking)]
fn read_proof(&self, keys: Vec<StorageKey>, hash: Option<Hash>) -> RpcResult<ReadProof<Hash>>;

/// New runtime version subscription
#[subscription(
Expand Down Expand Up @@ -285,8 +277,8 @@ pub trait StateApi<Hash> {
///
/// 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<String>,
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/chain/chain_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ where
&self.client
}

async fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error> {
fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error> {
self.client.header(BlockId::Hash(self.unwrap_or_best(hash))).map_err(client_err)
}

async fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error> {
fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error> {
self.client.block(&BlockId::Hash(self.unwrap_or_best(hash))).map_err(client_err)
}

Expand Down
12 changes: 6 additions & 6 deletions client/rpc/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ where
}

/// Get header of a relay chain block.
async fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error>;
fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error>;

/// Get header and body of a relay chain block.
async fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error>;
fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error>;

/// Get hash of the n-th block in the canon chain.
///
Expand Down Expand Up @@ -134,12 +134,12 @@ where
Block::Header: Unpin,
Client: HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
{
async fn header(&self, hash: Option<Block::Hash>) -> RpcResult<Option<Block::Header>> {
self.backend.header(hash).await.map_err(Into::into)
fn header(&self, hash: Option<Block::Hash>) -> RpcResult<Option<Block::Header>> {
self.backend.header(hash).map_err(Into::into)
}

async fn block(&self, hash: Option<Block::Hash>) -> RpcResult<Option<SignedBlock<Block>>> {
self.backend.block(hash).await.map_err(Into::into)
fn block(&self, hash: Option<Block::Hash>) -> RpcResult<Option<SignedBlock<Block>>> {
self.backend.block(hash).map_err(Into::into)
}

fn block_hash(
Expand Down
Loading