Split the service initialisation up into seperate functions (#6332)

* Seperate out the complexity in ServiceBuilder::build_common into seperate functions

* Fix line widths

* Move some functions to their respective crates
This commit is contained in:
Ashley
2020-06-16 15:50:21 +02:00
committed by GitHub
parent c44947bbcb
commit 761dbd7dcc
19 changed files with 452 additions and 330 deletions
+7 -8
View File
@@ -27,10 +27,11 @@ use sc_network::{network_state::NetworkState, NetworkStatus};
use sp_blockchain::HeaderMetadata;
use sp_runtime::traits::{Block as BlockT, Header};
use sp_transaction_pool::TransactionPool;
use sp_utils::mpsc::TracingUnboundedReceiver;
use sp_utils::{status_sinks, mpsc::tracing_unbounded};
use std::fmt::Display;
use std::sync::Arc;
use std::time::Duration;
use parking_lot::Mutex;
mod display;
@@ -60,12 +61,7 @@ impl<T: TransactionPool + MallocSizeOf> TransactionPoolAndMaybeMallogSizeOf for
/// Builds the informant and returns a `Future` that drives the informant.
pub fn build<B: BlockT, C>(
client: Arc<C>,
network_status_stream_builder: impl FnOnce(
Duration,
) -> TracingUnboundedReceiver<(
NetworkStatus<B>,
NetworkState,
)>,
network_status_sinks: Arc<Mutex<status_sinks::StatusSinks<(NetworkStatus<B>, NetworkState)>>>,
pool: Arc<impl TransactionPoolAndMaybeMallogSizeOf>,
format: OutputFormat,
) -> impl futures::Future<Output = ()>
@@ -76,7 +72,10 @@ where
let mut display = display::InformantDisplay::new(format.clone());
let client_1 = client.clone();
let display_notifications = network_status_stream_builder(Duration::from_millis(5000))
let (network_status_sink, network_status_stream) = tracing_unbounded("mpsc_network_status");
network_status_sinks.lock().push(Duration::from_millis(5000), network_status_sink);
let display_notifications = network_status_stream
.for_each(move |(net_status, _)| {
let info = client_1.usage_info();
if let Some(ref usage) = info.usage {