mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 12:51:05 +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:
@@ -22,7 +22,7 @@ use ahash::AHashSet;
|
||||
use libp2p::PeerId;
|
||||
use lru::LruCache;
|
||||
use prometheus_endpoint::{register, Counter, PrometheusError, Registry, U64};
|
||||
use sc_network::ObservedRole;
|
||||
use sc_network_common::protocol::event::ObservedRole;
|
||||
use sp_runtime::traits::{Block as BlockT, Hash, HashFor};
|
||||
use std::{borrow::Cow, collections::HashMap, iter, sync::Arc, time, time::Instant};
|
||||
|
||||
@@ -511,11 +511,23 @@ impl Metrics {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::multiaddr::Multiaddr;
|
||||
use futures::prelude::*;
|
||||
use sc_network::{Event, ReputationChange};
|
||||
use sp_runtime::testing::{Block as RawBlock, ExtrinsicWrapper, H256};
|
||||
use sc_network::ReputationChange;
|
||||
use sc_network_common::{
|
||||
protocol::event::Event,
|
||||
service::{
|
||||
NetworkBlock, NetworkEventStream, NetworkNotification, NetworkPeers,
|
||||
NotificationSender, NotificationSenderError,
|
||||
},
|
||||
};
|
||||
use sp_runtime::{
|
||||
testing::{Block as RawBlock, ExtrinsicWrapper, H256},
|
||||
traits::NumberFor,
|
||||
};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::HashSet,
|
||||
pin::Pin,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
@@ -569,28 +581,118 @@ mod tests {
|
||||
peer_reports: Vec<(PeerId, ReputationChange)>,
|
||||
}
|
||||
|
||||
impl<B: BlockT> Network<B> for NoOpNetwork {
|
||||
fn event_stream(&self) -> Pin<Box<dyn Stream<Item = Event> + Send>> {
|
||||
impl NetworkPeers for NoOpNetwork {
|
||||
fn set_authorized_peers(&self, _peers: HashSet<PeerId>) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn report_peer(&self, peer_id: PeerId, reputation_change: ReputationChange) {
|
||||
self.inner.lock().unwrap().peer_reports.push((peer_id, reputation_change));
|
||||
}
|
||||
|
||||
fn disconnect_peer(&self, _: PeerId, _: Cow<'static, str>) {
|
||||
fn set_authorized_only(&self, _reserved_only: bool) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn add_set_reserved(&self, _: PeerId, _: Cow<'static, str>) {}
|
||||
|
||||
fn remove_set_reserved(&self, _: PeerId, _: Cow<'static, str>) {}
|
||||
|
||||
fn write_notification(&self, _: PeerId, _: Cow<'static, str>, _: Vec<u8>) {
|
||||
fn add_known_address(&self, _peer_id: PeerId, _addr: Multiaddr) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn announce(&self, _: B::Hash, _: Option<Vec<u8>>) {
|
||||
fn report_peer(&self, who: PeerId, cost_benefit: ReputationChange) {
|
||||
self.inner.lock().unwrap().peer_reports.push((who, cost_benefit));
|
||||
}
|
||||
|
||||
fn disconnect_peer(&self, _who: PeerId, _protocol: Cow<'static, str>) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn accept_unreserved_peers(&self) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn deny_unreserved_peers(&self) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn add_reserved_peer(&self, _peer: String) -> Result<(), String> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn remove_reserved_peer(&self, _peer_id: PeerId) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn set_reserved_peers(
|
||||
&self,
|
||||
_protocol: Cow<'static, str>,
|
||||
_peers: HashSet<Multiaddr>,
|
||||
) -> Result<(), String> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn add_peers_to_reserved_set(
|
||||
&self,
|
||||
_protocol: Cow<'static, str>,
|
||||
_peers: HashSet<Multiaddr>,
|
||||
) -> Result<(), String> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn remove_peers_from_reserved_set(
|
||||
&self,
|
||||
_protocol: Cow<'static, str>,
|
||||
_peers: Vec<PeerId>,
|
||||
) {
|
||||
}
|
||||
|
||||
fn add_to_peers_set(
|
||||
&self,
|
||||
_protocol: Cow<'static, str>,
|
||||
_peers: HashSet<Multiaddr>,
|
||||
) -> Result<(), String> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn remove_from_peers_set(&self, _protocol: Cow<'static, str>, _peers: Vec<PeerId>) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn sync_num_connected(&self) -> usize {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkEventStream for NoOpNetwork {
|
||||
fn event_stream(&self, _name: &'static str) -> Pin<Box<dyn Stream<Item = Event> + Send>> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkNotification for NoOpNetwork {
|
||||
fn write_notification(
|
||||
&self,
|
||||
_target: PeerId,
|
||||
_protocol: Cow<'static, str>,
|
||||
_message: Vec<u8>,
|
||||
) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn notification_sender(
|
||||
&self,
|
||||
_target: PeerId,
|
||||
_protocol: Cow<'static, str>,
|
||||
) -> Result<Box<dyn NotificationSender>, NotificationSenderError> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkBlock<<Block as BlockT>::Hash, NumberFor<Block>> for NoOpNetwork {
|
||||
fn announce_block(&self, _hash: <Block as BlockT>::Hash, _data: Option<Vec<u8>>) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn new_best_block_imported(
|
||||
&self,
|
||||
_hash: <Block as BlockT>::Hash,
|
||||
_number: NumberFor<Block>,
|
||||
) {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user