From 2a556e81b835d2066de6d3fb668d2f42440a89c9 Mon Sep 17 00:00:00 2001 From: Roman Proskuryakov Date: Thu, 6 May 2021 14:57:50 +0300 Subject: [PATCH] Remove: * `NetworkStatusSinks` * `NetworkStatus` * `NetworkWorker::status()` * `sc_service::SpawnTasksParams::network_status_sinks` * `sc_service::Configuration::informant_output_format` Also: * `sc_service::build_network()` does not return `network_status_sinks` * `sc_service::run()` and `sc_informant::build()` do not report `NetworkStatus` events (it was broken for some time) --- Cargo.lock | 7 - bin/node-template/node/src/service.rs | 6 +- bin/node/cli/src/service.rs | 9 +- client/cli/src/config.rs | 1 - client/informant/Cargo.toml | 5 - client/informant/src/display.rs | 204 -------------------------- client/informant/src/lib.rs | 59 +------- client/network/src/lib.rs | 20 --- client/network/src/service.rs | 15 +- client/service/src/builder.rs | 20 +-- client/service/src/config.rs | 2 - client/service/src/lib.rs | 54 +------ client/service/src/metrics.rs | 107 +------------- client/service/test/src/lib.rs | 1 - test-utils/test-runner/Cargo.toml | 1 - test-utils/test-runner/src/node.rs | 3 +- test-utils/test-runner/src/utils.rs | 3 - utils/browser/Cargo.toml | 1 - utils/browser/src/lib.rs | 3 - 19 files changed, 18 insertions(+), 503 deletions(-) delete mode 100644 client/informant/src/display.rs diff --git a/Cargo.lock b/Cargo.lock index 4f7bce5aaa3c6..ca77458c3e562 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7529,14 +7529,9 @@ dependencies = [ "ansi_term 0.12.1", "futures 0.3.13", "log", - "parity-util-mem", "sc-client-api", - "sc-network", "sp-blockchain", "sp-runtime", - "sp-transaction-pool", - "sp-utils", - "wasm-timer", ] [[package]] @@ -9436,7 +9431,6 @@ dependencies = [ "log", "rand 0.7.3", "sc-chain-spec", - "sc-informant", "sc-network", "sc-service", "sc-tracing", @@ -9759,7 +9753,6 @@ dependencies = [ "sc-client-api", "sc-consensus-manual-seal", "sc-executor", - "sc-informant", "sc-network", "sc-rpc", "sc-rpc-server", diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index c73956d885bf3..9509a0f417652 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -158,7 +158,7 @@ pub fn new_full(mut config: Configuration) -> Result config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config()); - let (network, network_status_sinks, system_rpc_tx, network_starter) = + let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { config: &config, client: client.clone(), @@ -208,7 +208,6 @@ pub fn new_full(mut config: Configuration) -> Result on_demand: None, remote_blockchain: None, backend, - network_status_sinks, system_rpc_tx, config, telemetry: telemetry.as_mut(), @@ -384,7 +383,7 @@ pub fn new_light(mut config: Configuration) -> Result }, )?; - let (network, network_status_sinks, system_rpc_tx, network_starter) = + let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { config: &config, client: client.clone(), @@ -412,7 +411,6 @@ pub fn new_light(mut config: Configuration) -> Result keystore: keystore_container.sync_keystore(), backend, network, - network_status_sinks, system_rpc_tx, telemetry: telemetry.as_mut(), })?; diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index a13f8be9af136..7355da4e96854 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -204,7 +204,6 @@ pub struct NewFullBase { pub task_manager: TaskManager, pub client: Arc, pub network: Arc::Hash>>, - pub network_status_sinks: sc_service::NetworkStatusSinks, pub transaction_pool: Arc>, } @@ -242,7 +241,7 @@ pub fn new_full_base( ) ); - let (network, network_status_sinks, system_rpc_tx, network_starter) = + let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { config: &config, client: client.clone(), @@ -279,7 +278,6 @@ pub fn new_full_base( task_manager: &mut task_manager, on_demand: None, remote_blockchain: None, - network_status_sinks: network_status_sinks.clone(), system_rpc_tx, telemetry: telemetry.as_mut(), }, @@ -415,7 +413,6 @@ pub fn new_full_base( task_manager, client, network, - network_status_sinks, transaction_pool, }) } @@ -519,7 +516,7 @@ pub fn new_light_base( telemetry.as_ref().map(|x| x.handle()), )?; - let (network, network_status_sinks, system_rpc_tx, network_starter) = + let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { config: &config, client: client.clone(), @@ -554,7 +551,7 @@ pub fn new_light_base( client: client.clone(), transaction_pool: transaction_pool.clone(), keystore: keystore_container.sync_keystore(), - config, backend, network_status_sinks, system_rpc_tx, + config, backend, system_rpc_tx, network: network.clone(), task_manager: &mut task_manager, telemetry: telemetry.as_mut(), diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index a21a79afe9fdb..fd383e96137c1 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -543,7 +543,6 @@ pub trait CliConfiguration: Sized { announce_block: self.announce_block()?, role, base_path: Some(base_path), - informant_output_format: Default::default(), }) } diff --git a/client/informant/Cargo.toml b/client/informant/Cargo.toml index d552a123c3788..ffd5e86419516 100644 --- a/client/informant/Cargo.toml +++ b/client/informant/Cargo.toml @@ -16,11 +16,6 @@ targets = ["x86_64-unknown-linux-gnu"] ansi_term = "0.12.1" futures = "0.3.9" 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" diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs deleted file mode 100644 index 0caef4e5fbae8..0000000000000 --- a/client/informant/src/display.rs +++ /dev/null @@ -1,204 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -use crate::OutputFormat; -use ansi_term::Colour; -use log::info; -use sc_client_api::ClientInfo; -use sc_network::{NetworkStatus, SyncState}; -use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Saturating, Zero}; -use std::{ - convert::{TryFrom, TryInto}, - fmt, -}; -use wasm_timer::Instant; - -/// State of the informant display system. -/// -/// This is the system that handles the line that gets regularly printed and that looks something -/// like: -/// -/// > Syncing 5.4 bps, target=#531028 (4 peers), best: #90683 (0x4ca8…51b8), -/// > finalized #360 (0x6f24…a38b), ⬇ 5.5kiB/s ⬆ 0.9kiB/s -/// -/// # Usage -/// -/// Call `InformantDisplay::new` to initialize the state, then regularly call `display` with the -/// information to display. -/// -pub struct InformantDisplay { - /// Head of chain block number from the last time `display` has been called. - /// `None` if `display` has never been called. - last_number: Option>, - /// The last time `display` or `new` has been called. - last_update: Instant, - /// The last seen total of bytes received. - last_total_bytes_inbound: u64, - /// The last seen total of bytes sent. - last_total_bytes_outbound: u64, - /// The format to print output in. - format: OutputFormat, -} - -impl InformantDisplay { - /// Builds a new informant display system. - pub fn new(format: OutputFormat) -> InformantDisplay { - InformantDisplay { - last_number: None, - last_update: Instant::now(), - last_total_bytes_inbound: 0, - last_total_bytes_outbound: 0, - format, - } - } - - /// Displays the informant by calling `info!`. - pub fn display(&mut self, info: &ClientInfo, net_status: NetworkStatus) { - let best_number = info.chain.best_number; - let best_hash = info.chain.best_hash; - let finalized_number = info.chain.finalized_number; - let num_connected_peers = net_status.num_connected_peers; - let speed = speed::(best_number, self.last_number, self.last_update); - let total_bytes_inbound = net_status.total_bytes_inbound; - let total_bytes_outbound = net_status.total_bytes_outbound; - - let now = Instant::now(); - let elapsed = (now - self.last_update).as_secs(); - self.last_update = now; - self.last_number = Some(best_number); - - let diff_bytes_inbound = total_bytes_inbound - self.last_total_bytes_inbound; - let diff_bytes_outbound = total_bytes_outbound - self.last_total_bytes_outbound; - let (avg_bytes_per_sec_inbound, avg_bytes_per_sec_outbound) = - if elapsed > 0 { - self.last_total_bytes_inbound = total_bytes_inbound; - self.last_total_bytes_outbound = total_bytes_outbound; - (diff_bytes_inbound / elapsed, diff_bytes_outbound / elapsed) - } else { - (diff_bytes_inbound, diff_bytes_outbound) - }; - - let (level, status, target) = match (net_status.sync_state, net_status.best_seen_block) { - (SyncState::Idle, _) => ("💤", "Idle".into(), "".into()), - (SyncState::Downloading, None) => ("⚙️ ", format!("Preparing{}", speed), "".into()), - (SyncState::Downloading, Some(n)) => ( - "⚙️ ", - format!("Syncing{}", speed), - format!(", target=#{}", n), - ), - }; - - if self.format.enable_color { - info!( - target: "substrate", - "{} {}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", - level, - Colour::White.bold().paint(&status), - target, - Colour::White.bold().paint(format!("{}", num_connected_peers)), - Colour::White.bold().paint(format!("{}", best_number)), - best_hash, - Colour::White.bold().paint(format!("{}", finalized_number)), - info.chain.finalized_hash, - Colour::Green.paint(format!("⬇ {}", TransferRateFormat(avg_bytes_per_sec_inbound))), - Colour::Red.paint(format!("⬆ {}", TransferRateFormat(avg_bytes_per_sec_outbound))), - ) - } else { - info!( - target: "substrate", - "{} {}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", - level, - status, - target, - num_connected_peers, - best_number, - best_hash, - finalized_number, - info.chain.finalized_hash, - TransferRateFormat(avg_bytes_per_sec_inbound), - TransferRateFormat(avg_bytes_per_sec_outbound), - ) - } - } -} - -/// Calculates `(best_number - last_number) / (now - last_update)` and returns a `String` -/// representing the speed of import. -fn speed( - best_number: NumberFor, - last_number: Option>, - last_update: Instant -) -> String { - // Number of milliseconds elapsed since last time. - let elapsed_ms = { - let elapsed = last_update.elapsed(); - let since_last_millis = elapsed.as_secs() * 1000; - let since_last_subsec_millis = elapsed.subsec_millis() as u64; - since_last_millis + since_last_subsec_millis - }; - - // Number of blocks that have been imported since last time. - let diff = match last_number { - None => return String::new(), - Some(n) => best_number.saturating_sub(n) - }; - - if let Ok(diff) = TryInto::::try_into(diff) { - // If the number of blocks can be converted to a regular integer, then it's easy: just - // do the math and turn it into a `f64`. - let speed = diff.saturating_mul(10_000).checked_div(u128::from(elapsed_ms)) - .map_or(0.0, |s| s as f64) / 10.0; - format!(" {:4.1} bps", speed) - - } else { - // If the number of blocks can't be converted to a regular integer, then we need a more - // algebraic approach and we stay within the realm of integers. - let one_thousand = NumberFor::::from(1_000u32); - let elapsed = NumberFor::::from( - >::try_from(elapsed_ms).unwrap_or(u32::max_value()) - ); - - let speed = diff.saturating_mul(one_thousand).checked_div(&elapsed) - .unwrap_or_else(Zero::zero); - format!(" {} bps", speed) - } -} - -/// Contains a number of bytes per second. Implements `fmt::Display` and shows this number of bytes -/// per second in a nice way. -struct TransferRateFormat(u64); -impl fmt::Display for TransferRateFormat { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - // Special case 0. - if self.0 == 0 { - return write!(f, "0") - } - - // Under 0.1 kiB, display plain bytes. - if self.0 < 100 { - return write!(f, "{} B/s", self.0) - } - - // Under 1.0 MiB/sec, display the value in kiB/sec. - if self.0 < 1024 * 1024 { - return write!(f, "{:.1}kiB/s", self.0 as f64 / 1024.0) - } - - write!(f, "{:.1}MiB/s", self.0 as f64 / (1024.0 * 1024.0)) - } -} diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index c955834c0f111..221a2b6f5df43 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -20,17 +20,11 @@ use ansi_term::Colour; use futures::prelude::*; -use log::{info, trace, warn}; -use parity_util_mem::MallocSizeOf; +use log::{info, warn}; use sc_client_api::{BlockchainEvents, UsageProvider}; -use sc_network::NetworkStatus; 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; +use std::{fmt::Display, sync::Arc, collections::VecDeque}; /// The format to print telemetry output in. #[derive(Clone, Debug)] @@ -49,62 +43,15 @@ impl Default for OutputFormat { } } -/// Marker trait for a type that implements `TransactionPool` and `MallocSizeOf` on `not(target_os = "unknown")`. -#[cfg(target_os = "unknown")] -pub trait TransactionPoolAndMaybeMallogSizeOf: TransactionPool {} - -/// Marker trait for a type that implements `TransactionPool` and `MallocSizeOf` on `not(target_os = "unknown")`. -#[cfg(not(target_os = "unknown"))] -pub trait TransactionPoolAndMaybeMallogSizeOf: TransactionPool + MallocSizeOf {} - -#[cfg(target_os = "unknown")] -impl TransactionPoolAndMaybeMallogSizeOf for T {} - -#[cfg(not(target_os = "unknown"))] -impl TransactionPoolAndMaybeMallogSizeOf for T {} - /// Builds the informant and returns a `Future` that drives the informant. pub fn build( client: Arc, - network_status_sinks: Arc>>, - pool: Arc, - format: OutputFormat, ) -> impl futures::Future where C: UsageProvider + HeaderMetadata + BlockchainEvents, >::Error: Display, { - 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 - .for_each(move |net_status| { - let info = client_1.usage_info(); - if let Some(ref usage) = info.usage { - trace!(target: "usage", "Usage statistics: {}", usage); - } else { - trace!( - target: "usage", - "Usage statistics not displayed as backend does not provide it", - ) - } - #[cfg(not(target_os = "unknown"))] - trace!( - target: "usage", - "Subsystems memory [txpool: {} kB]", - parity_util_mem::malloc_size(&*pool) / 1024, - ); - display.display(&info, net_status); - future::ready(()) - }); - - future::join( - display_notifications, - display_block_import(client), - ).map(|_| ()) + display_block_import(client) } fn display_block_import(client: Arc) -> impl Future diff --git a/client/network/src/lib.rs b/client/network/src/lib.rs index 556e71da23831..80bcaee43a080 100644 --- a/client/network/src/lib.rs +++ b/client/network/src/lib.rs @@ -275,7 +275,6 @@ pub use service::{ }; pub use sc_peerset::ReputationChange; -use sp_runtime::traits::{Block as BlockT, NumberFor}; /// The maximum allowed number of established connections per peer. /// @@ -303,22 +302,3 @@ pub trait NetworkStateInfo { /// Returns the local Peer ID. fn local_peer_id(&self) -> PeerId; } - -/// Overview status of the network. -#[derive(Clone)] -pub struct NetworkStatus { - /// Current global sync state. - pub sync_state: SyncState, - /// Target sync block number. - pub best_seen_block: Option>, - /// Number of peers participating in syncing. - pub num_sync_peers: u32, - /// Total number of connected peers - pub num_connected_peers: usize, - /// Total number of active peers. - pub num_active_peers: usize, - /// The total number of bytes received. - pub total_bytes_inbound: u64, - /// The total number of bytes sent. - pub total_bytes_outbound: u64, -} diff --git a/client/network/src/service.rs b/client/network/src/service.rs index 99036c5effad8..88ace3914c602 100644 --- a/client/network/src/service.rs +++ b/client/network/src/service.rs @@ -28,7 +28,7 @@ //! which is then processed by [`NetworkWorker::poll`]. use crate::{ - ExHashT, NetworkStateInfo, NetworkStatus, + ExHashT, NetworkStateInfo, behaviour::{self, Behaviour, BehaviourOut}, config::{parse_str_addr, Params, TransportConfig}, DhtEvent, @@ -440,19 +440,6 @@ impl NetworkWorker { }) } - /// High-level network status information. - pub fn status(&self) -> NetworkStatus { - NetworkStatus { - sync_state: self.sync_state(), - best_seen_block: self.best_seen_block(), - num_sync_peers: self.num_sync_peers(), - num_connected_peers: self.num_connected_peers(), - num_active_peers: self.num_active_peers(), - total_bytes_inbound: self.total_bytes_inbound(), - total_bytes_outbound: self.total_bytes_outbound(), - } - } - /// Returns the total number of bytes received so far. pub fn total_bytes_inbound(&self) -> u64 { self.service.bandwidth.total_inbound() diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 2c8557a5456e6..15df0bad61fb5 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use crate::{ - error::Error, MallocSizeOfWasm, RpcHandlers, NetworkStatusSinks, + error::Error, MallocSizeOfWasm, RpcHandlers, start_rpc_servers, build_network_future, TransactionPoolAdapter, TaskManager, SpawnTaskHandle, metrics::MetricsService, client::{light, Client, ClientConfig}, @@ -504,8 +504,6 @@ pub struct SpawnTasksParams<'a, TBl: BlockT, TCl, TExPool, TRpc, Backend> { pub remote_blockchain: Option>>, /// A shared network instance. pub network: Arc::Hash>>, - /// Sinks to propagate network status updates. - pub network_status_sinks: NetworkStatusSinks, /// A Sender for RPC requests. pub system_rpc_tx: TracingUnboundedSender>, /// Telemetry instance for this node. @@ -575,7 +573,6 @@ pub fn spawn_tasks( rpc_extensions_builder, remote_blockchain, network, - network_status_sinks, system_rpc_tx, telemetry, } = params; @@ -638,8 +635,7 @@ pub fn spawn_tasks( spawn_handle.spawn("telemetry-periodic-send", metrics_service.run( client.clone(), - transaction_pool.clone(), - network_status_sinks.clone() + transaction_pool.clone() ) ); @@ -662,12 +658,7 @@ pub fn spawn_tasks( ).into())); // Spawn informant task - spawn_handle.spawn("informant", sc_informant::build( - client.clone(), - network_status_sinks.status.clone(), - transaction_pool.clone(), - config.informant_output_format, - )); + spawn_handle.spawn("informant", sc_informant::build(client.clone())); task_manager.keep_alive((config.base_path, rpc, rpc_handlers.clone())); @@ -850,7 +841,6 @@ pub fn build_network( ) -> Result< ( Arc::Hash>>, - NetworkStatusSinks, TracingUnboundedSender>, NetworkStarter, ), @@ -944,7 +934,6 @@ pub fn build_network( let has_bootnodes = !network_params.network_config.boot_nodes.is_empty(); let network_mut = sc_network::NetworkWorker::new(network_params)?; let network = network_mut.service().clone(); - let network_status_sinks = NetworkStatusSinks::new(); let (system_rpc_tx, system_rpc_rx) = tracing_unbounded("mpsc_system_rpc"); @@ -952,7 +941,6 @@ pub fn build_network( config.role.clone(), network_mut, client, - network_status_sinks.clone(), system_rpc_rx, has_bootnodes, config.announce_block, @@ -995,7 +983,7 @@ pub fn build_network( future.await }); - Ok((network, network_status_sinks, system_rpc_tx, NetworkStarter(network_start_tx))) + Ok((network, system_rpc_tx, NetworkStarter(network_start_tx))) } /// Object used to start the network. diff --git a/client/service/src/config.rs b/client/service/src/config.rs index f82a877545e8c..1fd37dff1fb4d 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -124,8 +124,6 @@ pub struct Configuration { pub announce_block: bool, /// Base path of the configuration pub base_path: Option, - /// Configuration of the output format that the informant uses. - pub informant_output_format: sc_informant::OutputFormat, } /// Type for tasks spawned by the executor. diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 0e47b775e4a43..ae2cfbc8b8941 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -37,17 +37,16 @@ mod task_manager; use std::{io, pin::Pin}; use std::net::SocketAddr; use std::collections::HashMap; -use std::time::Duration; use std::task::Poll; use futures::{Future, FutureExt, Stream, StreamExt, stream, compat::*}; -use sc_network::{NetworkStatus, network_state::NetworkState, PeerId}; +use sc_network::PeerId; use log::{warn, debug, error}; use codec::{Encode, Decode}; use sp_runtime::generic::BlockId; use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; use parity_util_mem::MallocSizeOf; -use sp_utils::{status_sinks, mpsc::{tracing_unbounded, TracingUnboundedReceiver}}; +use sp_utils::mpsc::TracingUnboundedReceiver; pub use self::error::Error; pub use self::builder::{ @@ -124,42 +123,6 @@ impl RpcHandlers { } } -/// Sinks to propagate network status updates. -/// For each element, every time the `Interval` fires we push an element on the sender. -#[derive(Clone)] -pub struct NetworkStatusSinks { - status: Arc>>, - state: Arc>, -} - -impl NetworkStatusSinks { - fn new() -> Self { - Self { - status: Arc::new(status_sinks::StatusSinks::new()), - state: Arc::new(status_sinks::StatusSinks::new()), - } - } - - /// Returns a receiver that periodically yields a [`NetworkStatus`]. - pub fn status_stream(&self, interval: Duration) - -> TracingUnboundedReceiver> - { - let (sink, stream) = tracing_unbounded("mpsc_network_status"); - self.status.push(interval, sink); - stream - } - - /// Returns a receiver that periodically yields a [`NetworkState`]. - pub fn state_stream(&self, interval: Duration) - -> TracingUnboundedReceiver - { - let (sink, stream) = tracing_unbounded("mpsc_network_state"); - self.state.push(interval, sink); - stream - } - -} - /// An incomplete set of chain components, but enough to run the chain ops subcommands. pub struct PartialComponents { /// A shared client instance. @@ -191,7 +154,6 @@ async fn build_network_future< role: Role, mut network: sc_network::NetworkWorker, client: Arc, - status_sinks: NetworkStatusSinks, mut rpc_rx: TracingUnboundedReceiver>, should_have_peers: bool, announce_imported_blocks: bool, @@ -335,18 +297,6 @@ async fn build_network_future< // used in the future to perform actions in response of things that happened on // the network. _ = (&mut network).fuse() => {} - - // At a regular interval, we send high-level status as well as - // detailed state information of the network on what are called - // "status sinks". - - status_sink = status_sinks.status.next().fuse() => { - status_sink.send(network.status()); - } - - state_sink = status_sinks.state.next().fuse() => { - state_sink.send(network.network_state()); - } } } } diff --git a/client/service/src/metrics.rs b/client/service/src/metrics.rs index 43e5b8eaaded7..ca05e4d500aa7 100644 --- a/client/service/src/metrics.rs +++ b/client/service/src/metrics.rs @@ -18,15 +18,14 @@ use std::{convert::TryFrom, time::SystemTime}; -use crate::{NetworkStatus, NetworkState, NetworkStatusSinks, config::Configuration}; +use crate::config::Configuration; use futures_timer::Delay; use prometheus_endpoint::{register, Gauge, U64, Registry, PrometheusError, Opts, GaugeVec}; use sc_telemetry::{telemetry, TelemetryHandle, SUBSTRATE_INFO}; use sp_api::ProvideRuntimeApi; -use sp_runtime::traits::{NumberFor, Block, SaturatedConversion, UniqueSaturatedInto}; +use sp_runtime::traits::{Block, SaturatedConversion}; use sp_transaction_pool::{PoolStatus, MaintainedTransactionPool}; use sp_utils::metrics::register_globals; -use sp_utils::mpsc::TracingUnboundedReceiver; use sc_client_api::{ClientInfo, UsageProvider}; use sc_network::config::Role; use std::sync::Arc; @@ -110,8 +109,6 @@ impl PrometheusMetrics { pub struct MetricsService { metrics: Option, last_update: Instant, - last_total_bytes_inbound: u64, - last_total_bytes_outbound: u64, telemetry: Option, } @@ -121,8 +118,6 @@ impl MetricsService { pub fn new(telemetry: Option) -> Self { MetricsService { metrics: None, - last_total_bytes_inbound: 0, - last_total_bytes_outbound: 0, last_update: Instant::now(), telemetry, } @@ -149,8 +144,6 @@ impl MetricsService { ) .map(|p| MetricsService { metrics: Some(p), - last_total_bytes_inbound: 0, - last_total_bytes_outbound: 0, last_update: Instant::now(), telemetry, }) @@ -163,7 +156,6 @@ impl MetricsService { mut self, client: Arc, transactions: Arc, - network: NetworkStatusSinks, ) where TBl: Block, TCl: ProvideRuntimeApi + UsageProvider, @@ -172,40 +164,14 @@ impl MetricsService { let mut timer = Delay::new(Duration::from_secs(0)); let timer_interval = Duration::from_secs(5); - // Metric and telemetry update interval. - let net_status_interval = timer_interval; - let net_state_interval = Duration::from_secs(30); - - // Source of network information. - let mut net_status_rx = Some(network.status_stream(net_status_interval)); - let mut net_state_rx = Some(network.state_stream(net_state_interval)); - loop { // Wait for the next tick of the timer. (&mut timer).await; - // Try to get the latest network information. - let mut net_status = None; - let mut net_state = None; - if let Some(rx) = net_status_rx.as_mut() { - match Self::latest(rx) { - Ok(status) => { net_status = status; } - Err(()) => { net_status_rx = None; } - } - } - if let Some(rx) = net_state_rx.as_mut() { - match Self::latest(rx) { - Ok(state) => { net_state = state; } - Err(()) => { net_state_rx = None; } - } - } - // Update / Send the metrics. self.update( &client.usage_info(), &transactions.status(), - net_status, - net_state, ); // Schedule next tick. @@ -213,34 +179,12 @@ impl MetricsService { } } - // Try to get the latest value from a receiver, dropping intermediate values. - fn latest(rx: &mut TracingUnboundedReceiver) -> Result, ()> { - let mut value = None; - - while let Ok(next) = rx.try_next() { - match next { - Some(v) => { - value = Some(v) - } - None => { - log::error!("Receiver closed unexpectedly."); - return Err(()) - } - } - } - - Ok(value) - } - fn update( &mut self, info: &ClientInfo, txpool_status: &PoolStatus, - net_status: Option>, - net_state: Option, ) { let now = Instant::now(); - let elapsed = (now - self.last_update).as_secs(); self.last_update = now; let best_number = info.chain.best_number.saturated_into::(); @@ -293,52 +237,5 @@ impl MetricsService { ); } } - - // Update/send network status information, if any. - if let Some(net_status) = net_status { - let num_peers = net_status.num_connected_peers; - let total_bytes_inbound = net_status.total_bytes_inbound; - let total_bytes_outbound = net_status.total_bytes_outbound; - - let diff_bytes_inbound = total_bytes_inbound - self.last_total_bytes_inbound; - let diff_bytes_outbound = total_bytes_outbound - self.last_total_bytes_outbound; - let (avg_bytes_per_sec_inbound, avg_bytes_per_sec_outbound) = - if elapsed > 0 { - self.last_total_bytes_inbound = total_bytes_inbound; - self.last_total_bytes_outbound = total_bytes_outbound; - (diff_bytes_inbound / elapsed, diff_bytes_outbound / elapsed) - } else { - (diff_bytes_inbound, diff_bytes_outbound) - }; - - telemetry!( - self.telemetry; - SUBSTRATE_INFO; - "system.interval"; - "peers" => num_peers, - "bandwidth_download" => avg_bytes_per_sec_inbound, - "bandwidth_upload" => avg_bytes_per_sec_outbound, - ); - - if let Some(metrics) = self.metrics.as_ref() { - let best_seen_block: Option = net_status - .best_seen_block - .map(|num: NumberFor| UniqueSaturatedInto::::unique_saturated_into(num)); - - if let Some(best_seen_block) = best_seen_block { - metrics.block_height.with_label_values(&["sync_target"]).set(best_seen_block); - } - } - } - - // Send network state information, if any. - if let Some(net_state) = net_state { - telemetry!( - self.telemetry; - SUBSTRATE_INFO; - "system.network_state"; - "state" => net_state, - ); - } } } diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index a80c53a8c21c5..0ab4e32a176ea 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -277,7 +277,6 @@ fn node_config Node { client.clone(), ); - let (network, network_status_sinks, system_rpc_tx, network_starter) = { + let (network, system_rpc_tx, network_starter) = { let params = BuildNetworkParams { config: &config, client: client.clone(), @@ -182,7 +182,6 @@ impl Node { rpc_extensions_builder: Box::new(move |_, _| jsonrpc_core::IoHandler::default()), remote_blockchain: None, network, - network_status_sinks, system_rpc_tx, telemetry: None }; diff --git a/test-utils/test-runner/src/utils.rs b/test-utils/test-runner/src/utils.rs index d8ab3860f28a8..ef2bc20cdb858 100644 --- a/test-utils/test-runner/src/utils.rs +++ b/test-utils/test-runner/src/utils.rs @@ -23,7 +23,6 @@ use log::LevelFilter; use sc_service::{BasePath, ChainSpec, Configuration, TaskExecutor, DatabaseConfig, KeepBlocks, TransactionStorageMode}; use sp_keyring::sr25519::Keyring::Alice; use sc_network::{multiaddr, config::{NetworkConfiguration, TransportConfig, Role}}; -use sc_informant::OutputFormat; use sc_service::config::KeystoreConfig; use sc_executor::WasmExecutionMethod; use sc_client_api::execution_extensions::ExecutionStrategies; @@ -85,7 +84,6 @@ pub fn default_config(task_executor: TaskExecutor, mut chain_spec: Box