removes use of sc_client::Client from sc-rpc (#5063)

* removes use of sc_client::Client from sc-rpc

* remove Client impl from sc-finality-benches

* remove client impl from sc-finality-grandpa

* read_proof accepts iterator

* remove generic Executor param from ExecutorProvider

* fix long ass line

* code style changes

* merge with master

Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
This commit is contained in:
Benjamin Kampmann
2020-03-05 16:41:10 +01:00
committed by GitHub
parent dc85ccb7df
commit 99ae5342eb
34 changed files with 739 additions and 544 deletions
+15 -23
View File
@@ -22,8 +22,7 @@ mod tests;
use std::{sync::Arc, convert::TryInto};
use log::warn;
use sc_client::Client;
use sp_blockchain::Error as ClientError;
use sp_blockchain::{Error as ClientError, HeaderBackend};
use rpc::futures::{
Sink, Future,
@@ -36,7 +35,7 @@ use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use codec::{Encode, Decode};
use sp_core::{Bytes, traits::BareCryptoStorePtr};
use sp_api::ProvideRuntimeApi;
use sp_runtime::{generic, traits};
use sp_runtime::generic;
use sp_transaction_pool::{
TransactionPool, InPoolTransaction, TransactionStatus,
BlockHash, TxHash, TransactionFor, error::IntoPoolError,
@@ -48,9 +47,9 @@ pub use sc_rpc_api::author::*;
use self::error::{Error, FutureResult, Result};
/// Authoring API
pub struct Author<B, E, P, Block: traits::Block, RA> {
pub struct Author<P, Client> {
/// Substrate client
client: Arc<Client<B, E, Block, RA>>,
client: Arc<Client>,
/// Transactions pool
pool: Arc<P>,
/// Subscriptions manager
@@ -59,10 +58,10 @@ pub struct Author<B, E, P, Block: traits::Block, RA> {
keystore: BareCryptoStorePtr,
}
impl<B, E, P, Block: traits::Block, RA> Author<B, E, P, Block, RA> {
impl<P, Client> Author<P, Client> {
/// Create new instance of Authoring API.
pub fn new(
client: Arc<Client<B, E, Block, RA>>,
client: Arc<Client>,
pool: Arc<P>,
subscriptions: Subscriptions,
keystore: BareCryptoStorePtr,
@@ -76,18 +75,11 @@ impl<B, E, P, Block: traits::Block, RA> Author<B, E, P, Block, RA> {
}
}
impl<B, E, P, RA> AuthorApi<TxHash<P>, BlockHash<P>>
for Author<B, E, P, <P as TransactionPool>::Block, RA>
where
B: sc_client_api::backend::Backend<<P as TransactionPool>::Block> + Send + Sync + 'static,
E: sc_client::CallExecutor<<P as TransactionPool>::Block> + Send + Sync + 'static,
P: TransactionPool + Sync + Send + 'static,
P::Block: traits::Block,
P::Error: 'static,
RA: Send + Sync + 'static,
Client<B, E, P::Block, RA>: ProvideRuntimeApi<P::Block>,
<Client<B, E, P::Block, RA> as ProvideRuntimeApi<P::Block>>::Api:
SessionKeys<P::Block, Error = ClientError>,
impl<P, Client> AuthorApi<TxHash<P>, BlockHash<P>> for Author<P, Client>
where
P: TransactionPool + Sync + Send + 'static,
Client: HeaderBackend<P::Block> + ProvideRuntimeApi<P::Block> + Send + Sync + 'static,
Client::Api: SessionKeys<P::Block, Error = ClientError>,
{
type Metadata = crate::metadata::Metadata;
@@ -105,7 +97,7 @@ where
}
fn rotate_keys(&self) -> Result<Bytes> {
let best_block_hash = self.client.chain_info().best_hash;
let best_block_hash = self.client.info().best_hash;
self.client.runtime_api().generate_session_keys(
&generic::BlockId::Hash(best_block_hash),
None,
@@ -113,7 +105,7 @@ where
}
fn has_session_keys(&self, session_keys: Bytes) -> Result<bool> {
let best_block_hash = self.client.chain_info().best_hash;
let best_block_hash = self.client.info().best_hash;
let keys = self.client.runtime_api().decode_session_keys(
&generic::BlockId::Hash(best_block_hash),
session_keys.to_vec(),
@@ -133,7 +125,7 @@ where
Ok(xt) => xt,
Err(err) => return Box::new(result(Err(err.into()))),
};
let best_block_hash = self.client.chain_info().best_hash;
let best_block_hash = self.client.info().best_hash;
Box::new(self.pool
.submit_one(&generic::BlockId::hash(best_block_hash), xt)
.compat()
@@ -176,7 +168,7 @@ where
xt: Bytes,
) {
let submit = || -> Result<_> {
let best_block_hash = self.client.chain_info().best_hash;
let best_block_hash = self.client.info().best_hash;
let dxt = TransactionFor::<P>::decode(&mut &xt[..])
.map_err(error::Error::from)?;
Ok(
+3 -3
View File
@@ -25,8 +25,8 @@ use sp_core::{
};
use rpc::futures::Stream as _;
use substrate_test_runtime_client::{
self, AccountKeyring, runtime::{Extrinsic, Transfer, SessionKeys, RuntimeApi, Block},
DefaultTestClientBuilderExt, TestClientBuilderExt, Backend, Client, Executor,
self, AccountKeyring, runtime::{Extrinsic, Transfer, SessionKeys, Block},
DefaultTestClientBuilderExt, TestClientBuilderExt, Backend, Client,
};
use sc_transaction_pool::{BasicPool, FullChainApi};
use tokio::runtime;
@@ -75,7 +75,7 @@ impl Default for TestSetup {
}
impl TestSetup {
fn author(&self) -> Author<Backend, Executor, FullTransactionPool, Block, RuntimeApi> {
fn author(&self) -> Author<FullTransactionPool, Client<Backend>> {
Author {
client: self.client.clone(),
pool: self.pool.clone(),
+14 -12
View File
@@ -20,37 +20,39 @@ use std::sync::Arc;
use rpc::futures::future::result;
use sc_rpc_api::Subscriptions;
use sc_client_api::{CallExecutor, backend::Backend};
use sc_client::Client;
use sc_client_api::{BlockchainEvents, BlockBody};
use sp_runtime::{generic::{BlockId, SignedBlock}, traits::{Block as BlockT}};
use super::{ChainBackend, client_err, error::FutureResult};
use std::marker::PhantomData;
use sp_blockchain::HeaderBackend;
/// Blockchain API backend for full nodes. Reads all the data from local database.
pub struct FullChain<B, E, Block: BlockT, RA> {
pub struct FullChain<Block: BlockT, Client> {
/// Substrate client.
client: Arc<Client<B, E, Block, RA>>,
client: Arc<Client>,
/// Current subscriptions.
subscriptions: Subscriptions,
/// phantom member to pin the block type
_phantom: PhantomData<Block>,
}
impl<B, E, Block: BlockT, RA> FullChain<B, E, Block, RA> {
impl<Block: BlockT, Client> FullChain<Block, Client> {
/// Create new Chain API RPC handler.
pub fn new(client: Arc<Client<B, E, Block, RA>>, subscriptions: Subscriptions) -> Self {
pub fn new(client: Arc<Client>, subscriptions: Subscriptions) -> Self {
Self {
client,
subscriptions,
_phantom: PhantomData,
}
}
}
impl<B, E, Block, RA> ChainBackend<B, E, Block, RA> for FullChain<B, E, Block, RA> where
impl<Block, Client> ChainBackend<Client, Block> for FullChain<Block, Client> where
Block: BlockT + 'static,
B: Backend<Block> + Send + Sync + 'static,
E: CallExecutor<Block> + Send + Sync + 'static,
RA: Send + Sync + 'static,
Client: BlockBody<Block> + HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
{
fn client(&self) -> &Arc<Client<B, E, Block, RA>> {
fn client(&self) -> &Arc<Client> {
&self.client
}
@@ -60,7 +62,7 @@ impl<B, E, Block, RA> ChainBackend<B, E, Block, RA> for FullChain<B, E, Block, R
fn header(&self, hash: Option<Block::Hash>) -> FutureResult<Option<Block::Header>> {
Box::new(result(self.client
.header(&BlockId::Hash(self.unwrap_or_best(hash)))
.header(BlockId::Hash(self.unwrap_or_best(hash)))
.map_err(client_err)
))
}
+10 -10
View File
@@ -22,7 +22,7 @@ use rpc::futures::future::{result, Future, Either};
use sc_rpc_api::Subscriptions;
use sc_client::{
Client, light::{fetcher::{Fetcher, RemoteBodyRequest}, blockchain::RemoteBlockchain},
light::{fetcher::{Fetcher, RemoteBodyRequest}, blockchain::RemoteBlockchain},
};
use sp_runtime::{
generic::{BlockId, SignedBlock},
@@ -30,12 +30,14 @@ use sp_runtime::{
};
use super::{ChainBackend, client_err, error::FutureResult};
use sp_blockchain::HeaderBackend;
use sc_client_api::BlockchainEvents;
/// Blockchain API backend for light nodes. Reads all the data from local
/// database, if available, or fetches it from remote node otherwise.
pub struct LightChain<B, E, Block: BlockT, RA, F> {
pub struct LightChain<Block: BlockT, Client, F> {
/// Substrate client.
client: Arc<Client<B, E, Block, RA>>,
client: Arc<Client>,
/// Current subscriptions.
subscriptions: Subscriptions,
/// Remote blockchain reference
@@ -44,10 +46,10 @@ pub struct LightChain<B, E, Block: BlockT, RA, F> {
fetcher: Arc<F>,
}
impl<B, E, Block: BlockT, RA, F: Fetcher<Block>> LightChain<B, E, Block, RA, F> {
impl<Block: BlockT, Client, F: Fetcher<Block>> LightChain<Block, Client, F> {
/// Create new Chain API RPC handler.
pub fn new(
client: Arc<Client<B, E, Block, RA>>,
client: Arc<Client>,
subscriptions: Subscriptions,
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
fetcher: Arc<F>,
@@ -61,14 +63,12 @@ impl<B, E, Block: BlockT, RA, F: Fetcher<Block>> LightChain<B, E, Block, RA, F>
}
}
impl<B, E, Block, RA, F> ChainBackend<B, E, Block, RA> for LightChain<B, E, Block, RA, F> where
impl<Block, Client, F> ChainBackend<Client, Block> for LightChain<Block, Client, F> where
Block: BlockT + 'static,
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
E: sc_client::CallExecutor<Block> + Send + Sync + 'static,
RA: Send + Sync + 'static,
Client: BlockchainEvents<Block> + HeaderBackend<Block> + Send + Sync + 'static,
F: Fetcher<Block> + Send + Sync + 'static,
{
fn client(&self) -> &Arc<Client<B, E, Block, RA>> {
fn client(&self) -> &Arc<Client> {
&self.client
}
+32 -36
View File
@@ -32,7 +32,7 @@ use rpc::{
use sc_rpc_api::Subscriptions;
use sc_client::{
self, Client, BlockchainEvents,
self, BlockchainEvents,
light::{fetcher::Fetcher, blockchain::RemoteBlockchain},
};
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
@@ -45,16 +45,17 @@ use sp_runtime::{
use self::error::{Result, Error, FutureResult};
pub use sc_rpc_api::chain::*;
use sp_blockchain::HeaderBackend;
use sc_client_api::BlockBody;
/// Blockchain backend API
trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
trait ChainBackend<Client, Block: BlockT>: Send + Sync + 'static
where
Block: BlockT + 'static,
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
E: sc_client::CallExecutor<Block> + Send + Sync + 'static,
Client: HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
{
/// Get client reference.
fn client(&self) -> &Arc<Client<B, E, Block, RA>>;
fn client(&self) -> &Arc<Client>;
/// Get subscriptions reference.
fn subscriptions(&self) -> &Subscriptions;
@@ -62,7 +63,7 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
/// Tries to unwrap passed block hash, or uses best block hash otherwise.
fn unwrap_or_best(&self, hash: Option<Block::Hash>) -> Block::Hash {
match hash.into() {
None => self.client().chain_info().best_hash,
None => self.client().info().best_hash,
Some(hash) => hash,
}
}
@@ -81,9 +82,9 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
number: Option<NumberOrHex<NumberFor<Block>>>,
) -> Result<Option<Block::Hash>> {
Ok(match number {
None => Some(self.client().chain_info().best_hash),
None => Some(self.client().info().best_hash),
Some(num_or_hex) => self.client()
.header(&BlockId::number(num_or_hex.to_number()?))
.header(BlockId::number(num_or_hex.to_number()?))
.map_err(client_err)?
.map(|h| h.hash()),
})
@@ -91,7 +92,7 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
/// Get hash of the last finalized block in the canon chain.
fn finalized_head(&self) -> Result<Block::Hash> {
Ok(self.client().chain_info().finalized_hash)
Ok(self.client().info().finalized_hash)
}
/// All new head subscription
@@ -104,7 +105,7 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
self.client(),
self.subscriptions(),
subscriber,
|| self.client().chain_info().best_hash,
|| self.client().info().best_hash,
|| self.client().import_notification_stream()
.map(|notification| Ok::<_, ()>(notification.header))
.compat(),
@@ -130,7 +131,7 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
self.client(),
self.subscriptions(),
subscriber,
|| self.client().chain_info().best_hash,
|| self.client().info().best_hash,
|| self.client().import_notification_stream()
.filter(|notification| future::ready(notification.is_new_best))
.map(|notification| Ok::<_, ()>(notification.header))
@@ -157,7 +158,7 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
self.client(),
self.subscriptions(),
subscriber,
|| self.client().chain_info().finalized_hash,
|| self.client().info().finalized_hash,
|| self.client().finality_notification_stream()
.map(|notification| Ok::<_, ()>(notification.header))
.compat(),
@@ -175,15 +176,13 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
}
/// Create new state API that works on full node.
pub fn new_full<B, E, Block: BlockT, RA>(
client: Arc<Client<B, E, Block, RA>>,
pub fn new_full<Block: BlockT, Client>(
client: Arc<Client>,
subscriptions: Subscriptions,
) -> Chain<B, E, Block, RA>
) -> Chain<Block, Client>
where
Block: BlockT + 'static,
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
E: sc_client::CallExecutor<Block> + Send + Sync + 'static + Clone,
RA: Send + Sync + 'static,
Client: BlockBody<Block> + HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
{
Chain {
backend: Box::new(self::chain_full::FullChain::new(client, subscriptions)),
@@ -191,17 +190,15 @@ pub fn new_full<B, E, Block: BlockT, RA>(
}
/// Create new state API that works on light node.
pub fn new_light<B, E, Block: BlockT, RA, F: Fetcher<Block>>(
client: Arc<Client<B, E, Block, RA>>,
pub fn new_light<Block: BlockT, Client, F: Fetcher<Block>>(
client: Arc<Client>,
subscriptions: Subscriptions,
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
fetcher: Arc<F>,
) -> Chain<B, E, Block, RA>
) -> Chain<Block, Client>
where
Block: BlockT + 'static,
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
E: sc_client::CallExecutor<Block> + Send + Sync + 'static + Clone,
RA: Send + Sync + 'static,
Client: BlockBody<Block> + HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
F: Send + Sync + 'static,
{
Chain {
@@ -215,15 +212,15 @@ pub fn new_light<B, E, Block: BlockT, RA, F: Fetcher<Block>>(
}
/// Chain API with subscriptions support.
pub struct Chain<B, E, Block: BlockT, RA> {
backend: Box<dyn ChainBackend<B, E, Block, RA>>,
pub struct Chain<Block: BlockT, Client> {
backend: Box<dyn ChainBackend<Client, Block>>,
}
impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>> for Chain<B, E, Block, RA> where
Block: BlockT + 'static,
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
E: sc_client::CallExecutor<Block> + Send + Sync + 'static,
RA: Send + Sync + 'static
impl<Block, Client> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>> for
Chain<Block, Client>
where
Block: BlockT + 'static,
Client: HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
{
type Metadata = crate::metadata::Metadata;
@@ -281,16 +278,15 @@ impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, Sig
}
/// Subscribe to new headers.
fn subscribe_headers<B, E, Block, RA, F, G, S, ERR>(
client: &Arc<Client<B, E, Block, RA>>,
fn subscribe_headers<Block, Client, F, G, S, ERR>(
client: &Arc<Client>,
subscriptions: &Subscriptions,
subscriber: Subscriber<Block::Header>,
best_block_hash: G,
stream: F,
) where
Block: BlockT + 'static,
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
E: sc_client::CallExecutor<Block> + Send + Sync + 'static,
Client: HeaderBackend<Block> + 'static,
F: FnOnce() -> S,
G: FnOnce() -> Block::Hash,
ERR: ::std::fmt::Debug,
@@ -298,7 +294,7 @@ fn subscribe_headers<B, E, Block, RA, F, G, S, ERR>(
{
subscriptions.add(subscriber, |sink| {
// send current head right at the start.
let header = client.header(&BlockId::Hash(best_block_hash()))
let header = client.header(BlockId::Hash(best_block_hash()))
.map_err(client_err)
.and_then(|header| {
header.ok_or_else(|| "Best header missing.".to_owned().into())
+27 -27
View File
@@ -27,26 +27,26 @@ use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use rpc::{Result as RpcResult, futures::{Future, future::result}};
use sc_rpc_api::Subscriptions;
use sc_client::{Client, CallExecutor, light::{blockchain::RemoteBlockchain, fetcher::Fetcher}};
use sc_client::{light::{blockchain::RemoteBlockchain, fetcher::Fetcher}};
use sp_core::{Bytes, storage::{StorageKey, StorageData, StorageChangeSet}};
use sp_version::RuntimeVersion;
use sp_runtime::traits::Block as BlockT;
use sp_api::{Metadata, ProvideRuntimeApi};
use sp_api::{Metadata, ProvideRuntimeApi, CallApiAt};
use self::error::{Error, FutureResult};
pub use sc_rpc_api::state::*;
use sc_client_api::{ExecutorProvider, StorageProvider, BlockchainEvents, Backend};
use sp_blockchain::{HeaderMetadata, HeaderBackend};
const STORAGE_KEYS_PAGED_MAX_COUNT: u32 = 1000;
/// State backend API.
pub trait StateBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
pub trait StateBackend<Block: BlockT, Client>: Send + Sync + 'static
where
Block: BlockT + 'static,
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
E: sc_client::CallExecutor<Block> + Send + Sync + 'static,
RA: Send + Sync + 'static,
Client: Send + Sync + 'static,
{
/// Call runtime method at given block.
fn call(
@@ -194,18 +194,18 @@ pub trait StateBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
}
/// Create new state API that works on full node.
pub fn new_full<B, E, Block: BlockT, RA>(
client: Arc<Client<B, E, Block, RA>>,
pub fn new_full<BE, Block: BlockT, Client>(
client: Arc<Client>,
subscriptions: Subscriptions,
) -> State<B, E, Block, RA>
) -> State<Block, Client>
where
Block: BlockT + 'static,
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
E: CallExecutor<Block> + Send + Sync + 'static + Clone,
RA: Send + Sync + 'static,
Client<B, E, Block, RA>: ProvideRuntimeApi<Block>,
<Client<B, E, Block, RA> as ProvideRuntimeApi<Block>>::Api:
Metadata<Block, Error = sp_blockchain::Error>,
BE: Backend<Block> + 'static,
Client: ExecutorProvider<Block> + StorageProvider<Block, BE> + HeaderBackend<Block>
+ HeaderMetadata<Block, Error = sp_blockchain::Error> + BlockchainEvents<Block>
+ CallApiAt<Block, Error = sp_blockchain::Error>
+ ProvideRuntimeApi<Block> + Send + Sync + 'static,
Client::Api: Metadata<Block, Error = sp_blockchain::Error>,
{
State {
backend: Box::new(self::state_full::FullState::new(client, subscriptions)),
@@ -213,17 +213,19 @@ pub fn new_full<B, E, Block: BlockT, RA>(
}
/// Create new state API that works on light node.
pub fn new_light<B, E, Block: BlockT, RA, F: Fetcher<Block>>(
client: Arc<Client<B, E, Block, RA>>,
pub fn new_light<BE, Block: BlockT, Client, F: Fetcher<Block>>(
client: Arc<Client>,
subscriptions: Subscriptions,
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
fetcher: Arc<F>,
) -> State<B, E, Block, RA>
) -> State<Block, Client>
where
Block: BlockT + 'static,
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
E: CallExecutor<Block> + Send + Sync + 'static + Clone,
RA: Send + Sync + 'static,
BE: Backend<Block> + 'static,
Client: ExecutorProvider<Block> + StorageProvider<Block, BE>
+ HeaderMetadata<Block, Error = sp_blockchain::Error>
+ ProvideRuntimeApi<Block> + HeaderBackend<Block> + BlockchainEvents<Block>
+ Send + Sync + 'static,
F: Send + Sync + 'static,
{
State {
@@ -237,16 +239,14 @@ pub fn new_light<B, E, Block: BlockT, RA, F: Fetcher<Block>>(
}
/// State API with subscriptions support.
pub struct State<B, E, Block, RA> {
backend: Box<dyn StateBackend<B, E, Block, RA>>,
pub struct State<Block, Client> {
backend: Box<dyn StateBackend<Block, Client>>,
}
impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA>
impl<Block, Client> StateApi<Block::Hash> for State<Block, Client>
where
Block: BlockT + 'static,
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
E: CallExecutor<Block> + Send + Sync + 'static + Clone,
RA: Send + Sync + 'static,
Client: Send + Sync + 'static,
{
type Metadata = crate::metadata::Metadata;
+24 -24
View File
@@ -26,12 +26,8 @@ use rpc::{Result as RpcResult, futures::{stream, Future, Sink, Stream, future::r
use sc_rpc_api::Subscriptions;
use sc_client_api::backend::Backend;
use sp_blockchain::{
Result as ClientResult, Error as ClientError, HeaderMetadata, CachedHeaderMetadata
};
use sc_client::{
Client, CallExecutor, BlockchainEvents
};
use sp_blockchain::{Result as ClientResult, Error as ClientError, HeaderMetadata, CachedHeaderMetadata, HeaderBackend};
use sc_client::BlockchainEvents;
use sp_core::{
Bytes, storage::{well_known_keys, StorageKey, StorageData, StorageChangeSet, ChildInfo},
};
@@ -40,9 +36,11 @@ use sp_runtime::{
generic::BlockId, traits::{Block as BlockT, NumberFor, SaturatedConversion},
};
use sp_api::{Metadata, ProvideRuntimeApi};
use sp_api::{Metadata, ProvideRuntimeApi, CallApiAt};
use super::{StateBackend, error::{FutureResult, Error, Result}, client_err, child_resolution_error};
use std::marker::PhantomData;
use sc_client_api::{CallExecutor, StorageProvider, ExecutorProvider};
/// Ranges to query in state_queryStorage.
struct QueryStorageRange<Block: BlockT> {
@@ -59,25 +57,27 @@ struct QueryStorageRange<Block: BlockT> {
}
/// State API backend for full nodes.
pub struct FullState<B, E, Block: BlockT, RA> {
client: Arc<Client<B, E, Block, RA>>,
pub struct FullState<BE, Block: BlockT, Client> {
client: Arc<Client>,
subscriptions: Subscriptions,
_phantom: PhantomData<(BE, Block)>
}
impl<B, E, Block: BlockT, RA> FullState<B, E, Block, RA>
impl<BE, Block: BlockT, Client> FullState<BE, Block, Client>
where
BE: Backend<Block>,
Client: StorageProvider<Block, BE> + HeaderBackend<Block>
+ HeaderMetadata<Block, Error = sp_blockchain::Error>,
Block: BlockT + 'static,
B: Backend<Block> + Send + Sync + 'static,
E: CallExecutor<Block> + Send + Sync + 'static + Clone,
{
/// Create new state API backend for full nodes.
pub fn new(client: Arc<Client<B, E, Block, RA>>, subscriptions: Subscriptions) -> Self {
Self { client, subscriptions }
pub fn new(client: Arc<Client>, subscriptions: Subscriptions) -> Self {
Self { client, subscriptions, _phantom: PhantomData }
}
/// Returns given block hash or best block hash if None is passed.
fn block_or_best(&self, hash: Option<Block::Hash>) -> ClientResult<Block::Hash> {
Ok(hash.unwrap_or_else(|| self.client.chain_info().best_hash))
Ok(hash.unwrap_or_else(|| self.client.info().best_hash))
}
/// Splits the `query_storage` block range into 'filtered' and 'unfiltered' subranges.
@@ -212,14 +212,14 @@ impl<B, E, Block: BlockT, RA> FullState<B, E, Block, RA>
}
}
impl<B, E, Block, RA> StateBackend<B, E, Block, RA> for FullState<B, E, Block, RA> where
impl<BE, Block, Client> StateBackend<Block, Client> for FullState<BE, Block, Client> where
Block: BlockT + 'static,
B: Backend<Block> + Send + Sync + 'static,
E: CallExecutor<Block> + Send + Sync + 'static + Clone,
RA: Send + Sync + 'static,
Client<B, E, Block, RA>: ProvideRuntimeApi<Block>,
<Client<B, E, Block, RA> as ProvideRuntimeApi<Block>>::Api:
Metadata<Block, Error = sp_blockchain::Error>,
BE: Backend<Block> + 'static,
Client: ExecutorProvider<Block> + StorageProvider<Block, BE> + HeaderBackend<Block>
+ HeaderMetadata<Block, Error = sp_blockchain::Error> + BlockchainEvents<Block>
+ CallApiAt<Block, Error = sp_blockchain::Error> + ProvideRuntimeApi<Block>
+ Send + Sync + 'static,
Client::Api: Metadata<Block, Error = sp_blockchain::Error>,
{
fn call(
&self,
@@ -424,7 +424,7 @@ impl<B, E, Block, RA> StateBackend<B, E, Block, RA> for FullState<B, E, Block, R
let stream = stream
.filter_map(move |_| {
let info = client.chain_info();
let info = client.info();
let version = client
.runtime_version_at(&BlockId::hash(info.best_hash))
.map_err(client_err)
@@ -478,7 +478,7 @@ impl<B, E, Block, RA> StateBackend<B, E, Block, RA> for FullState<B, E, Block, R
// initial values
let initial = stream::iter_result(keys
.map(|keys| {
let block = self.client.chain_info().best_hash;
let block = self.client.info().best_hash;
let changes = keys
.into_iter()
.map(|key| self.storage(Some(block.clone()).into(), key.clone())
+10 -15
View File
@@ -39,10 +39,9 @@ use rpc::{
};
use sc_rpc_api::Subscriptions;
use sc_client_api::backend::Backend;
use sp_blockchain::Error as ClientError;
use sp_blockchain::{Error as ClientError, HeaderBackend};
use sc_client::{
BlockchainEvents, Client, CallExecutor,
BlockchainEvents,
light::{
blockchain::{future_header, RemoteBlockchain},
fetcher::{Fetcher, RemoteCallRequest, RemoteReadRequest, RemoteReadChildRequest},
@@ -60,8 +59,8 @@ use super::{StateBackend, error::{FutureResult, Error}, client_err};
type StorageMap = HashMap<StorageKey, Option<StorageData>>;
/// State API backend for light nodes.
pub struct LightState<Block: BlockT, F: Fetcher<Block>, B, E, RA> {
client: Arc<Client<B, E, Block, RA>>,
pub struct LightState<Block: BlockT, F: Fetcher<Block>, Client> {
client: Arc<Client>,
subscriptions: Subscriptions,
version_subscriptions: SimpleSubscriptions<Block::Hash, RuntimeVersion>,
storage_subscriptions: Arc<Mutex<StorageSubscriptions<Block>>>,
@@ -134,16 +133,14 @@ impl<Hash, V> SharedRequests<Hash, V> for SimpleSubscriptions<Hash, V> where
}
}
impl<Block: BlockT, F: Fetcher<Block> + 'static, B, E, RA> LightState<Block, F, B, E, RA>
impl<Block: BlockT, F: Fetcher<Block> + 'static, Client> LightState<Block, F, Client>
where
Block: BlockT,
B: Backend<Block> + Send + Sync + 'static,
E: CallExecutor<Block> + Send + Sync + 'static + Clone,
RA: Send + Sync + 'static,
Client: HeaderBackend<Block> + Send + Sync + 'static,
{
/// Create new state API backend for light nodes.
pub fn new(
client: Arc<Client<B, E, Block, RA>>,
client: Arc<Client>,
subscriptions: Subscriptions,
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
fetcher: Arc<F>,
@@ -164,16 +161,14 @@ impl<Block: BlockT, F: Fetcher<Block> + 'static, B, E, RA> LightState<Block, F,
/// Returns given block hash or best block hash if None is passed.
fn block_or_best(&self, hash: Option<Block::Hash>) -> Block::Hash {
hash.unwrap_or_else(|| self.client.chain_info().best_hash)
hash.unwrap_or_else(|| self.client.info().best_hash)
}
}
impl<Block, F, B, E, RA> StateBackend<B, E, Block, RA> for LightState<Block, F, B, E, RA>
impl<Block, F, Client> StateBackend<Block, Client> for LightState<Block, F, Client>
where
Block: BlockT,
B: Backend<Block> + Send + Sync + 'static,
E: CallExecutor<Block> + Send + Sync + 'static + Clone,
RA: Send + Sync + 'static,
Client: BlockchainEvents<Block> + HeaderBackend<Block> + Send + Sync + 'static,
F: Fetcher<Block> + 'static
{
fn call(