mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
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:
committed by
GitHub
parent
dc85ccb7df
commit
99ae5342eb
@@ -28,10 +28,7 @@ use parking_lot::RwLock;
|
||||
use sp_blockchain::{HeaderBackend, Error as ClientError, HeaderMetadata};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use sc_client_api::{
|
||||
backend::Backend,
|
||||
utils::is_descendent_of,
|
||||
};
|
||||
use sc_client_api::{backend::Backend, utils::is_descendent_of};
|
||||
use sc_client::apply_aux;
|
||||
use finality_grandpa::{
|
||||
BlockNumberOps, Equivocation, Error as GrandpaError, round::State as RoundState,
|
||||
|
||||
@@ -34,16 +34,15 @@
|
||||
//! finality proof (that finalizes some block C that is ancestor of the B and descendant
|
||||
//! of the U) could be returned.
|
||||
|
||||
use std::iter;
|
||||
use std::sync::Arc;
|
||||
use log::{trace, warn};
|
||||
|
||||
use sp_blockchain::{Backend as BlockchainBackend, Error as ClientError, Result as ClientResult};
|
||||
use sc_client_api::{
|
||||
backend::Backend, CallExecutor, StorageProof,
|
||||
backend::Backend, StorageProof,
|
||||
light::{FetchChecker, RemoteReadRequest},
|
||||
StorageProvider, ProofProvider,
|
||||
};
|
||||
use sc_client::Client;
|
||||
use parity_scale_codec::{Encode, Decode};
|
||||
use finality_grandpa::BlockNumberOps;
|
||||
use sp_runtime::{
|
||||
@@ -67,12 +66,25 @@ pub trait AuthoritySetForFinalityProver<Block: BlockT>: Send + Sync {
|
||||
fn prove_authorities(&self, block: &BlockId<Block>) -> ClientResult<StorageProof>;
|
||||
}
|
||||
|
||||
/// Client-based implementation of AuthoritySetForFinalityProver.
|
||||
impl<B, E, Block: BlockT, RA> AuthoritySetForFinalityProver<Block> for Client<B, E, Block, RA>
|
||||
/// Trait that combines `StorageProvider` and `ProofProvider`
|
||||
pub trait StorageAndProofProvider<Block, BE>: StorageProvider<Block, BE> + ProofProvider<Block> + Send + Sync
|
||||
where
|
||||
B: Backend<Block> + Send + Sync + 'static,
|
||||
E: CallExecutor<Block> + 'static + Clone + Send + Sync,
|
||||
RA: Send + Sync,
|
||||
Block: BlockT,
|
||||
BE: Backend<Block> + Send + Sync,
|
||||
{}
|
||||
|
||||
/// Blanket implementation.
|
||||
impl<Block, BE, P> StorageAndProofProvider<Block, BE> for P
|
||||
where
|
||||
Block: BlockT,
|
||||
BE: Backend<Block> + Send + Sync,
|
||||
P: StorageProvider<Block, BE> + ProofProvider<Block> + Send + Sync,
|
||||
{}
|
||||
|
||||
/// Implementation of AuthoritySetForFinalityProver.
|
||||
impl<BE, Block: BlockT> AuthoritySetForFinalityProver<Block> for Arc<dyn StorageAndProofProvider<Block, BE>>
|
||||
where
|
||||
BE: Backend<Block> + Send + Sync + 'static,
|
||||
{
|
||||
fn authorities(&self, block: &BlockId<Block>) -> ClientResult<AuthorityList> {
|
||||
let storage_key = StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec());
|
||||
@@ -83,7 +95,7 @@ impl<B, E, Block: BlockT, RA> AuthoritySetForFinalityProver<Block> for Client<B,
|
||||
}
|
||||
|
||||
fn prove_authorities(&self, block: &BlockId<Block>) -> ClientResult<StorageProof> {
|
||||
self.read_proof(block, iter::once(GRANDPA_AUTHORITIES_KEY))
|
||||
self.read_proof(block, &mut std::iter::once(GRANDPA_AUTHORITIES_KEY))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,11 +158,13 @@ impl<B, Block: BlockT> FinalityProofProvider<B, Block>
|
||||
///
|
||||
/// - backend for accessing blockchain data;
|
||||
/// - authority_provider for calling and proving runtime methods.
|
||||
pub fn new(
|
||||
pub fn new<P>(
|
||||
backend: Arc<B>,
|
||||
authority_provider: Arc<dyn AuthoritySetForFinalityProver<Block>>,
|
||||
) -> Self {
|
||||
FinalityProofProvider { backend, authority_provider }
|
||||
authority_provider: P,
|
||||
) -> Self
|
||||
where P: AuthoritySetForFinalityProver<Block> + 'static,
|
||||
{
|
||||
FinalityProofProvider { backend, authority_provider: Arc::new(authority_provider) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -541,8 +541,7 @@ impl<Backend, Block: BlockT, Client, SC> GrandpaBlockImport<Backend, Block, Clie
|
||||
}
|
||||
}
|
||||
|
||||
impl<BE, Block: BlockT, Client, SC>
|
||||
GrandpaBlockImport<BE, Block, Client, SC>
|
||||
impl<BE, Block: BlockT, Client, SC> GrandpaBlockImport<BE, Block, Client, SC>
|
||||
where
|
||||
BE: Backend<Block>,
|
||||
Client: crate::ClientForGrandpa<Block, BE>,
|
||||
|
||||
@@ -57,11 +57,11 @@ use futures::StreamExt;
|
||||
use log::{debug, info};
|
||||
use futures::channel::mpsc;
|
||||
use sc_client_api::{
|
||||
backend::{AuxStore, Backend},
|
||||
LockImportRun, BlockchainEvents, CallExecutor,
|
||||
backend::{AuxStore, Backend}, ExecutionStrategy, Finalizer, TransactionFor,
|
||||
ExecutionStrategy, Finalizer, TransactionFor, ExecutorProvider,
|
||||
};
|
||||
use sp_blockchain::{HeaderBackend, Error as ClientError, HeaderMetadata};
|
||||
use sc_client::Client;
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use sp_runtime::generic::BlockId;
|
||||
use sp_runtime::traits::{NumberFor, Block as BlockT, DigestFor, Zero};
|
||||
@@ -96,7 +96,7 @@ mod observer;
|
||||
mod until_imported;
|
||||
mod voting_rule;
|
||||
|
||||
pub use finality_proof::FinalityProofProvider;
|
||||
pub use finality_proof::{FinalityProofProvider, StorageAndProofProvider};
|
||||
pub use justification::GrandpaJustification;
|
||||
pub use light_import::light_block_import;
|
||||
pub use voting_rule::{
|
||||
@@ -266,7 +266,7 @@ impl<Block: BlockT, Client> BlockStatus<Block> for Arc<Client> where
|
||||
pub trait ClientForGrandpa<Block, BE>:
|
||||
LockImportRun<Block, BE> + Finalizer<Block, BE> + AuxStore
|
||||
+ HeaderMetadata<Block, Error = sp_blockchain::Error> + HeaderBackend<Block>
|
||||
+ BlockchainEvents<Block> + ProvideRuntimeApi<Block>
|
||||
+ BlockchainEvents<Block> + ProvideRuntimeApi<Block> + ExecutorProvider<Block>
|
||||
+ BlockImport<Block, Transaction = TransactionFor<BE, Block>, Error = sp_consensus::Error>
|
||||
where
|
||||
BE: Backend<Block>,
|
||||
@@ -279,7 +279,7 @@ impl<Block, BE, T> ClientForGrandpa<Block, BE> for T
|
||||
Block: BlockT,
|
||||
T: LockImportRun<Block, BE> + Finalizer<Block, BE> + AuxStore
|
||||
+ HeaderMetadata<Block, Error = sp_blockchain::Error> + HeaderBackend<Block>
|
||||
+ BlockchainEvents<Block> + ProvideRuntimeApi<Block>
|
||||
+ BlockchainEvents<Block> + ProvideRuntimeApi<Block> + ExecutorProvider<Block>
|
||||
+ BlockImport<Block, Transaction = TransactionFor<BE, Block>, Error = sp_consensus::Error>,
|
||||
{}
|
||||
|
||||
@@ -387,11 +387,8 @@ pub trait GenesisAuthoritySetProvider<Block: BlockT> {
|
||||
fn get(&self) -> Result<AuthorityList, ClientError>;
|
||||
}
|
||||
|
||||
impl<B, E, Block: BlockT, RA> GenesisAuthoritySetProvider<Block> for Client<B, E, Block, RA>
|
||||
where
|
||||
B: Backend<Block> + Send + Sync + 'static,
|
||||
E: CallExecutor<Block> + Send + Sync,
|
||||
RA: Send + Sync,
|
||||
impl<Block: BlockT, E> GenesisAuthoritySetProvider<Block> for Arc<dyn ExecutorProvider<Block, Executor = E>>
|
||||
where E: CallExecutor<Block>,
|
||||
{
|
||||
fn get(&self) -> Result<AuthorityList, ClientError> {
|
||||
// This implementation uses the Grandpa runtime API instead of reading directly from the
|
||||
|
||||
@@ -18,7 +18,9 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use log::{info, trace, warn};
|
||||
use parking_lot::RwLock;
|
||||
use sc_client_api::backend::{AuxStore, Backend, Finalizer, TransactionFor};
|
||||
use sc_client_api::{
|
||||
backend::{AuxStore, Backend, Finalizer, TransactionFor},
|
||||
};
|
||||
use sp_blockchain::{HeaderBackend, Error as ClientError, well_known_cache_keys};
|
||||
use parity_scale_codec::{Encode, Decode};
|
||||
use sp_consensus::{
|
||||
|
||||
@@ -328,7 +328,7 @@ impl<B, BE, C, N> Future for ObserverWork<B, BE, C, N>
|
||||
where
|
||||
B: BlockT,
|
||||
BE: Backend<B> + Unpin + 'static,
|
||||
C: crate::ClientForGrandpa<B, BE>+ 'static,
|
||||
C: crate::ClientForGrandpa<B, BE> + 'static,
|
||||
N: NetworkT<B>,
|
||||
NumberFor<B>: BlockNumberOps,
|
||||
{
|
||||
|
||||
@@ -39,7 +39,7 @@ use sp_consensus::{
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
result,
|
||||
pin::Pin, task,
|
||||
pin::Pin,
|
||||
};
|
||||
use parity_scale_codec::Decode;
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, HashFor};
|
||||
@@ -170,8 +170,7 @@ impl TestNetFactory for GrandpaTestNet {
|
||||
) -> Option<Arc<dyn sc_network::config::FinalityProofProvider<Block>>> {
|
||||
match client {
|
||||
PeersClient::Full(_, ref backend) => {
|
||||
let authorities_provider = Arc::new(self.test_config.clone());
|
||||
Some(Arc::new(FinalityProofProvider::new(backend.clone(), authorities_provider)))
|
||||
Some(Arc::new(FinalityProofProvider::new(backend.clone(), self.test_config.clone())))
|
||||
},
|
||||
PeersClient::Light(_, _) => None,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user