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