From eac2ae7b9a94402a26b6f2b7b9b4a848a90f3d08 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Mon, 6 Jan 2020 16:45:02 +0100 Subject: [PATCH] service/src/lib.rs: Register network event stream for authority disc (#678) * service/src/lib.rs: Register network event stream for authority disc Previously one would create a sender and receiver channel pair, pass the sender to the build_network_future through the service builder and funnel network events returned from polling the network service into the sender to be consumed by the authority discovery module owning the receiver. With recent changes it is now possible to register an event_stream with the network service directly, thus one does not need to make the detour through the build_network_future. This commit is an adjusted clone of one targeting the Substrate repository. * service/src/lib.rs: Fix futures::stream imports * [TMP] *: Replace polkadot-upstream with feature branch * Revert "[TMP] *: Replace polkadot-upstream with feature branch" This reverts commit 0c947b04ab80488bfca16c5aeac9657b77a93a44. --- service/src/lib.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/service/src/lib.rs b/service/src/lib.rs index 6e5d4833ea53d..37db8cf423f1d 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -18,7 +18,6 @@ pub mod chain_spec; -use futures01::sync::mpsc; use futures::{FutureExt, TryFutureExt, task::{Spawn, SpawnError, FutureObj}}; use client::LongestChain; use std::sync::Arc; @@ -280,8 +279,12 @@ pub fn new_full(config: Configuration) Dispatch: NativeExecutionDispatch + 'static, Extrinsic: RuntimeExtrinsic, { - use sc_network::DhtEvent; - use futures::{compat::Stream01CompatExt, stream::StreamExt}; + use sc_network::Event; + use futures01::Stream; + use futures::{ + compat::Stream01CompatExt, + stream::StreamExt, + }; let is_collator = config.custom.collating_for.is_some(); let is_authority = config.roles.is_authority() && !is_collator; @@ -305,19 +308,11 @@ pub fn new_full(config: Configuration) let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config, Runtime, Dispatch); - // Dht event channel from the network to the authority discovery module. Use - // bounded channel to ensure back-pressure. Authority discovery is triggering one - // event per authority within the current authority set. This estimates the - // authority set size to be somewhere below 10 000 thereby setting the channel - // buffer size to 10 000. - let (dht_event_tx, dht_event_rx) = mpsc::channel::(10000); - let service = builder .with_network_protocol(|config| Ok(PolkadotProtocol::new(config.custom.collating_for.clone())))? .with_finality_proof_provider(|client, backend| Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _) )? - .with_dht_event_tx(dht_event_tx)? .build()?; let (block_import, link_half, babe_link) = import_setup.take() @@ -441,15 +436,20 @@ pub fn new_full(config: Configuration) service.spawn_essential_task(babe); if authority_discovery_enabled { - let future03_dht_event_rx = dht_event_rx.compat() + let network = service.network(); + let dht_event_stream = network.event_stream().filter_map(|e| match e { + Event::Dht(e) => Some(e), + _ => None, + }); + let future03_dht_event_stream = dht_event_stream.compat() .map(|x| x.expect(" never returns an error; qed")) .boxed(); let authority_discovery = authority_discovery::AuthorityDiscovery::new( service.client(), - service.network(), + network, sentry_nodes, service.keystore(), - future03_dht_event_rx, + future03_dht_event_stream, ); let future01_authority_discovery = authority_discovery.map(|x| Ok(x)).compat();