From 6c3a2c0d38970251a8d3ebaf190cc701663f7f44 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 28 May 2020 14:25:01 +0200 Subject: [PATCH 01/36] Initial commit Forked at: 49b15615184fad010749d3e34282f70a3845da34 Parent branch: origin/master From 9c2e7267423305705916c30d605893524113c8e3 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 28 May 2020 14:40:00 +0200 Subject: [PATCH 02/36] Add a Service Configuration's field + adapt informant + provide means to CLI --- client/cli/src/commands/mod.rs | 7 +++++++ client/cli/src/config.rs | 6 ++++++ client/cli/src/lib.rs | 5 +++++ client/cli/src/runner.rs | 5 ++++- client/informant/src/display.rs | 27 +++++++++++++++------------ client/informant/src/lib.rs | 25 ++++++++++++++++++++----- client/service/src/config.rs | 2 ++ 7 files changed, 59 insertions(+), 18 deletions(-) diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 62757890ef01d..dfb734644bf2e 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -32,6 +32,7 @@ pub use self::purge_chain_cmd::PurgeChainCmd; pub use self::revert_cmd::RevertCmd; pub use self::run_cmd::RunCmd; pub use self::export_state_cmd::ExportStateCmd; +use crate::SubstrateCli; use std::fmt::Debug; use structopt::StructOpt; @@ -402,6 +403,12 @@ macro_rules! substrate_cli_subcommands { $($enum::$variant(cmd) => cmd.log_filters()),* } } + + fn informant_prefix(&self) -> $crate::Result { + match self { + $($enum::$variant(cmd) => cmd.informant_prefix::()),* + } + } } } } diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index a1ee1b0cc1da9..282352e4a46e7 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -393,6 +393,11 @@ pub trait CliConfiguration: Sized { Ok(true) } + /// A prefix for the informant's logs + fn informant_prefix(&self) -> Result { + Ok(C::informant_prefix().to_string()) + } + /// Create a Configuration object from the current object fn create_configuration( &self, @@ -464,6 +469,7 @@ pub trait CliConfiguration: Sized { max_runtime_instances, announce_block: self.announce_block()?, role, + informant_prefix: self.informant_prefix::()?, }) } diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 36d3649926f90..75be59ac96b7d 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -84,6 +84,11 @@ pub trait SubstrateCli: Sized { /// Chain spec factory fn load_spec(&self, id: &str) -> std::result::Result, String>; + /// A prefix for the informant's logs + fn informant_prefix() -> &'static str { + "" + } + /// Helper function used to parse the command line arguments. This is the equivalent of /// `structopt`'s `from_iter()` except that it takes a `VersionInfo` argument to provide the name of /// the application, author, "about" and version. It will also set `AppSettings::GlobalVersion`. diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 2d27743163ae4..9587606c45fc1 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -209,9 +209,12 @@ impl Runner { F: FnOnce(Configuration) -> std::result::Result, T: AbstractService + Unpin, { + let prefix = self.config.informant_prefix.clone(); let service = service_builder(self.config)?; - let informant_future = sc_informant::build(&service, sc_informant::OutputFormat::Coloured); + let informant_future = sc_informant::build(&service, sc_informant::OutputFormat::Coloured { + prefix, + }); let _informant_handle = self.tokio_runtime.spawn(informant_future); // we eagerly drop the service so that the internal exit future is fired, diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index 42f498998362e..4a20af281487b 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -67,16 +67,18 @@ impl InformantDisplay { self.last_update = Instant::now(); self.last_number = Some(best_number); - let (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)), + 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 == OutputFormat::Coloured { - info!( + match &self.format { + OutputFormat::Coloured { prefix } => info!( target: "substrate", - "{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", + "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", + level, + prefix, Colour::White.bold().paint(&status), target, Colour::White.bold().paint(format!("{}", num_connected_peers)), @@ -86,11 +88,12 @@ impl InformantDisplay { info.chain.finalized_hash, Colour::Green.paint(format!("⬇ {}", TransferRateFormat(net_status.average_download_per_sec))), Colour::Red.paint(format!("⬆ {}", TransferRateFormat(net_status.average_upload_per_sec))), - ); - } else { - info!( + ), + OutputFormat::Plain { prefix } => info!( target: "substrate", - "{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", + "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", + level, + prefix, status, target, num_connected_peers, @@ -100,7 +103,7 @@ impl InformantDisplay { info.chain.finalized_hash, TransferRateFormat(net_status.average_download_per_sec), TransferRateFormat(net_status.average_upload_per_sec), - ); + ), } } } diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 6eea9c1d0434c..3c3daf559c382 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -29,10 +29,14 @@ use std::time::Duration; mod display; /// The format to print telemetry output in. -#[derive(PartialEq)] +#[derive(Clone)] pub enum OutputFormat { - Coloured, - Plain, + Coloured { + prefix: String, + }, + Plain { + prefix: String, + }, } /// Creates an informant in the form of a `Future` that must be polled regularly. @@ -40,7 +44,7 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur let client = service.client(); let pool = service.transaction_pool(); - let mut display = display::InformantDisplay::new(format); + let mut display = display::InformantDisplay::new(format.clone()); let display_notifications = service .network_status(Duration::from_millis(5000)) @@ -97,7 +101,18 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur last_best = Some((n.header.number().clone(), n.hash.clone())); } - info!(target: "substrate", "✨ Imported #{} ({})", Colour::White.bold().paint(format!("{}", n.header.number())), n.hash); + match &format { + OutputFormat::Coloured { prefix } => info!( + target: "substrate", + "✨ {}Imported #{} ({})", + prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash, + ), + OutputFormat::Plain { prefix } => info!( + target: "substrate", "✨ {}Imported #{} ({})", + prefix, format!("{}", n.header.number()), n.hash, + ), + } + future::ready(()) }); diff --git a/client/service/src/config.rs b/client/service/src/config.rs index cc9c742ed68db..d3144b563f44e 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -102,6 +102,8 @@ pub struct Configuration { pub max_runtime_instances: usize, /// Announce block automatically after they have been imported pub announce_block: bool, + /// A prefix for the informant's logs + pub informant_prefix: String, } /// Type for tasks spawned by the executor. From c966d4b88abac0408fb4da50dd29c68e2e06d9b5 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 28 May 2020 14:46:25 +0200 Subject: [PATCH 03/36] CLEANUP Forked at: 49b15615184fad010749d3e34282f70a3845da34 Parent branch: origin/master --- client/informant/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 3c3daf559c382..65942ebf5ee3f 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -105,11 +105,11 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur OutputFormat::Coloured { prefix } => info!( target: "substrate", "✨ {}Imported #{} ({})", - prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash, + prefix, Colour::White.bold().paint(n.header.number().to_string()), n.hash, ), OutputFormat::Plain { prefix } => info!( target: "substrate", "✨ {}Imported #{} ({})", - prefix, format!("{}", n.header.number()), n.hash, + prefix, n.header.number(), n.hash, ), } From a3c306ebe94720f350c5bc74b9c5fcde2565d340 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 28 May 2020 15:11:53 +0200 Subject: [PATCH 04/36] fix tests --- client/service/test/src/lib.rs | 1 + utils/browser/src/lib.rs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index 63c7e0795dc1a..74f5e12873ba2 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -210,6 +210,7 @@ fn node_config Client { // Spawn informant wasm_bindgen_futures::spawn_local( - sc_informant::build(&service, sc_informant::OutputFormat::Plain).map(drop) + sc_informant::build( + &service, + sc_informant::OutputFormat::Plain { prefix: Default::default() }, + ).map(drop) ); // We dispatch a background task responsible for processing the service. From d3c1d5241a8b46816c743e55c5987606c576d89e Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 28 May 2020 16:22:08 +0200 Subject: [PATCH 05/36] fixed bad path to object --- client/cli/src/commands/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index dfb734644bf2e..5bc91b6ce598d 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -32,7 +32,6 @@ pub use self::purge_chain_cmd::PurgeChainCmd; pub use self::revert_cmd::RevertCmd; pub use self::run_cmd::RunCmd; pub use self::export_state_cmd::ExportStateCmd; -use crate::SubstrateCli; use std::fmt::Debug; use structopt::StructOpt; @@ -404,7 +403,7 @@ macro_rules! substrate_cli_subcommands { } } - fn informant_prefix(&self) -> $crate::Result { + fn informant_prefix(&self) -> $crate::Result { match self { $($enum::$variant(cmd) => cmd.informant_prefix::()),* } From cd86c583c92668426c35cc174401155bf2880c1f Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Fri, 29 May 2020 12:51:34 +0200 Subject: [PATCH 06/36] Change OutputFormat enum to struct --- client/cli/src/runner.rs | 3 ++- client/informant/src/display.rs | 15 ++++++++------- client/informant/src/lib.rs | 28 +++++++++++++--------------- utils/browser/src/lib.rs | 2 +- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 9587606c45fc1..fa45e9a8b30ef 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -212,7 +212,8 @@ impl Runner { let prefix = self.config.informant_prefix.clone(); let service = service_builder(self.config)?; - let informant_future = sc_informant::build(&service, sc_informant::OutputFormat::Coloured { + let informant_future = sc_informant::build(&service, sc_informant::OutputFormat { + colors: true, prefix, }); let _informant_handle = self.tokio_runtime.spawn(informant_future); diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index 4a20af281487b..afa45620a3507 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -73,12 +73,12 @@ impl InformantDisplay { (SyncState::Downloading, Some(n)) => ("⚙️ ", format!("Syncing{}", speed), format!(", target=#{}", n)), }; - match &self.format { - OutputFormat::Coloured { prefix } => info!( + if self.format.colors { + info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", level, - prefix, + self.format.prefix, Colour::White.bold().paint(&status), target, Colour::White.bold().paint(format!("{}", num_connected_peers)), @@ -88,12 +88,13 @@ impl InformantDisplay { info.chain.finalized_hash, Colour::Green.paint(format!("⬇ {}", TransferRateFormat(net_status.average_download_per_sec))), Colour::Red.paint(format!("⬆ {}", TransferRateFormat(net_status.average_upload_per_sec))), - ), - OutputFormat::Plain { prefix } => info!( + ) + } else { + info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", level, - prefix, + self.format.prefix, status, target, num_connected_peers, @@ -103,7 +104,7 @@ impl InformantDisplay { info.chain.finalized_hash, TransferRateFormat(net_status.average_download_per_sec), TransferRateFormat(net_status.average_upload_per_sec), - ), + ) } } } diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 65942ebf5ee3f..460a437881edd 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -30,13 +30,9 @@ mod display; /// The format to print telemetry output in. #[derive(Clone)] -pub enum OutputFormat { - Coloured { - prefix: String, - }, - Plain { - prefix: String, - }, +pub struct OutputFormat { + pub prefix: String, + pub colors: bool, } /// Creates an informant in the form of a `Future` that must be polled regularly. @@ -101,16 +97,18 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur last_best = Some((n.header.number().clone(), n.hash.clone())); } - match &format { - OutputFormat::Coloured { prefix } => info!( + if format.colors { + info!( target: "substrate", "✨ {}Imported #{} ({})", - prefix, Colour::White.bold().paint(n.header.number().to_string()), n.hash, - ), - OutputFormat::Plain { prefix } => info!( - target: "substrate", "✨ {}Imported #{} ({})", - prefix, n.header.number(), n.hash, - ), + format.prefix, Colour::White.bold().paint(n.header.number().to_string()), n.hash, + ) + } else { + info!( + target: "substrate", + "✨ {}Imported #{} ({})", + format.prefix, n.header.number(), n.hash, + ) } future::ready(()) diff --git a/utils/browser/src/lib.rs b/utils/browser/src/lib.rs index 2293501d06ee0..7f7fc1f8a2999 100644 --- a/utils/browser/src/lib.rs +++ b/utils/browser/src/lib.rs @@ -121,7 +121,7 @@ pub fn start_client(mut service: impl AbstractService) -> Client { wasm_bindgen_futures::spawn_local( sc_informant::build( &service, - sc_informant::OutputFormat::Plain { prefix: Default::default() }, + sc_informant::OutputFormat { colors: false, prefix: Default::default() }, ).map(drop) ); From 6c0029b4b1867e9e8748905807eb4cd1e561051e Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 07:45:03 +0200 Subject: [PATCH 07/36] Add informant_prefix to builder and service --- client/service/src/builder.rs | 29 ++++++++++++++++++++++++++++- client/service/src/lib.rs | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index d921606ea6b16..d89c9e5176d42 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -100,6 +100,7 @@ pub struct ServiceBuilder>>, marker: PhantomData<(TBl, TRtApi)>, block_announce_validator_builder: Option) -> Box + Send> + Send>>, + informant_prefix_builder: Option String + Send>>, } /// A utility trait for building an RPC extension given a `DenyUnsafe` instance. @@ -363,6 +364,7 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> { rpc_extensions_builder: Box::new(|_| ()), remote_backend: None, block_announce_validator_builder: None, + informant_prefix_builder: None, marker: PhantomData, }) } @@ -446,6 +448,7 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> { rpc_extensions_builder: Box::new(|_| ()), remote_backend: Some(remote_blockchain), block_announce_validator_builder: None, + informant_prefix_builder: None, marker: PhantomData, }) } @@ -519,6 +522,7 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, + informant_prefix_builder: self.informant_prefix_builder, marker: self.marker, }) } @@ -564,6 +568,7 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, + informant_prefix_builder: self.informant_prefix_builder, marker: self.marker, }) } @@ -602,6 +607,7 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, + informant_prefix_builder: self.informant_prefix_builder, marker: self.marker, }) } @@ -668,6 +674,7 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, + informant_prefix_builder: self.informant_prefix_builder, marker: self.marker, }) } @@ -732,6 +739,7 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, + informant_prefix_builder: self.informant_prefix_builder, marker: self.marker, }) } @@ -769,6 +777,7 @@ impl rpc_extensions_builder: Box::new(rpc_extensions_builder), remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, + informant_prefix_builder: self.informant_prefix_builder, marker: self.marker, }) } @@ -814,9 +823,23 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: Some(Box::new(block_announce_validator_builder)), + informant_prefix_builder: self.informant_prefix_builder, marker: self.marker, }) } + + /// Defines the informant's prefix for the logs. An empty string by default. + pub fn with_informant_prefix( + self, + informant_prefix_builder: impl FnOnce() -> String + Send + 'static, + ) -> Result, Error> + where TSc: Clone, TFchr: Clone { + Ok(ServiceBuilder { + informant_prefix_builder: Some(Box::new(informant_prefix_builder)), + ..self + }) + } } /// Implemented on `ServiceBuilder`. Allows running block commands, such as import/export/validate @@ -933,8 +956,11 @@ ServiceBuilder< rpc_extensions_builder, remote_backend, block_announce_validator_builder, + informant_prefix_builder, } = self; + let informant_prefix = informant_prefix_builder.map(|f| f()).unwrap_or_else(String::new); + sp_session::generate_initial_session_keys( client.clone(), &BlockId::Hash(client.chain_info().best_hash), @@ -1338,7 +1364,8 @@ ServiceBuilder< _telemetry_on_connect_sinks: telemetry_connection_sinks.clone(), keystore, marker: PhantomData::, - prometheus_registry: config.prometheus_config.map(|config| config.registry) + prometheus_registry: config.prometheus_config.map(|config| config.registry), + informant_prefix, }) } } diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 4f2be23f877ba..fdac5cef8a120 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -127,6 +127,7 @@ pub struct Service { keystore: sc_keystore::KeyStorePtr, marker: PhantomData, prometheus_registry: Option, + informant_prefix: String, } impl Unpin for Service {} From ed89283c08b3f1fb11de1002f17845be87870687 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 07:45:26 +0200 Subject: [PATCH 08/36] Revert "Change OutputFormat enum to struct" This reverts commit cd86c583c92668426c35cc174401155bf2880c1f. --- client/cli/src/runner.rs | 3 +-- client/informant/src/display.rs | 15 +++++++-------- client/informant/src/lib.rs | 28 +++++++++++++++------------- utils/browser/src/lib.rs | 2 +- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index fa45e9a8b30ef..9587606c45fc1 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -212,8 +212,7 @@ impl Runner { let prefix = self.config.informant_prefix.clone(); let service = service_builder(self.config)?; - let informant_future = sc_informant::build(&service, sc_informant::OutputFormat { - colors: true, + let informant_future = sc_informant::build(&service, sc_informant::OutputFormat::Coloured { prefix, }); let _informant_handle = self.tokio_runtime.spawn(informant_future); diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index afa45620a3507..4a20af281487b 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -73,12 +73,12 @@ impl InformantDisplay { (SyncState::Downloading, Some(n)) => ("⚙️ ", format!("Syncing{}", speed), format!(", target=#{}", n)), }; - if self.format.colors { - info!( + match &self.format { + OutputFormat::Coloured { prefix } => info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", level, - self.format.prefix, + prefix, Colour::White.bold().paint(&status), target, Colour::White.bold().paint(format!("{}", num_connected_peers)), @@ -88,13 +88,12 @@ impl InformantDisplay { info.chain.finalized_hash, Colour::Green.paint(format!("⬇ {}", TransferRateFormat(net_status.average_download_per_sec))), Colour::Red.paint(format!("⬆ {}", TransferRateFormat(net_status.average_upload_per_sec))), - ) - } else { - info!( + ), + OutputFormat::Plain { prefix } => info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", level, - self.format.prefix, + prefix, status, target, num_connected_peers, @@ -104,7 +103,7 @@ impl InformantDisplay { info.chain.finalized_hash, TransferRateFormat(net_status.average_download_per_sec), TransferRateFormat(net_status.average_upload_per_sec), - ) + ), } } } diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 460a437881edd..65942ebf5ee3f 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -30,9 +30,13 @@ mod display; /// The format to print telemetry output in. #[derive(Clone)] -pub struct OutputFormat { - pub prefix: String, - pub colors: bool, +pub enum OutputFormat { + Coloured { + prefix: String, + }, + Plain { + prefix: String, + }, } /// Creates an informant in the form of a `Future` that must be polled regularly. @@ -97,18 +101,16 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur last_best = Some((n.header.number().clone(), n.hash.clone())); } - if format.colors { - info!( + match &format { + OutputFormat::Coloured { prefix } => info!( target: "substrate", "✨ {}Imported #{} ({})", - format.prefix, Colour::White.bold().paint(n.header.number().to_string()), n.hash, - ) - } else { - info!( - target: "substrate", - "✨ {}Imported #{} ({})", - format.prefix, n.header.number(), n.hash, - ) + prefix, Colour::White.bold().paint(n.header.number().to_string()), n.hash, + ), + OutputFormat::Plain { prefix } => info!( + target: "substrate", "✨ {}Imported #{} ({})", + prefix, n.header.number(), n.hash, + ), } future::ready(()) diff --git a/utils/browser/src/lib.rs b/utils/browser/src/lib.rs index 7f7fc1f8a2999..2293501d06ee0 100644 --- a/utils/browser/src/lib.rs +++ b/utils/browser/src/lib.rs @@ -121,7 +121,7 @@ pub fn start_client(mut service: impl AbstractService) -> Client { wasm_bindgen_futures::spawn_local( sc_informant::build( &service, - sc_informant::OutputFormat { colors: false, prefix: Default::default() }, + sc_informant::OutputFormat::Plain { prefix: Default::default() }, ).map(drop) ); From ad18c29574857554eeff0538a96ef8800bed7354 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 07:46:00 +0200 Subject: [PATCH 09/36] Revert "fix tests" This reverts commit a3c306ebe94720f350c5bc74b9c5fcde2565d340. --- client/service/test/src/lib.rs | 1 - utils/browser/src/lib.rs | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index 74f5e12873ba2..63c7e0795dc1a 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -210,7 +210,6 @@ fn node_config Client { // Spawn informant wasm_bindgen_futures::spawn_local( - sc_informant::build( - &service, - sc_informant::OutputFormat::Plain { prefix: Default::default() }, - ).map(drop) + sc_informant::build(&service, sc_informant::OutputFormat::Plain).map(drop) ); // We dispatch a background task responsible for processing the service. From ff258dce8e6570ab402ac397df5813795ff9f9b6 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 07:47:51 +0200 Subject: [PATCH 10/36] Revert "Add a Service Configuration's field + adapt informant + provide means to CLI" This reverts commit 9c2e7267423305705916c30d605893524113c8e3. --- client/cli/src/commands/mod.rs | 6 ------ client/cli/src/config.rs | 6 ------ client/cli/src/lib.rs | 5 ----- client/cli/src/runner.rs | 5 +---- client/informant/src/display.rs | 27 ++++++++++++--------------- client/informant/src/lib.rs | 25 +++++-------------------- client/service/src/config.rs | 2 -- 7 files changed, 18 insertions(+), 58 deletions(-) diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 5bc91b6ce598d..62757890ef01d 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -402,12 +402,6 @@ macro_rules! substrate_cli_subcommands { $($enum::$variant(cmd) => cmd.log_filters()),* } } - - fn informant_prefix(&self) -> $crate::Result { - match self { - $($enum::$variant(cmd) => cmd.informant_prefix::()),* - } - } } } } diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index 282352e4a46e7..a1ee1b0cc1da9 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -393,11 +393,6 @@ pub trait CliConfiguration: Sized { Ok(true) } - /// A prefix for the informant's logs - fn informant_prefix(&self) -> Result { - Ok(C::informant_prefix().to_string()) - } - /// Create a Configuration object from the current object fn create_configuration( &self, @@ -469,7 +464,6 @@ pub trait CliConfiguration: Sized { max_runtime_instances, announce_block: self.announce_block()?, role, - informant_prefix: self.informant_prefix::()?, }) } diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 75be59ac96b7d..36d3649926f90 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -84,11 +84,6 @@ pub trait SubstrateCli: Sized { /// Chain spec factory fn load_spec(&self, id: &str) -> std::result::Result, String>; - /// A prefix for the informant's logs - fn informant_prefix() -> &'static str { - "" - } - /// Helper function used to parse the command line arguments. This is the equivalent of /// `structopt`'s `from_iter()` except that it takes a `VersionInfo` argument to provide the name of /// the application, author, "about" and version. It will also set `AppSettings::GlobalVersion`. diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 9587606c45fc1..2d27743163ae4 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -209,12 +209,9 @@ impl Runner { F: FnOnce(Configuration) -> std::result::Result, T: AbstractService + Unpin, { - let prefix = self.config.informant_prefix.clone(); let service = service_builder(self.config)?; - let informant_future = sc_informant::build(&service, sc_informant::OutputFormat::Coloured { - prefix, - }); + let informant_future = sc_informant::build(&service, sc_informant::OutputFormat::Coloured); let _informant_handle = self.tokio_runtime.spawn(informant_future); // we eagerly drop the service so that the internal exit future is fired, diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index 4a20af281487b..42f498998362e 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -67,18 +67,16 @@ impl InformantDisplay { self.last_update = Instant::now(); self.last_number = Some(best_number); - 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)), + let (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)), }; - match &self.format { - OutputFormat::Coloured { prefix } => info!( + if self.format == OutputFormat::Coloured { + info!( target: "substrate", - "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", - level, - prefix, + "{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", Colour::White.bold().paint(&status), target, Colour::White.bold().paint(format!("{}", num_connected_peers)), @@ -88,12 +86,11 @@ impl InformantDisplay { info.chain.finalized_hash, Colour::Green.paint(format!("⬇ {}", TransferRateFormat(net_status.average_download_per_sec))), Colour::Red.paint(format!("⬆ {}", TransferRateFormat(net_status.average_upload_per_sec))), - ), - OutputFormat::Plain { prefix } => info!( + ); + } else { + info!( target: "substrate", - "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", - level, - prefix, + "{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", status, target, num_connected_peers, @@ -103,7 +100,7 @@ impl InformantDisplay { info.chain.finalized_hash, TransferRateFormat(net_status.average_download_per_sec), TransferRateFormat(net_status.average_upload_per_sec), - ), + ); } } } diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 65942ebf5ee3f..6eea9c1d0434c 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -29,14 +29,10 @@ use std::time::Duration; mod display; /// The format to print telemetry output in. -#[derive(Clone)] +#[derive(PartialEq)] pub enum OutputFormat { - Coloured { - prefix: String, - }, - Plain { - prefix: String, - }, + Coloured, + Plain, } /// Creates an informant in the form of a `Future` that must be polled regularly. @@ -44,7 +40,7 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur let client = service.client(); let pool = service.transaction_pool(); - let mut display = display::InformantDisplay::new(format.clone()); + let mut display = display::InformantDisplay::new(format); let display_notifications = service .network_status(Duration::from_millis(5000)) @@ -101,18 +97,7 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur last_best = Some((n.header.number().clone(), n.hash.clone())); } - match &format { - OutputFormat::Coloured { prefix } => info!( - target: "substrate", - "✨ {}Imported #{} ({})", - prefix, Colour::White.bold().paint(n.header.number().to_string()), n.hash, - ), - OutputFormat::Plain { prefix } => info!( - target: "substrate", "✨ {}Imported #{} ({})", - prefix, n.header.number(), n.hash, - ), - } - + info!(target: "substrate", "✨ Imported #{} ({})", Colour::White.bold().paint(format!("{}", n.header.number())), n.hash); future::ready(()) }); diff --git a/client/service/src/config.rs b/client/service/src/config.rs index d3144b563f44e..cc9c742ed68db 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -102,8 +102,6 @@ pub struct Configuration { pub max_runtime_instances: usize, /// Announce block automatically after they have been imported pub announce_block: bool, - /// A prefix for the informant's logs - pub informant_prefix: String, } /// Type for tasks spawned by the executor. From f5cf9978544ffdf553edd39922b2009200730787 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 07:58:33 +0200 Subject: [PATCH 11/36] Implementation using the ServiceBuilder --- client/informant/src/display.rs | 21 ++++++++++++++------- client/informant/src/lib.rs | 5 +++-- client/service/src/lib.rs | 7 +++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index 42f498998362e..fb3ef80b3c6d3 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -45,15 +45,18 @@ pub struct InformantDisplay { last_update: Instant, /// The format to print output in. format: OutputFormat, + /// Prefix to every log line + prefix: String, } impl InformantDisplay { /// Builds a new informant display system. - pub fn new(format: OutputFormat) -> InformantDisplay { + pub fn new(format: OutputFormat, prefix: String) -> InformantDisplay { InformantDisplay { last_number: None, last_update: Instant::now(), format, + prefix, } } @@ -67,16 +70,18 @@ impl InformantDisplay { self.last_update = Instant::now(); self.last_number = Some(best_number); - let (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)), + 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 == OutputFormat::Coloured { info!( target: "substrate", - "{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", + "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", + level, + self.prefix, Colour::White.bold().paint(&status), target, Colour::White.bold().paint(format!("{}", num_connected_peers)), @@ -90,7 +95,9 @@ impl InformantDisplay { } else { info!( target: "substrate", - "{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", + "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", + level, + self.prefix, status, target, num_connected_peers, diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 6eea9c1d0434c..7ca893490fc3f 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -39,8 +39,9 @@ pub enum OutputFormat { pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futures::Future { let client = service.client(); let pool = service.transaction_pool(); + let prefix = service.informant_prefix(); - let mut display = display::InformantDisplay::new(format); + let mut display = display::InformantDisplay::new(format, prefix.clone()); let display_notifications = service .network_status(Duration::from_millis(5000)) @@ -97,7 +98,7 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur last_best = Some((n.header.number().clone(), n.hash.clone())); } - info!(target: "substrate", "✨ Imported #{} ({})", Colour::White.bold().paint(format!("{}", n.header.number())), n.hash); + info!(target: "substrate", "✨ {}Imported #{} ({})", prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash); future::ready(()) }); diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index fdac5cef8a120..037aab4041e4b 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -211,6 +211,9 @@ pub trait AbstractService: Future> + Send + Unpin + S /// Get the prometheus metrics registry, if available. fn prometheus_registry(&self) -> Option; + + /// Get the informant's prefix for logs + fn informant_prefix(&self) -> String; } impl AbstractService for @@ -311,6 +314,10 @@ where fn prometheus_registry(&self) -> Option { self.prometheus_registry.clone() } + + fn informant_prefix(&self) -> String { + self.informant_prefix.clone() + } } impl Future for From 1b0276114479994e0fe68ed02808b6d6e1361cb5 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 08:02:00 +0200 Subject: [PATCH 12/36] reduce line length --- client/informant/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 7ca893490fc3f..88264ff677525 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -98,7 +98,10 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur last_best = Some((n.header.number().clone(), n.hash.clone())); } - info!(target: "substrate", "✨ {}Imported #{} ({})", prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash); + info!( + target: "substrate", "✨ {}Imported #{} ({})", + prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash, + ); future::ready(()) }); From b81f8ffd3bdfa0678b433ad9a3f5da970b8eb9ed Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 08:52:17 +0200 Subject: [PATCH 13/36] fix line width again --- client/informant/src/display.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index fb3ef80b3c6d3..20115ad3f73a8 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -73,7 +73,11 @@ impl InformantDisplay { 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)), + (SyncState::Downloading, Some(n)) => ( + "⚙️ ", + format!("Syncing{}", speed), + format!(", target=#{}", n), + ), }; if self.format == OutputFormat::Coloured { From a04e7889e191cdfe712d5fe722acb23b32e2ba18 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 12:34:57 +0200 Subject: [PATCH 14/36] WIP Forked at: 49b15615184fad010749d3e34282f70a3845da34 Parent branch: origin/master --- Cargo.lock | 2 ++ client/informant/Cargo.toml | 2 ++ client/informant/src/lib.rs | 42 ++++++++++++++++++++++++++----------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06b1b42b10453..56d1c82a183d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6419,6 +6419,8 @@ dependencies = [ "sc-service", "sp-blockchain", "sp-runtime", + "sp-transaction-pool", + "sp-utils", "wasm-timer", ] diff --git a/client/informant/Cargo.toml b/client/informant/Cargo.toml index cd24fa6958684..0156cb98a7170 100644 --- a/client/informant/Cargo.toml +++ b/client/informant/Cargo.toml @@ -22,3 +22,5 @@ sc-network = { version = "0.8.0-rc2", path = "../network" } sc-service = { version = "0.8.0-rc2", default-features = false, path = "../service" } sp-blockchain = { version = "2.0.0-rc2", path = "../../primitives/blockchain" } sp-runtime = { version = "2.0.0-rc2", path = "../../primitives/runtime" } +sp-utils = { version = "2.0.0-rc2", path = "../../primitives/utils" } +sp-transaction-pool = { version = "2.0.0-rc2", path = "../../primitives/transaction-pool" } diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 88264ff677525..ba787a000a5c1 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -19,11 +19,19 @@ //! Console informant. Prints sync progress and block events. Runs on the calling thread. use ansi_term::Colour; -use sc_client_api::{BlockchainEvents, UsageProvider}; use futures::prelude::*; -use log::{info, warn, trace}; +use log::{info, trace, warn}; +use parity_util_mem::MallocSizeOf; +use sc_client_api::{BlockchainEvents, UsageProvider}; +use sc_network::network_state::NetworkState; +use sc_service::{AbstractService, NetworkStatus}; +use sp_blockchain::HeaderMetadata; +use sp_runtime::traits::Block as BlockT; use sp_runtime::traits::Header; -use sc_service::AbstractService; +use sp_transaction_pool::TransactionPool; +use sp_utils::mpsc::TracingUnboundedReceiver; +use std::fmt::Display; +use std::sync::Arc; use std::time::Duration; mod display; @@ -36,17 +44,28 @@ pub enum OutputFormat { } /// Creates an informant in the form of a `Future` that must be polled regularly. -pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futures::Future { - let client = service.client(); - let pool = service.transaction_pool(); - let prefix = service.informant_prefix(); - +pub fn build( + client: Arc, + network_status_stream_builder: impl FnOnce( + Duration, + ) -> TracingUnboundedReceiver<( + NetworkStatus, + NetworkState, + )>, + pool: Arc, + prefix: String, + format: OutputFormat, +) -> impl futures::Future +where + C: UsageProvider + HeaderMetadata + BlockchainEvents, + >::Error: Display, +{ let mut display = display::InformantDisplay::new(format, prefix.clone()); - let display_notifications = service - .network_status(Duration::from_millis(5000)) + let client_1 = client.clone(); + let display_notifications = network_status_stream_builder(Duration::from_millis(5000)) .for_each(move |(net_status, _)| { - let info = client.usage_info(); + let info = client_1.usage_info(); if let Some(ref usage) = info.usage { trace!(target: "usage", "Usage statistics: {}", usage); } else { @@ -65,7 +84,6 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur future::ready(()) }); - let client = service.client(); let mut last_best = { let info = client.usage_info(); Some((info.chain.best_number, info.chain.best_hash)) From cb8e40283f0e96dc4aef7e45ac74d94452cc7577 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 12:49:50 +0200 Subject: [PATCH 15/36] WIP Forked at: 49b15615184fad010749d3e34282f70a3845da34 Parent branch: origin/master --- Cargo.lock | 2 +- client/informant/Cargo.toml | 1 - client/informant/src/display.rs | 3 +-- client/informant/src/lib.rs | 3 +-- client/network/src/lib.rs | 20 ++++++++++++++++++++ client/service/Cargo.toml | 2 +- client/service/src/builder.rs | 11 ++++++++++- client/service/src/lib.rs | 31 ++----------------------------- 8 files changed, 36 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56d1c82a183d8..c14b5512ad28d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6416,7 +6416,6 @@ dependencies = [ "parity-util-mem", "sc-client-api", "sc-network", - "sc-service", "sp-blockchain", "sp-runtime", "sp-transaction-pool", @@ -6712,6 +6711,7 @@ dependencies = [ "sc-client-db", "sc-executor", "sc-finality-grandpa", + "sc-informant", "sc-keystore", "sc-network", "sc-offchain", diff --git a/client/informant/Cargo.toml b/client/informant/Cargo.toml index 0156cb98a7170..c97d151ebad86 100644 --- a/client/informant/Cargo.toml +++ b/client/informant/Cargo.toml @@ -19,7 +19,6 @@ parity-util-mem = { version = "0.6.1", default-features = false, features = ["pr wasm-timer = "0.2" sc-client-api = { version = "2.0.0-rc2", path = "../api" } sc-network = { version = "0.8.0-rc2", path = "../network" } -sc-service = { version = "0.8.0-rc2", default-features = false, path = "../service" } sp-blockchain = { version = "2.0.0-rc2", path = "../../primitives/blockchain" } sp-runtime = { version = "2.0.0-rc2", path = "../../primitives/runtime" } sp-utils = { version = "2.0.0-rc2", path = "../../primitives/utils" } diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index 20115ad3f73a8..b2a5eeef285be 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -17,9 +17,8 @@ use ansi_term::Colour; use sc_client_api::ClientInfo; use log::info; -use sc_network::SyncState; +use sc_network::{NetworkStatus, SyncState}; use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Zero, Saturating}; -use sc_service::NetworkStatus; use std::{convert::{TryFrom, TryInto}, fmt}; use wasm_timer::Instant; use crate::OutputFormat; diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index ba787a000a5c1..fb629eb7c0dd7 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -23,8 +23,7 @@ use futures::prelude::*; use log::{info, trace, warn}; use parity_util_mem::MallocSizeOf; use sc_client_api::{BlockchainEvents, UsageProvider}; -use sc_network::network_state::NetworkState; -use sc_service::{AbstractService, NetworkStatus}; +use sc_network::{NetworkStatus, network_state::NetworkState}; use sp_blockchain::HeaderMetadata; use sp_runtime::traits::Block as BlockT; use sp_runtime::traits::Header; diff --git a/client/network/src/lib.rs b/client/network/src/lib.rs index 7cc5e8537159e..a00808360f33a 100644 --- a/client/network/src/lib.rs +++ b/client/network/src/lib.rs @@ -269,6 +269,7 @@ pub use libp2p::{Multiaddr, PeerId}; pub use libp2p::multiaddr; pub use sc_peerset::ReputationChange; +use sp_runtime::traits::{Block as BlockT, NumberFor}; /// The maximum allowed number of established connections per peer. /// @@ -313,3 +314,22 @@ 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, + /// Downloaded bytes per second averaged over the past few seconds. + pub average_download_per_sec: u64, + /// Uploaded bytes per second averaged over the past few seconds. + pub average_upload_per_sec: u64, +} diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index fc5991bc3f131..b6b1c820c5abe 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -65,7 +65,7 @@ sc-rpc-server = { version = "2.0.0-rc2", path = "../rpc-servers" } sc-rpc = { version = "2.0.0-rc2", path = "../rpc" } sc-block-builder = { version = "0.8.0-rc2", path = "../block-builder" } sp-block-builder = { version = "2.0.0-rc2", path = "../../primitives/block-builder" } - +sc-informant = { version = "0.8.0-rc2", path = "../informant" } sc-telemetry = { version = "2.0.0-rc2", path = "../telemetry" } sc-offchain = { version = "2.0.0-rc2", path = "../offchain" } parity-multiaddr = { package = "parity-multiaddr", version = "0.7.3" } diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index d89c9e5176d42..0b583d20e10bc 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -1348,6 +1348,16 @@ ServiceBuilder< } } + // Spawn informant task + let informant_future = sc_informant::build( + self.client.clone(), + |duration| (), + transaction_pool.clone(), + informant_prefix, + sc_informant::OutputFormat::Coloured, + ); + let _informant_handle = spawn_handle.spawn("informant", informant_future); + Ok(Service { client, task_manager, @@ -1365,7 +1375,6 @@ ServiceBuilder< keystore, marker: PhantomData::, prometheus_registry: config.prometheus_config.map(|config| config.registry), - informant_prefix, }) } } diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 037aab4041e4b..4896cb5bfad18 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -52,11 +52,11 @@ use futures::{ sink::SinkExt, task::{Spawn, FutureObj, SpawnError}, }; -use sc_network::{NetworkService, network_state::NetworkState, PeerId}; +use sc_network::{NetworkService, NetworkStatus, network_state::NetworkState, PeerId}; use log::{log, warn, debug, error, Level}; use codec::{Encode, Decode}; use sp_runtime::generic::BlockId; -use sp_runtime::traits::{NumberFor, Block as BlockT}; +use sp_runtime::traits::{Block as BlockT}; use parity_util_mem::MallocSizeOf; use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender}; @@ -127,7 +127,6 @@ pub struct Service { keystore: sc_keystore::KeyStorePtr, marker: PhantomData, prometheus_registry: Option, - informant_prefix: String, } impl Unpin for Service {} @@ -211,9 +210,6 @@ pub trait AbstractService: Future> + Send + Unpin + S /// Get the prometheus metrics registry, if available. fn prometheus_registry(&self) -> Option; - - /// Get the informant's prefix for logs - fn informant_prefix(&self) -> String; } impl AbstractService for @@ -314,10 +310,6 @@ where fn prometheus_registry(&self) -> Option { self.prometheus_registry.clone() } - - fn informant_prefix(&self) -> String { - self.informant_prefix.clone() - } } impl Future for @@ -495,25 +487,6 @@ fn build_network_future< }) } -/// Overview status of the network. -#[derive(Clone)] -pub struct NetworkStatus { - /// Current global sync state. - pub sync_state: sc_network::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, - /// Downloaded bytes per second averaged over the past few seconds. - pub average_download_per_sec: u64, - /// Uploaded bytes per second averaged over the past few seconds. - pub average_upload_per_sec: u64, -} - #[cfg(not(target_os = "unknown"))] // Wrapper for HTTP and WS servers that makes sure they are properly shut down. mod waiting { From 5dceb40ed0fe818bf5cff7aaf130a210c12c7d44 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 13:11:10 +0200 Subject: [PATCH 16/36] WIP Forked at: 49b15615184fad010749d3e34282f70a3845da34 Parent branch: origin/master --- client/cli/src/runner.rs | 3 --- client/service/src/builder.rs | 9 +++++++-- utils/browser/src/lib.rs | 5 ----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 2d27743163ae4..8cc06f369b6eb 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -211,9 +211,6 @@ impl Runner { { let service = service_builder(self.config)?; - let informant_future = sc_informant::build(&service, sc_informant::OutputFormat::Coloured); - let _informant_handle = self.tokio_runtime.spawn(informant_future); - // we eagerly drop the service so that the internal exit future is fired, // but we need to keep holding a reference to the global telemetry guard // and drop the runtime first. diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 0b583d20e10bc..8ae5c02408215 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -1349,9 +1349,14 @@ ServiceBuilder< } // Spawn informant task + let network_status_sinks_1 = network_status_sinks.clone(); let informant_future = sc_informant::build( - self.client.clone(), - |duration| (), + client.clone(), + move |interval| { + let (sink, stream) = tracing_unbounded("mpsc_network_status"); + network_status_sinks_1.lock().push(interval, sink); + stream + }, transaction_pool.clone(), informant_prefix, sc_informant::OutputFormat::Coloured, diff --git a/utils/browser/src/lib.rs b/utils/browser/src/lib.rs index 408ba24cfed22..19f7ad6326fac 100644 --- a/utils/browser/src/lib.rs +++ b/utils/browser/src/lib.rs @@ -116,11 +116,6 @@ struct RpcMessage { /// Create a Client object that connects to a service. pub fn start_client(mut service: impl AbstractService) -> Client { - // Spawn informant - wasm_bindgen_futures::spawn_local( - sc_informant::build(&service, sc_informant::OutputFormat::Plain).map(drop) - ); - // We dispatch a background task responsible for processing the service. // // The main action performed by the code below consists in polling the service with From bf7e14449f29657e3fc36149ac3b37f49ce2acd9 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 13:19:00 +0200 Subject: [PATCH 17/36] use struct instead of enum --- client/informant/src/display.rs | 20 ++++++++------------ client/informant/src/lib.rs | 15 ++++++++------- client/service/src/builder.rs | 3 +-- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index b2a5eeef285be..c7aec078c655e 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -44,18 +44,15 @@ pub struct InformantDisplay { last_update: Instant, /// The format to print output in. format: OutputFormat, - /// Prefix to every log line - prefix: String, } impl InformantDisplay { /// Builds a new informant display system. - pub fn new(format: OutputFormat, prefix: String) -> InformantDisplay { + pub fn new(format: OutputFormat) -> InformantDisplay { InformantDisplay { last_number: None, last_update: Instant::now(), format, - prefix, } } @@ -79,12 +76,12 @@ impl InformantDisplay { ), }; - if self.format == OutputFormat::Coloured { - info!( + match &self.format { + OutputFormat { colors: true, prefix } => info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", level, - self.prefix, + prefix, Colour::White.bold().paint(&status), target, Colour::White.bold().paint(format!("{}", num_connected_peers)), @@ -94,13 +91,12 @@ impl InformantDisplay { info.chain.finalized_hash, Colour::Green.paint(format!("⬇ {}", TransferRateFormat(net_status.average_download_per_sec))), Colour::Red.paint(format!("⬆ {}", TransferRateFormat(net_status.average_upload_per_sec))), - ); - } else { - info!( + ), + OutputFormat { colors: false, prefix } => info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", level, - self.prefix, + prefix, status, target, num_connected_peers, @@ -110,7 +106,7 @@ impl InformantDisplay { info.chain.finalized_hash, TransferRateFormat(net_status.average_download_per_sec), TransferRateFormat(net_status.average_upload_per_sec), - ); + ), } } } diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index fb629eb7c0dd7..3a1293fd23158 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -36,10 +36,12 @@ use std::time::Duration; mod display; /// The format to print telemetry output in. -#[derive(PartialEq)] -pub enum OutputFormat { - Coloured, - Plain, +#[derive(Clone)] +pub struct OutputFormat { + /// Use colors to display the logs + pub colors: bool, + /// Add a prefix before every log line + pub prefix: String, } /// Creates an informant in the form of a `Future` that must be polled regularly. @@ -52,14 +54,13 @@ pub fn build( NetworkState, )>, pool: Arc, - prefix: String, format: OutputFormat, ) -> impl futures::Future where C: UsageProvider + HeaderMetadata + BlockchainEvents, >::Error: Display, { - let mut display = display::InformantDisplay::new(format, prefix.clone()); + let mut display = display::InformantDisplay::new(format.clone()); let client_1 = client.clone(); let display_notifications = network_status_stream_builder(Duration::from_millis(5000)) @@ -117,7 +118,7 @@ where info!( target: "substrate", "✨ {}Imported #{} ({})", - prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash, + format.prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash, ); future::ready(()) }); diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 8ae5c02408215..e554d2eb262db 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -1358,8 +1358,7 @@ ServiceBuilder< stream }, transaction_pool.clone(), - informant_prefix, - sc_informant::OutputFormat::Coloured, + sc_informant::OutputFormat { colors: true, prefix: informant_prefix }, ); let _informant_handle = spawn_handle.spawn("informant", informant_future); From d8daabbe5cfc660378bdc38cad133119ff6d73b3 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 2 Jun 2020 14:31:04 +0200 Subject: [PATCH 18/36] WIP Forked at: 49b15615184fad010749d3e34282f70a3845da34 Parent branch: origin/master --- client/informant/src/display.rs | 21 ++-- client/informant/src/lib.rs | 164 ++++++++++++++++++-------------- 2 files changed, 110 insertions(+), 75 deletions(-) diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index c7aec078c655e..c9427cc03372b 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -14,14 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . +use crate::OutputFormat; use ansi_term::Colour; -use sc_client_api::ClientInfo; use log::info; +use sc_client_api::ClientInfo; use sc_network::{NetworkStatus, SyncState}; -use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Zero, Saturating}; -use std::{convert::{TryFrom, TryInto}, fmt}; +use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Saturating, Zero}; +use std::{ + convert::{TryFrom, TryInto}, + fmt, +}; use wasm_timer::Instant; -use crate::OutputFormat; /// State of the informant display system. /// @@ -77,7 +80,10 @@ impl InformantDisplay { }; match &self.format { - OutputFormat { colors: true, prefix } => info!( + OutputFormat { + colors: true, + prefix, + } => info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", level, @@ -92,7 +98,10 @@ impl InformantDisplay { Colour::Green.paint(format!("⬇ {}", TransferRateFormat(net_status.average_download_per_sec))), Colour::Red.paint(format!("⬆ {}", TransferRateFormat(net_status.average_upload_per_sec))), ), - OutputFormat { colors: false, prefix } => info!( + OutputFormat { + colors: false, + prefix, + } => info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", level, diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 3a1293fd23158..1c60c7e9b3a5a 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -23,10 +23,9 @@ use futures::prelude::*; use log::{info, trace, warn}; use parity_util_mem::MallocSizeOf; use sc_client_api::{BlockchainEvents, UsageProvider}; -use sc_network::{NetworkStatus, network_state::NetworkState}; +use sc_network::{network_state::NetworkState, NetworkStatus}; use sp_blockchain::HeaderMetadata; -use sp_runtime::traits::Block as BlockT; -use sp_runtime::traits::Header; +use sp_runtime::traits::{Block as BlockT, Header}; use sp_transaction_pool::TransactionPool; use sp_utils::mpsc::TracingUnboundedReceiver; use std::fmt::Display; @@ -44,7 +43,80 @@ pub struct OutputFormat { pub prefix: String, } +macro_rules! build { + ($client:expr, $network_status_stream_builder:expr, $pool:expr, $format:expr) => {{ + let mut display = display::InformantDisplay::new($format.clone()); + + let client_1 = $client.clone(); + let display_notifications = $network_status_stream_builder(Duration::from_millis(5000)) + .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(()) + }); + + let mut last_best = { + let info = $client.usage_info(); + Some((info.chain.best_number, info.chain.best_hash)) + }; + + let display_block_import = $client.import_notification_stream().for_each(move |n| { + // detect and log reorganizations. + if let Some((ref last_num, ref last_hash)) = last_best { + if n.header.parent_hash() != last_hash && n.is_new_best { + let maybe_ancestor = sp_blockchain::lowest_common_ancestor( + &*$client, + last_hash.clone(), + n.hash, + ); + + match maybe_ancestor { + Ok(ref ancestor) if ancestor.hash != *last_hash => info!( + "♻️ Reorg on #{},{} to #{},{}, common ancestor #{},{}", + Colour::Red.bold().paint(format!("{}", last_num)), last_hash, + Colour::Green.bold().paint(format!("{}", n.header.number())), n.hash, + Colour::White.bold().paint(format!("{}", ancestor.number)), ancestor.hash, + ), + Ok(_) => {}, + Err(e) => warn!("Error computing tree route: {}", e), + } + } + } + + if n.is_new_best { + last_best = Some((n.header.number().clone(), n.hash.clone())); + } + + info!( + target: "substrate", "✨ {}Imported #{} ({})", + $format.prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash, + ); + future::ready(()) + }); + + future::join( + display_notifications, + display_block_import + ).map(|_| ()) + }} +} + /// Creates an informant in the form of a `Future` that must be polled regularly. +#[cfg(not(target_os = "unknown"))] pub fn build( client: Arc, network_status_stream_builder: impl FnOnce( @@ -60,71 +132,25 @@ where C: UsageProvider + HeaderMetadata + BlockchainEvents, >::Error: Display, { - let mut display = display::InformantDisplay::new(format.clone()); - - let client_1 = client.clone(); - let display_notifications = network_status_stream_builder(Duration::from_millis(5000)) - .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(()) - }); - - let mut last_best = { - let info = client.usage_info(); - Some((info.chain.best_number, info.chain.best_hash)) - }; - - let display_block_import = client.import_notification_stream().for_each(move |n| { - // detect and log reorganizations. - if let Some((ref last_num, ref last_hash)) = last_best { - if n.header.parent_hash() != last_hash && n.is_new_best { - let maybe_ancestor = sp_blockchain::lowest_common_ancestor( - &*client, - last_hash.clone(), - n.hash, - ); + build!(client, network_status_stream_builder, pool, format) +} - match maybe_ancestor { - Ok(ref ancestor) if ancestor.hash != *last_hash => info!( - "♻️ Reorg on #{},{} to #{},{}, common ancestor #{},{}", - Colour::Red.bold().paint(format!("{}", last_num)), last_hash, - Colour::Green.bold().paint(format!("{}", n.header.number())), n.hash, - Colour::White.bold().paint(format!("{}", ancestor.number)), ancestor.hash, - ), - Ok(_) => {}, - Err(e) => warn!("Error computing tree route: {}", e), - } - } - } - - if n.is_new_best { - last_best = Some((n.header.number().clone(), n.hash.clone())); - } - - info!( - target: "substrate", "✨ {}Imported #{} ({})", - format.prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash, - ); - future::ready(()) - }); - - future::join( - display_notifications, - display_block_import - ).map(|_| ()) +/// Creates an informant in the form of a `Future` that must be polled regularly. +#[cfg(target_os = "unknown")] +pub fn build( + client: Arc, + network_status_stream_builder: impl FnOnce( + Duration, + ) -> TracingUnboundedReceiver<( + NetworkStatus, + NetworkState, + )>, + pool: Arc, + format: OutputFormat, +) -> impl futures::Future +where + C: UsageProvider + HeaderMetadata + BlockchainEvents, + >::Error: Display, +{ + build!(client, network_status_stream_builder, pool, format) } From 4133e3ca72dab542203d426a728af5250c69e3a8 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 3 Jun 2020 10:11:27 +0200 Subject: [PATCH 19/36] Update client/service/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/service/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 4896cb5bfad18..67ac7bdb4fbd7 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -56,7 +56,7 @@ use sc_network::{NetworkService, NetworkStatus, network_state::NetworkState, Pee use log::{log, warn, debug, error, Level}; use codec::{Encode, Decode}; use sp_runtime::generic::BlockId; -use sp_runtime::traits::{Block as BlockT}; +use sp_runtime::traits::Block as BlockT; use parity_util_mem::MallocSizeOf; use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender}; From 23d775e961f576185d2a022824666f136128c6aa Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 3 Jun 2020 10:26:29 +0200 Subject: [PATCH 20/36] improve doc --- client/service/src/builder.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index e554d2eb262db..4d8e6b595b082 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -829,6 +829,26 @@ impl } /// Defines the informant's prefix for the logs. An empty string by default. + /// + /// By default substrate will show logs without a prefix. Example: + /// + /// ```text + /// 2020-05-28 15:11:06 ✨ BOO! Imported #2 (0xc21c…2ca8) + /// 2020-05-28 15:11:07 💤 BOO! Idle (0 peers), best: #2 (0xc21c…2ca8), finalized #0 (0x7299…e6df), ⬇ 0 ⬆ 0 + /// ``` + /// + /// But you can define a prefix by using this function. Example: + /// + /// ```rust,ignore + /// service.with_informant_prefix(|| "[MyNode] ".to_string()); + /// ``` + /// + /// This will output: + /// + /// ```text + /// 2020-05-28 15:11:06 ✨ [MyNode] Imported #2 (0xc21c…2ca8) + /// 2020-05-28 15:11:07 💤 [MyNode] Idle (0 peers), best: #2 (0xc21c…2ca8), finalized #0 (0x7299…e6df), ⬇ 0 ⬆ 0 + /// ``` pub fn with_informant_prefix( self, informant_prefix_builder: impl FnOnce() -> String + Send + 'static, From f006ccf44e3e7fac0e4585adabeb08acc2c3688b Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 3 Jun 2020 10:28:09 +0200 Subject: [PATCH 21/36] Update client/service/src/builder.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/service/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 4d8e6b595b082..e275b94c56f11 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -979,7 +979,7 @@ ServiceBuilder< informant_prefix_builder, } = self; - let informant_prefix = informant_prefix_builder.map(|f| f()).unwrap_or_else(String::new); + let informant_prefix = informant_prefix_builder.map(|f| f()).unwrap_or_default(); sp_session::generate_initial_session_keys( client.clone(), From b5dd8d871f553f1ece7768522310f26a2c698a97 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 3 Jun 2020 10:28:37 +0200 Subject: [PATCH 22/36] Update client/service/src/builder.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/service/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index e275b94c56f11..e296d30133e63 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -1380,7 +1380,7 @@ ServiceBuilder< transaction_pool.clone(), sc_informant::OutputFormat { colors: true, prefix: informant_prefix }, ); - let _informant_handle = spawn_handle.spawn("informant", informant_future); + spawn_handle.spawn("informant", informant_future); Ok(Service { client, From e32866ad397a14d0045d350d8bb8c783acb784a3 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 3 Jun 2020 10:37:05 +0200 Subject: [PATCH 23/36] change code --- client/informant/src/display.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index c9427cc03372b..eed28990b4ec5 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -79,15 +79,12 @@ impl InformantDisplay { ), }; - match &self.format { - OutputFormat { - colors: true, - prefix, - } => info!( + if self.format.colors { + info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", level, - prefix, + self.format.prefix, Colour::White.bold().paint(&status), target, Colour::White.bold().paint(format!("{}", num_connected_peers)), @@ -97,15 +94,13 @@ impl InformantDisplay { info.chain.finalized_hash, Colour::Green.paint(format!("⬇ {}", TransferRateFormat(net_status.average_download_per_sec))), Colour::Red.paint(format!("⬆ {}", TransferRateFormat(net_status.average_upload_per_sec))), - ), - OutputFormat { - colors: false, - prefix, - } => info!( + ) + } else { + info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", level, - prefix, + self.format.prefix, status, target, num_connected_peers, @@ -115,7 +110,7 @@ impl InformantDisplay { info.chain.finalized_hash, TransferRateFormat(net_status.average_download_per_sec), TransferRateFormat(net_status.average_upload_per_sec), - ), + ) } } } From 1b38e33cc84ff991bc14173ab15a5c9377bcf649 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 3 Jun 2020 10:41:25 +0200 Subject: [PATCH 24/36] Update client/informant/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/informant/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 1c60c7e9b3a5a..5d1a9be00dab6 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -37,8 +37,8 @@ mod display; /// The format to print telemetry output in. #[derive(Clone)] pub struct OutputFormat { - /// Use colors to display the logs - pub colors: bool, + /// Enable color output in logs. + pub enable_color: bool, /// Add a prefix before every log line pub prefix: String, } From 552351873f047e16509862436fd317c5c8950020 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 3 Jun 2020 10:43:25 +0200 Subject: [PATCH 25/36] enable_color --- client/informant/src/display.rs | 2 +- client/service/src/builder.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index eed28990b4ec5..4491eb61d69ca 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -79,7 +79,7 @@ impl InformantDisplay { ), }; - if self.format.colors { + if self.format.enable_color { info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index e296d30133e63..5e79b28fe1e8c 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -1378,7 +1378,7 @@ ServiceBuilder< stream }, transaction_pool.clone(), - sc_informant::OutputFormat { colors: true, prefix: informant_prefix }, + sc_informant::OutputFormat { enable_color: true, prefix: informant_prefix }, ); spawn_handle.spawn("informant", informant_future); From 36c414861c2395d2c412c0921a58f7c939cfc4b9 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 3 Jun 2020 10:43:32 +0200 Subject: [PATCH 26/36] reorg log --- client/informant/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 5d1a9be00dab6..c175ac83f2c6d 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -86,7 +86,8 @@ macro_rules! build { match maybe_ancestor { Ok(ref ancestor) if ancestor.hash != *last_hash => info!( - "♻️ Reorg on #{},{} to #{},{}, common ancestor #{},{}", + "♻️ {}Reorg on #{},{} to #{},{}, common ancestor #{},{}", + $format.prefix, Colour::Red.bold().paint(format!("{}", last_num)), last_hash, Colour::Green.bold().paint(format!("{}", n.header.number())), n.hash, Colour::White.bold().paint(format!("{}", ancestor.number)), ancestor.hash, From 9728c25cca2abbb84924577b565fa7aa5a545fd4 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 3 Jun 2020 11:02:01 +0200 Subject: [PATCH 27/36] remove macro --- client/informant/src/lib.rs | 169 +++++++++++++++++------------------- 1 file changed, 78 insertions(+), 91 deletions(-) diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index c175ac83f2c6d..46a2894225442 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -43,101 +43,21 @@ pub struct OutputFormat { pub prefix: String, } -macro_rules! build { - ($client:expr, $network_status_stream_builder:expr, $pool:expr, $format:expr) => {{ - let mut display = display::InformantDisplay::new($format.clone()); - - let client_1 = $client.clone(); - let display_notifications = $network_status_stream_builder(Duration::from_millis(5000)) - .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(()) - }); - - let mut last_best = { - let info = $client.usage_info(); - Some((info.chain.best_number, info.chain.best_hash)) - }; - - let display_block_import = $client.import_notification_stream().for_each(move |n| { - // detect and log reorganizations. - if let Some((ref last_num, ref last_hash)) = last_best { - if n.header.parent_hash() != last_hash && n.is_new_best { - let maybe_ancestor = sp_blockchain::lowest_common_ancestor( - &*$client, - last_hash.clone(), - n.hash, - ); - - match maybe_ancestor { - Ok(ref ancestor) if ancestor.hash != *last_hash => info!( - "♻️ {}Reorg on #{},{} to #{},{}, common ancestor #{},{}", - $format.prefix, - Colour::Red.bold().paint(format!("{}", last_num)), last_hash, - Colour::Green.bold().paint(format!("{}", n.header.number())), n.hash, - Colour::White.bold().paint(format!("{}", ancestor.number)), ancestor.hash, - ), - Ok(_) => {}, - Err(e) => warn!("Error computing tree route: {}", e), - } - } - } - - if n.is_new_best { - last_best = Some((n.header.number().clone(), n.hash.clone())); - } +/// An empty trait that implements `TransactionPool` +#[cfg(target_os = "unknown")] +pub trait TransactionPoolAndMaybeMallogSizeOf: TransactionPool {} - info!( - target: "substrate", "✨ {}Imported #{} ({})", - $format.prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash, - ); - future::ready(()) - }); +/// An empty trait that implements `TransactionPool` and `MallocSizeOf` +#[cfg(not(target_os = "unknown"))] +pub trait TransactionPoolAndMaybeMallogSizeOf: TransactionPool + MallocSizeOf {} - future::join( - display_notifications, - display_block_import - ).map(|_| ()) - }} -} +#[cfg(target_os = "unknown")] +impl TransactionPoolAndMaybeMallogSizeOf for T {} -/// Creates an informant in the form of a `Future` that must be polled regularly. #[cfg(not(target_os = "unknown"))] -pub fn build( - client: Arc, - network_status_stream_builder: impl FnOnce( - Duration, - ) -> TracingUnboundedReceiver<( - NetworkStatus, - NetworkState, - )>, - pool: Arc, - format: OutputFormat, -) -> impl futures::Future -where - C: UsageProvider + HeaderMetadata + BlockchainEvents, - >::Error: Display, -{ - build!(client, network_status_stream_builder, pool, format) -} +impl TransactionPoolAndMaybeMallogSizeOf for T {} /// Creates an informant in the form of a `Future` that must be polled regularly. -#[cfg(target_os = "unknown")] pub fn build( client: Arc, network_status_stream_builder: impl FnOnce( @@ -146,12 +66,79 @@ pub fn build( NetworkStatus, NetworkState, )>, - pool: Arc, + pool: Arc, format: OutputFormat, ) -> impl futures::Future where C: UsageProvider + HeaderMetadata + BlockchainEvents, >::Error: Display, { - build!(client, network_status_stream_builder, pool, format) + let mut display = display::InformantDisplay::new(format.clone()); + + let client_1 = client.clone(); + let display_notifications = network_status_stream_builder(Duration::from_millis(5000)) + .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(()) + }); + + let mut last_best = { + let info = client.usage_info(); + Some((info.chain.best_number, info.chain.best_hash)) + }; + + let display_block_import = client.import_notification_stream().for_each(move |n| { + // detect and log reorganizations. + if let Some((ref last_num, ref last_hash)) = last_best { + if n.header.parent_hash() != last_hash && n.is_new_best { + let maybe_ancestor = sp_blockchain::lowest_common_ancestor( + &*client, + last_hash.clone(), + n.hash, + ); + + match maybe_ancestor { + Ok(ref ancestor) if ancestor.hash != *last_hash => info!( + "♻️ {}Reorg on #{},{} to #{},{}, common ancestor #{},{}", + format.prefix, + Colour::Red.bold().paint(format!("{}", last_num)), last_hash, + Colour::Green.bold().paint(format!("{}", n.header.number())), n.hash, + Colour::White.bold().paint(format!("{}", ancestor.number)), ancestor.hash, + ), + Ok(_) => {}, + Err(e) => warn!("Error computing tree route: {}", e), + } + } + } + + if n.is_new_best { + last_best = Some((n.header.number().clone(), n.hash.clone())); + } + + info!( + target: "substrate", "✨ {}Imported #{} ({})", + format.prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash, + ); + future::ready(()) + }); + + future::join( + display_notifications, + display_block_import + ).map(|_| ()) } From 036a1ea3d4d5e317cd7101576773e6348183c9ea Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 3 Jun 2020 14:19:41 +0200 Subject: [PATCH 28/36] Removed builder for informant prefix --- client/service/src/builder.rs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 5e79b28fe1e8c..bbc0269027a7b 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -100,7 +100,7 @@ pub struct ServiceBuilder>>, marker: PhantomData<(TBl, TRtApi)>, block_announce_validator_builder: Option) -> Box + Send> + Send>>, - informant_prefix_builder: Option String + Send>>, + informant_prefix: String, } /// A utility trait for building an RPC extension given a `DenyUnsafe` instance. @@ -364,7 +364,7 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> { rpc_extensions_builder: Box::new(|_| ()), remote_backend: None, block_announce_validator_builder: None, - informant_prefix_builder: None, + informant_prefix: Default::default(), marker: PhantomData, }) } @@ -448,7 +448,7 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> { rpc_extensions_builder: Box::new(|_| ()), remote_backend: Some(remote_blockchain), block_announce_validator_builder: None, - informant_prefix_builder: None, + informant_prefix: Default::default(), marker: PhantomData, }) } @@ -522,7 +522,7 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, - informant_prefix_builder: self.informant_prefix_builder, + informant_prefix: self.informant_prefix, marker: self.marker, }) } @@ -568,7 +568,7 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, - informant_prefix_builder: self.informant_prefix_builder, + informant_prefix: self.informant_prefix, marker: self.marker, }) } @@ -607,7 +607,7 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, - informant_prefix_builder: self.informant_prefix_builder, + informant_prefix: self.informant_prefix, marker: self.marker, }) } @@ -674,7 +674,7 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, - informant_prefix_builder: self.informant_prefix_builder, + informant_prefix: self.informant_prefix, marker: self.marker, }) } @@ -739,7 +739,7 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, - informant_prefix_builder: self.informant_prefix_builder, + informant_prefix: self.informant_prefix, marker: self.marker, }) } @@ -777,7 +777,7 @@ impl rpc_extensions_builder: Box::new(rpc_extensions_builder), remote_backend: self.remote_backend, block_announce_validator_builder: self.block_announce_validator_builder, - informant_prefix_builder: self.informant_prefix_builder, + informant_prefix: self.informant_prefix, marker: self.marker, }) } @@ -823,7 +823,7 @@ impl rpc_extensions_builder: self.rpc_extensions_builder, remote_backend: self.remote_backend, block_announce_validator_builder: Some(Box::new(block_announce_validator_builder)), - informant_prefix_builder: self.informant_prefix_builder, + informant_prefix: self.informant_prefix, marker: self.marker, }) } @@ -851,12 +851,12 @@ impl /// ``` pub fn with_informant_prefix( self, - informant_prefix_builder: impl FnOnce() -> String + Send + 'static, + informant_prefix: String, ) -> Result, Error> where TSc: Clone, TFchr: Clone { Ok(ServiceBuilder { - informant_prefix_builder: Some(Box::new(informant_prefix_builder)), + informant_prefix: informant_prefix, ..self }) } @@ -976,11 +976,9 @@ ServiceBuilder< rpc_extensions_builder, remote_backend, block_announce_validator_builder, - informant_prefix_builder, + informant_prefix, } = self; - let informant_prefix = informant_prefix_builder.map(|f| f()).unwrap_or_default(); - sp_session::generate_initial_session_keys( client.clone(), &BlockId::Hash(client.chain_info().best_hash), From f4940588c0dfd7e42c880ac2bca52cc113e2495c Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 3 Jun 2020 14:21:37 +0200 Subject: [PATCH 29/36] fix doc --- client/service/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index bbc0269027a7b..b6d89ce7d38f8 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -840,7 +840,7 @@ impl /// But you can define a prefix by using this function. Example: /// /// ```rust,ignore - /// service.with_informant_prefix(|| "[MyNode] ".to_string()); + /// service.with_informant_prefix("[MyNode] ".to_string()); /// ``` /// /// This will output: From 6ba7627dbd2250d2c7a8f15c8d6dffab4147b204 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Mon, 8 Jun 2020 18:34:34 +0200 Subject: [PATCH 30/36] Update client/informant/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/informant/src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 46a2894225442..d8c3f6dee8e90 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -131,8 +131,11 @@ where } info!( - target: "substrate", "✨ {}Imported #{} ({})", - format.prefix, Colour::White.bold().paint(format!("{}", n.header.number())), n.hash, + target: "substrate", + "✨ {}Imported #{} ({})", + format.prefix, + Colour::White.bold().paint(format!("{}", n.header.number())), + n.hash, ); future::ready(()) }); From c1ec56a6a562cfbae70b8704d75ab61795e2880c Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Mon, 8 Jun 2020 18:34:50 +0200 Subject: [PATCH 31/36] Update client/informant/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/informant/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index d8c3f6dee8e90..c3c42032d6f38 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -43,7 +43,7 @@ pub struct OutputFormat { pub prefix: String, } -/// An empty trait that implements `TransactionPool` +/// Marker trait for a type that implements `TransactionPool` and `MallocSizeOf` on `not(target_os = "unknown")`. #[cfg(target_os = "unknown")] pub trait TransactionPoolAndMaybeMallogSizeOf: TransactionPool {} From d3349041b8ff28a9a44e4a6b496f832e0ff8ec19 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Mon, 8 Jun 2020 18:35:02 +0200 Subject: [PATCH 32/36] Update client/informant/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/informant/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index c3c42032d6f38..8ef6ef3c1d062 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -47,7 +47,7 @@ pub struct OutputFormat { #[cfg(target_os = "unknown")] pub trait TransactionPoolAndMaybeMallogSizeOf: TransactionPool {} -/// An empty trait that implements `TransactionPool` and `MallocSizeOf` +/// 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 {} From f73afa46809e78e9a275138da44c9c63d7d16a87 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Mon, 8 Jun 2020 18:35:29 +0200 Subject: [PATCH 33/36] Update client/informant/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/informant/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 8ef6ef3c1d062..1fe1304ff52fa 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -57,7 +57,7 @@ impl TransactionPoolAndMaybeMallogSizeOf for T {} #[cfg(not(target_os = "unknown"))] impl TransactionPoolAndMaybeMallogSizeOf for T {} -/// Creates an informant in the form of a `Future` that must be polled regularly. +/// Builds the informant and returns a `Future` that drives the informant. pub fn build( client: Arc, network_status_stream_builder: impl FnOnce( From 89a9c2b93a5cfd1bc9bb910909c7a247d254deb6 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Mon, 8 Jun 2020 18:36:46 +0200 Subject: [PATCH 34/36] Update client/service/src/builder.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/service/src/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index b6d89ce7d38f8..638ae51adf5e5 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -833,8 +833,8 @@ impl /// By default substrate will show logs without a prefix. Example: /// /// ```text - /// 2020-05-28 15:11:06 ✨ BOO! Imported #2 (0xc21c…2ca8) - /// 2020-05-28 15:11:07 💤 BOO! Idle (0 peers), best: #2 (0xc21c…2ca8), finalized #0 (0x7299…e6df), ⬇ 0 ⬆ 0 + /// 2020-05-28 15:11:06 ✨ Imported #2 (0xc21c…2ca8) + /// 2020-05-28 15:11:07 💤 Idle (0 peers), best: #2 (0xc21c…2ca8), finalized #0 (0x7299…e6df), ⬇ 0 ⬆ 0 /// ``` /// /// But you can define a prefix by using this function. Example: From a82f2cbb8f01bbf42ab8f2529bb5805bdc8dcdbd Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Mon, 8 Jun 2020 18:37:13 +0200 Subject: [PATCH 35/36] Update client/service/src/builder.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/service/src/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 638ae51adf5e5..e34390b980237 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -846,8 +846,8 @@ impl /// This will output: /// /// ```text - /// 2020-05-28 15:11:06 ✨ [MyNode] Imported #2 (0xc21c…2ca8) - /// 2020-05-28 15:11:07 💤 [MyNode] Idle (0 peers), best: #2 (0xc21c…2ca8), finalized #0 (0x7299…e6df), ⬇ 0 ⬆ 0 + /// 2020-05-28 15:11:06 ✨ [Prefix] Imported #2 (0xc21c…2ca8) + /// 2020-05-28 15:11:07 💤 [Prefix] Idle (0 peers), best: #2 (0xc21c…2ca8), finalized #0 (0x7299…e6df), ⬇ 0 ⬆ 0 /// ``` pub fn with_informant_prefix( self, From f75b06a78eeb6ccf0d0e14697c0656991f26b670 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Mon, 8 Jun 2020 18:37:25 +0200 Subject: [PATCH 36/36] Update client/service/src/builder.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/service/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index e34390b980237..cf437a9385b46 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -840,7 +840,7 @@ impl /// But you can define a prefix by using this function. Example: /// /// ```rust,ignore - /// service.with_informant_prefix("[MyNode] ".to_string()); + /// service.with_informant_prefix("[Prefix] ".to_string()); /// ``` /// /// This will output: