diff --git a/Cargo.lock b/Cargo.lock index d90de9da4f579..b0d0206a35300 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/client/authority-discovery/Cargo.toml b/client/authority-discovery/Cargo.toml index b7a140f24a111..d9e9df4f2a97c 100644 --- a/client/authority-discovery/Cargo.toml +++ b/client/authority-discovery/Cargo.toml @@ -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 } diff --git a/client/authority-discovery/src/lib.rs b/client/authority-discovery/src/lib.rs index f0ef374551617..db3802b168fe5 100644 --- a/client/authority-discovery/src/lib.rs +++ b/client/authority-discovery/src/lib.rs @@ -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( where Block: BlockT + Unpin + 'static, Network: NetworkProvider, - Client: ProvideRuntimeApi + Send + Sync + 'static + HeaderBackend, - >::Api: AuthorityDiscoveryApi, + Client: AuthorityDiscovery + Send + Sync + 'static + HeaderBackend, DhtEventStream: Stream + Unpin, { new_worker_and_service_with_config( @@ -150,8 +148,7 @@ pub fn new_worker_and_service_with_config + Send + Sync + 'static + HeaderBackend, - >::Api: AuthorityDiscoveryApi, + Client: AuthorityDiscovery + HeaderBackend + 'static, DhtEventStream: Stream + Unpin, { let (to_worker, from_service) = mpsc::channel(0); diff --git a/client/authority-discovery/src/worker.rs b/client/authority-discovery/src/worker.rs index f13a1cf33581b..4121b64e00b9b 100644 --- a/client/authority-discovery/src/worker.rs +++ b/client/authority-discovery/src/worker.rs @@ -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 { phantom: PhantomData, } +/// 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 { + /// Retrieve authority identifiers of the current and next authority set. + async fn authorities(&self, at: Block::Hash) + -> std::result::Result, ApiError>; +} + +#[async_trait::async_trait] +impl AuthorityDiscovery for T +where + T: ProvideRuntimeApi + Send + Sync, + T::Api: AuthorityDiscoveryApi, + Block: BlockT, +{ + async fn authorities( + &self, + at: Block::Hash, + ) -> std::result::Result, ApiError> { + self.runtime_api().authorities(&BlockId::Hash(at)) + } +} + impl Worker where Block: BlockT + Unpin + 'static, Network: NetworkProvider, - Client: ProvideRuntimeApi + Send + Sync + 'static + HeaderBackend, - >::Api: AuthorityDiscoveryApi, + Client: AuthorityDiscovery + HeaderBackend + 'static, DhtEventStream: Stream + 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::>(); - 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) diff --git a/client/authority-discovery/src/worker/tests.rs b/client/authority-discovery/src/worker/tests.rs index 7b0ee45833e19..8e7a221877574 100644 --- a/client/authority-discovery/src/worker/tests.rs +++ b/client/authority-discovery/src/worker/tests.rs @@ -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}; diff --git a/client/network/common/Cargo.toml b/client/network/common/Cargo.toml index ea50c8b794ccb..47d43e8b4b03f 100644 --- a/client/network/common/Cargo.toml +++ b/client/network/common/Cargo.toml @@ -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" diff --git a/client/network/src/behaviour.rs b/client/network/src/behaviour.rs index 4ff415788f4ea..4177c2452c7f7 100644 --- a/client/network/src/behaviour.rs +++ b/client/network/src/behaviour.rs @@ -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 where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { /// All the substrate-specific protocols. substrate: Protocol, @@ -85,7 +78,7 @@ where /// Discovers nodes of the network. discovery: DiscoveryBehaviour, /// Bitswap server for blockchain data. - bitswap: Toggle>, + bitswap: Toggle>, /// Generic request-response protocols. request_responses: request_responses::RequestResponsesBehaviour, @@ -208,13 +201,7 @@ pub enum BehaviourOut { impl Behaviour where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + '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, - bitswap: Option>, + bitswap: Option>, light_client_request_protocol_config: ProtocolConfig, // All remaining request protocol configs. mut request_response_protocols: Vec, @@ -352,13 +339,7 @@ fn reported_roles_to_observed_role(roles: Roles) -> ObservedRole { impl NetworkBehaviourEventProcess for Behaviour where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { fn inject_event(&mut self, event: void::Void) { void::unreachable(event) @@ -368,13 +349,7 @@ where impl NetworkBehaviourEventProcess> for Behaviour where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { fn inject_event(&mut self, event: CustomMessageOutcome) { match event { @@ -483,13 +458,7 @@ where impl NetworkBehaviourEventProcess for Behaviour where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { fn inject_event(&mut self, event: request_responses::Event) { match event { @@ -515,13 +484,7 @@ where impl NetworkBehaviourEventProcess for Behaviour where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { fn inject_event(&mut self, event: peer_info::PeerInfoEvent) { let peer_info::PeerInfoEvent::Identified { @@ -548,13 +511,7 @@ where impl NetworkBehaviourEventProcess for Behaviour where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { fn inject_event(&mut self, out: DiscoveryOut) { match out { @@ -592,13 +549,7 @@ where impl Behaviour where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { fn poll( &mut self, diff --git a/client/network/src/bitswap.rs b/client/network/src/bitswap.rs index 2dab45adc5618..52fa0c36caedf 100644 --- a/client/network/src/bitswap.rs +++ b/client/network/src/bitswap.rs @@ -178,24 +178,99 @@ impl Prefix { } } +/// Bitswap trait +pub trait BitswapT { + /// 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: ::Hash, + ) -> sp_blockchain::Result>>; + + /// 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 { +struct BitswapInternal { client: Arc, ready_blocks: VecDeque<(PeerId, BitswapMessage)>, _block: PhantomData, } -impl Bitswap { +impl BitswapInternal { /// Create a new instance of the bitswap protocol handler. pub fn new(client: Arc) -> Self { Self { client, ready_blocks: Default::default(), _block: PhantomData::default() } } } -impl NetworkBehaviour for Bitswap +impl BitswapT for BitswapInternal +where + Block: BlockT, + Client: BlockBackend, +{ + fn indexed_transaction( + &self, + hash: ::Hash, + ) -> sp_blockchain::Result>> { + 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 { + inner: Box + Sync + Send>, +} + +impl Bitswap { + /// Create new Bitswap wrapper + pub fn from_client + Send + Sync + 'static>( + client: Arc, + ) -> Self { + let inner = Box::new(BitswapInternal::new(client)) as Box<_>; + Self { inner } + } +} + +impl BitswapT for Bitswap { + fn indexed_transaction( + &self, + hash: ::Hash, + ) -> sp_blockchain::Result>> { + self.inner.indexed_transaction(hash) + } + + fn ready_blocks(&mut self) -> &mut VecDeque<(PeerId, BitswapMessage)> { + self.inner.ready_blocks() + } +} + +impl BitswapT for Box +where + T: BitswapT, +{ + fn indexed_transaction( + &self, + hash: ::Hash, + ) -> sp_blockchain::Result>> { + T::indexed_transaction(self, hash) + } + + fn ready_blocks(&mut self) -> &mut VecDeque<(PeerId, BitswapMessage)> { + T::ready_blocks(self) + } +} + +impl NetworkBehaviour for Bitswap where B: BlockT, - Client: BlockBackend + Send + Sync + 'static, { type ConnectionHandler = OneShotHandler; 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> { - 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, diff --git a/client/network/src/config.rs b/client/network/src/config.rs index 52fa28e76e207..521aa42827563 100644 --- a/client/network/src/config.rs +++ b/client/network/src/config.rs @@ -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, + /// Bitswap block request protocol implementation. + pub bitswap: Option>, + /// Pool of transactions. /// /// The network worker will fetch transactions from this object in order to propagate them on diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index 351e7d207ad1e..64794538999b0 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -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 BlockAnnouncesHandshake { impl Protocol where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + '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 { impl NetworkBehaviour for Protocol where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { type ConnectionHandler = ::ConnectionHandler; type OutEvent = CustomMessageOutcome; diff --git a/client/network/src/service.rs b/client/network/src/service.rs index 68ac4b8db8a7d..7a196da25260a 100644 --- a/client/network/src/service.rs +++ b/client/network/src/service.rs @@ -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 NetworkWorker where B: BlockT + 'static, H: ExHashT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: sp_blockchain::HeaderBackend + '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 where B: BlockT + 'static, H: ExHashT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { /// Updated by the `NetworkWorker` and loaded by the `NetworkService`. external_addresses: Arc>>, @@ -1336,13 +1321,7 @@ impl Future for NetworkWorker where B: BlockT + 'static, H: ExHashT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + '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 Unpin for NetworkWorker where B: BlockT + 'static, H: ExHashT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { } @@ -2002,13 +1974,7 @@ where struct NetworkLink<'a, B, Client> where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { protocol: &'a mut Swarm>, } @@ -2016,13 +1982,7 @@ where impl<'a, B, Client> Link for NetworkLink<'a, B, Client> where B: BlockT, - Client: HeaderBackend - + BlockBackend - + HeaderMetadata - + ProofProvider - + Send - + Sync - + 'static, + Client: HeaderBackend + 'static, { fn blocks_processed( &mut self, diff --git a/client/network/src/service/tests.rs b/client/network/src/service/tests.rs index e2fe58423abfe..e0d8798aef91e 100644 --- a/client/network/src/service/tests.rs +++ b/client/network/src/service/tests.rs @@ -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, diff --git a/client/network/test/src/lib.rs b/client/network/test/src/lib.rs index fbe56f463d0f3..323af13943de7 100644 --- a/client/network/test/src/lib.rs +++ b/client/network/test/src/lib.rs @@ -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, diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index de04af259600b..f03ba6de2866d 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -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>>, } - /// Build the network service, the network status sinks and an RPC sender. pub fn build_network( params: BuildNetworkParams, @@ -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.