Simplify trait bounds in network to prepare for collator-rpc (#12082)

* Hack towards PoC

* Abstract away runtime requirement

* blockchainevents

* Remove bitswap

* Remove unused sync more

* Remove unused features in network

* Re-enable bitswap change

* Remove `Chain` trait bound

* Reimplement blockchain-rpc-events

* Move network to cumulus

* Make AuthorityDiscovery async

* Remove `ProofProvider` requirement from network behaviour

* Extract bitswap

* Adjustments after merge

* Remove HeaderMetadata trait from network

* Introduce NetworkHeaderBackend

* Add comments

* Improve comments

* Move NetworkHeaderBackend to new module

* Improve naming, remove redundand send + sync

* Clean up generics

* Fix CI

* Improve comment and readability

* Remove NetworkHeaderBackend

* Fix Cargo.lock

Co-authored-by: Sebastian Kunert <skunert@Sebastians-MacBook-Pro.fritz.box>
This commit is contained in:
Sebastian Kunert
2022-08-31 14:55:46 +02:00
committed by GitHub
parent 30951822ba
commit 800bc5cd8c
14 changed files with 165 additions and 155 deletions
+2
View File
@@ -7742,6 +7742,7 @@ dependencies = [
name = "sc-authority-discovery"
version = "0.10.0-dev"
dependencies = [
"async-trait",
"futures",
"futures-timer",
"ip_network",
@@ -8451,6 +8452,7 @@ dependencies = [
"sc-peerset",
"serde",
"smallvec",
"sp-blockchain",
"sp-consensus",
"sp-finality-grandpa",
"sp-runtime",
@@ -35,6 +35,7 @@ sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" }
sp-core = { version = "6.0.0", path = "../../primitives/core" }
sp-keystore = { version = "0.12.0", path = "../../primitives/keystore" }
sp-runtime = { version = "6.0.0", path = "../../primitives/runtime" }
async-trait = "0.1.56"
[dev-dependencies]
quickcheck = { version = "1.0.3", default-features = false }
@@ -29,7 +29,7 @@
pub use crate::{
service::Service,
worker::{NetworkProvider, Role, Worker},
worker::{AuthorityDiscovery, NetworkProvider, Role, Worker},
};
use std::{collections::HashSet, sync::Arc, time::Duration};
@@ -40,10 +40,9 @@ use futures::{
};
use libp2p::{Multiaddr, PeerId};
use sc_client_api::blockchain::HeaderBackend;
use sc_network_common::protocol::event::DhtEvent;
use sp_api::ProvideRuntimeApi;
use sp_authority_discovery::{AuthorityDiscoveryApi, AuthorityId};
use sp_authority_discovery::AuthorityId;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block as BlockT;
mod error;
@@ -122,8 +121,7 @@ pub fn new_worker_and_service<Client, Network, Block, DhtEventStream>(
where
Block: BlockT + Unpin + 'static,
Network: NetworkProvider,
Client: ProvideRuntimeApi<Block> + Send + Sync + 'static + HeaderBackend<Block>,
<Client as ProvideRuntimeApi<Block>>::Api: AuthorityDiscoveryApi<Block>,
Client: AuthorityDiscovery<Block> + Send + Sync + 'static + HeaderBackend<Block>,
DhtEventStream: Stream<Item = DhtEvent> + Unpin,
{
new_worker_and_service_with_config(
@@ -150,8 +148,7 @@ pub fn new_worker_and_service_with_config<Client, Network, Block, DhtEventStream
where
Block: BlockT + Unpin + 'static,
Network: NetworkProvider,
Client: ProvideRuntimeApi<Block> + Send + Sync + 'static + HeaderBackend<Block>,
<Client as ProvideRuntimeApi<Block>>::Api: AuthorityDiscoveryApi<Block>,
Client: AuthorityDiscovery<Block> + HeaderBackend<Block> + 'static,
DhtEventStream: Stream<Item = DhtEvent> + Unpin,
{
let (to_worker, from_service) = mpsc::channel(0);
@@ -43,15 +43,16 @@ use log::{debug, error, log_enabled};
use prometheus_endpoint::{register, Counter, CounterVec, Gauge, Opts, U64};
use prost::Message;
use rand::{seq::SliceRandom, thread_rng};
use sc_client_api::blockchain::HeaderBackend;
use sc_network_common::{
protocol::event::DhtEvent,
service::{KademliaKey, NetworkDHTProvider, NetworkSigner, NetworkStateInfo, Signature},
};
use sp_api::ProvideRuntimeApi;
use sp_api::{ApiError, ProvideRuntimeApi};
use sp_authority_discovery::{
AuthorityDiscoveryApi, AuthorityId, AuthorityPair, AuthoritySignature,
};
use sp_blockchain::HeaderBackend;
use sp_core::crypto::{key_types, CryptoTypePublicPair, Pair};
use sp_keystore::CryptoStore;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
@@ -150,12 +151,35 @@ pub struct Worker<Client, Network, Block, DhtEventStream> {
phantom: PhantomData<Block>,
}
/// Wrapper for [`AuthorityDiscoveryApi`](sp_authority_discovery::AuthorityDiscoveryApi). Can be
/// be implemented by any struct without dependency on the runtime.
#[async_trait::async_trait]
pub trait AuthorityDiscovery<Block: BlockT> {
/// Retrieve authority identifiers of the current and next authority set.
async fn authorities(&self, at: Block::Hash)
-> std::result::Result<Vec<AuthorityId>, ApiError>;
}
#[async_trait::async_trait]
impl<Block, T> AuthorityDiscovery<Block> for T
where
T: ProvideRuntimeApi<Block> + Send + Sync,
T::Api: AuthorityDiscoveryApi<Block>,
Block: BlockT,
{
async fn authorities(
&self,
at: Block::Hash,
) -> std::result::Result<Vec<AuthorityId>, ApiError> {
self.runtime_api().authorities(&BlockId::Hash(at))
}
}
impl<Client, Network, Block, DhtEventStream> Worker<Client, Network, Block, DhtEventStream>
where
Block: BlockT + Unpin + 'static,
Network: NetworkProvider,
Client: ProvideRuntimeApi<Block> + Send + Sync + 'static + HeaderBackend<Block>,
<Client as ProvideRuntimeApi<Block>>::Api: AuthorityDiscoveryApi<Block>,
Client: AuthorityDiscovery<Block> + HeaderBackend<Block> + 'static,
DhtEventStream: Stream<Item = DhtEvent> + Unpin,
{
/// Construct a [`Worker`].
@@ -354,7 +378,7 @@ where
}
async fn refill_pending_lookups_queue(&mut self) -> Result<()> {
let id = BlockId::hash(self.client.info().best_hash);
let best_hash = self.client.info().best_hash;
let local_keys = match &self.role {
Role::PublishAndDiscover(key_store) => key_store
@@ -367,8 +391,8 @@ where
let mut authorities = self
.client
.runtime_api()
.authorities(&id)
.authorities(best_hash)
.await
.map_err(|e| Error::CallingRuntime(e.into()))?
.into_iter()
.filter(|id| !local_keys.contains(id.as_ref()))
@@ -574,10 +598,10 @@ where
.into_iter()
.collect::<HashSet<_>>();
let id = BlockId::hash(client.info().best_hash);
let best_hash = client.info().best_hash;
let authorities = client
.runtime_api()
.authorities(&id)
.authorities(best_hash)
.await
.map_err(|e| Error::CallingRuntime(e.into()))?
.into_iter()
.map(Into::into)
@@ -32,6 +32,7 @@ use futures::{
use libp2p::{core::multiaddr, identity::Keypair, PeerId};
use prometheus_endpoint::prometheus::default_registry;
use sc_client_api::HeaderBackend;
use sc_network_common::service::{KademliaKey, Signature, SigningError};
use sp_api::{ApiRef, ProvideRuntimeApi};
use sp_keystore::{testing::KeyStore, CryptoStore};
@@ -32,4 +32,5 @@ serde = { version = "1.0.136", features = ["derive"] }
sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" }
sp-finality-grandpa = { version = "4.0.0-dev", path = "../../../primitives/finality-grandpa" }
sp-runtime = { version = "6.0.0", path = "../../../primitives/runtime" }
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
thiserror = "1.0"
+11 -60
View File
@@ -39,7 +39,6 @@ use libp2p::{
};
use log::debug;
use sc_client_api::{BlockBackend, ProofProvider};
use sc_consensus::import_queue::{IncomingBlock, Origin};
use sc_network_common::{
config::ProtocolId,
@@ -47,7 +46,7 @@ use sc_network_common::{
request_responses::{IfDisconnected, ProtocolConfig, RequestFailure},
};
use sc_peerset::PeersetHandle;
use sp_blockchain::{HeaderBackend, HeaderMetadata};
use sp_blockchain::HeaderBackend;
use sp_consensus::BlockOrigin;
use sp_runtime::{
traits::{Block as BlockT, NumberFor},
@@ -69,13 +68,7 @@ pub use crate::request_responses::{InboundFailure, OutboundFailure, RequestId, R
pub struct Behaviour<B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
/// All the substrate-specific protocols.
substrate: Protocol<B, Client>,
@@ -85,7 +78,7 @@ where
/// Discovers nodes of the network.
discovery: DiscoveryBehaviour,
/// Bitswap server for blockchain data.
bitswap: Toggle<Bitswap<B, Client>>,
bitswap: Toggle<Bitswap<B>>,
/// Generic request-response protocols.
request_responses: request_responses::RequestResponsesBehaviour,
@@ -208,13 +201,7 @@ pub enum BehaviourOut<B: BlockT> {
impl<B, Client> Behaviour<B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
/// Builds a new `Behaviour`.
pub fn new(
@@ -225,7 +212,7 @@ where
block_request_protocol_config: ProtocolConfig,
state_request_protocol_config: ProtocolConfig,
warp_sync_protocol_config: Option<ProtocolConfig>,
bitswap: Option<Bitswap<B, Client>>,
bitswap: Option<Bitswap<B>>,
light_client_request_protocol_config: ProtocolConfig,
// All remaining request protocol configs.
mut request_response_protocols: Vec<ProtocolConfig>,
@@ -352,13 +339,7 @@ fn reported_roles_to_observed_role(roles: Roles) -> ObservedRole {
impl<B, Client> NetworkBehaviourEventProcess<void::Void> for Behaviour<B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
fn inject_event(&mut self, event: void::Void) {
void::unreachable(event)
@@ -368,13 +349,7 @@ where
impl<B, Client> NetworkBehaviourEventProcess<CustomMessageOutcome<B>> for Behaviour<B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
fn inject_event(&mut self, event: CustomMessageOutcome<B>) {
match event {
@@ -483,13 +458,7 @@ where
impl<B, Client> NetworkBehaviourEventProcess<request_responses::Event> for Behaviour<B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
fn inject_event(&mut self, event: request_responses::Event) {
match event {
@@ -515,13 +484,7 @@ where
impl<B, Client> NetworkBehaviourEventProcess<peer_info::PeerInfoEvent> for Behaviour<B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
fn inject_event(&mut self, event: peer_info::PeerInfoEvent) {
let peer_info::PeerInfoEvent::Identified {
@@ -548,13 +511,7 @@ where
impl<B, Client> NetworkBehaviourEventProcess<DiscoveryOut> for Behaviour<B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
fn inject_event(&mut self, out: DiscoveryOut) {
match out {
@@ -592,13 +549,7 @@ where
impl<B, Client> Behaviour<B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
fn poll(
&mut self,
+84 -8
View File
@@ -178,24 +178,99 @@ impl Prefix {
}
}
/// Bitswap trait
pub trait BitswapT<B: BlockT> {
/// Get single indexed transaction by content hash.
///
/// Note that this will only fetch transactions
/// that are indexed by the runtime with `storage_index_transaction`.
fn indexed_transaction(
&self,
hash: <B as BlockT>::Hash,
) -> sp_blockchain::Result<Option<Vec<u8>>>;
/// Queue of blocks ready to be sent out on `poll()`
fn ready_blocks(&mut self) -> &mut VecDeque<(PeerId, BitswapMessage)>;
}
/// Network behaviour that handles sending and receiving IPFS blocks.
pub struct Bitswap<B, Client> {
struct BitswapInternal<B, Client> {
client: Arc<Client>,
ready_blocks: VecDeque<(PeerId, BitswapMessage)>,
_block: PhantomData<B>,
}
impl<B, Client> Bitswap<B, Client> {
impl<B, Client> BitswapInternal<B, Client> {
/// Create a new instance of the bitswap protocol handler.
pub fn new(client: Arc<Client>) -> Self {
Self { client, ready_blocks: Default::default(), _block: PhantomData::default() }
}
}
impl<B, Client> NetworkBehaviour for Bitswap<B, Client>
impl<Block, Client> BitswapT<Block> for BitswapInternal<Block, Client>
where
Block: BlockT,
Client: BlockBackend<Block>,
{
fn indexed_transaction(
&self,
hash: <Block as BlockT>::Hash,
) -> sp_blockchain::Result<Option<Vec<u8>>> {
self.client.indexed_transaction(&hash)
}
fn ready_blocks(&mut self) -> &mut VecDeque<(PeerId, BitswapMessage)> {
&mut self.ready_blocks
}
}
/// Wrapper for bitswap trait object implement NetworkBehaviour
pub struct Bitswap<Block: BlockT> {
inner: Box<dyn BitswapT<Block> + Sync + Send>,
}
impl<B: BlockT> Bitswap<B> {
/// Create new Bitswap wrapper
pub fn from_client<Client: BlockBackend<B> + Send + Sync + 'static>(
client: Arc<Client>,
) -> Self {
let inner = Box::new(BitswapInternal::new(client)) as Box<_>;
Self { inner }
}
}
impl<Block: BlockT> BitswapT<Block> for Bitswap<Block> {
fn indexed_transaction(
&self,
hash: <Block as BlockT>::Hash,
) -> sp_blockchain::Result<Option<Vec<u8>>> {
self.inner.indexed_transaction(hash)
}
fn ready_blocks(&mut self) -> &mut VecDeque<(PeerId, BitswapMessage)> {
self.inner.ready_blocks()
}
}
impl<Block: BlockT, T> BitswapT<Block> for Box<T>
where
T: BitswapT<Block>,
{
fn indexed_transaction(
&self,
hash: <Block as BlockT>::Hash,
) -> sp_blockchain::Result<Option<Vec<u8>>> {
T::indexed_transaction(self, hash)
}
fn ready_blocks(&mut self) -> &mut VecDeque<(PeerId, BitswapMessage)> {
T::ready_blocks(self)
}
}
impl<B> NetworkBehaviour for Bitswap<B>
where
B: BlockT,
Client: BlockBackend<B> + Send + Sync + 'static,
{
type ConnectionHandler = OneShotHandler<BitswapConfig, BitswapMessage, HandlerEvent>;
type OutEvent = void::Void;
@@ -214,10 +289,11 @@ where
HandlerEvent::Request(msg) => msg,
};
trace!(target: LOG_TARGET, "Received request: {:?} from {}", request, peer);
if self.ready_blocks.len() > MAX_RESPONSE_QUEUE {
if self.ready_blocks().len() > MAX_RESPONSE_QUEUE {
debug!(target: LOG_TARGET, "Ignored request: queue is full");
return
}
let mut response = BitswapMessage {
wantlist: None,
blocks: Default::default(),
@@ -253,7 +329,7 @@ where
}
let mut hash = B::Hash::default();
hash.as_mut().copy_from_slice(&cid.hash().digest()[0..32]);
let transaction = match self.client.indexed_transaction(&hash) {
let transaction = match self.indexed_transaction(hash) {
Ok(ex) => ex,
Err(e) => {
error!(target: LOG_TARGET, "Error retrieving transaction {}: {}", hash, e);
@@ -292,7 +368,7 @@ where
}
}
trace!(target: LOG_TARGET, "Response: {:?}", response);
self.ready_blocks.push_back((peer, response));
self.ready_blocks().push_back((peer, response));
}
fn poll(
@@ -300,7 +376,7 @@ where
_ctx: &mut Context,
_: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
if let Some((peer_id, message)) = self.ready_blocks.pop_front() {
if let Some((peer_id, message)) = self.ready_blocks().pop_front() {
return Poll::Ready(NetworkBehaviourAction::NotifyHandler {
peer_id,
handler: NotifyHandler::Any,
+4 -1
View File
@@ -31,7 +31,7 @@ pub use sc_network_common::{
pub use libp2p::{build_multiaddr, core::PublicKey, identity};
use crate::ExHashT;
use crate::{bitswap::Bitswap, ExHashT};
use core::{fmt, iter};
use futures::future;
@@ -80,6 +80,9 @@ where
/// Client that contains the blockchain.
pub chain: Arc<Client>,
/// Bitswap block request protocol implementation.
pub bitswap: Option<Bitswap<B>>,
/// Pool of transactions.
///
/// The network worker will fetch transactions from this object in order to propagate them on
+4 -17
View File
@@ -40,7 +40,7 @@ use message::{
};
use notifications::{Notifications, NotificationsOut};
use prometheus_endpoint::{register, Gauge, GaugeVec, Opts, PrometheusError, Registry, U64};
use sc_client_api::{BlockBackend, HeaderBackend, ProofProvider};
use sc_client_api::HeaderBackend;
use sc_consensus::import_queue::{BlockImportError, BlockImportStatus, IncomingBlock, Origin};
use sc_network_common::{
config::ProtocolId,
@@ -56,7 +56,6 @@ use sc_network_common::{
},
};
use sp_arithmetic::traits::SaturatedConversion;
use sp_blockchain::HeaderMetadata;
use sp_consensus::BlockOrigin;
use sp_runtime::{
generic::BlockId,
@@ -262,13 +261,7 @@ impl<B: BlockT> BlockAnnouncesHandshake<B> {
impl<B, Client> Protocol<B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
/// Create a new instance.
pub fn new(
@@ -373,7 +366,7 @@ where
let block_announces_protocol = {
let genesis_hash =
chain.block_hash(0u32.into()).ok().flatten().expect("Genesis block exists; qed");
chain.hash(0u32.into()).ok().flatten().expect("Genesis block exists; qed");
if let Some(fork_id) = fork_id {
format!("/{}/{}/block-announces/1", hex::encode(genesis_hash), fork_id)
} else {
@@ -1318,13 +1311,7 @@ pub enum CustomMessageOutcome<B: BlockT> {
impl<B, Client> NetworkBehaviour for Protocol<B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
type ConnectionHandler = <Notifications as NetworkBehaviour>::ConnectionHandler;
type OutEvent = CustomMessageOutcome<B>;
+9 -49
View File
@@ -29,7 +29,6 @@
use crate::{
behaviour::{self, Behaviour, BehaviourOut},
bitswap::Bitswap,
config::{Params, TransportConfig},
discovery::DiscoveryConfig,
error::Error,
@@ -59,7 +58,6 @@ use libp2p::{
use log::{debug, error, info, trace, warn};
use metrics::{Histogram, HistogramVec, MetricSources, Metrics};
use parking_lot::Mutex;
use sc_client_api::{BlockBackend, ProofProvider};
use sc_consensus::{BlockImportError, BlockImportStatus, ImportQueue, Link};
use sc_network_common::{
config::MultiaddrWithPeerId,
@@ -75,7 +73,7 @@ use sc_network_common::{
};
use sc_peerset::PeersetHandle;
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use sp_blockchain::{HeaderBackend, HeaderMetadata};
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use std::{
borrow::Cow,
@@ -137,13 +135,7 @@ impl<B, H, Client> NetworkWorker<B, H, Client>
where
B: BlockT + 'static,
H: ExHashT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: sp_blockchain::HeaderBackend<B> + 'static,
{
/// Creates the network service.
///
@@ -220,7 +212,7 @@ where
params.protocol_id.clone(),
params
.chain
.block_hash(0u32.into())
.hash(0u32.into())
.ok()
.flatten()
.expect("Genesis block exists; qed"),
@@ -374,7 +366,6 @@ where
};
let behaviour = {
let bitswap = params.network_config.ipfs_server.then(|| Bitswap::new(params.chain));
let result = Behaviour::new(
protocol,
user_agent,
@@ -383,7 +374,7 @@ where
params.block_request_protocol_config,
params.state_request_protocol_config,
params.warp_sync_protocol_config,
bitswap,
params.bitswap,
params.light_client_request_protocol_config,
params.network_config.request_response_protocols,
peerset_handle.clone(),
@@ -1297,13 +1288,7 @@ pub struct NetworkWorker<B, H, Client>
where
B: BlockT + 'static,
H: ExHashT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
/// Updated by the `NetworkWorker` and loaded by the `NetworkService`.
external_addresses: Arc<Mutex<Vec<Multiaddr>>>,
@@ -1336,13 +1321,7 @@ impl<B, H, Client> Future for NetworkWorker<B, H, Client>
where
B: BlockT + 'static,
H: ExHashT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
type Output = ();
@@ -1375,7 +1354,6 @@ where
Poll::Ready(None) => return Poll::Ready(()),
Poll::Pending => break,
};
match msg {
ServiceToWorkerMsg::AnnounceBlock(hash, data) => this
.network_service
@@ -1988,13 +1966,7 @@ impl<B, H, Client> Unpin for NetworkWorker<B, H, Client>
where
B: BlockT + 'static,
H: ExHashT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
}
@@ -2002,13 +1974,7 @@ where
struct NetworkLink<'a, B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
protocol: &'a mut Swarm<Behaviour<B, Client>>,
}
@@ -2016,13 +1982,7 @@ where
impl<'a, B, Client> Link<B> for NetworkLink<'a, B, Client>
where
B: BlockT,
Client: HeaderBackend<B>
+ BlockBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ ProofProvider<B>
+ Send
+ Sync
+ 'static,
Client: HeaderBackend<B> + 'static,
{
fn blocks_processed(
&mut self,
@@ -146,6 +146,7 @@ fn build_test_full_node(
import_queue,
chain_sync: Box::new(chain_sync),
metrics_registry: None,
bitswap: None,
block_request_protocol_config,
state_request_protocol_config,
light_client_request_protocol_config,
+1
View File
@@ -883,6 +883,7 @@ where
import_queue,
chain_sync: Box::new(chain_sync),
metrics_registry: None,
bitswap: None,
block_request_protocol_config,
state_request_protocol_config,
light_client_request_protocol_config,
+7 -2
View File
@@ -37,7 +37,7 @@ use sc_client_db::{Backend, DatabaseSettings};
use sc_consensus::import_queue::ImportQueue;
use sc_executor::RuntimeVersionOf;
use sc_keystore::LocalKeystore;
use sc_network::{config::SyncMode, NetworkService};
use sc_network::{bitswap::Bitswap, config::SyncMode, NetworkService};
use sc_network_common::{
service::{NetworkStateInfo, NetworkStatusProvider, NetworkTransaction},
sync::warp::WarpSyncProvider,
@@ -711,7 +711,6 @@ pub struct BuildNetworkParams<'a, TBl: BlockT, TExPool, TImpQu, TCl> {
/// An optional warp sync provider.
pub warp_sync: Option<Arc<dyn WarpSyncProvider<TBl>>>,
}
/// Build the network service, the network status sinks and an RPC sender.
pub fn build_network<TBl, TExPool, TImpQu, TCl>(
params: BuildNetworkParams<TBl, TExPool, TImpQu, TCl>,
@@ -857,6 +856,7 @@ where
fork_id: config.chain_spec.fork_id().map(ToOwned::to_owned),
import_queue: Box::new(import_queue),
chain_sync: Box::new(chain_sync),
bitswap: config.network.ipfs_server.then(|| Bitswap::from_client(client.clone())),
metrics_registry: config.prometheus_config.as_ref().map(|config| config.registry.clone()),
block_request_protocol_config,
state_request_protocol_config,
@@ -923,6 +923,11 @@ where
pub struct NetworkStarter(oneshot::Sender<()>);
impl NetworkStarter {
/// Create a new NetworkStarter
pub fn new(sender: oneshot::Sender<()>) -> Self {
NetworkStarter(sender)
}
/// Start the network. Call this after all sub-components have been initialized.
///
/// > **Note**: If you don't call this function, the networking will not work.