mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 11:21:07 +00:00
client: Do not set fork sync request via network-gossip (#4439)
The finality-grandpa module needs two sets of functionalities from the network: 1. Everything gossip related, e.g. event_stream, write_notification, ... 2. The ability to set a fork sync request for a specific block hash. Instead of embedding (2) inside of (1) this patch extracts (2) from (1) having finality-grandpa depend on a `Network` that fulfills the `network_gossip::Network` trait and that can set block sync requests. On the one hand this improves the overall structure splitting things that don't logically belong together. On the other hand it does reintroduce a lot of trait bounds within finality-grandpa.
This commit is contained in:
committed by
GitHub
parent
da87c3c1e3
commit
8f1b5b840d
@@ -24,7 +24,7 @@ use sc_network::{Event, ReputationChange};
|
||||
use futures::{prelude::*, channel::mpsc, compat::Compat01As03, task::SpawnExt as _};
|
||||
use libp2p::PeerId;
|
||||
use parking_lot::Mutex;
|
||||
use sp_runtime::{traits::{Block as BlockT, NumberFor}, ConsensusEngineId};
|
||||
use sp_runtime::{traits::Block as BlockT, ConsensusEngineId};
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
/// Wraps around an implementation of the `Network` crate and provides gossiping capabilities on
|
||||
@@ -234,19 +234,6 @@ impl<B: BlockT> GossipEngine<B> {
|
||||
pub fn announce(&self, block: B::Hash, associated_data: Vec<u8>) {
|
||||
self.inner.lock().context_ext.announce(block, associated_data);
|
||||
}
|
||||
|
||||
/// Notifies the sync service to try and sync the given block from the given
|
||||
/// peers.
|
||||
///
|
||||
/// If the given vector of peers is empty then the underlying implementation
|
||||
/// should make a best effort to fetch the block from any peers it is
|
||||
/// connected to (NOTE: this assumption will change in the future #3629).
|
||||
///
|
||||
/// Note: this method isn't strictly related to gossiping and should eventually be moved
|
||||
/// somewhere else.
|
||||
pub fn set_sync_fork_request(&self, peers: Vec<sc_network::PeerId>, hash: B::Hash, number: NumberFor<B>) {
|
||||
self.inner.lock().context_ext.set_sync_fork_request(peers, hash, number);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT> Clone for GossipEngine<B> {
|
||||
@@ -287,15 +274,10 @@ impl<B: BlockT, N: Network<B>> Context<B> for ContextOverService<N> {
|
||||
|
||||
trait ContextExt<B: BlockT> {
|
||||
fn announce(&self, block: B::Hash, associated_data: Vec<u8>);
|
||||
fn set_sync_fork_request(&self, peers: Vec<sc_network::PeerId>, hash: B::Hash, number: NumberFor<B>);
|
||||
}
|
||||
|
||||
impl<B: BlockT, N: Network<B>> ContextExt<B> for ContextOverService<N> {
|
||||
fn announce(&self, block: B::Hash, associated_data: Vec<u8>) {
|
||||
Network::announce(&self.network, block, associated_data)
|
||||
}
|
||||
|
||||
fn set_sync_fork_request(&self, peers: Vec<sc_network::PeerId>, hash: B::Hash, number: NumberFor<B>) {
|
||||
Network::set_sync_fork_request(&self.network, peers, hash, number)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ pub use self::state_machine::{Validator, ValidatorContext, ValidationResult};
|
||||
pub use self::state_machine::DiscardAll;
|
||||
|
||||
use sc_network::{specialization::NetworkSpecialization, Event, ExHashT, NetworkService, PeerId, ReputationChange};
|
||||
use sp_runtime::{traits::{Block as BlockT, NumberFor}, ConsensusEngineId};
|
||||
use sp_runtime::{traits::Block as BlockT, ConsensusEngineId};
|
||||
use std::sync::Arc;
|
||||
|
||||
mod bridge;
|
||||
@@ -93,17 +93,6 @@ pub trait Network<B: BlockT> {
|
||||
/// Note: this method isn't strictly related to gossiping and should eventually be moved
|
||||
/// somewhere else.
|
||||
fn announce(&self, block: B::Hash, associated_data: Vec<u8>);
|
||||
|
||||
/// Notifies the sync service to try and sync the given block from the given
|
||||
/// peers.
|
||||
///
|
||||
/// If the given vector of peers is empty then the underlying implementation
|
||||
/// should make a best effort to fetch the block from any peers it is
|
||||
/// connected to (NOTE: this assumption will change in the future #3629).
|
||||
///
|
||||
/// Note: this method isn't strictly related to gossiping and should eventually be moved
|
||||
/// somewhere else.
|
||||
fn set_sync_fork_request(&self, peers: Vec<PeerId>, hash: B::Hash, number: NumberFor<B>);
|
||||
}
|
||||
|
||||
impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Network<B> for Arc<NetworkService<B, S, H>> {
|
||||
@@ -133,8 +122,4 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Network<B> for Arc<Netw
|
||||
fn announce(&self, block: B::Hash, associated_data: Vec<u8>) {
|
||||
NetworkService::announce_block(self, block, associated_data)
|
||||
}
|
||||
|
||||
fn set_sync_fork_request(&self, peers: Vec<sc_network::PeerId>, hash: B::Hash, number: NumberFor<B>) {
|
||||
NetworkService::set_sync_fork_request(self, peers, hash, number)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user