mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 01:41:03 +00:00
removes use of sc_client::Client from sc_finality_grandpa (#5030)
* removes use of sc_client::Client from sc_finality_grandpa * code formatting * code formatting * removes use of sc_client::Client from sc_finality_grandpa
This commit is contained in:
@@ -26,10 +26,9 @@ use finality_grandpa::{
|
||||
use log::{debug, info, warn};
|
||||
|
||||
use sp_consensus::SelectChain;
|
||||
use sc_client_api::{CallExecutor, backend::{Backend, AuxStore}};
|
||||
use sc_client::Client;
|
||||
use sc_client_api::backend::Backend;
|
||||
use sp_runtime::traits::{NumberFor, Block as BlockT};
|
||||
|
||||
use sp_blockchain::HeaderMetadata;
|
||||
use crate::{
|
||||
global_communication, CommandOrError, CommunicationIn, Config, environment,
|
||||
LinkHalf, Error, aux_schema::PersistentData, VoterCommand, VoterSetState,
|
||||
@@ -38,17 +37,21 @@ use crate::authorities::SharedAuthoritySet;
|
||||
use crate::communication::{Network as NetworkT, NetworkBridge};
|
||||
use crate::consensus_changes::SharedConsensusChanges;
|
||||
use sp_finality_grandpa::AuthorityId;
|
||||
use std::marker::{PhantomData, Unpin};
|
||||
|
||||
struct ObserverChain<'a, Block: BlockT, B, E, RA>(&'a Client<B, E, Block, RA>);
|
||||
struct ObserverChain<'a, Block: BlockT, Client> {
|
||||
client: &'a Arc<Client>,
|
||||
_phantom: PhantomData<Block>,
|
||||
}
|
||||
|
||||
impl<'a, Block: BlockT, B, E, RA> finality_grandpa::Chain<Block::Hash, NumberFor<Block>>
|
||||
for ObserverChain<'a, Block, B, E, RA> where
|
||||
B: Backend<Block>,
|
||||
E: CallExecutor<Block>,
|
||||
impl<'a, Block, Client> finality_grandpa::Chain<Block::Hash, NumberFor<Block>>
|
||||
for ObserverChain<'a, Block, Client> where
|
||||
Block: BlockT,
|
||||
Client: HeaderMetadata<Block, Error = sp_blockchain::Error>,
|
||||
NumberFor<Block>: BlockNumberOps,
|
||||
{
|
||||
fn ancestry(&self, base: Block::Hash, block: Block::Hash) -> Result<Vec<Block::Hash>, GrandpaError> {
|
||||
environment::ancestry(&self.0, base, block)
|
||||
environment::ancestry(&self.client, base, block)
|
||||
}
|
||||
|
||||
fn best_chain_containing(&self, _block: Block::Hash) -> Option<(Block::Hash, NumberFor<Block>)> {
|
||||
@@ -57,8 +60,8 @@ impl<'a, Block: BlockT, B, E, RA> finality_grandpa::Chain<Block::Hash, NumberFor
|
||||
}
|
||||
}
|
||||
|
||||
fn grandpa_observer<B, E, Block: BlockT, RA, S, F>(
|
||||
client: &Arc<Client<B, E, Block, RA>>,
|
||||
fn grandpa_observer<BE, Block: BlockT, Client, S, F>(
|
||||
client: &Arc<Client>,
|
||||
authority_set: &SharedAuthoritySet<Block::Hash, NumberFor<Block>>,
|
||||
consensus_changes: &SharedConsensusChanges<Block::Hash, NumberFor<Block>>,
|
||||
voters: &Arc<VoterSet<AuthorityId>>,
|
||||
@@ -67,13 +70,12 @@ fn grandpa_observer<B, E, Block: BlockT, RA, S, F>(
|
||||
note_round: F,
|
||||
) -> impl Future<Output=Result<(), CommandOrError<Block::Hash, NumberFor<Block>>>> where
|
||||
NumberFor<Block>: BlockNumberOps,
|
||||
B: Backend<Block>,
|
||||
E: CallExecutor<Block> + Send + Sync + 'static,
|
||||
RA: Send + Sync,
|
||||
S: Stream<
|
||||
Item = Result<CommunicationIn<Block>, CommandOrError<Block::Hash, NumberFor<Block>>>,
|
||||
>,
|
||||
F: Fn(u64),
|
||||
BE: Backend<Block>,
|
||||
Client: crate::ClientForGrandpa<Block, BE>,
|
||||
{
|
||||
let authority_set = authority_set.clone();
|
||||
let consensus_changes = consensus_changes.clone();
|
||||
@@ -101,7 +103,7 @@ fn grandpa_observer<B, E, Block: BlockT, RA, S, F>(
|
||||
let validation_result = match finality_grandpa::validate_commit(
|
||||
&commit,
|
||||
&voters,
|
||||
&ObserverChain(&*client),
|
||||
&ObserverChain { client: &client, _phantom: PhantomData },
|
||||
) {
|
||||
Ok(r) => r,
|
||||
Err(e) => return future::err(e.into()),
|
||||
@@ -113,7 +115,7 @@ fn grandpa_observer<B, E, Block: BlockT, RA, S, F>(
|
||||
|
||||
// commit is valid, finalize the block it targets
|
||||
match environment::finalize_block(
|
||||
&client,
|
||||
client.clone(),
|
||||
&authority_set,
|
||||
&consensus_changes,
|
||||
None,
|
||||
@@ -153,19 +155,17 @@ fn grandpa_observer<B, E, Block: BlockT, RA, S, F>(
|
||||
/// NOTE: this is currently not part of the crate's public API since we don't consider
|
||||
/// it stable enough to use on a live network.
|
||||
#[allow(unused)]
|
||||
pub fn run_grandpa_observer<B, E, Block: BlockT, N, RA, SC>(
|
||||
pub fn run_grandpa_observer<BE, Block: BlockT, Client, N, SC>(
|
||||
config: Config,
|
||||
link: LinkHalf<B, E, Block, RA, SC>,
|
||||
link: LinkHalf<Block, Client, SC>,
|
||||
network: N,
|
||||
on_exit: impl futures::Future<Output=()> + Clone + Send + Unpin + 'static,
|
||||
) -> sp_blockchain::Result<impl Future<Output = ()> + Unpin + Send + 'static> where
|
||||
B: Backend<Block> + 'static,
|
||||
E: CallExecutor<Block> + Send + Sync + 'static,
|
||||
BE: Backend<Block> + Unpin + 'static,
|
||||
N: NetworkT<Block> + Send + Clone + 'static,
|
||||
SC: SelectChain<Block> + 'static,
|
||||
NumberFor<Block>: BlockNumberOps,
|
||||
RA: Send + Sync + 'static,
|
||||
Client<B, E, Block, RA>: AuxStore,
|
||||
Client: crate::ClientForGrandpa<Block, BE> + 'static,
|
||||
{
|
||||
let LinkHalf {
|
||||
client,
|
||||
@@ -199,28 +199,27 @@ pub fn run_grandpa_observer<B, E, Block: BlockT, N, RA, SC>(
|
||||
|
||||
/// Future that powers the observer.
|
||||
#[must_use]
|
||||
struct ObserverWork<B: BlockT, N: NetworkT<B>, E, Backend, RA> {
|
||||
struct ObserverWork<B: BlockT, BE, Client, N: NetworkT<B>> {
|
||||
observer: Pin<Box<dyn Future<Output = Result<(), CommandOrError<B::Hash, NumberFor<B>>>> + Send>>,
|
||||
client: Arc<Client<Backend, E, B, RA>>,
|
||||
client: Arc<Client>,
|
||||
network: NetworkBridge<B, N>,
|
||||
persistent_data: PersistentData<B>,
|
||||
keystore: Option<sc_keystore::KeyStorePtr>,
|
||||
voter_commands_rx: mpsc::UnboundedReceiver<VoterCommand<B::Hash, NumberFor<B>>>,
|
||||
_phantom: PhantomData<BE>,
|
||||
}
|
||||
|
||||
impl<B, N, E, Bk, RA> ObserverWork<B, N, E, Bk, RA>
|
||||
impl<B, BE, Client, Network> ObserverWork<B, BE, Client, Network>
|
||||
where
|
||||
B: BlockT,
|
||||
N: NetworkT<B>,
|
||||
BE: Backend<B> + 'static,
|
||||
Client: crate::ClientForGrandpa<B, BE> + 'static,
|
||||
Network: NetworkT<B>,
|
||||
NumberFor<B>: BlockNumberOps,
|
||||
RA: 'static + Send + Sync,
|
||||
E: CallExecutor<B> + Send + Sync + 'static,
|
||||
Bk: Backend<B> + 'static,
|
||||
Client<Bk, E, B, RA>: AuxStore,
|
||||
{
|
||||
fn new(
|
||||
client: Arc<Client<Bk, E, B, RA>>,
|
||||
network: NetworkBridge<B, N>,
|
||||
client: Arc<Client>,
|
||||
network: NetworkBridge<B, Network>,
|
||||
persistent_data: PersistentData<B>,
|
||||
keystore: Option<sc_keystore::KeyStorePtr>,
|
||||
voter_commands_rx: mpsc::UnboundedReceiver<VoterCommand<B::Hash, NumberFor<B>>>,
|
||||
@@ -235,6 +234,7 @@ where
|
||||
persistent_data,
|
||||
keystore,
|
||||
voter_commands_rx,
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
work.rebuild_observer();
|
||||
work
|
||||
@@ -251,12 +251,12 @@ where
|
||||
let (global_in, _) = global_communication(
|
||||
set_id,
|
||||
&voters,
|
||||
&self.client,
|
||||
self.client.clone(),
|
||||
&self.network,
|
||||
&self.keystore,
|
||||
);
|
||||
|
||||
let last_finalized_number = self.client.chain_info().finalized_number;
|
||||
let last_finalized_number = self.client.info().finalized_number;
|
||||
|
||||
// NOTE: since we are not using `round_communication` we have to
|
||||
// manually note the round with the gossip validator, otherwise we won't
|
||||
@@ -324,15 +324,13 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, N, E, Bk, RA> Future for ObserverWork<B, N, E, Bk, RA>
|
||||
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,
|
||||
N: NetworkT<B>,
|
||||
NumberFor<B>: BlockNumberOps,
|
||||
RA: 'static + Send + Sync,
|
||||
E: CallExecutor<B> + Send + Sync + 'static,
|
||||
Bk: Backend<B> + 'static,
|
||||
Client<Bk, E, B, RA>: AuxStore,
|
||||
{
|
||||
type Output = Result<(), Error>;
|
||||
|
||||
@@ -379,6 +377,7 @@ mod tests {
|
||||
use crate::{aux_schema, communication::tests::{Event, make_test_network}};
|
||||
use substrate_test_runtime_client::{TestClientBuilder, TestClientBuilderExt};
|
||||
use sc_network::PeerId;
|
||||
use sp_blockchain::HeaderBackend as _;
|
||||
|
||||
use futures::executor;
|
||||
|
||||
@@ -406,7 +405,7 @@ mod tests {
|
||||
|
||||
let persistent_data = aux_schema::load_persistent(
|
||||
&*backend,
|
||||
client.chain_info().genesis_hash,
|
||||
client.info().genesis_hash,
|
||||
0,
|
||||
|| Ok(vec![]),
|
||||
).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user