* `NetworkStatusSinks`
* `sc_service::SpawnTasksParams::network_status_sinks`

Also:
* `sc_service::build_network()` does not return `network_status_sinks`
This commit is contained in:
Roman Proskuryakov
2021-05-27 12:54:37 +00:00
committed by GitHub
parent fa89414bba
commit 8dfb8cd978
10 changed files with 96 additions and 132 deletions
+1 -1
View File
@@ -15,12 +15,12 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
ansi_term = "0.12.1"
futures = "0.3.9"
futures-timer = "3.0.1"
log = "0.4.8"
parity-util-mem = { version = "0.9.0", default-features = false, features = ["primitive-types"] }
sc-client-api = { version = "3.0.0", path = "../api" }
sc-network = { version = "0.9.0", path = "../network" }
sp-blockchain = { version = "3.0.0", path = "../../primitives/blockchain" }
sp-runtime = { version = "3.0.0", path = "../../primitives/runtime" }
sp-utils = { version = "3.0.0", path = "../../primitives/utils" }
sp-transaction-pool = { version = "3.0.0", path = "../../primitives/transaction-pool" }
wasm-timer = "0.2"
+19 -12
View File
@@ -20,18 +20,23 @@
use ansi_term::Colour;
use futures::prelude::*;
use futures_timer::Delay;
use log::{info, trace, warn};
use parity_util_mem::MallocSizeOf;
use sc_client_api::{BlockchainEvents, UsageProvider};
use sc_network::NetworkStatus;
use sc_network::NetworkService;
use sp_blockchain::HeaderMetadata;
use sp_runtime::traits::{Block as BlockT, Header};
use sp_transaction_pool::TransactionPool;
use sp_utils::{status_sinks, mpsc::tracing_unbounded};
use std::{fmt::Display, sync::Arc, time::Duration, collections::VecDeque};
mod display;
/// Creates a stream that returns a new value every `duration`.
fn interval(duration: Duration) -> impl Stream<Item = ()> + Unpin {
futures::stream::unfold((), move |_| Delay::new(duration).map(|_| Some(((), ())))).map(drop)
}
/// The format to print telemetry output in.
#[derive(Clone, Debug)]
pub struct OutputFormat {
@@ -64,12 +69,12 @@ impl<T: TransactionPool> TransactionPoolAndMaybeMallogSizeOf for T {}
impl<T: TransactionPool + MallocSizeOf> TransactionPoolAndMaybeMallogSizeOf for T {}
/// Builds the informant and returns a `Future` that drives the informant.
pub fn build<B: BlockT, C>(
pub async fn build<B: BlockT, C>(
client: Arc<C>,
network_status_sinks: Arc<status_sinks::StatusSinks<NetworkStatus<B>>>,
network: Arc<NetworkService<B, <B as BlockT>::Hash>>,
pool: Arc<impl TransactionPoolAndMaybeMallogSizeOf>,
format: OutputFormat,
) -> impl futures::Future<Output = ()>
)
where
C: UsageProvider<B> + HeaderMetadata<B> + BlockchainEvents<B>,
<C as HeaderMetadata<B>>::Error: Display,
@@ -77,10 +82,12 @@ where
let mut display = display::InformantDisplay::new(format.clone());
let client_1 = client.clone();
let (network_status_sink, network_status_stream) = tracing_unbounded("mpsc_network_status");
network_status_sinks.push(Duration::from_millis(5000), network_status_sink);
let display_notifications = network_status_stream
let display_notifications = interval(Duration::from_millis(5000))
.filter_map(|_| async {
let status = network.status().await;
status.ok()
})
.for_each(move |net_status| {
let info = client_1.usage_info();
if let Some(ref usage) = info.usage {
@@ -101,10 +108,10 @@ where
future::ready(())
});
future::join(
display_notifications,
display_block_import(client),
).map(|_| ())
futures::select! {
() = display_notifications.fuse() => (),
() = display_block_import(client).fuse() => (),
};
}
fn display_block_import<B: BlockT, C>(client: Arc<C>) -> impl Future<Output = ()>