Commit eac2ae7b authored by Max Inden's avatar Max Inden Committed by Gavin Wood
Browse files

service/src/ Register network event stream for authority disc (#678)

* service/src/ 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

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

* service/src/ Fix futures::stream imports

* [TMP] *: Replace polkadot-upstream with feature branch

* Revert "[TMP] *: Replace polkadot-upstream with feature branch"

This reverts commit 0c947b04.
parent c3661f0f
Pipeline #73476 passed with stages
in 14 minutes and 29 seconds
......@@ -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<Runtime, Dispatch, Extrinsic>(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::{
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<Runtime, Dispatch, Extrinsic>(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::<DhtEvent>(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 _)
let (block_import, link_half, babe_link) = import_setup.take()
......@@ -441,15 +436,20 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
if authority_discovery_enabled {
let future03_dht_event_rx = dht_event_rx.compat()
let 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("<mpsc::channel::Receiver as Stream> never returns an error; qed"))
let authority_discovery = authority_discovery::AuthorityDiscovery::new(
let future01_authority_discovery =|x| Ok(x)).compat();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment