mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 03:55:40 +00:00
Network sync refactoring (part 6) (#11940)
* Extract `NetworkKVProvider` trait in `sc-authority-discovery` and remove unnecessary dependency * Extract `NetworkSyncForkRequest` trait in `sc-finality-grandpa` * Relax requirements on `SyncOracle` trait, remove extra native methods from `NetworkService` that are already provided by trait impls * Move `NetworkSigner` trait from `sc-authority-discovery` into `sc-network-common` and de-duplicate methods on `NetworkService` * Move `NetworkKVProvider` trait from `sc-authority-discovery` into `sc-network-common` and de-duplicate methods on `NetworkService` * Minimize `sc-authority-discovery` dependency on `sc-network` * Move `NetworkSyncForkRequest` trait from `sc-finality-grandpa` to `sc-network-common` and de-duplicate methods in `NetworkService` * Extract `NetworkStatusProvider` trait and de-duplicate methods on `NetworkService` * Extract `NetworkPeers` trait and de-duplicate methods on `NetworkService` * Extract `NetworkEventStream` trait and de-duplicate methods on `NetworkService` * Move more methods from `NetworkService` into `NetworkPeers` trait * Move `NetworkStateInfo` trait into `sc-network-common` * Extract `NetworkNotification` trait and de-duplicate methods on `NetworkService` * Extract `NetworkRequest` trait and de-duplicate methods on `NetworkService` * Remove `NetworkService::local_peer_id()`, it is already provided by `NetworkStateInfo` impl * Extract `NetworkTransaction` trait and de-duplicate methods on `NetworkService` * Extract `NetworkBlock` trait and de-duplicate methods on `NetworkService` * Remove dependencies on `NetworkService` from most of the methods of `sc-service` * Address simple review comments
This commit is contained in:
@@ -45,7 +45,7 @@ use finality_grandpa::{
|
||||
Message::{Precommit, Prevote, PrimaryPropose},
|
||||
};
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use sc_network::{NetworkService, ReputationChange};
|
||||
use sc_network::ReputationChange;
|
||||
use sc_network_gossip::{GossipEngine, Network as GossipNetwork};
|
||||
use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_INFO};
|
||||
use sp_keystore::SyncCryptoStorePtr;
|
||||
@@ -58,6 +58,7 @@ use crate::{
|
||||
use gossip::{
|
||||
FullCatchUpMessage, FullCommitMessage, GossipMessage, GossipValidator, PeerReport, VoteMessage,
|
||||
};
|
||||
use sc_network_common::service::{NetworkBlock, NetworkSyncForkRequest};
|
||||
use sc_utils::mpsc::TracingUnboundedReceiver;
|
||||
use sp_finality_grandpa::{AuthorityId, AuthoritySignature, RoundNumber, SetId as SetIdNumber};
|
||||
|
||||
@@ -156,34 +157,26 @@ const TELEMETRY_VOTERS_LIMIT: usize = 10;
|
||||
///
|
||||
/// Something that provides both the capabilities needed for the `gossip_network::Network` trait as
|
||||
/// well as the ability to set a fork sync request for a particular block.
|
||||
pub trait Network<Block: BlockT>: GossipNetwork<Block> + Clone + Send + 'static {
|
||||
/// 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).
|
||||
fn set_sync_fork_request(
|
||||
&self,
|
||||
peers: Vec<sc_network::PeerId>,
|
||||
hash: Block::Hash,
|
||||
number: NumberFor<Block>,
|
||||
);
|
||||
pub trait Network<Block: BlockT>:
|
||||
NetworkSyncForkRequest<Block::Hash, NumberFor<Block>>
|
||||
+ NetworkBlock<Block::Hash, NumberFor<Block>>
|
||||
+ GossipNetwork<Block>
|
||||
+ Clone
|
||||
+ Send
|
||||
+ 'static
|
||||
{
|
||||
}
|
||||
|
||||
impl<B, H> Network<B> for Arc<NetworkService<B, H>>
|
||||
impl<Block, T> Network<Block> for T
|
||||
where
|
||||
B: BlockT,
|
||||
H: sc_network::ExHashT,
|
||||
Block: BlockT,
|
||||
T: NetworkSyncForkRequest<Block::Hash, NumberFor<Block>>
|
||||
+ NetworkBlock<Block::Hash, NumberFor<Block>>
|
||||
+ GossipNetwork<Block>
|
||||
+ Clone
|
||||
+ Send
|
||||
+ 'static,
|
||||
{
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a unique topic for a round and set-id combo.
|
||||
@@ -467,7 +460,7 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
|
||||
hash: B::Hash,
|
||||
number: NumberFor<B>,
|
||||
) {
|
||||
Network::set_sync_fork_request(&self.service, peers, hash, number)
|
||||
self.service.set_sync_fork_request(peers, hash, number)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user