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
+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,