From b866b7cc971bfc9537fe660baaaa080637b8b67e Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 4 Aug 2020 21:55:51 +0200 Subject: [PATCH 01/29] init_logger: switch from log-based to tracing-based and add compatibility layer --- Cargo.lock | 69 ++++++++++++++++++++++++-- client/cli/Cargo.toml | 3 ++ client/cli/src/lib.rs | 112 +++++++++++++++++------------------------- 3 files changed, 115 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe237f2341b23..81ff0d41cbb79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3245,6 +3245,15 @@ dependencies = [ "libc", ] +[[package]] +name = "matchers" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" +dependencies = [ + "regex-automata", +] + [[package]] name = "matches" version = "0.1.8" @@ -5883,6 +5892,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" dependencies = [ "byteorder", + "regex-syntax", ] [[package]] @@ -6248,6 +6258,9 @@ dependencies = [ "tempfile", "time", "tokio 0.2.21", + "tracing", + "tracing-log", + "tracing-subscriber", ] [[package]] @@ -7437,6 +7450,15 @@ dependencies = [ "opaque-debug 0.2.3", ] +[[package]] +name = "sharded-slab" +version = "0.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06d5a3f5166fb5b42a5439f2eee8b9de149e235961e3eb21c5808fc3ea17ff3e" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "0.1.1" @@ -9263,11 +9285,52 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.10" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2734b5a028fa697686f16c6d18c2c6a3c7e41513f9a213abb6754c4acb3c8d7" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-log" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e0f8c7178e13481ff6765bd169b33e8d554c5d2bbede5e32c356194be02b9b9" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6ccba2f8f16e0ed268fc765d9b7ff22e965e7185d32f8f1ec8294fe17d86e79" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa83a9a47081cd522c09c81b31aec2c9273424976f922ad61c053b58350b715" +checksum = "f7b33f8b2ef2ab0c3778c12646d9c42a24f7772bee4cdafc72199644a9f58fdc" dependencies = [ + "ansi_term 0.12.1", + "chrono", "lazy_static", + "matchers", + "regex", + "serde", + "serde_json", + "sharded-slab", + "smallvec 1.4.1", + "tracing-core", + "tracing-log", + "tracing-serde", ] [[package]] @@ -9361,7 +9424,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bfd5b7557925ce778ff9b9ef90e3ade34c524b5ff10e239c69a42d546d2af56" dependencies = [ - "rand 0.3.23", + "rand 0.7.3", ] [[package]] diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 85a1eb0fe0a4c..de0eeb99570c0 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -44,6 +44,9 @@ sc-tracing = { version = "2.0.0-rc5", path = "../tracing" } chrono = "0.4.10" parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] } serde = "1.0.111" +tracing = "0.1.10" +tracing-log = "0.1.1" +tracing-subscriber = "0.2.10" [target.'cfg(not(target_os = "unknown"))'.dependencies] rpassword = "4.0.1" diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 7899e48b0a261..6243e863fcf8e 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -32,10 +32,7 @@ pub use arg_enums::*; pub use commands::*; pub use config::*; pub use error::*; -use lazy_static::lazy_static; -use log::info; pub use params::*; -use regex::Regex; pub use runner::*; use sc_service::{Configuration, TaskExecutor}; pub use sc_service::{ChainSpec, Role}; @@ -230,77 +227,60 @@ pub trait SubstrateCli: Sized { /// Initialize the logger pub fn init_logger(pattern: &str) { - use ansi_term::Colour; - - let mut builder = env_logger::Builder::new(); - // Disable info logging by default for some modules: - builder.filter(Some("ws"), log::LevelFilter::Off); - builder.filter(Some("yamux"), log::LevelFilter::Off); - builder.filter(Some("cranelift_codegen"), log::LevelFilter::Off); - builder.filter(Some("hyper"), log::LevelFilter::Warn); - builder.filter(Some("cranelift_wasm"), log::LevelFilter::Warn); - // Always log the special target `sc_tracing`, overrides global level - builder.filter(Some("sc_tracing"), log::LevelFilter::Info); - // Enable info for others. - builder.filter(None, log::LevelFilter::Info); - - if let Ok(lvl) = std::env::var("RUST_LOG") { - builder.parse_filters(&lvl); + match tracing_log::LogTracer::init() { + Ok(_) => (), + Err(_) => log::info!("💬 Not registering Substrate logger, as there is already a global logger registered!"), } - builder.parse_filters(pattern); - let isatty = atty::is(atty::Stream::Stderr); - let enable_color = isatty; + let mut env_filter = tracing_subscriber::EnvFilter::default() + // Disable info logging by default for some modules. + .add_directive("ws=off".parse().expect("provided directive is valid")) + .add_directive("yamux=off".parse().expect("provided directive is valid")) + .add_directive("cranelift_codegen=off".parse().expect("provided directive is valid")) + // Set warn logging by default for some modules. + .add_directive("cranelife_wasm=warn".parse().expect("provided directive is valid")) + .add_directive("hyper=warn".parse().expect("provided directive is valid")) + // Always log the special target `sc_tracing`, overrides global level. + .add_directive("sc_tracing=info".parse().expect("provided directive is valid")) + // Enable info for others. + .add_directive(tracing_subscriber::filter::LevelFilter::INFO.into()); - builder.format(move |buf, record| { - let now = time::now(); - let timestamp = - time::strftime("%Y-%m-%d %H:%M:%S", &now).expect("Error formatting log timestamp"); - - let mut output = if log::max_level() <= log::LevelFilter::Info { - format!( - "{} {}", - Colour::Black.bold().paint(timestamp), - record.args(), - ) - } else { - let name = ::std::thread::current() - .name() - .map_or_else(Default::default, |x| { - format!("{}", Colour::Blue.bold().paint(x)) - }); - let millis = (now.tm_nsec as f32 / 1000000.0).floor() as usize; - let timestamp = format!("{}.{:03}", timestamp, millis); - format!( - "{} {} {} {} {}", - Colour::Black.bold().paint(timestamp), - name, - record.level(), - record.target(), - record.args() - ) - }; - - if !isatty && record.level() <= log::Level::Info && atty::is(atty::Stream::Stdout) { - // duplicate INFO/WARN output to console - println!("{}", output); + if let Ok(lvl) = std::env::var("RUST_LOG") { + if lvl != "" { + match lvl.parse() { + Ok(directive) => { + env_filter = env_filter.add_directive(directive); + } + // We're not sure if log or tracing is available at this moment, so silently ignore the + // parse error. + Err(_) => (), + } } + } - if !enable_color { - output = kill_color(output.as_ref()); + if pattern != "" { + match pattern.parse() { + Ok(directive) => { + env_filter = env_filter.add_directive(directive); + } + // We're not sure if log or tracing is available at this moment, so silently ignore the + // parse error. + Err(_) => (), } + } - writeln!(buf, "{}", output) - }); + let isatty = atty::is(atty::Stream::Stderr); + let enable_color = isatty; - if builder.try_init().is_err() { - info!("💬 Not registering Substrate logger, as there is already a global logger registered!"); - } -} + let subscriber = tracing_subscriber::FmtSubscriber::builder() + .with_env_filter(env_filter) + .with_target(false) + .with_ansi(enable_color) + .compact() + .finish(); -fn kill_color(s: &str) -> String { - lazy_static! { - static ref RE: Regex = Regex::new("\x1b\\[[^m]+m").expect("Error initializing color regex"); + match tracing::subscriber::set_global_default(subscriber) { + Ok(_) => (), + Err(_) => tracing::info!("💬 Not registering Substrate subscriber, as there is already a global subscriber registered!"), } - RE.replace_all(s, "").to_string() } From 5180a85c15e31eea5f8fe0391d2aacf62062b7cb Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 4 Aug 2020 22:27:01 +0200 Subject: [PATCH 02/29] Move tracing profiling subscriber related config realization --- client/cli/src/config.rs | 4 +++- client/cli/src/lib.rs | 20 ++++++++++++++++---- client/service/src/builder.rs | 13 +------------ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index efda45a0eca9a..337773b60ad30 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -497,11 +497,13 @@ pub trait CliConfiguration: Sized { /// 3. Initialize the logger fn init(&self) -> Result<()> { let logger_pattern = self.log_filters()?; + let tracing_receiver = self.tracing_receiver()?; + let tracing_targets = self.tracing_targets()?; sp_panic_handler::set(&C::support_url(), &C::impl_version()); fdlimit::raise_fd_limit(); - init_logger(&logger_pattern); + init_logger(&logger_pattern, tracing_receiver, tracing_targets); Ok(()) } diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 6243e863fcf8e..e88bc9dd7bc4f 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -43,6 +43,7 @@ use structopt::{ clap::{self, AppSettings}, StructOpt, }; +use tracing_subscriber::layer::SubscriberExt; /// Substrate client CLI /// @@ -226,7 +227,11 @@ pub trait SubstrateCli: Sized { } /// Initialize the logger -pub fn init_logger(pattern: &str) { +pub fn init_logger( + pattern: &str, + tracing_receiver: sc_tracing::TracingReceiver, + tracing_targets: Option +) { match tracing_log::LogTracer::init() { Ok(_) => (), Err(_) => log::info!("💬 Not registering Substrate logger, as there is already a global logger registered!"), @@ -279,8 +284,15 @@ pub fn init_logger(pattern: &str) { .compact() .finish(); - match tracing::subscriber::set_global_default(subscriber) { - Ok(_) => (), - Err(_) => tracing::info!("💬 Not registering Substrate subscriber, as there is already a global subscriber registered!"), + if let Some(tracing_targets) = tracing_targets { + match tracing::subscriber::set_global_default(subscriber) { + Ok(_) => (), + Err(_) => tracing::info!("💬 Not registering Substrate subscriber, as there is already a global subscriber registered!"), + } + } else { + match tracing::subscriber::set_global_default(subscriber) { + Ok(_) => (), + Err(_) => tracing::info!("💬 Not registering Substrate subscriber, as there is already a global subscriber registered!"), + } } } diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 4c7c1f57ee04b..b553815701d8e 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -560,17 +560,6 @@ pub fn spawn_tasks( )) }); - // Instrumentation - if let Some(tracing_targets) = config.tracing_targets.as_ref() { - let subscriber = sc_tracing::ProfilingSubscriber::new( - config.tracing_receiver, tracing_targets - ); - match tracing::subscriber::set_global_default(subscriber) { - Ok(_) => (), - Err(e) => error!(target: "tracing", "Unable to set global default subscriber {}", e), - } - } - // Spawn informant task spawn_handle.spawn("informant", sc_informant::build( client.clone(), @@ -668,7 +657,7 @@ fn build_telemetry( let startup_time = SystemTime::UNIX_EPOCH.elapsed() .map(|dur| dur.as_millis()) .unwrap_or(0); - + spawn_handle.spawn( "telemetry-worker", telemetry.clone() From 05745199f75086d03193ca4af6f99a14f7384df3 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Wed, 5 Aug 2020 15:29:35 +0200 Subject: [PATCH 03/29] sp-tracing: change profiling to be a layer instead of a subscriber --- Cargo.lock | 1 + client/tracing/Cargo.toml | 2 +- client/tracing/src/lib.rs | 64 +++++++++++++++------------------------ 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81ff0d41cbb79..d4ba04f8536b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7166,6 +7166,7 @@ dependencies = [ "sp-tracing", "tracing", "tracing-core", + "tracing-subscriber", ] [[package]] diff --git a/client/tracing/Cargo.toml b/client/tracing/Cargo.toml index 998dfb94de0c7..9b73343667f39 100644 --- a/client/tracing/Cargo.toml +++ b/client/tracing/Cargo.toml @@ -20,8 +20,8 @@ serde = "1.0.101" serde_json = "1.0.41" slog = { version = "2.5.2", features = ["nested-values"] } tracing-core = "0.1.7" +tracing-subscriber = "0.2.10" sp-tracing = { version = "2.0.0-rc2", path = "../../primitives/tracing" } - sc-telemetry = { version = "2.0.0-rc5", path = "../telemetry" } [dev-dependencies] diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index c2b036e218f15..0b6211de5f201 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -26,19 +26,18 @@ use rustc_hash::FxHashMap; use std::fmt; -use std::sync::atomic::{AtomicU64, Ordering}; use std::time::{Duration, Instant}; use parking_lot::Mutex; use serde::ser::{Serialize, Serializer, SerializeMap}; use tracing_core::{ - event::Event, field::{Visit, Field}, Level, metadata::Metadata, span::{Attributes, Id, Record}, subscriber::Subscriber, }; +use tracing_subscriber::layer::{Layer, Context}; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; use sp_tracing::proxy::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; @@ -71,7 +70,7 @@ pub trait TraceHandler: Send + Sync { #[derive(Debug)] pub struct SpanDatum { /// id for this span - pub id: u64, + pub id: Id, /// Name of the span pub name: String, /// Target, typically module @@ -193,19 +192,18 @@ impl slog::Value for Values { } /// Responsible for assigning ids to new spans, which are not re-used. -pub struct ProfilingSubscriber { - next_id: AtomicU64, +pub struct ProfilingLayer { targets: Vec<(String, Level)>, trace_handler: Box, - span_data: Mutex>, + span_data: Mutex>, } -impl ProfilingSubscriber { +impl ProfilingLayer { /// Takes a `TracingReceiver` and a comma separated list of targets, /// either with a level: "pallet=trace,frame=debug" /// or without: "pallet,frame" in which case the level defaults to `trace`. /// wasm_tracing indicates whether to enable wasm traces - pub fn new(receiver: TracingReceiver, targets: &str) -> ProfilingSubscriber { + pub fn new(receiver: TracingReceiver, targets: &str) -> Self { match receiver { TracingReceiver::Log => Self::new_with_handler(Box::new(LogTraceHandler), targets), TracingReceiver::Telemetry => Self::new_with_handler( @@ -221,11 +219,10 @@ impl ProfilingSubscriber { /// or without: "pallet" in which case the level defaults to `trace`. /// wasm_tracing indicates whether to enable wasm traces pub fn new_with_handler(trace_handler: Box, targets: &str) - -> ProfilingSubscriber + -> Self { let targets: Vec<_> = targets.split(',').map(|s| parse_target(s)).collect(); - ProfilingSubscriber { - next_id: AtomicU64::new(1), + Self { targets, trace_handler, span_data: Mutex::new(FxHashMap::default()), @@ -259,29 +256,22 @@ fn parse_target(s: &str) -> (String, Level) { } } -impl Subscriber for ProfilingSubscriber { - fn enabled(&self, metadata: &Metadata<'_>) -> bool { - if metadata.target() == PROXY_TARGET || self.check_target(metadata.target(), metadata.level()) { - log::debug!(target: "tracing", "Enabled target: {}, level: {}", metadata.target(), metadata.level()); - true - } else { - log::debug!(target: "tracing", "Disabled target: {}, level: {}", metadata.target(), metadata.level()); - false - } +impl Layer for ProfilingLayer { + fn enabled(&self, metadata: &Metadata<'_>, _ctx: Context) -> bool { + metadata.target() == PROXY_TARGET || self.check_target(metadata.target(), metadata.level()) } - fn new_span(&self, attrs: &Attributes<'_>) -> Id { - let id = self.next_id.fetch_add(1, Ordering::Relaxed); + fn new_span(&self, attrs: &Attributes<'_>, id: &Id, _ctx: Context) { let mut values = Values::default(); attrs.record(&mut values); // If this is a wasm trace, check if target/level is enabled if let Some(wasm_target) = values.string_values.get(WASM_TARGET_KEY) { if !self.check_target(wasm_target, attrs.metadata().level()) { - return Id::from_u64(id); + return } } let span_datum = SpanDatum { - id, + id: id.clone(), name: attrs.metadata().name().to_owned(), target: attrs.metadata().target().to_owned(), level: attrs.metadata().level().clone(), @@ -290,41 +280,36 @@ impl Subscriber for ProfilingSubscriber { overall_time: ZERO_DURATION, values, }; - self.span_data.lock().insert(id, span_datum); - Id::from_u64(id) + self.span_data.lock().insert(id.clone(), span_datum); } - fn record(&self, span: &Id, values: &Record<'_>) { + fn on_record(&self, span: &Id, values: &Record<'_>, _ctx: Context) { let mut span_data = self.span_data.lock(); - if let Some(s) = span_data.get_mut(&span.into_u64()) { + if let Some(s) = span_data.get_mut(&span) { values.record(&mut s.values); } } - fn record_follows_from(&self, _span: &Id, _follows: &Id) {} - - fn event(&self, _event: &Event<'_>) {} - - fn enter(&self, span: &Id) { + fn on_enter(&self, span: &Id, _ctx: Context) { let mut span_data = self.span_data.lock(); let start_time = Instant::now(); - if let Some(mut s) = span_data.get_mut(&span.into_u64()) { + if let Some(mut s) = span_data.get_mut(&span) { s.start_time = start_time; } } - fn exit(&self, span: &Id) { + fn on_exit(&self, span: &Id, _ctx: Context) { let end_time = Instant::now(); let mut span_data = self.span_data.lock(); - if let Some(mut s) = span_data.get_mut(&span.into_u64()) { + if let Some(mut s) = span_data.get_mut(&span) { s.overall_time = end_time - s.start_time + s.overall_time; } } - fn try_close(&self, span: Id) -> bool { + fn on_close(&self, span: Id, _ctx: Context) { let span_datum = { let mut span_data = self.span_data.lock(); - span_data.remove(&span.into_u64()) + span_data.remove(&span) }; if let Some(mut span_datum) = span_datum { if span_datum.name == WASM_TRACE_IDENTIFIER { @@ -340,7 +325,6 @@ impl Subscriber for ProfilingSubscriber { self.trace_handler.handle_span(span_datum); } }; - true } } @@ -361,7 +345,7 @@ impl TraceHandler for LogTraceHandler { fn handle_span(&self, span_datum: SpanDatum) { if span_datum.values.is_empty() { log::log!( - log_level(span_datum.level), + log_level(span_datum.level), "{}: {}, time: {}", span_datum.target, span_datum.name, From 036d066a3ca1d4987ec611d1e011447abddcd82b Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Wed, 5 Aug 2020 15:32:12 +0200 Subject: [PATCH 04/29] Enable profiling layer in cli --- client/cli/src/lib.rs | 4 +++- client/service/src/builder.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index e88bc9dd7bc4f..9f5599f45ccc0 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -285,7 +285,9 @@ pub fn init_logger( .finish(); if let Some(tracing_targets) = tracing_targets { - match tracing::subscriber::set_global_default(subscriber) { + let profiling = sc_tracing::ProfilingLayer::new(tracing_receiver, &tracing_targets); + + match tracing::subscriber::set_global_default(subscriber.with(profiling)) { Ok(_) => (), Err(_) => tracing::info!("💬 Not registering Substrate subscriber, as there is already a global subscriber registered!"), } diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index b553815701d8e..93d813d65bd56 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -36,7 +36,7 @@ use sp_consensus::{ use futures::{FutureExt, StreamExt, future::ready}; use jsonrpc_pubsub::manager::SubscriptionManager; use sc_keystore::Store as Keystore; -use log::{info, warn, error}; +use log::{info, warn}; use sc_network::config::{Role, FinalityProofProvider, OnDemand, BoxFinalityProofRequestBuilder}; use sc_network::NetworkService; use parking_lot::RwLock; From bf668a7414a84ddc8689ada52f02402cf98abb02 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Wed, 5 Aug 2020 16:01:19 +0200 Subject: [PATCH 05/29] Change all test env_logger init to sp_tracing::try_init_simple --- Cargo.lock | 4 +- bin/node/rpc-client/src/main.rs | 2 +- client/authority-discovery/src/tests.rs | 4 +- client/consensus/aura/src/lib.rs | 2 +- client/consensus/babe/src/tests.rs | 14 ++--- client/db/src/lib.rs | 2 +- client/db/src/storage_cache.rs | 4 +- .../src/communication/tests.rs | 2 +- client/finality-grandpa/src/tests.rs | 18 +++---- client/network/src/light_client_handler.rs | 2 +- .../src/protocol/sync/extra_requests.rs | 2 +- client/network/test/src/sync.rs | 52 +++++++++---------- client/offchain/src/api.rs | 2 +- client/offchain/src/lib.rs | 2 +- client/service/test/src/client/mod.rs | 7 ++- client/service/test/src/lib.rs | 2 +- client/tracing/Cargo.toml | 7 +-- client/tracing/src/lib.rs | 10 ++-- frame/staking/src/mock.rs | 2 +- primitives/tracing/Cargo.toml | 4 +- primitives/tracing/src/lib.rs | 11 +++- utils/frame/rpc/system/src/lib.rs | 8 +-- 22 files changed, 86 insertions(+), 77 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4ba04f8536b0..643982357060b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7165,8 +7165,6 @@ dependencies = [ "slog", "sp-tracing", "tracing", - "tracing-core", - "tracing-subscriber", ] [[package]] @@ -8269,6 +8267,8 @@ dependencies = [ "log", "rental", "tracing", + "tracing-log", + "tracing-subscriber", ] [[package]] diff --git a/bin/node/rpc-client/src/main.rs b/bin/node/rpc-client/src/main.rs index eadd1c8d47247..31f1efa28ccd0 100644 --- a/bin/node/rpc-client/src/main.rs +++ b/bin/node/rpc-client/src/main.rs @@ -35,7 +35,7 @@ use jsonrpc_core_client::{ }; fn main() { - env_logger::init(); + sp_tracing::try_init_simple(); rt::run(rt::lazy(|| { let uri = "http://localhost:9933"; diff --git a/client/authority-discovery/src/tests.rs b/client/authority-discovery/src/tests.rs index 09a65fd138c11..8e2debd4aa039 100644 --- a/client/authority-discovery/src/tests.rs +++ b/client/authority-discovery/src/tests.rs @@ -239,7 +239,7 @@ fn new_registers_metrics() { #[test] fn request_addresses_of_others_triggers_dht_get_query() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let (_dht_event_tx, dht_event_rx) = channel(1000); // Generate authority keys @@ -270,7 +270,7 @@ fn request_addresses_of_others_triggers_dht_get_query() { #[test] fn publish_discover_cycle() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); // Node A publishing its address. diff --git a/client/consensus/aura/src/lib.rs b/client/consensus/aura/src/lib.rs index 4e6cb49f1129d..584b2678f0e45 100644 --- a/client/consensus/aura/src/lib.rs +++ b/client/consensus/aura/src/lib.rs @@ -973,7 +973,7 @@ mod tests { #[test] #[allow(deprecated)] fn authoring_blocks() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let net = AuraTestNet::new(3); let peers = &[ diff --git a/client/consensus/babe/src/tests.rs b/client/consensus/babe/src/tests.rs index 958d7845edbc6..26b34d9fcf7c7 100644 --- a/client/consensus/babe/src/tests.rs +++ b/client/consensus/babe/src/tests.rs @@ -346,7 +346,7 @@ impl TestNetFactory for BabeTestNet { #[test] #[should_panic] fn rejects_empty_block() { - env_logger::try_init().unwrap(); + sp_tracing::try_init_simple(); let mut net = BabeTestNet::new(3); let block_builder = |builder: BlockBuilder<_, _, _>| { builder.build().unwrap().block @@ -359,7 +359,7 @@ fn rejects_empty_block() { fn run_one_test( mutator: impl Fn(&mut TestHeader, Stage) + Send + Sync + 'static, ) { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let mutator = Arc::new(mutator) as Mutator; MUTATOR.with(|m| *m.borrow_mut() = mutator.clone()); @@ -488,7 +488,7 @@ fn rejects_missing_consensus_digests() { #[test] fn wrong_consensus_engine_id_rejected() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let sig = AuthorityPair::generate().0.sign(b""); let bad_seal: Item = DigestItem::Seal([0; 4], sig.to_vec()); assert!(bad_seal.as_babe_pre_digest().is_none()); @@ -497,14 +497,14 @@ fn wrong_consensus_engine_id_rejected() { #[test] fn malformed_pre_digest_rejected() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let bad_seal: Item = DigestItem::Seal(BABE_ENGINE_ID, [0; 64].to_vec()); assert!(bad_seal.as_babe_pre_digest().is_none()); } #[test] fn sig_is_not_pre_digest() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let sig = AuthorityPair::generate().0.sign(b""); let bad_seal: Item = DigestItem::Seal(BABE_ENGINE_ID, sig.to_vec()); assert!(bad_seal.as_babe_pre_digest().is_none()); @@ -513,7 +513,7 @@ fn sig_is_not_pre_digest() { #[test] fn can_author_block() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let keystore_path = tempfile::tempdir().expect("Creates keystore path"); let keystore = sc_keystore::Store::open(keystore_path.path(), None).expect("Creates keystore"); let pair = keystore.write().insert_ephemeral_from_seed::("//Alice") @@ -820,7 +820,7 @@ fn verify_slots_are_strictly_increasing() { #[test] fn babe_transcript_generation_match() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let keystore_path = tempfile::tempdir().expect("Creates keystore path"); let keystore = sc_keystore::Store::open(keystore_path.path(), None).expect("Creates keystore"); let pair = keystore.write().insert_ephemeral_from_seed::("//Alice") diff --git a/client/db/src/lib.rs b/client/db/src/lib.rs index d854c80bf3535..9a6415f2fbdfa 100644 --- a/client/db/src/lib.rs +++ b/client/db/src/lib.rs @@ -1908,7 +1908,7 @@ pub(crate) mod tests { #[test] fn delete_only_when_negative_rc() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let key; let backend = Backend::::new_test(1, 0); diff --git a/client/db/src/storage_cache.rs b/client/db/src/storage_cache.rs index 434b301ed6240..0b4b6d4f88ef5 100644 --- a/client/db/src/storage_cache.rs +++ b/client/db/src/storage_cache.rs @@ -1024,7 +1024,7 @@ mod tests { #[test] fn simple_fork() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let root_parent = H256::random(); let key = H256::random()[..].to_vec(); @@ -1245,7 +1245,7 @@ mod tests { #[test] fn fix_storage_mismatch_issue() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let root_parent = H256::random(); let key = H256::random()[..].to_vec(); diff --git a/client/finality-grandpa/src/communication/tests.rs b/client/finality-grandpa/src/communication/tests.rs index 273804f7a4508..928e1305a8ada 100644 --- a/client/finality-grandpa/src/communication/tests.rs +++ b/client/finality-grandpa/src/communication/tests.rs @@ -361,7 +361,7 @@ fn good_commit_leads_to_relay() { #[test] fn bad_commit_leads_to_report() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let private = [Ed25519Keyring::Alice, Ed25519Keyring::Bob, Ed25519Keyring::Charlie]; let public = make_ids(&private[..]); let voter_set = Arc::new(VoterSet::new(public.iter().cloned()).unwrap()); diff --git a/client/finality-grandpa/src/tests.rs b/client/finality-grandpa/src/tests.rs index e2b9671f04df3..abdcfa14cc00c 100644 --- a/client/finality-grandpa/src/tests.rs +++ b/client/finality-grandpa/src/tests.rs @@ -414,7 +414,7 @@ fn add_forced_change( #[test] fn finalize_3_voters_no_observers() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let mut runtime = Runtime::new().unwrap(); let peers = &[Ed25519Keyring::Alice, Ed25519Keyring::Bob, Ed25519Keyring::Charlie]; let voters = make_ids(peers); @@ -519,7 +519,7 @@ fn finalize_3_voters_1_full_observer() { #[test] fn transition_3_voters_twice_1_full_observer() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let peers_a = &[ Ed25519Keyring::Alice, Ed25519Keyring::Bob, @@ -789,7 +789,7 @@ fn sync_justifications_on_change_blocks() { #[test] fn finalizes_multiple_pending_changes_in_order() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let mut runtime = Runtime::new().unwrap(); let peers_a = &[Ed25519Keyring::Alice, Ed25519Keyring::Bob, Ed25519Keyring::Charlie]; @@ -849,7 +849,7 @@ fn finalizes_multiple_pending_changes_in_order() { #[test] fn force_change_to_new_set() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let mut runtime = Runtime::new().unwrap(); // two of these guys are offline. let genesis_authorities = &[ @@ -1011,7 +1011,7 @@ fn voter_persists_its_votes() { use futures::future; use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver}; - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let mut runtime = Runtime::new().unwrap(); // we have two authorities but we'll only be running the voter for alice @@ -1267,7 +1267,7 @@ fn voter_persists_its_votes() { #[test] fn finalize_3_voters_1_light_observer() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let mut runtime = Runtime::new().unwrap(); let authorities = &[Ed25519Keyring::Alice, Ed25519Keyring::Bob, Ed25519Keyring::Charlie]; let voters = make_ids(authorities); @@ -1312,7 +1312,7 @@ fn finalize_3_voters_1_light_observer() { #[test] fn finality_proof_is_fetched_by_light_client_when_consensus_data_changes() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut runtime = Runtime::new().unwrap(); let peers = &[Ed25519Keyring::Alice]; @@ -1342,7 +1342,7 @@ fn empty_finality_proof_is_returned_to_light_client_when_authority_set_is_differ // for debug: to ensure that without forced change light client will sync finality proof const FORCE_CHANGE: bool = true; - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut runtime = Runtime::new().unwrap(); // two of these guys are offline. @@ -1406,7 +1406,7 @@ fn empty_finality_proof_is_returned_to_light_client_when_authority_set_is_differ #[test] fn voter_catches_up_to_latest_round_when_behind() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let mut runtime = Runtime::new().unwrap(); let peers = &[Ed25519Keyring::Alice, Ed25519Keyring::Bob]; diff --git a/client/network/src/light_client_handler.rs b/client/network/src/light_client_handler.rs index 678a717a898ff..af5909af49b59 100644 --- a/client/network/src/light_client_handler.rs +++ b/client/network/src/light_client_handler.rs @@ -2004,7 +2004,7 @@ mod tests { #[test] fn send_receive_header() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let chan = oneshot::channel(); let request = light::RemoteHeaderRequest { cht_root: Default::default(), diff --git a/client/network/src/protocol/sync/extra_requests.rs b/client/network/src/protocol/sync/extra_requests.rs index d025b86b2536f..df336c25339fd 100644 --- a/client/network/src/protocol/sync/extra_requests.rs +++ b/client/network/src/protocol/sync/extra_requests.rs @@ -463,7 +463,7 @@ mod tests { #[test] fn request_is_rescheduled_when_earlier_block_is_finalized() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut finality_proofs = ExtraRequests::::new("test"); diff --git a/client/network/test/src/sync.rs b/client/network/test/src/sync.rs index 1cf2a8fee3798..86e274aae10eb 100644 --- a/client/network/test/src/sync.rs +++ b/client/network/test/src/sync.rs @@ -24,7 +24,7 @@ use sp_consensus::block_validation::Validation; use substrate_test_runtime::Header; fn test_ancestor_search_when_common_is(n: usize) { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); net.peer(0).push_blocks(n, false); @@ -42,7 +42,7 @@ fn test_ancestor_search_when_common_is(n: usize) { #[test] fn sync_peers_works() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); block_on(futures::future::poll_fn::<(), _>(|cx| { @@ -58,7 +58,7 @@ fn sync_peers_works() { #[test] fn sync_cycle_from_offline_to_syncing_to_offline() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); for peer in 0..3 { // Offline, and not major syncing. @@ -113,7 +113,7 @@ fn sync_cycle_from_offline_to_syncing_to_offline() { #[test] fn syncing_node_not_major_syncing_when_disconnected() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); // Generate blocks. @@ -147,7 +147,7 @@ fn syncing_node_not_major_syncing_when_disconnected() { #[test] fn sync_from_two_peers_works() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); net.peer(1).push_blocks(100, false); net.peer(2).push_blocks(100, false); @@ -159,7 +159,7 @@ fn sync_from_two_peers_works() { #[test] fn sync_from_two_peers_with_ancestry_search_works() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); net.peer(0).push_blocks(10, true); net.peer(1).push_blocks(100, false); @@ -171,7 +171,7 @@ fn sync_from_two_peers_with_ancestry_search_works() { #[test] fn ancestry_search_works_when_backoff_is_one() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); net.peer(0).push_blocks(1, false); @@ -185,7 +185,7 @@ fn ancestry_search_works_when_backoff_is_one() { #[test] fn ancestry_search_works_when_ancestor_is_genesis() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); net.peer(0).push_blocks(13, true); @@ -214,7 +214,7 @@ fn ancestry_search_works_when_common_is_hundred() { #[test] fn sync_long_chain_works() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(2); net.peer(1).push_blocks(500, false); net.block_until_sync(); @@ -224,7 +224,7 @@ fn sync_long_chain_works() { #[test] fn sync_no_common_longer_chain_fails() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); net.peer(0).push_blocks(20, true); net.peer(1).push_blocks(20, false); @@ -242,7 +242,7 @@ fn sync_no_common_longer_chain_fails() { #[test] fn sync_justifications() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = JustificationTestNet::new(3); net.peer(0).push_blocks(20, false); net.block_until_sync(); @@ -283,7 +283,7 @@ fn sync_justifications() { #[test] fn sync_justifications_across_forks() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = JustificationTestNet::new(3); // we push 5 blocks net.peer(0).push_blocks(5, false); @@ -315,7 +315,7 @@ fn sync_justifications_across_forks() { #[test] fn sync_after_fork_works() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); net.peer(0).push_blocks(30, false); net.peer(1).push_blocks(30, false); @@ -338,7 +338,7 @@ fn sync_after_fork_works() { #[test] fn syncs_all_forks() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(4); net.peer(0).push_blocks(2, false); net.peer(1).push_blocks(2, false); @@ -356,7 +356,7 @@ fn syncs_all_forks() { #[test] fn own_blocks_are_announced() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); net.block_until_sync(); // connect'em net.peer(0).generate_blocks(1, BlockOrigin::Own, |builder| builder.build().unwrap().block); @@ -372,7 +372,7 @@ fn own_blocks_are_announced() { #[test] fn blocks_are_not_announced_by_light_nodes() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(0); // full peer0 is connected to light peer @@ -401,7 +401,7 @@ fn blocks_are_not_announced_by_light_nodes() { #[test] fn can_sync_small_non_best_forks() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(2); net.peer(0).push_blocks(30, false); net.peer(1).push_blocks(30, false); @@ -464,7 +464,7 @@ fn can_sync_small_non_best_forks() { #[test] fn can_not_sync_from_light_peer() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); // given the network with 1 full nodes (#0) and 1 light node (#1) let mut net = TestNet::new(1); @@ -497,7 +497,7 @@ fn can_not_sync_from_light_peer() { #[test] fn light_peer_imports_header_from_announce() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); fn import_with_announce(net: &mut TestNet, hash: H256) { net.peer(0).announce_block(hash, Vec::new()); @@ -530,7 +530,7 @@ fn light_peer_imports_header_from_announce() { #[test] fn can_sync_explicit_forks() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(2); net.peer(0).push_blocks(30, false); net.peer(1).push_blocks(30, false); @@ -584,7 +584,7 @@ fn can_sync_explicit_forks() { #[test] fn syncs_header_only_forks() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(0); net.add_full_peer_with_config(Default::default()); net.add_full_peer_with_config(FullPeerConfig { keep_blocks: Some(3), ..Default::default() }); @@ -602,7 +602,7 @@ fn syncs_header_only_forks() { #[test] fn does_not_sync_announced_old_best_block() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(3); let old_hash = net.peer(0).push_blocks(1, false); @@ -630,7 +630,7 @@ fn does_not_sync_announced_old_best_block() { #[test] fn full_sync_requires_block_body() { // Check that we don't sync headers-only in full mode. - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(2); net.peer(0).push_headers(1); @@ -649,7 +649,7 @@ fn full_sync_requires_block_body() { #[test] fn imports_stale_once() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); fn import_with_announce(net: &mut TestNet, hash: H256) { // Announce twice @@ -685,7 +685,7 @@ fn imports_stale_once() { #[test] fn can_sync_to_peers_with_wrong_common_block() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let mut net = TestNet::new(2); net.peer(0).push_blocks(2, true); @@ -727,7 +727,7 @@ impl BlockAnnounceValidator for NewBestBlockAnnounceValidator { #[test] fn sync_blocks_when_block_announce_validator_says_it_is_new_best() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); log::trace!(target: "sync", "Test"); let mut net = TestNet::with_fork_choice(ForkChoiceStrategy::Custom(false)); net.add_full_peer_with_config(Default::default()); diff --git a/client/offchain/src/api.rs b/client/offchain/src/api.rs index 5287ac8251eeb..4792cea5033f5 100644 --- a/client/offchain/src/api.rs +++ b/client/offchain/src/api.rs @@ -307,7 +307,7 @@ mod tests { } fn offchain_api() -> (Api, AsyncApi) { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let db = LocalStorage::new_test(); let mock = Arc::new(MockNetworkStateInfo()); let shared_client = SharedClient::new(); diff --git a/client/offchain/src/lib.rs b/client/offchain/src/lib.rs index 3b17c14f19652..482fafe723d2a 100644 --- a/client/offchain/src/lib.rs +++ b/client/offchain/src/lib.rs @@ -244,7 +244,7 @@ mod tests { #[test] fn should_call_into_runtime_and_produce_extrinsic() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let client = Arc::new(substrate_test_runtime_client::new()); let spawner = sp_core::testing::TaskExecutor::new(); diff --git a/client/service/test/src/client/mod.rs b/client/service/test/src/client/mod.rs index 8d073df272fd9..e45a7dd49e68b 100644 --- a/client/service/test/src/client/mod.rs +++ b/client/service/test/src/client/mod.rs @@ -1206,7 +1206,7 @@ fn get_header_by_block_number_doesnt_panic() { #[test] fn state_reverted_on_reorg() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let mut client = substrate_test_runtime_client::new(); let current_balance = |client: &substrate_test_runtime_client::TestClient| @@ -1266,7 +1266,7 @@ fn state_reverted_on_reorg() { #[test] fn doesnt_import_blocks_that_revert_finality() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let tmp = tempfile::tempdir().unwrap(); // we need to run with archive pruning to avoid pruning non-canonical @@ -1467,7 +1467,7 @@ fn respects_block_rules() { #[test] fn returns_status_for_pruned_blocks() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); let tmp = tempfile::tempdir().unwrap(); // set to prune after 1 block @@ -1801,4 +1801,3 @@ fn cleans_up_closed_notification_sinks_on_block_import() { assert_eq!(client.import_notification_sinks().lock().len(), 0); assert_eq!(client.finality_notification_sinks().lock().len(), 0); } - diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index 0d589cee7e12d..cfe815f174fac 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -289,7 +289,7 @@ impl TestNet where )>, base_port: u16 ) -> TestNet { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); fdlimit::raise_fd_limit(); let runtime = Runtime::new().expect("Error creating tokio runtime"); let mut net = TestNet { diff --git a/client/tracing/Cargo.toml b/client/tracing/Cargo.toml index 9b73343667f39..beccedc19bb9d 100644 --- a/client/tracing/Cargo.toml +++ b/client/tracing/Cargo.toml @@ -19,10 +19,7 @@ rustc-hash = "1.1.0" serde = "1.0.101" serde_json = "1.0.41" slog = { version = "2.5.2", features = ["nested-values"] } -tracing-core = "0.1.7" -tracing-subscriber = "0.2.10" +tracing = "0.1.10" + sp-tracing = { version = "2.0.0-rc2", path = "../../primitives/tracing" } sc-telemetry = { version = "2.0.0-rc5", path = "../telemetry" } - -[dev-dependencies] -tracing = "0.1.10" diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 0b6211de5f201..f0cfbd1c98ef4 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -30,7 +30,7 @@ use std::time::{Duration, Instant}; use parking_lot::Mutex; use serde::ser::{Serialize, Serializer, SerializeMap}; -use tracing_core::{ +use tracing::{ field::{Visit, Field}, Level, metadata::Metadata, @@ -385,6 +385,7 @@ impl TraceHandler for TelemetryTraceHandler { mod tests { use super::*; use std::sync::Arc; + use tracing_subscriber::layer::SubscriberExt; struct TestTraceHandler { spans: Arc>>, @@ -396,16 +397,17 @@ mod tests { } } - fn setup_subscriber() -> (ProfilingSubscriber, Arc>>) { + fn setup_subscriber() -> (tracing_subscriber::layer::Layered, Arc>>) { let spans = Arc::new(Mutex::new(Vec::new())); let handler = TestTraceHandler { spans: spans.clone(), }; - let test_subscriber = ProfilingSubscriber::new_with_handler( + let layer = ProfilingLayer::new_with_handler( Box::new(handler), "test_target" ); - (test_subscriber, spans) + let subscriber = tracing_subscriber::fmt().finish().with(layer); + (subscriber, spans) } #[test] diff --git a/frame/staking/src/mock.rs b/frame/staking/src/mock.rs index 84201827704e1..031062c6798db 100644 --- a/frame/staking/src/mock.rs +++ b/frame/staking/src/mock.rs @@ -451,7 +451,7 @@ impl ExtBuilder { MAX_ITERATIONS.with(|v| *v.borrow_mut() = self.max_offchain_iterations); } pub fn build(self) -> sp_io::TestExternalities { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); self.set_associated_constants(); let mut storage = frame_system::GenesisConfig::default() .build_storage::() diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index fc3d311298dde..36a464b57fd90 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -15,7 +15,9 @@ targets = ["x86_64-unknown-linux-gnu"] tracing = { version = "0.1.13", optional = true } rental = { version = "0.5.5", optional = true } log = { version = "0.4.8", optional = true } +tracing-subscriber = { version = "0.2.10", optional = true } +tracing-log = { version = "0.1.1", optional = true } [features] default = [ "std" ] -std = [ "tracing", "rental", "log" ] +std = [ "tracing", "rental", "log", "tracing-subscriber", "tracing-log" ] diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index e82d8861cd3f5..b8b8be070dcd5 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -44,6 +44,15 @@ pub mod proxy; #[cfg(feature = "std")] use std::sync::atomic::{AtomicBool, Ordering}; +#[cfg(feature = "std")] +/// Try to init a simple tracing subscriber with log compatibility layer. +/// Ignores any error. Useful for testing. +pub fn try_init_simple() { + let _ = tracing_log::LogTracer::init(); + let subscriber = tracing_subscriber::fmt().finish(); + let _ = tracing::subscriber::set_global_default(subscriber); +} + /// Flag to signal whether to run wasm tracing #[cfg(feature = "std")] static WASM_TRACING_ENABLED: AtomicBool = AtomicBool::new(false); @@ -114,4 +123,4 @@ pub fn wasm_tracing_enabled() -> bool { #[cfg(feature = "std")] pub fn set_wasm_tracing(b: bool) { WASM_TRACING_ENABLED.store(b, Ordering::Relaxed) -} \ No newline at end of file +} diff --git a/utils/frame/rpc/system/src/lib.rs b/utils/frame/rpc/system/src/lib.rs index 2bb46369fea54..cefe39534a167 100644 --- a/utils/frame/rpc/system/src/lib.rs +++ b/utils/frame/rpc/system/src/lib.rs @@ -294,7 +294,7 @@ mod tests { #[test] fn should_return_next_nonce_for_some_account() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); // given let client = Arc::new(substrate_test_runtime_client::new()); @@ -333,7 +333,7 @@ mod tests { #[test] fn dry_run_should_deny_unsafe() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); // given let client = Arc::new(substrate_test_runtime_client::new()); @@ -356,7 +356,7 @@ mod tests { #[test] fn dry_run_should_work() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); // given let client = Arc::new(substrate_test_runtime_client::new()); @@ -388,7 +388,7 @@ mod tests { #[test] fn dry_run_should_indicate_error() { - let _ = env_logger::try_init(); + sp_tracing::try_init_simple(); // given let client = Arc::new(substrate_test_runtime_client::new()); From 9c2f0e586ff286dc267138f425df7c9c1b3dd7ca Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Wed, 5 Aug 2020 16:03:10 +0200 Subject: [PATCH 06/29] Remove all local env_logger dependency --- Cargo.lock | 15 --------------- bin/node/rpc-client/Cargo.toml | 1 - client/authority-discovery/Cargo.toml | 1 - client/cli/Cargo.toml | 1 - client/consensus/aura/Cargo.toml | 1 - client/consensus/babe/Cargo.toml | 1 - client/consensus/manual-seal/Cargo.toml | 1 - client/db/Cargo.toml | 1 - client/finality-grandpa/Cargo.toml | 1 - client/network/Cargo.toml | 1 - client/network/test/Cargo.toml | 1 - client/offchain/Cargo.toml | 1 - client/service/test/Cargo.toml | 1 - client/state-db/Cargo.toml | 3 --- frame/staking/Cargo.toml | 1 - utils/frame/rpc/system/Cargo.toml | 1 - 16 files changed, 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 643982357060b..3227cf8ae92e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3753,7 +3753,6 @@ dependencies = [ name = "node-rpc-client" version = "2.0.0-rc5" dependencies = [ - "env_logger 0.7.1", "futures 0.1.29", "hyper 0.12.35", "jsonrpc-core-client", @@ -4780,7 +4779,6 @@ dependencies = [ name = "pallet-staking" version = "2.0.0-rc5" dependencies = [ - "env_logger 0.7.1", "frame-benchmarking", "frame-support", "frame-system", @@ -6126,7 +6124,6 @@ version = "0.8.0-rc5" dependencies = [ "bytes 0.5.4", "derive_more", - "env_logger 0.7.1", "futures 0.3.5", "futures-timer 3.0.2", "libp2p", @@ -6227,7 +6224,6 @@ dependencies = [ "atty", "chrono", "derive_more", - "env_logger 0.7.1", "fdlimit", "futures 0.3.5", "lazy_static", @@ -6306,7 +6302,6 @@ name = "sc-client-db" version = "0.8.0-rc5" dependencies = [ "blake2-rfc", - "env_logger 0.7.1", "hash-db", "kvdb 0.7.0", "kvdb-memorydb 0.7.0", @@ -6350,7 +6345,6 @@ name = "sc-consensus-aura" version = "0.8.0-rc5" dependencies = [ "derive_more", - "env_logger 0.7.1", "futures 0.3.5", "futures-timer 3.0.2", "log", @@ -6388,7 +6382,6 @@ name = "sc-consensus-babe" version = "0.8.0-rc5" dependencies = [ "derive_more", - "env_logger 0.7.1", "fork-tree", "futures 0.3.5", "futures-timer 3.0.2", @@ -6482,7 +6475,6 @@ version = "0.8.0-rc5" dependencies = [ "assert_matches", "derive_more", - "env_logger 0.7.1", "futures 0.3.5", "jsonrpc-core", "jsonrpc-core-client", @@ -6658,7 +6650,6 @@ version = "0.8.0-rc5" dependencies = [ "assert_matches", "derive_more", - "env_logger 0.7.1", "finality-grandpa", "fork-tree", "futures 0.3.5", @@ -6776,7 +6767,6 @@ dependencies = [ "bytes 0.5.4", "derive_more", "either", - "env_logger 0.7.1", "erased-serde", "fnv", "fork-tree", @@ -6847,7 +6837,6 @@ dependencies = [ name = "sc-network-test" version = "0.8.0-rc5" dependencies = [ - "env_logger 0.7.1", "futures 0.3.5", "futures-timer 3.0.2", "libp2p", @@ -6874,7 +6863,6 @@ name = "sc-offchain" version = "2.0.0-rc5" dependencies = [ "bytes 0.5.4", - "env_logger 0.7.1", "fnv", "futures 0.3.5", "futures-timer 3.0.2", @@ -7085,7 +7073,6 @@ dependencies = [ name = "sc-service-test" version = "2.0.0-rc5" dependencies = [ - "env_logger 0.7.1", "fdlimit", "futures 0.1.29", "futures 0.3.5", @@ -7121,7 +7108,6 @@ dependencies = [ name = "sc-state-db" version = "0.8.0-rc5" dependencies = [ - "env_logger 0.7.1", "log", "parity-scale-codec", "parity-util-mem 0.7.0", @@ -8534,7 +8520,6 @@ dependencies = [ name = "substrate-frame-rpc-system" version = "2.0.0-rc5" dependencies = [ - "env_logger 0.7.1", "frame-system-rpc-runtime-api", "futures 0.3.5", "jsonrpc-core", diff --git a/bin/node/rpc-client/Cargo.toml b/bin/node/rpc-client/Cargo.toml index d1a76f2ab3754..7f4540e2da121 100644 --- a/bin/node/rpc-client/Cargo.toml +++ b/bin/node/rpc-client/Cargo.toml @@ -11,7 +11,6 @@ repository = "https://github.com/paritytech/substrate/" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -env_logger = "0.7.0" futures = "0.1.29" hyper = "0.12.35" jsonrpc-core-client = { version = "14.2.0", default-features = false, features = ["http"] } diff --git a/client/authority-discovery/Cargo.toml b/client/authority-discovery/Cargo.toml index 2866fc141a203..d2eef2d03d086 100644 --- a/client/authority-discovery/Cargo.toml +++ b/client/authority-discovery/Cargo.toml @@ -37,7 +37,6 @@ sp-runtime = { version = "2.0.0-rc5", path = "../../primitives/runtime" } sp-api = { version = "2.0.0-rc5", path = "../../primitives/api" } [dev-dependencies] -env_logger = "0.7.0" quickcheck = "0.9.0" sc-peerset = { version = "2.0.0-rc5", path = "../peerset" } substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../test-utils/runtime/client"} diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index de0eeb99570c0..75bbafba4cb08 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -13,7 +13,6 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] derive_more = "0.99.2" -env_logger = "0.7.0" log = "0.4.8" atty = "0.2.13" regex = "1.3.4" diff --git a/client/consensus/aura/Cargo.toml b/client/consensus/aura/Cargo.toml index 6bf60335b7bd5..c0808679defbd 100644 --- a/client/consensus/aura/Cargo.toml +++ b/client/consensus/aura/Cargo.toml @@ -44,5 +44,4 @@ sc-network = { version = "0.8.0-rc5", path = "../../network" } sc-network-test = { version = "0.8.0-rc5", path = "../../network/test" } sc-service = { version = "0.8.0-rc5", default-features = false, path = "../../service" } substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../../test-utils/runtime/client" } -env_logger = "0.7.0" tempfile = "3.1.0" diff --git a/client/consensus/babe/Cargo.toml b/client/consensus/babe/Cargo.toml index 1b6b705139cf5..c954d195b0f00 100644 --- a/client/consensus/babe/Cargo.toml +++ b/client/consensus/babe/Cargo.toml @@ -59,7 +59,6 @@ sc-network-test = { version = "0.8.0-rc5", path = "../../network/test" } sc-service = { version = "0.8.0-rc5", default-features = false, path = "../../service" } substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../../test-utils/runtime/client" } sc-block-builder = { version = "0.8.0-rc5", path = "../../block-builder" } -env_logger = "0.7.0" rand_chacha = "0.2.2" tempfile = "3.1.0" diff --git a/client/consensus/manual-seal/Cargo.toml b/client/consensus/manual-seal/Cargo.toml index ab77f355bfade..54c89ff6ee60b 100644 --- a/client/consensus/manual-seal/Cargo.toml +++ b/client/consensus/manual-seal/Cargo.toml @@ -37,5 +37,4 @@ sc-basic-authorship = { path = "../../basic-authorship", version = "0.8.0-rc5" } substrate-test-runtime-client = { path = "../../../test-utils/runtime/client", version = "2.0.0-rc5" } substrate-test-runtime-transaction-pool = { path = "../../../test-utils/runtime/transaction-pool", version = "2.0.0-rc5" } tokio = { version = "0.2", features = ["rt-core", "macros"] } -env_logger = "0.7.0" tempfile = "3.1.0" diff --git a/client/db/Cargo.toml b/client/db/Cargo.toml index 50e14fcaae602..620aa5daf0316 100644 --- a/client/db/Cargo.toml +++ b/client/db/Cargo.toml @@ -40,7 +40,6 @@ prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0. [dev-dependencies] sp-keyring = { version = "2.0.0-rc5", path = "../../primitives/keyring" } substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../test-utils/runtime/client" } -env_logger = "0.7.0" quickcheck = "0.9" kvdb-rocksdb = "0.9" tempfile = "3" diff --git a/client/finality-grandpa/Cargo.toml b/client/finality-grandpa/Cargo.toml index 7b2e58b8be9a6..520ec537fbc4e 100644 --- a/client/finality-grandpa/Cargo.toml +++ b/client/finality-grandpa/Cargo.toml @@ -54,7 +54,6 @@ sp-keyring = { version = "2.0.0-rc5", path = "../../primitives/keyring" } substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../test-utils/runtime/client" } sp-consensus-babe = { version = "0.8.0-rc5", path = "../../primitives/consensus/babe" } sp-state-machine = { version = "0.8.0-rc5", path = "../../primitives/state-machine" } -env_logger = "0.7.0" tokio = { version = "0.2", features = ["rt-core"] } tempfile = "3.1.0" sp-api = { version = "2.0.0-rc5", path = "../../primitives/api" } diff --git a/client/network/Cargo.toml b/client/network/Cargo.toml index 11346fdd3ffc6..83a903548cd26 100644 --- a/client/network/Cargo.toml +++ b/client/network/Cargo.toml @@ -68,7 +68,6 @@ features = ["identify", "kad", "mdns", "mplex", "noise", "ping", "tcp-async-std" [dev-dependencies] async-std = "1.6.2" assert_matches = "1.3" -env_logger = "0.7.0" libp2p = { version = "0.22.0", default-features = false, features = ["secio"] } quickcheck = "0.9.0" rand = "0.7.2" diff --git a/client/network/test/Cargo.toml b/client/network/test/Cargo.toml index eb7788f541638..f72068495961e 100644 --- a/client/network/test/Cargo.toml +++ b/client/network/test/Cargo.toml @@ -28,7 +28,6 @@ sp-runtime = { version = "2.0.0-rc5", path = "../../../primitives/runtime" } sp-core = { version = "2.0.0-rc5", path = "../../../primitives/core" } sc-block-builder = { version = "0.8.0-rc5", path = "../../block-builder" } sp-consensus-babe = { version = "0.8.0-rc5", path = "../../../primitives/consensus/babe" } -env_logger = "0.7.0" substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../../test-utils/runtime/client" } substrate-test-runtime = { version = "2.0.0-rc5", path = "../../../test-utils/runtime" } tempfile = "3.1.0" diff --git a/client/offchain/Cargo.toml b/client/offchain/Cargo.toml index ef2b00daab4d3..d4be5ca97f4a5 100644 --- a/client/offchain/Cargo.toml +++ b/client/offchain/Cargo.toml @@ -36,7 +36,6 @@ hyper = "0.13.2" hyper-rustls = "0.21.0" [dev-dependencies] -env_logger = "0.7.0" sc-client-db = { version = "0.8.0-rc5", default-features = true, path = "../db/" } sc-transaction-pool = { version = "2.0.0-rc5", path = "../../client/transaction-pool" } sp-transaction-pool = { version = "2.0.0-rc5", path = "../../primitives/transaction-pool" } diff --git a/client/service/test/Cargo.toml b/client/service/test/Cargo.toml index d8f069eadfd72..dffa59650b646 100644 --- a/client/service/test/Cargo.toml +++ b/client/service/test/Cargo.toml @@ -17,7 +17,6 @@ tempfile = "3.1.0" tokio = "0.1.22" futures01 = { package = "futures", version = "0.1.29" } log = "0.4.8" -env_logger = "0.7.0" fdlimit = "0.1.4" parking_lot = "0.10.0" sc-light = { version = "2.0.0-rc5", path = "../../light" } diff --git a/client/state-db/Cargo.toml b/client/state-db/Cargo.toml index 685f68f083510..56ea35be4d946 100644 --- a/client/state-db/Cargo.toml +++ b/client/state-db/Cargo.toml @@ -19,6 +19,3 @@ sp-core = { version = "2.0.0-rc5", path = "../../primitives/core" } codec = { package = "parity-scale-codec", version = "1.3.4", features = ["derive"] } parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] } parity-util-mem-derive = "0.1.0" - -[dev-dependencies] -env_logger = "0.7.0" diff --git a/frame/staking/Cargo.toml b/frame/staking/Cargo.toml index f0bc0c0ac7ca6..06e111eeab486 100644 --- a/frame/staking/Cargo.toml +++ b/frame/staking/Cargo.toml @@ -40,7 +40,6 @@ substrate-test-utils = { version = "2.0.0-rc5", path = "../../test-utils" } frame-benchmarking = { version = "2.0.0-rc5", path = "../benchmarking" } rand_chacha = { version = "0.2" } parking_lot = "0.10.2" -env_logger = "0.7.1" hex = "0.4" [features] diff --git a/utils/frame/rpc/system/Cargo.toml b/utils/frame/rpc/system/Cargo.toml index 33a949fddd070..528615402dd8f 100644 --- a/utils/frame/rpc/system/Cargo.toml +++ b/utils/frame/rpc/system/Cargo.toml @@ -31,5 +31,4 @@ sc-rpc-api = { version = "0.8.0-rc5", path = "../../../../client/rpc-api" } [dev-dependencies] substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../../../test-utils/runtime/client" } -env_logger = "0.7.0" sc-transaction-pool = { version = "2.0.0-rc5", path = "../../../../client/transaction-pool" } From bd558482b1c3b150eef3cbaaff4008c9af8fd9cf Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Wed, 5 Aug 2020 16:15:17 +0200 Subject: [PATCH 07/29] Add missing tracing-subscriber dependency --- Cargo.lock | 1 + client/tracing/Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 3227cf8ae92e2..7f806dc42cb12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7151,6 +7151,7 @@ dependencies = [ "slog", "sp-tracing", "tracing", + "tracing-subscriber", ] [[package]] diff --git a/client/tracing/Cargo.toml b/client/tracing/Cargo.toml index beccedc19bb9d..34b8950da805b 100644 --- a/client/tracing/Cargo.toml +++ b/client/tracing/Cargo.toml @@ -20,6 +20,7 @@ serde = "1.0.101" serde_json = "1.0.41" slog = { version = "2.5.2", features = ["nested-values"] } tracing = "0.1.10" +tracing-subscriber = "0.2.10" sp-tracing = { version = "2.0.0-rc2", path = "../../primitives/tracing" } sc-telemetry = { version = "2.0.0-rc5", path = "../telemetry" } From 0d7761116bed0290d47c2b40474a9ba0a252e0be Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 6 Aug 2020 17:22:59 +0200 Subject: [PATCH 08/29] frame-sudo: fix tests --- frame/sudo/src/tests.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/frame/sudo/src/tests.rs b/frame/sudo/src/tests.rs index 79424d2824f90..cba1e1cf60540 100644 --- a/frame/sudo/src/tests.rs +++ b/frame/sudo/src/tests.rs @@ -18,9 +18,9 @@ //! Tests for the module. use super::*; -use mock::{ +use mock::{ Sudo, SudoCall, Origin, Call, Test, new_test_ext, LoggerCall, Logger, System, TestEvent, -}; +}; use frame_support::{assert_ok, assert_noop}; #[test] @@ -28,8 +28,8 @@ fn test_setup_works() { // Environment setup, logger storage, and sudo `key` retrieval should work as expected. new_test_ext(1).execute_with(|| { assert_eq!(Sudo::key(), 1u64); - assert_eq!(Logger::i32_log(), vec![]); - assert_eq!(Logger::account_log(), vec![]); + assert!(Logger::i32_log().is_empty()); + assert!(Logger::account_log().is_empty()); }); } @@ -40,8 +40,8 @@ fn sudo_basics() { // A privileged function should work when `sudo` is passed the root `key` as `origin`. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log(42, 1_000))); assert_ok!(Sudo::sudo(Origin::signed(1), call)); - assert_eq!(Logger::i32_log(), vec![42i32]); - + assert_eq!(Logger::i32_log(), vec![42i32]); + // A privileged function should not work when `sudo` is passed a non-root `key` as `origin`. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log(42, 1_000))); assert_noop!(Sudo::sudo(Origin::signed(2), call), Error::::RequireSudo); @@ -58,7 +58,7 @@ fn sudo_emits_events_correctly() { let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log(42, 1))); assert_ok!(Sudo::sudo(Origin::signed(1), call)); let expected_event = TestEvent::sudo(RawEvent::Sudid(Ok(()))); - assert!(System::events().iter().any(|a| a.event == expected_event)); + assert!(System::events().iter().any(|a| a.event == expected_event)); }) } @@ -68,16 +68,16 @@ fn sudo_unchecked_weight_basics() { // A privileged function should work when `sudo` is passed the root `key` as origin. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log(42, 1_000))); assert_ok!(Sudo::sudo_unchecked_weight(Origin::signed(1), call, 1_000)); - assert_eq!(Logger::i32_log(), vec![42i32]); + assert_eq!(Logger::i32_log(), vec![42i32]); // A privileged function should not work when called with a non-root `key`. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log(42, 1_000))); assert_noop!( - Sudo::sudo_unchecked_weight(Origin::signed(2), call, 1_000), + Sudo::sudo_unchecked_weight(Origin::signed(2), call, 1_000), Error::::RequireSudo, ); // `I32Log` is unchanged after unsuccessful call. - assert_eq!(Logger::i32_log(), vec![42i32]); + assert_eq!(Logger::i32_log(), vec![42i32]); // Controls the dispatched weight. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log(42, 1))); @@ -103,7 +103,7 @@ fn sudo_unchecked_weight_emits_events_correctly() { #[test] fn set_key_basics() { - new_test_ext(1).execute_with(|| { + new_test_ext(1).execute_with(|| { // A root `key` can change the root `key` assert_ok!(Sudo::set_key(Origin::signed(1), 2)); assert_eq!(Sudo::key(), 2u64); @@ -117,7 +117,7 @@ fn set_key_basics() { #[test] fn set_key_emits_events_correctly() { - new_test_ext(1).execute_with(|| { + new_test_ext(1).execute_with(|| { // Set block number to 1 because events are not emitted on block 0. System::set_block_number(1); @@ -138,8 +138,8 @@ fn sudo_as_basics() { // A privileged function will not work when passed to `sudo_as`. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log(42, 1_000))); assert_ok!(Sudo::sudo_as(Origin::signed(1), 2, call)); - assert_eq!(Logger::i32_log(), vec![]); - assert_eq!(Logger::account_log(), vec![]); + assert!(Logger::i32_log().is_empty()); + assert!(Logger::account_log().is_empty()); // A non-privileged function should not work when called with a non-root `key`. let call = Box::new(Call::Logger(LoggerCall::non_privileged_log(42, 1))); @@ -156,7 +156,7 @@ fn sudo_as_basics() { #[test] fn sudo_as_emits_events_correctly() { - new_test_ext(1).execute_with(|| { + new_test_ext(1).execute_with(|| { // Set block number to 1 because events are not emitted on block 0. System::set_block_number(1); From 4acd09f4ab752bb34b9cd0f67c983ecbd53fed1b Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 6 Aug 2020 17:26:19 +0200 Subject: [PATCH 09/29] frame-support: fix tests --- frame/support/src/storage/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/support/src/storage/mod.rs b/frame/support/src/storage/mod.rs index 347fd814136d7..228a595842df2 100644 --- a/frame/support/src/storage/mod.rs +++ b/frame/support/src/storage/mod.rs @@ -634,7 +634,7 @@ mod test { assert_eq!(MyStorage::final_prefix().to_vec(), k); // test iteration - assert_eq!(MyStorage::iter_values().collect::>(), vec![]); + assert!(MyStorage::iter_values().collect::>().is_empty()); unhashed::put(&[&k[..], &vec![1][..]].concat(), &1u64); unhashed::put(&[&k[..], &vec![1, 1][..]].concat(), &2u64); @@ -645,13 +645,13 @@ mod test { // test removal MyStorage::remove_all(); - assert_eq!(MyStorage::iter_values().collect::>(), vec![]); + assert!(MyStorage::iter_values().collect::>().is_empty()); // test migration unhashed::put(&[&k[..], &vec![1][..]].concat(), &1u32); unhashed::put(&[&k[..], &vec![8][..]].concat(), &2u32); - assert_eq!(MyStorage::iter_values().collect::>(), vec![]); + assert!(MyStorage::iter_values().collect::>().is_empty()); MyStorage::translate_values(|v: u32| v as u64).unwrap(); assert_eq!(MyStorage::iter_values().collect::>(), vec![1, 2]); MyStorage::remove_all(); From 3af13c6540f0353df063dc2fad17e5607583d3d5 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 6 Aug 2020 18:14:52 +0200 Subject: [PATCH 10/29] Fix frame/pallet and executor tests --- Cargo.lock | 220 ++++++++++++++++--- bin/node/rpc-client/Cargo.toml | 1 + client/executor/Cargo.toml | 1 + client/executor/src/integration_tests/mod.rs | 8 +- client/network/test/Cargo.toml | 5 +- client/service/test/Cargo.toml | 1 + frame/elections-phragmen/src/lib.rs | 76 +++---- frame/elections/src/tests.rs | 14 +- frame/example/src/lib.rs | 2 +- frame/scored-pool/src/tests.rs | 2 +- frame/staking/Cargo.toml | 1 + frame/staking/src/tests.rs | 4 +- frame/support/test/tests/decl_storage.rs | 10 +- 13 files changed, 262 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f806dc42cb12..d83bca13577f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,7 +83,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" dependencies = [ "block-cipher-trait", - "byteorder", + "byteorder 1.3.4", "opaque-debug 0.2.3", ] @@ -94,7 +94,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4925647ee64e5056cf231608957ce7c81e12d6d6e316b9ce1404778cc1d35fa7" dependencies = [ "block-cipher", - "byteorder", + "byteorder 1.3.4", "opaque-debug 0.2.3", ] @@ -300,6 +300,17 @@ dependencies = [ "webpki-roots 0.19.0", ] +[[package]] +name = "async-trait" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a265e3abeffdce30b2e26b7a11b222fe37c6067404001b434101457d0385eb92" +dependencies = [ + "proc-macro2", + "quote 1.0.6", + "syn 1.0.33", +] + [[package]] name = "atty" version = "0.2.14" @@ -361,7 +372,7 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5753e2a71534719bf3f4e57006c3a4f0d2c672a4b676eec84161f763eca87dbf" dependencies = [ - "byteorder", + "byteorder 1.3.4", "serde", ] @@ -418,7 +429,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84ce5b6108f8e154604bd4eb76a2f726066c3464d5a552a4229262a18c9bb471" dependencies = [ "byte-tools", - "byteorder", + "byteorder 1.3.4", "crypto-mac 0.8.0", "digest 0.9.0", "opaque-debug 0.2.3", @@ -464,7 +475,7 @@ checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" dependencies = [ "block-padding", "byte-tools", - "byteorder", + "byteorder 1.3.4", "generic-array 0.12.3", ] @@ -562,6 +573,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" +[[package]] +name = "byteorder" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" + [[package]] name = "byteorder" version = "1.3.4" @@ -574,7 +591,7 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" dependencies = [ - "byteorder", + "byteorder 1.3.4", "either", "iovec", ] @@ -827,7 +844,7 @@ version = "0.66.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d9badfe36176cb653506091693bc2bb1970c9bddfcd6ec7fac404f7eaec6f38" dependencies = [ - "byteorder", + "byteorder 1.3.4", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", @@ -971,7 +988,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76f9212ddf2f4a9eb2d401635190600656a1f88a932ef53d06e7fa4c7e02fb8e" dependencies = [ - "byteorder", + "byteorder 1.3.4", "cast", "itertools 0.8.2", ] @@ -1110,13 +1127,23 @@ dependencies = [ "stream-cipher 0.3.2", ] +[[package]] +name = "cuckoofilter" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dd43f7cfaffe0a386636a10baea2ee05cc50df3b77bea4a456c9572a939bf1f" +dependencies = [ + "byteorder 0.5.3", + "rand 0.3.23", +] + [[package]] name = "curve25519-dalek" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26778518a7f6cffa1d25a44b602b62b979bd88adb9e99ffec546998cf3404839" dependencies = [ - "byteorder", + "byteorder 1.3.4", "digest 0.8.1", "rand_core 0.5.1", "subtle 2.2.2", @@ -1192,7 +1219,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4d33be9473d06f75f58220f71f7a9317aca647dc061dbd3c361b0bef505fbea" dependencies = [ - "byteorder", + "byteorder 1.3.4", "quick-error", ] @@ -1514,7 +1541,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32529fc42e86ec06e5047092082aab9ad459b070c5d2a76b14f4f5ce70bf2e84" dependencies = [ - "byteorder", + "byteorder 1.3.4", "rand 0.7.3", "rustc-hex", "static_assertions", @@ -2094,7 +2121,7 @@ version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" dependencies = [ - "byteorder", + "byteorder 1.3.4", "bytes 0.4.12", "fnv", "futures 0.1.29", @@ -2823,16 +2850,23 @@ dependencies = [ "lazy_static", "libp2p-core", "libp2p-core-derive", + "libp2p-deflate", "libp2p-dns", + "libp2p-floodsub", + "libp2p-gossipsub", "libp2p-identify", "libp2p-kad", "libp2p-mdns", "libp2p-mplex", "libp2p-noise", "libp2p-ping", + "libp2p-plaintext", + "libp2p-pnet", + "libp2p-request-response", "libp2p-secio", "libp2p-swarm", "libp2p-tcp", + "libp2p-uds", "libp2p-wasm-ext", "libp2p-websocket", "libp2p-yamux", @@ -2888,6 +2922,17 @@ dependencies = [ "syn 1.0.33", ] +[[package]] +name = "libp2p-deflate" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abeff37fa533fead23fc71b14ed0a2aced36c0c65c3d0078aff07821fb71029e" +dependencies = [ + "flate2", + "futures 0.3.5", + "libp2p-core", +] + [[package]] name = "libp2p-dns" version = "0.20.0" @@ -2899,6 +2944,48 @@ dependencies = [ "log", ] +[[package]] +name = "libp2p-floodsub" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d4f310a02441b681075037ffb41649ee8836619559311b801ef3d5cdbe14cf" +dependencies = [ + "cuckoofilter", + "fnv", + "futures 0.3.5", + "libp2p-core", + "libp2p-swarm", + "prost", + "prost-build", + "rand 0.7.3", + "smallvec 1.4.1", +] + +[[package]] +name = "libp2p-gossipsub" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a70f76b6c53ae9c97c234498c799802e43f91766bcf4a2a1f94f9339617d713b" +dependencies = [ + "base64 0.11.0", + "byteorder 1.3.4", + "bytes 0.5.4", + "fnv", + "futures 0.3.5", + "futures_codec", + "libp2p-core", + "libp2p-swarm", + "log", + "lru 0.4.3", + "prost", + "prost-build", + "rand 0.7.3", + "sha2 0.8.1", + "smallvec 1.4.1", + "unsigned-varint 0.4.0", + "wasm-timer", +] + [[package]] name = "libp2p-identify" version = "0.20.0" @@ -3017,6 +3104,52 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-plaintext" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53f0308a97f6fdd37a2bc388070e471c3ce9d92aa45c99d75c87c2dc5d5cac96" +dependencies = [ + "bytes 0.5.4", + "futures 0.3.5", + "futures_codec", + "libp2p-core", + "log", + "prost", + "prost-build", + "rw-stream-sink", + "unsigned-varint 0.4.0", + "void", +] + +[[package]] +name = "libp2p-pnet" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d0db10e139d22d7af0b23ed7949449ec86262798aa0fd01595abdbcb02dc87" +dependencies = [ + "futures 0.3.5", + "log", + "pin-project", + "rand 0.7.3", + "salsa20", + "sha3", +] + +[[package]] +name = "libp2p-request-response" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f48682b48a96545a323edd150c1d64fc1e250240bba02866e9f902e3dc032a9" +dependencies = [ + "async-trait", + "futures 0.3.5", + "libp2p-core", + "libp2p-swarm", + "smallvec 1.4.1", + "wasm-timer", +] + [[package]] name = "libp2p-secio" version = "0.20.0" @@ -3078,6 +3211,18 @@ dependencies = [ "socket2", ] +[[package]] +name = "libp2p-uds" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9db9fce9e3588c3118475d9ca761c5c133b639a624a7341e2a61e4b28c376b8" +dependencies = [ + "async-std", + "futures 0.3.5", + "libp2p-core", + "log", +] + [[package]] name = "libp2p-wasm-ext" version = "0.20.1" @@ -3323,7 +3468,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6feca46f4fa3443a01769d768727f10c10a20fdb65e52dc16a81f0c8269bb78" dependencies = [ - "byteorder", + "byteorder 1.3.4", "keccak", "rand_core 0.5.1", "zeroize", @@ -3508,7 +3653,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29449d242064c48d3057a194b049a2bdcccadda16faa18a91468677b44e8d422" dependencies = [ "bitflags", - "byteorder", + "byteorder 1.3.4", "enum-primitive-derive", "libc", "num-traits 0.2.11", @@ -3759,6 +3904,7 @@ dependencies = [ "log", "node-primitives", "sc-rpc", + "sp-tracing", ] [[package]] @@ -4800,6 +4946,7 @@ dependencies = [ "sp-staking", "sp-std", "sp-storage", + "sp-tracing", "static_assertions", "substrate-test-utils", ] @@ -5002,7 +5149,7 @@ checksum = "cc20af3143a62c16e7c9e92ea5c6ae49f7d271d97d4d8fe73afc28f0514a3d0f" dependencies = [ "arrayref", "bs58", - "byteorder", + "byteorder 1.3.4", "data-encoding", "multihash", "percent-encoding 2.1.0", @@ -5110,7 +5257,7 @@ version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16ad52817c4d343339b3bc2e26861bd21478eda0b7509acf83505727000512ac" dependencies = [ - "byteorder", + "byteorder 1.3.4", ] [[package]] @@ -5203,7 +5350,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9" dependencies = [ - "byteorder", + "byteorder 1.3.4", "crypto-mac 0.7.0", ] @@ -5436,7 +5583,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe50036aa1b71e553a4a0c48ab7baabf8aa8c7a5a61aae06bf38c2eab7430475" dependencies = [ "bitflags", - "byteorder", + "byteorder 1.3.4", "chrono", "hex", "lazy_static", @@ -5514,7 +5661,7 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f7a12f176deee919f4ba55326ee17491c8b707d0987aed822682c821b660192" dependencies = [ - "byteorder", + "byteorder 1.3.4", "log", "parity-wasm 0.41.0", ] @@ -5769,7 +5916,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03b418169fb9c46533f326efd6eed2576699c44ca92d3052a066214a8d828929" dependencies = [ - "byteorder", + "byteorder 1.3.4", "rand_core 0.3.1", ] @@ -5889,7 +6036,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" dependencies = [ - "byteorder", + "byteorder 1.3.4", "regex-syntax", ] @@ -6109,6 +6256,26 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "salsa20" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2324b0e8c3bb9a586a571fdb3136f70e7e2c748de00a78043f86e0cff91f91fe" +dependencies = [ + "byteorder 1.3.4", + "salsa20-core", + "stream-cipher 0.3.2", +] + +[[package]] +name = "salsa20-core" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fe6cc1b9f5a5867853ade63099de70f042f7679e408d1ffe52821c9248e6e69" +dependencies = [ + "stream-cipher 0.3.2", +] + [[package]] name = "same-file" version = "1.0.6" @@ -6589,6 +6756,7 @@ dependencies = [ "substrate-test-runtime", "test-case", "tracing", + "tracing-subscriber", "wabt", "wasmi", ] @@ -6853,6 +7021,7 @@ dependencies = [ "sp-consensus-babe", "sp-core", "sp-runtime", + "sp-tracing", "substrate-test-runtime", "substrate-test-runtime-client", "tempfile", @@ -7096,6 +7265,7 @@ dependencies = [ "sp-runtime", "sp-state-machine", "sp-storage", + "sp-tracing", "sp-transaction-pool", "sp-trie", "substrate-test-runtime", @@ -7853,7 +8023,7 @@ version = "2.0.0-rc5" dependencies = [ "base58", "blake2-rfc", - "byteorder", + "byteorder 1.3.4", "criterion 0.2.11", "derive_more", "dyn-clonable", @@ -9401,7 +9571,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712d261e83e727c8e2dbb75dacac67c36e35db36a958ee504f2164fc052434e1" dependencies = [ "block-cipher-trait", - "byteorder", + "byteorder 1.3.4", "opaque-debug 0.2.3", ] @@ -9426,7 +9596,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e75a4cdd7b87b28840dba13c483b9a88ee6bbf16ba5c951ee1ecfcf723078e0d" dependencies = [ - "byteorder", + "byteorder 1.3.4", "crunchy", "rustc-hex", "static_assertions", @@ -10047,7 +10217,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c51a2c47b5798ccc774ffb93ff536aec7c4275d722fd9c740c83cdd1af1f2d94" dependencies = [ - "byteorder", + "byteorder 1.3.4", "bytes 0.4.12", "httparse", "log", diff --git a/bin/node/rpc-client/Cargo.toml b/bin/node/rpc-client/Cargo.toml index 7f4540e2da121..0c9bd1cbc51be 100644 --- a/bin/node/rpc-client/Cargo.toml +++ b/bin/node/rpc-client/Cargo.toml @@ -16,4 +16,5 @@ hyper = "0.12.35" jsonrpc-core-client = { version = "14.2.0", default-features = false, features = ["http"] } log = "0.4.8" node-primitives = { version = "2.0.0-rc5", path = "../primitives" } +sp-tracing = { version = "2.0.0-rc5", path = "../../../primitives/tracing" } sc-rpc = { version = "2.0.0-rc5", path = "../../../client/rpc" } diff --git a/client/executor/Cargo.toml b/client/executor/Cargo.toml index 2a6844c31f323..c1e2461d4a4cc 100644 --- a/client/executor/Cargo.toml +++ b/client/executor/Cargo.toml @@ -47,6 +47,7 @@ sp-runtime = { version = "2.0.0-rc5", path = "../../primitives/runtime" } sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } sc-tracing = { version = "2.0.0-rc5", path = "../tracing" } tracing = "0.1.14" +tracing-subscriber = "0.2.10" [features] default = [ "std" ] diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 5276884e92319..470718d13ce4e 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -30,6 +30,7 @@ use test_case::test_case; use sp_trie::{TrieConfiguration, trie_types::Layout}; use sp_wasm_interface::HostFunctions as _; use sp_runtime::traits::BlakeTwo256; +use tracing_subscriber::layer::SubscriberExt; use crate::WasmExecutionMethod; @@ -675,8 +676,11 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) { let handler = TestTraceHandler(traces.clone()); // Create subscriber with wasm_tracing disabled - let test_subscriber = sc_tracing::ProfilingSubscriber::new_with_handler( - Box::new(handler), "integration_test_span_target"); + let test_subscriber = tracing_subscriber::fmt().finish().with( + sc_tracing::ProfilingLayer::new_with_handler( + Box::new(handler), "integration_test_span_target" + ) + ); let _guard = tracing::subscriber::set_default(test_subscriber); diff --git a/client/network/test/Cargo.toml b/client/network/test/Cargo.toml index f72068495961e..81bcfed35151e 100644 --- a/client/network/test/Cargo.toml +++ b/client/network/test/Cargo.toml @@ -19,7 +19,7 @@ parking_lot = "0.10.0" futures = "0.3.4" futures-timer = "3.0.1" rand = "0.7.2" -libp2p = { version = "0.22.0", default-features = false } +libp2p = "0.22.0" sp-consensus = { version = "0.8.0-rc5", path = "../../../primitives/consensus/common" } sc-consensus = { version = "0.8.0-rc5", path = "../../../client/consensus/common" } sc-client-api = { version = "2.0.0-rc5", path = "../../api" } @@ -31,4 +31,5 @@ sp-consensus-babe = { version = "0.8.0-rc5", path = "../../../primitives/consens substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../../test-utils/runtime/client" } substrate-test-runtime = { version = "2.0.0-rc5", path = "../../../test-utils/runtime" } tempfile = "3.1.0" -sc-service = { version = "0.8.0-rc5", default-features = false, features = ["test-helpers"], path = "../../service" } +sp-tracing = { version = "2.0.0-rc5", path = "../../../primitives/tracing" } +sc-service = { version = "0.8.0-rc5", features = ["test-helpers"], path = "../../service" } diff --git a/client/service/test/Cargo.toml b/client/service/test/Cargo.toml index dffa59650b646..ffa066e7a842e 100644 --- a/client/service/test/Cargo.toml +++ b/client/service/test/Cargo.toml @@ -41,3 +41,4 @@ sc-block-builder = { version = "0.8.0-rc5", path = "../../block-builder" } sc-executor = { version = "0.8.0-rc5", path = "../../executor" } sp-panic-handler = { version = "2.0.0-rc5", path = "../../../primitives/panic-handler" } parity-scale-codec = "1.3.4" +sp-tracing = { version = "2.0.0-rc5", path = "../../../primitives/tracing" } diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 50c5de9bc0de4..f9c91bc403ed7 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -1382,7 +1382,7 @@ mod tests { assert!( Elections::members().iter().chain( Elections::runners_up().iter() - ).all(|(_, s)| *s != Zero::zero()) + ).all(|(_, s)| *s != u64::zero()) ); } @@ -1437,15 +1437,15 @@ mod tests { assert_eq!(Elections::term_duration(), 5); assert_eq!(Elections::election_rounds(), 0); - assert_eq!(Elections::members(), vec![]); - assert_eq!(Elections::runners_up(), vec![]); + assert!(Elections::members().is_empty()); + assert!(Elections::runners_up().is_empty()); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); assert_eq!(>::decode_len(), None); assert!(Elections::is_candidate(&1).is_err()); - assert_eq!(all_voters(), vec![]); - assert_eq!(votes_of(&1), vec![]); + assert!(all_voters().is_empty()); + assert!(votes_of(&1).is_empty()); }); } @@ -1520,16 +1520,16 @@ mod tests { assert_eq!(Elections::desired_members(), 2); assert_eq!(Elections::election_rounds(), 0); - assert_eq!(Elections::members_ids(), vec![]); - assert_eq!(Elections::runners_up(), vec![]); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::members_ids().is_empty()); + assert!(Elections::runners_up().is_empty()); + assert!(Elections::candidates().is_empty()); System::set_block_number(5); Elections::end_block(System::block_number()); - assert_eq!(Elections::members_ids(), vec![]); - assert_eq!(Elections::runners_up(), vec![]); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::members_ids().is_empty()); + assert!(Elections::runners_up().is_empty()); + assert!(Elections::candidates().is_empty()); }); } @@ -1572,18 +1572,18 @@ mod tests { assert!(Elections::is_candidate(&2).is_ok()); assert_eq!(Elections::candidates(), vec![1, 2]); - assert_eq!(Elections::members_ids(), vec![]); - assert_eq!(Elections::runners_up(), vec![]); + assert!(Elections::members_ids().is_empty()); + assert!(Elections::runners_up().is_empty()); System::set_block_number(5); Elections::end_block(System::block_number()); assert!(Elections::is_candidate(&1).is_err()); assert!(Elections::is_candidate(&2).is_err()); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); - assert_eq!(Elections::members_ids(), vec![]); - assert_eq!(Elections::runners_up(), vec![]); + assert!(Elections::members_ids().is_empty()); + assert!(Elections::runners_up().is_empty()); }); } @@ -1611,8 +1611,8 @@ mod tests { Elections::end_block(System::block_number()); assert_eq!(Elections::members_ids(), vec![5]); - assert_eq!(Elections::runners_up(), vec![]); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::runners_up().is_empty()); + assert!(Elections::candidates().is_empty()); assert_noop!( submit_candidacy(Origin::signed(5)), @@ -1726,7 +1726,7 @@ mod tests { Elections::end_block(System::block_number()); assert_eq!(Elections::members_ids(), vec![4, 5]); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); assert_ok!(vote(Origin::signed(3), vec![4, 5], 10)); }); @@ -1749,7 +1749,7 @@ mod tests { Elections::end_block(System::block_number()); assert_eq!(Elections::members_ids(), vec![4, 5]); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); assert_ok!(vote(Origin::signed(3), vec![4, 5], 10)); assert_eq!(PRIME.with(|p| *p.borrow()), Some(4)); @@ -1775,7 +1775,7 @@ mod tests { Elections::end_block(System::block_number()); assert_eq!(Elections::members_ids(), vec![3, 5]); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); assert_eq!(PRIME.with(|p| *p.borrow()), Some(5)); }); @@ -1860,7 +1860,7 @@ mod tests { assert_ok!(Elections::remove_voter(Origin::signed(2))); assert_eq_uvec!(all_voters(), vec![3]); - assert_eq!(votes_of(&2), vec![]); + assert!(votes_of(&2).is_empty()); assert_eq!(Elections::locked_stake_of(&2), 0); assert_eq!(balances(&2), (20, 0)); @@ -1882,7 +1882,7 @@ mod tests { assert_ok!(vote(Origin::signed(2), vec![5], 20)); assert_ok!(Elections::remove_voter(Origin::signed(2))); - assert_eq!(all_voters(), vec![]); + assert!(all_voters().is_empty()); assert_noop!(Elections::remove_voter(Origin::signed(2)), Error::::MustBeVoter); }); @@ -1992,7 +1992,7 @@ mod tests { assert_eq!(Elections::members_ids(), vec![4, 5]); assert_eq!(Elections::runners_up_ids(), vec![6]); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); // all of them have a member or runner-up that they voted for. assert_eq!(Elections::is_defunct_voter(&votes_of(&5)), false); @@ -2028,7 +2028,7 @@ mod tests { Elections::end_block(System::block_number()); assert_eq!(Elections::members_ids(), vec![4, 5]); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); assert_eq!(balances(&3), (28, 2)); assert_eq!(balances(&5), (45, 5)); @@ -2056,7 +2056,7 @@ mod tests { Elections::end_block(System::block_number()); assert_eq!(Elections::members_ids(), vec![4, 5]); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); assert_eq!(balances(&4), (35, 5)); assert_eq!(balances(&5), (45, 5)); @@ -2097,9 +2097,9 @@ mod tests { Elections::end_block(System::block_number()); assert_eq!(Elections::members(), vec![(3, 30), (5, 20)]); - assert_eq!(Elections::runners_up(), vec![]); + assert!(Elections::runners_up().is_empty()); assert_eq_uvec!(all_voters(), vec![2, 3, 4]); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); assert_eq!(>::decode_len(), None); assert_eq!(Elections::election_rounds(), 1); @@ -2164,9 +2164,9 @@ mod tests { System::set_block_number(5); Elections::end_block(System::block_number()); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); assert_eq!(Elections::election_rounds(), 1); - assert_eq!(Elections::members_ids(), vec![]); + assert!(Elections::members_ids().is_empty()); assert_eq!( System::events().iter().last().unwrap().event, @@ -2277,7 +2277,7 @@ mod tests { System::set_block_number(10); Elections::end_block(System::block_number()); - assert_eq!(Elections::members_ids(), vec![]); + assert!(Elections::members_ids().is_empty()); assert_eq!(balances(&5), (47, 0)); }); @@ -2362,7 +2362,7 @@ mod tests { assert_eq!(Elections::members(), vec![(4, 40), (5, 50)]); assert_eq!(Elections::runners_up(), vec![(2, 20), (3, 30)]); // no new candidates but old members and runners-up are always added. - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); assert_eq!(Elections::election_rounds(), b / 5); assert_eq_uvec!(all_voters(), vec![2, 3, 4, 5]); }; @@ -2474,7 +2474,7 @@ mod tests { // meanwhile, no one cares to become a candidate again. System::set_block_number(10); Elections::end_block(System::block_number()); - assert_eq!(Elections::members_ids(), vec![]); + assert!(Elections::members_ids().is_empty()); assert_eq!(Elections::election_rounds(), 2); }); } @@ -2642,14 +2642,14 @@ mod tests { Elections::end_block(System::block_number()); assert_eq!(Elections::members_ids(), vec![4, 5]); - assert_eq!(Elections::runners_up_ids(), vec![]); + assert!(Elections::runners_up_ids().is_empty()); assert_ok!(Elections::renounce_candidacy(Origin::signed(4), Renouncing::Member)); assert_eq!(balances(&4), (38, 2)); // 2 is voting bond. // no replacement assert_eq!(Elections::members_ids(), vec![5]); - assert_eq!(Elections::runners_up_ids(), vec![]); + assert!(Elections::runners_up_ids().is_empty()); }) } @@ -2713,7 +2713,7 @@ mod tests { assert_ok!(Elections::renounce_candidacy(Origin::signed(5), Renouncing::Candidate(1))); assert_eq!(balances(&5), (50, 0)); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); }) } @@ -2825,7 +2825,7 @@ mod tests { assert_eq!(Elections::members_ids(), vec![1, 4]); assert_eq!(Elections::runners_up_ids(), vec![2, 3]); - assert_eq!(Elections::candidates(), vec![]); + assert!(Elections::candidates().is_empty()); }) } } diff --git a/frame/elections/src/tests.rs b/frame/elections/src/tests.rs index 247b6272524b1..92f6e11252b05 100644 --- a/frame/elections/src/tests.rs +++ b/frame/elections/src/tests.rs @@ -46,14 +46,14 @@ fn params_should_work() { assert_eq!(Elections::voters(0), Vec::>::new()); assert_eq!(Elections::voter_info(1), None); - assert_eq!(Elections::all_approvals_of(&1), vec![]); + assert!(Elections::all_approvals_of(&1).is_empty()); }); } #[test] fn chunking_bool_to_flag_should_work() { ExtBuilder::default().build().execute_with(|| { - assert_eq!(Elections::bool_to_flag(vec![]), vec![]); + assert!(Elections::bool_to_flag(vec![]).is_empty()); assert_eq!(Elections::bool_to_flag(vec![false]), vec![0]); assert_eq!(Elections::bool_to_flag(vec![true]), vec![1]); assert_eq!(Elections::bool_to_flag(vec![true, true, true, true]), vec![15]); @@ -274,11 +274,11 @@ fn chunking_approval_storage_should_work() { assert_eq!(Elections::all_approvals_of(&2), vec![true]); // NOTE: these two are stored in mem differently though. - assert_eq!(Elections::all_approvals_of(&3), vec![]); - assert_eq!(Elections::all_approvals_of(&4), vec![]); + assert!(Elections::all_approvals_of(&3).is_empty()); + assert!(Elections::all_approvals_of(&4).is_empty()); assert_eq!(Elections::approvals_of((3, 0)), vec![0]); - assert_eq!(Elections::approvals_of((4, 0)), vec![]); + assert!(Elections::approvals_of((4, 0)).is_empty()); }); } @@ -385,7 +385,7 @@ fn voting_locking_stake_and_reserving_bond_works() { assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0)); assert_eq!(balances(&2), (20, 0)); - assert_eq!(locks(&2), vec![]); + assert!(locks(&2).is_empty()); assert_ok!(Elections::set_approvals(Origin::signed(2), vec![], 0, 0, 15)); assert_eq!(balances(&2), (18, 2)); assert_eq!(locks(&2), vec![15]); @@ -401,7 +401,7 @@ fn voting_locking_stake_and_reserving_bond_works() { assert_ok!(Elections::retract_voter(Origin::signed(2), 0)); assert_eq!(balances(&2), (102, 0)); - assert_eq!(locks(&2), vec![]); + assert!(locks(&2).is_empty()); }); } diff --git a/frame/example/src/lib.rs b/frame/example/src/lib.rs index b41c8196c018f..02d15a2c0ca2c 100644 --- a/frame/example/src/lib.rs +++ b/frame/example/src/lib.rs @@ -842,7 +842,7 @@ mod tests { WatchDummy::(PhantomData).validate(&1, &call, &info, 150) .unwrap() .priority, - Bounded::max_value(), + u64::max_value(), ); assert_eq!( WatchDummy::(PhantomData).validate(&1, &call, &info, 250), diff --git a/frame/scored-pool/src/tests.rs b/frame/scored-pool/src/tests.rs index 9c0074ff6e689..44b71bc00ba47 100644 --- a/frame/scored-pool/src/tests.rs +++ b/frame/scored-pool/src/tests.rs @@ -153,7 +153,7 @@ fn unscored_entities_must_not_be_used_for_filling_members() { // then // the `None` candidates should not have been filled in - assert_eq!(ScoredPool::members(), vec![]); + assert!(ScoredPool::members().is_empty()); assert_eq!(MEMBERS.with(|m| m.borrow().clone()), ScoredPool::members()); }); } diff --git a/frame/staking/Cargo.toml b/frame/staking/Cargo.toml index 06e111eeab486..74468cf4497af 100644 --- a/frame/staking/Cargo.toml +++ b/frame/staking/Cargo.toml @@ -33,6 +33,7 @@ rand_chacha = { version = "0.2", default-features = false, optional = true } [dev-dependencies] sp-core = { version = "2.0.0-rc5", path = "../../primitives/core" } sp-storage = { version = "2.0.0-rc5", path = "../../primitives/storage" } +sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } pallet-balances = { version = "2.0.0-rc5", path = "../balances" } pallet-timestamp = { version = "2.0.0-rc5", path = "../timestamp" } pallet-staking-reward-curve = { version = "2.0.0-rc5", path = "../staking/reward-curve" } diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index e5015cbdc9283..55b70391aff55 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -1734,7 +1734,7 @@ fn bond_with_duplicate_vote_should_be_ignored_by_npos_election() { .collect::>(), vec![(31, 1000), (21, 1000), (11, 1000)], ); - assert_eq!(>::iter().map(|(n, _)| n).collect::>(), vec![]); + assert!(>::iter().map(|(n, _)| n).collect::>().is_empty()); // give the man some money let initial_balance = 1000; @@ -1782,7 +1782,7 @@ fn bond_with_duplicate_vote_should_be_ignored_by_npos_election_elected() { .collect::>(), vec![(31, 100), (21, 1000), (11, 1000)], ); - assert_eq!(>::iter().map(|(n, _)| n).collect::>(), vec![]); + assert!(>::iter().map(|(n, _)| n).collect::>().is_empty()); // give the man some money let initial_balance = 1000; diff --git a/frame/support/test/tests/decl_storage.rs b/frame/support/test/tests/decl_storage.rs index cda1d810d225c..944976330f956 100644 --- a/frame/support/test/tests/decl_storage.rs +++ b/frame/support/test/tests/decl_storage.rs @@ -520,7 +520,7 @@ mod test_append_and_len { fn default_for_option() { TestExternalities::default().execute_with(|| { assert_eq!(OptionVec::get(), None); - assert_eq!(JustVec::get(), vec![]); + assert!(JustVec::get().is_empty()); }); } @@ -553,7 +553,7 @@ mod test_append_and_len { let key = JustVec::hashed_key(); // Set it to some invalid value. frame_support::storage::unhashed::put_raw(&key, &*b"1"); - assert_eq!(JustVec::get(), Vec::new()); + assert!(JustVec::get().is_empty()); assert_eq!(frame_support::storage::unhashed::get_raw(&key), Some(b"1".to_vec())); JustVec::append(1); @@ -600,7 +600,7 @@ mod test_append_and_len { fn len_works_ignores_default_assignment() { TestExternalities::default().execute_with(|| { // vec - assert_eq!(JustVec::get(), vec![]); + assert!(JustVec::get().is_empty()); assert_eq!(JustVec::decode_len(), None); assert_eq!(JustVecWithDefault::get(), vec![6, 9]); @@ -610,7 +610,7 @@ mod test_append_and_len { assert_eq!(OptionVec::decode_len(), None); // map - assert_eq!(MapVec::get(0), vec![]); + assert!(MapVec::get(0).is_empty()); assert_eq!(MapVec::decode_len(0), None); assert_eq!(MapVecWithDefault::get(0), vec![6, 9]); @@ -620,7 +620,7 @@ mod test_append_and_len { assert_eq!(OptionMapVec::decode_len(0), None); // Double map - assert_eq!(DoubleMapVec::get(0, 0), vec![]); + assert!(DoubleMapVec::get(0, 0).is_empty()); assert_eq!(DoubleMapVec::decode_len(0, 1), None); assert_eq!(DoubleMapVecWithDefault::get(0, 0), vec![6, 9]); From fbefaffd86492ceb08b2398586231aa5e5cab664 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 6 Aug 2020 18:55:46 +0200 Subject: [PATCH 11/29] Fix the remaining tests --- Cargo.lock | 9 +++++++++ bin/node/bench/Cargo.toml | 7 ++++--- bin/node/bench/src/main.rs | 2 +- client/authority-discovery/Cargo.toml | 1 + client/consensus/aura/Cargo.toml | 1 + client/consensus/babe/Cargo.toml | 1 + client/db/Cargo.toml | 1 + client/finality-grandpa/Cargo.toml | 1 + client/network/Cargo.toml | 1 + client/offchain/Cargo.toml | 1 + utils/frame/rpc/system/Cargo.toml | 1 + 11 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d83bca13577f2..eec1864e9364b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3705,6 +3705,7 @@ dependencies = [ "sp-runtime", "sp-state-machine", "sp-timestamp", + "sp-tracing", "sp-transaction-pool", "sp-trie", "structopt", @@ -6310,6 +6311,7 @@ dependencies = [ "sp-blockchain", "sp-core", "sp-runtime", + "sp-tracing", "substrate-prometheus-endpoint", "substrate-test-runtime-client", ] @@ -6491,6 +6493,7 @@ dependencies = [ "sp-keyring", "sp-runtime", "sp-state-machine", + "sp-tracing", "sp-trie", "substrate-prometheus-endpoint", "substrate-test-runtime-client", @@ -6538,6 +6541,7 @@ dependencies = [ "sp-keyring", "sp-runtime", "sp-timestamp", + "sp-tracing", "sp-version", "substrate-prometheus-endpoint", "substrate-test-runtime-client", @@ -6589,6 +6593,7 @@ dependencies = [ "sp-keyring", "sp-runtime", "sp-timestamp", + "sp-tracing", "sp-utils", "sp-version", "substrate-prometheus-endpoint", @@ -6849,6 +6854,7 @@ dependencies = [ "sp-keyring", "sp-runtime", "sp-state-machine", + "sp-tracing", "sp-utils", "substrate-prometheus-endpoint", "substrate-test-runtime-client", @@ -6971,6 +6977,7 @@ dependencies = [ "sp-keyring", "sp-runtime", "sp-test-primitives", + "sp-tracing", "sp-utils", "substrate-prometheus-endpoint", "substrate-test-runtime", @@ -7052,6 +7059,7 @@ dependencies = [ "sp-core", "sp-offchain", "sp-runtime", + "sp-tracing", "sp-transaction-pool", "sp-utils", "substrate-test-runtime-client", @@ -8707,6 +8715,7 @@ dependencies = [ "sp-blockchain", "sp-core", "sp-runtime", + "sp-tracing", "sp-transaction-pool", "substrate-test-runtime-client", ] diff --git a/bin/node/bench/Cargo.toml b/bin/node/bench/Cargo.toml index 0f93039c3c1eb..5c3c68ce02abe 100644 --- a/bin/node/bench/Cargo.toml +++ b/bin/node/bench/Cargo.toml @@ -29,15 +29,16 @@ sp-consensus = { version = "0.8.0-rc5", path = "../../../primitives/consensus/co sp-transaction-pool = { version = "2.0.0-rc5", path = "../../../primitives/transaction-pool" } sc-basic-authorship = { version = "0.8.0-rc5", path = "../../../client/basic-authorship" } sp-inherents = { version = "2.0.0-rc5", path = "../../../primitives/inherents" } -sp-finality-tracker = { version = "2.0.0-rc5", default-features = false, path = "../../../primitives/finality-tracker" } -sp-timestamp = { version = "2.0.0-rc5", default-features = false, path = "../../../primitives/timestamp" } +sp-finality-tracker = { version = "2.0.0-rc5", path = "../../../primitives/finality-tracker" } +sp-timestamp = { version = "2.0.0-rc5", path = "../../../primitives/timestamp" } +sp-tracing = { version = "2.0.0-rc5", path = "../../../primitives/tracing" } hash-db = "0.15.2" tempfile = "3.1.0" fs_extra = "1" hex = "0.4.0" rand = { version = "0.7.2", features = ["small_rng"] } lazy_static = "1.4.0" -parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] } +parity-util-mem = { version = "0.7.0", features = ["primitive-types"] } parity-db = { version = "0.1.2" } sc-transaction-pool = { version = "2.0.0-rc5", path = "../../../client/transaction-pool" } futures = { version = "0.3.4", features = ["thread-pool"] } diff --git a/bin/node/bench/src/main.rs b/bin/node/bench/src/main.rs index 96ef1d920c1f5..46b659dd88387 100644 --- a/bin/node/bench/src/main.rs +++ b/bin/node/bench/src/main.rs @@ -79,7 +79,7 @@ fn main() { let opt = Opt::from_args(); if !opt.json { - sc_cli::init_logger(""); + sp_tracing::try_init_simple(); } let mut import_benchmarks = Vec::new(); diff --git a/client/authority-discovery/Cargo.toml b/client/authority-discovery/Cargo.toml index d2eef2d03d086..c7b207a2bc789 100644 --- a/client/authority-discovery/Cargo.toml +++ b/client/authority-discovery/Cargo.toml @@ -38,5 +38,6 @@ sp-api = { version = "2.0.0-rc5", path = "../../primitives/api" } [dev-dependencies] quickcheck = "0.9.0" +sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } sc-peerset = { version = "2.0.0-rc5", path = "../peerset" } substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../test-utils/runtime/client"} diff --git a/client/consensus/aura/Cargo.toml b/client/consensus/aura/Cargo.toml index c0808679defbd..0c7686e68346f 100644 --- a/client/consensus/aura/Cargo.toml +++ b/client/consensus/aura/Cargo.toml @@ -39,6 +39,7 @@ prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../.. [dev-dependencies] sp-keyring = { version = "2.0.0-rc5", path = "../../../primitives/keyring" } +sp-tracing = { version = "2.0.0-rc5", path = "../../../primitives/tracing" } sc-executor = { version = "0.8.0-rc5", path = "../../executor" } sc-network = { version = "0.8.0-rc5", path = "../../network" } sc-network-test = { version = "0.8.0-rc5", path = "../../network/test" } diff --git a/client/consensus/babe/Cargo.toml b/client/consensus/babe/Cargo.toml index c954d195b0f00..23e6867d50837 100644 --- a/client/consensus/babe/Cargo.toml +++ b/client/consensus/babe/Cargo.toml @@ -53,6 +53,7 @@ retain_mut = "0.1.1" [dev-dependencies] sp-keyring = { version = "2.0.0-rc5", path = "../../../primitives/keyring" } +sp-tracing = { version = "2.0.0-rc5", path = "../../../primitives/tracing" } sc-executor = { version = "0.8.0-rc5", path = "../../executor" } sc-network = { version = "0.8.0-rc5", path = "../../network" } sc-network-test = { version = "0.8.0-rc5", path = "../../network/test" } diff --git a/client/db/Cargo.toml b/client/db/Cargo.toml index 620aa5daf0316..109d3de9a3551 100644 --- a/client/db/Cargo.toml +++ b/client/db/Cargo.toml @@ -39,6 +39,7 @@ prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0. [dev-dependencies] sp-keyring = { version = "2.0.0-rc5", path = "../../primitives/keyring" } +sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../test-utils/runtime/client" } quickcheck = "0.9" kvdb-rocksdb = "0.9" diff --git a/client/finality-grandpa/Cargo.toml b/client/finality-grandpa/Cargo.toml index 520ec537fbc4e..44e35e0dc1149 100644 --- a/client/finality-grandpa/Cargo.toml +++ b/client/finality-grandpa/Cargo.toml @@ -54,6 +54,7 @@ sp-keyring = { version = "2.0.0-rc5", path = "../../primitives/keyring" } substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../test-utils/runtime/client" } sp-consensus-babe = { version = "0.8.0-rc5", path = "../../primitives/consensus/babe" } sp-state-machine = { version = "0.8.0-rc5", path = "../../primitives/state-machine" } +sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } tokio = { version = "0.2", features = ["rt-core"] } tempfile = "3.1.0" sp-api = { version = "2.0.0-rc5", path = "../../primitives/api" } diff --git a/client/network/Cargo.toml b/client/network/Cargo.toml index 83a903548cd26..9d6cfeab525c2 100644 --- a/client/network/Cargo.toml +++ b/client/network/Cargo.toml @@ -73,6 +73,7 @@ quickcheck = "0.9.0" rand = "0.7.2" sp-keyring = { version = "2.0.0-rc5", path = "../../primitives/keyring" } sp-test-primitives = { version = "2.0.0-rc5", path = "../../primitives/test-primitives" } +sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } substrate-test-runtime = { version = "2.0.0-rc5", path = "../../test-utils/runtime" } substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../test-utils/runtime/client" } tempfile = "3.1.0" diff --git a/client/offchain/Cargo.toml b/client/offchain/Cargo.toml index d4be5ca97f4a5..fba59f837aa27 100644 --- a/client/offchain/Cargo.toml +++ b/client/offchain/Cargo.toml @@ -39,6 +39,7 @@ hyper-rustls = "0.21.0" sc-client-db = { version = "0.8.0-rc5", default-features = true, path = "../db/" } sc-transaction-pool = { version = "2.0.0-rc5", path = "../../client/transaction-pool" } sp-transaction-pool = { version = "2.0.0-rc5", path = "../../primitives/transaction-pool" } +sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../test-utils/runtime/client" } tokio = "0.2" lazy_static = "1.4.0" diff --git a/utils/frame/rpc/system/Cargo.toml b/utils/frame/rpc/system/Cargo.toml index 528615402dd8f..a9456e62b9749 100644 --- a/utils/frame/rpc/system/Cargo.toml +++ b/utils/frame/rpc/system/Cargo.toml @@ -31,4 +31,5 @@ sc-rpc-api = { version = "0.8.0-rc5", path = "../../../../client/rpc-api" } [dev-dependencies] substrate-test-runtime-client = { version = "2.0.0-rc5", path = "../../../../test-utils/runtime/client" } +sp-tracing = { version = "2.0.0-rc5", path = "../../../../primitives/tracing" } sc-transaction-pool = { version = "2.0.0-rc5", path = "../../../../client/transaction-pool" } From d161fdb9555a271ba07522ddef824bc07729ddf1 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 6 Aug 2020 18:59:38 +0200 Subject: [PATCH 12/29] Use subscriber's try_init as recommended by @davidbarsky --- Cargo.lock | 1 - primitives/tracing/Cargo.toml | 3 +-- primitives/tracing/src/lib.rs | 4 +--- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f5d455f07da1..00925bc7d0b3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8357,7 +8357,6 @@ dependencies = [ "log", "rental", "tracing", - "tracing-log", "tracing-subscriber", ] diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 36a464b57fd90..626fc7f6e288b 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -16,8 +16,7 @@ tracing = { version = "0.1.13", optional = true } rental = { version = "0.5.5", optional = true } log = { version = "0.4.8", optional = true } tracing-subscriber = { version = "0.2.10", optional = true } -tracing-log = { version = "0.1.1", optional = true } [features] default = [ "std" ] -std = [ "tracing", "rental", "log", "tracing-subscriber", "tracing-log" ] +std = [ "tracing", "rental", "log", "tracing-subscriber" ] diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index b8b8be070dcd5..69b619f67b8f3 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -48,9 +48,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; /// Try to init a simple tracing subscriber with log compatibility layer. /// Ignores any error. Useful for testing. pub fn try_init_simple() { - let _ = tracing_log::LogTracer::init(); - let subscriber = tracing_subscriber::fmt().finish(); - let _ = tracing::subscriber::set_global_default(subscriber); + let _ = tracing_subscriber::fmt().try_init(); } /// Flag to signal whether to run wasm tracing From cd710490a4d7ecbe253975e023426650573bb891 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 6 Aug 2020 19:01:05 +0200 Subject: [PATCH 13/29] Be explict that the tracing-log feature is needed --- primitives/tracing/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 626fc7f6e288b..5a2a921537832 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"] tracing = { version = "0.1.13", optional = true } rental = { version = "0.5.5", optional = true } log = { version = "0.4.8", optional = true } -tracing-subscriber = { version = "0.2.10", optional = true } +tracing-subscriber = { version = "0.2.10", optional = true, features = ["tracing-log"] } [features] default = [ "std" ] From 86da56001862ef507aee92a36f4d59e6e0f00d8e Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 6 Aug 2020 21:00:12 +0200 Subject: [PATCH 14/29] Set subscriber writer to stderr --- client/cli/src/lib.rs | 1 + primitives/tracing/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 9f5599f45ccc0..de78826012396 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -281,6 +281,7 @@ pub fn init_logger( .with_env_filter(env_filter) .with_target(false) .with_ansi(enable_color) + .with_writer(std::io::stderr) .compact() .finish(); diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 69b619f67b8f3..523849433d2fa 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -48,7 +48,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; /// Try to init a simple tracing subscriber with log compatibility layer. /// Ignores any error. Useful for testing. pub fn try_init_simple() { - let _ = tracing_subscriber::fmt().try_init(); + let _ = tracing_subscriber::fmt().with_writer(std::io::stderr).try_init(); } /// Flag to signal whether to run wasm tracing From 3eb5daf46fa4c16583fe439078b20b0ef08dbe9c Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 6 Aug 2020 21:15:55 +0200 Subject: [PATCH 15/29] Shorter line width --- client/cli/src/lib.rs | 12 +++++++++--- client/tracing/src/lib.rs | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index de78826012396..00bb9a19deac8 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -234,7 +234,9 @@ pub fn init_logger( ) { match tracing_log::LogTracer::init() { Ok(_) => (), - Err(_) => log::info!("💬 Not registering Substrate logger, as there is already a global logger registered!"), + Err(_) => log::info!( + "💬 Not registering Substrate logger, as there is already a global logger registered!" + ), } let mut env_filter = tracing_subscriber::EnvFilter::default() @@ -290,12 +292,16 @@ pub fn init_logger( match tracing::subscriber::set_global_default(subscriber.with(profiling)) { Ok(_) => (), - Err(_) => tracing::info!("💬 Not registering Substrate subscriber, as there is already a global subscriber registered!"), + Err(_) => tracing::info!( + "💬 Not registering Substrate subscriber, as there is already a global subscriber registered!" + ), } } else { match tracing::subscriber::set_global_default(subscriber) { Ok(_) => (), - Err(_) => tracing::info!("💬 Not registering Substrate subscriber, as there is already a global subscriber registered!"), + Err(_) => tracing::info!( + "💬 Not registering Substrate subscriber, as there is already a global subscriber registered!" + ), } } } diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index f0cfbd1c98ef4..821dc975e5510 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -397,7 +397,12 @@ mod tests { } } - fn setup_subscriber() -> (tracing_subscriber::layer::Layered, Arc>>) { + type TestSubscriber = tracing_subscriber::layer::Layered< + ProfilingLayer, + tracing_subscriber::fmt::Subscriber + >; + + fn setup_subscriber() -> (TestSubscriber, Arc>>) { let spans = Arc::new(Mutex::new(Vec::new())); let handler = TestTraceHandler { spans: spans.clone(), From 6490ad33d5bc3db1e43dec5bc2958eb6275f5e90 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 6 Aug 2020 23:13:02 +0200 Subject: [PATCH 16/29] Update cargo lock tracing version --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 00925bc7d0b3f..ab8d196dffd5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9318,9 +9318,9 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] name = "tracing" -version = "0.1.14" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7c6b59d116d218cb2d990eb06b77b64043e0268ef7323aae63d8b30ae462923" +checksum = "f0aae59226cf195d8e74d4b34beae1859257efb4e5fed3f147d2dc2c7d372178" dependencies = [ "cfg-if", "tracing-attributes", @@ -9329,9 +9329,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99bbad0de3fd923c9c3232ead88510b783e5a4d16a6154adffa3d53308de984c" +checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b" dependencies = [ "proc-macro2", "quote", @@ -9340,9 +9340,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2734b5a028fa697686f16c6d18c2c6a3c7e41513f9a213abb6754c4acb3c8d7" +checksum = "d593f98af59ebc017c0648f0117525db358745a8894a8d684e185ba3f45954f9" dependencies = [ "lazy_static", ] From 9e1bce4bd089d223913fb82809b5780ce993ddb0 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Sun, 6 Sep 2020 20:17:08 +0200 Subject: [PATCH 17/29] Fix sc_tracing crate compile --- client/tracing/src/lib.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 43c9a20629b29..b4dff16c844db 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -38,7 +38,7 @@ use tracing::{ span::{Attributes, Id, Record}, subscriber::Subscriber, }; -use tracing_subscriber::layer::{Layer, Context}; +use tracing_subscriber::{CurrentSpan, layer::{Layer, Context}}; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; use sp_tracing::proxy::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; @@ -47,7 +47,7 @@ const ZERO_DURATION: Duration = Duration::from_nanos(0); const PROXY_TARGET: &'static str = "sp_tracing::proxy"; /// Responsible for assigning ids to new spans, which are not re-used. -pub struct ProfilingSubscriber { +pub struct ProfilingLayer { targets: Vec<(String, Level)>, trace_handler: Box, span_data: Mutex>, @@ -308,9 +308,7 @@ impl Layer for ProfilingLayer { } } - fn record_follows_from(&self, _span: &Id, _follows: &Id) {} - - fn event(&self, event: &Event<'_>) { + fn on_event(&self, event: &Event<'_>, _ctx: Context) { let mut values = Values::default(); event.record(&mut values); let trace_event = TraceEvent { @@ -323,7 +321,7 @@ impl Layer for ProfilingLayer { self.trace_handler.handle_event(trace_event); } - fn enter(&self, span: &Id, _ctx: Context) { + fn on_enter(&self, span: &Id, _ctx: Context) { self.current_span.enter(span.clone()); let mut span_data = self.span_data.lock(); let start_time = Instant::now(); From 635812fe251af64067e0db16cc2d912818f7852c Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Sun, 6 Sep 2020 20:25:23 +0200 Subject: [PATCH 18/29] Fix sc_authority_discovery crate test --- client/authority-discovery/src/worker/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/authority-discovery/src/worker/tests.rs b/client/authority-discovery/src/worker/tests.rs index baa6bd0fc7d62..940a9899e52d7 100644 --- a/client/authority-discovery/src/worker/tests.rs +++ b/client/authority-discovery/src/worker/tests.rs @@ -248,7 +248,7 @@ fn new_registers_metrics() { #[test] fn request_addresses_of_others_triggers_dht_get_query() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); let (_dht_event_tx, dht_event_rx) = channel(1000); // Generate authority keys @@ -282,7 +282,7 @@ fn request_addresses_of_others_triggers_dht_get_query() { #[test] fn publish_discover_cycle() { - let _ = ::env_logger::try_init(); + sp_tracing::try_init_simple(); // Node A publishing its address. From 14f304e4dfdb83a23ac136bb56d824698bde4452 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Wed, 9 Sep 2020 21:52:04 +0200 Subject: [PATCH 19/29] unremove default-features --- bin/node/bench/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/bench/Cargo.toml b/bin/node/bench/Cargo.toml index 4c13b60bea0e4..ec797e32de3f2 100644 --- a/bin/node/bench/Cargo.toml +++ b/bin/node/bench/Cargo.toml @@ -38,7 +38,7 @@ fs_extra = "1" hex = "0.4.0" rand = { version = "0.7.2", features = ["small_rng"] } lazy_static = "1.4.0" -parity-util-mem = { version = "0.7.0", features = ["primitive-types"] } +parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] } parity-db = { version = "0.1.2" } sc-transaction-pool = { version = "2.0.0-rc6", path = "../../../client/transaction-pool" } futures = { version = "0.3.4", features = ["thread-pool"] } From 02835a5ac9aa144155678e8f2092a541b1405916 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Wed, 9 Sep 2020 21:53:38 +0200 Subject: [PATCH 20/29] Leave enabled to default true --- client/tracing/src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index b4dff16c844db..27fa85109894e 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -274,10 +274,6 @@ fn parse_target(s: &str) -> (String, Level) { } impl Layer for ProfilingLayer { - fn enabled(&self, metadata: &Metadata<'_>, _ctx: Context) -> bool { - metadata.target() == PROXY_TARGET || self.check_target(metadata.target(), metadata.level()) - } - fn new_span(&self, attrs: &Attributes<'_>, id: &Id, _ctx: Context) { let mut values = Values::default(); attrs.record(&mut values); From a23f9ecb46e94a2ab8096e4c422010f83c209279 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Wed, 9 Sep 2020 21:54:58 +0200 Subject: [PATCH 21/29] Warn if global default cannot be set --- client/cli/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index db3edfbb19d76..376fed94c7e81 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -292,14 +292,14 @@ pub fn init_logger( match tracing::subscriber::set_global_default(subscriber.with(profiling)) { Ok(_) => (), - Err(_) => tracing::info!( + Err(_) => tracing::warn!( "💬 Not registering Substrate subscriber, as there is already a global subscriber registered!" ), } } else { match tracing::subscriber::set_global_default(subscriber) { Ok(_) => (), - Err(_) => tracing::info!( + Err(_) => tracing::warn!( "💬 Not registering Substrate subscriber, as there is already a global subscriber registered!" ), } From a13b04c01590d5f03e8ab1e7bc09953c28f07853 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Wed, 9 Sep 2020 22:03:22 +0200 Subject: [PATCH 22/29] Fix unused import --- client/tracing/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 27fa85109894e..cff217ac2a9cc 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -34,7 +34,6 @@ use tracing::{ event::Event, field::{Visit, Field}, Level, - metadata::Metadata, span::{Attributes, Id, Record}, subscriber::Subscriber, }; From 49522c447c63dc7cfa67146fb8972b6864720621 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 10 Sep 2020 08:32:14 +0200 Subject: [PATCH 23/29] Remove unused PROXY_TARGET --- client/tracing/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index cff217ac2a9cc..e509f2218a2ea 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -43,7 +43,6 @@ use sc_telemetry::{telemetry, SUBSTRATE_INFO}; use sp_tracing::proxy::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; const ZERO_DURATION: Duration = Duration::from_nanos(0); -const PROXY_TARGET: &'static str = "sp_tracing::proxy"; /// Responsible for assigning ids to new spans, which are not re-used. pub struct ProfilingLayer { From 763c26dbb1325998b0a2fbd1f5ae1e0fab4402fc Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Fri, 11 Sep 2020 12:57:24 +0200 Subject: [PATCH 24/29] Change all reference from rc5 to rc6 --- client/consensus/manual-seal/Cargo.toml | 28 ++++++++++++------------- client/service/test/Cargo.toml | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/client/consensus/manual-seal/Cargo.toml b/client/consensus/manual-seal/Cargo.toml index 3952674572a04..33f443bce9d12 100644 --- a/client/consensus/manual-seal/Cargo.toml +++ b/client/consensus/manual-seal/Cargo.toml @@ -22,23 +22,23 @@ parking_lot = "0.10.0" serde = { version = "1.0", features=["derive"] } assert_matches = "1.3.0" -sc-client-api = { path = "../../api", version = "2.0.0-rc5" } -sc-consensus-babe = { path = "../../consensus/babe", version = "0.8.0-rc5" } -sc-consensus-epochs = { path = "../../consensus/epochs", version = "0.8.0-rc5" } -sp-consensus-babe = { path = "../../../primitives/consensus/babe", version = "0.8.0-rc5" } -sc-keystore = { path = "../../keystore", version = "2.0.0-rc5" } +sc-client-api = { path = "../../api", version = "2.0.0-rc6" } +sc-consensus-babe = { path = "../../consensus/babe", version = "0.8.0-rc6" } +sc-consensus-epochs = { path = "../../consensus/epochs", version = "0.8.0-rc6" } +sp-consensus-babe = { path = "../../../primitives/consensus/babe", version = "0.8.0-rc6" } +sc-keystore = { path = "../../keystore", version = "2.0.0-rc6" } -sc-transaction-pool = { path = "../../transaction-pool", version = "2.0.0-rc5" } -sp-blockchain = { path = "../../../primitives/blockchain", version = "2.0.0-rc5" } -sp-consensus = { package = "sp-consensus", path = "../../../primitives/consensus/common", version = "0.8.0-rc5" } -sp-inherents = { path = "../../../primitives/inherents", version = "2.0.0-rc5" } -sp-runtime = { path = "../../../primitives/runtime", version = "2.0.0-rc5" } -sp-core = { path = "../../../primitives/core", version = "2.0.0-rc5" } -sp-api = { path = "../../../primitives/api", version = "2.0.0-rc5" } -sp-transaction-pool = { path = "../../../primitives/transaction-pool", version = "2.0.0-rc5" } +sc-transaction-pool = { path = "../../transaction-pool", version = "2.0.0-rc6" } +sp-blockchain = { path = "../../../primitives/blockchain", version = "2.0.0-rc6" } +sp-consensus = { package = "sp-consensus", path = "../../../primitives/consensus/common", version = "0.8.0-rc6" } +sp-inherents = { path = "../../../primitives/inherents", version = "2.0.0-rc6" } +sp-runtime = { path = "../../../primitives/runtime", version = "2.0.0-rc6" } +sp-core = { path = "../../../primitives/core", version = "2.0.0-rc6" } +sp-api = { path = "../../../primitives/api", version = "2.0.0-rc6" } +sp-transaction-pool = { path = "../../../primitives/transaction-pool", version = "2.0.0-rc6" } sp-timestamp = { path = "../../../primitives/timestamp", version = "2.0.0-rc6" } -prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0-rc5" } +prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0-rc6" } [dev-dependencies] tokio = { version = "0.2", features = ["rt-core", "macros"] } diff --git a/client/service/test/Cargo.toml b/client/service/test/Cargo.toml index 559020935231e..811eb3ffab355 100644 --- a/client/service/test/Cargo.toml +++ b/client/service/test/Cargo.toml @@ -41,4 +41,4 @@ sc-block-builder = { version = "0.8.0-rc6", path = "../../block-builder" } sc-executor = { version = "0.8.0-rc6", path = "../../executor" } sp-panic-handler = { version = "2.0.0-rc6", path = "../../../primitives/panic-handler" } parity-scale-codec = "1.3.4" -sp-tracing = { version = "2.0.0-rc5", path = "../../../primitives/tracing" } +sp-tracing = { version = "2.0.0-rc6\", path = "../../../primitives/tracing" } From bf0c78756b98620bffa0c4fd9fabf359d6e14102 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Fri, 11 Sep 2020 12:58:51 +0200 Subject: [PATCH 25/29] Change all reference of rc2 to rc6 --- client/informant/Cargo.toml | 4 ++-- client/light/Cargo.toml | 16 ++++++++-------- client/service/Cargo.toml | 2 +- client/tracing/Cargo.toml | 2 +- primitives/consensus/slots/Cargo.toml | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/client/informant/Cargo.toml b/client/informant/Cargo.toml index 6e6dc01f91e53..e711384d7f5ba 100644 --- a/client/informant/Cargo.toml +++ b/client/informant/Cargo.toml @@ -20,6 +20,6 @@ sc-client-api = { version = "2.0.0-rc6", path = "../api" } sc-network = { version = "0.8.0-rc6", path = "../network" } sp-blockchain = { version = "2.0.0-rc6", path = "../../primitives/blockchain" } sp-runtime = { version = "2.0.0-rc6", 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" } +sp-utils = { version = "2.0.0-rc6", path = "../../primitives/utils" } +sp-transaction-pool = { version = "2.0.0-rc6", path = "../../primitives/transaction-pool" } wasm-timer = "0.2" diff --git a/client/light/Cargo.toml b/client/light/Cargo.toml index 23b306d178e37..e160526ce8d29 100644 --- a/client/light/Cargo.toml +++ b/client/light/Cargo.toml @@ -13,15 +13,15 @@ documentation = "https://docs.rs/sc-light" parking_lot = "0.10.0" lazy_static = "1.4.0" hash-db = "0.15.2" -sp-runtime = { version = "2.0.0-rc2", path = "../../primitives/runtime" } -sp-externalities = { version = "0.8.0-rc2", path = "../../primitives/externalities" } -sp-blockchain = { version = "2.0.0-rc2", path = "../../primitives/blockchain" } -sp-core = { version = "2.0.0-rc2", path = "../../primitives/core" } -sp-state-machine = { version = "0.8.0-rc2", path = "../../primitives/state-machine" } -sc-client-api = { version = "2.0.0-rc2", path = "../api" } -sp-api = { version = "2.0.0-rc2", path = "../../primitives/api" } +sp-runtime = { version = "2.0.0-rc6", path = "../../primitives/runtime" } +sp-externalities = { version = "0.8.0-rc6", path = "../../primitives/externalities" } +sp-blockchain = { version = "2.0.0-rc6", path = "../../primitives/blockchain" } +sp-core = { version = "2.0.0-rc6", path = "../../primitives/core" } +sp-state-machine = { version = "0.8.0-rc6", path = "../../primitives/state-machine" } +sc-client-api = { version = "2.0.0-rc6", path = "../api" } +sp-api = { version = "2.0.0-rc6", path = "../../primitives/api" } codec = { package = "parity-scale-codec", version = "1.3.4" } -sc-executor = { version = "0.8.0-rc2", path = "../executor" } +sc-executor = { version = "0.8.0-rc6", path = "../executor" } [features] default = [] diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index fc4d3298a41d5..370ee679154e3 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -68,7 +68,7 @@ sc-rpc-server = { version = "2.0.0-rc6", path = "../rpc-servers" } sc-rpc = { version = "2.0.0-rc6", path = "../rpc" } sc-block-builder = { version = "0.8.0-rc6", path = "../block-builder" } sp-block-builder = { version = "2.0.0-rc6", path = "../../primitives/block-builder" } -sc-informant = { version = "0.8.0-rc2", path = "../informant" } +sc-informant = { version = "0.8.0-rc6", path = "../informant" } sc-telemetry = { version = "2.0.0-rc6", path = "../telemetry" } sc-offchain = { version = "2.0.0-rc6", path = "../offchain" } prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-rc6"} diff --git a/client/tracing/Cargo.toml b/client/tracing/Cargo.toml index 00279e6848df3..9444a9520f665 100644 --- a/client/tracing/Cargo.toml +++ b/client/tracing/Cargo.toml @@ -21,5 +21,5 @@ serde_json = "1.0.41" slog = { version = "2.5.2", features = ["nested-values"] } tracing = "0.1.18" tracing-subscriber = "0.2.10" -sp-tracing = { version = "2.0.0-rc2", path = "../../primitives/tracing" } +sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" } sc-telemetry = { version = "2.0.0-rc6", path = "../telemetry" } diff --git a/primitives/consensus/slots/Cargo.toml b/primitives/consensus/slots/Cargo.toml index ada913b645c7b..fecd3e03d781b 100644 --- a/primitives/consensus/slots/Cargo.toml +++ b/primitives/consensus/slots/Cargo.toml @@ -13,7 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } -sp-runtime = { version = "2.0.0-rc2", default-features = false, path = "../../runtime" } +sp-runtime = { version = "2.0.0-rc6", default-features = false, path = "../../runtime" } [features] default = ["std"] From 09202c759b58e56ab2be8732892cc2e8ca551937 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Fri, 11 Sep 2020 13:03:26 +0200 Subject: [PATCH 26/29] Fix styling --- client/cli/src/lib.rs | 45 ++++++++++++++--------------------- primitives/tracing/src/lib.rs | 2 +- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 376fed94c7e81..7bf646f5349ee 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -230,13 +230,12 @@ pub trait SubstrateCli: Sized { pub fn init_logger( pattern: &str, tracing_receiver: sc_tracing::TracingReceiver, - tracing_targets: Option + tracing_targets: Option, ) { - match tracing_log::LogTracer::init() { - Ok(_) => (), - Err(_) => log::info!( + if tracing_log::LogTracer::init().is_err() { + log::debug!( "💬 Not registering Substrate logger, as there is already a global logger registered!" - ), + ) } let mut env_filter = tracing_subscriber::EnvFilter::default() @@ -254,25 +253,19 @@ pub fn init_logger( if let Ok(lvl) = std::env::var("RUST_LOG") { if lvl != "" { - match lvl.parse() { - Ok(directive) => { - env_filter = env_filter.add_directive(directive); - } - // We're not sure if log or tracing is available at this moment, so silently ignore the - // parse error. - Err(_) => (), + // We're not sure if log or tracing is available at this moment, so silently ignore the + // parse error. + if let Ok(directive) = lvl.parse() { + env_filter = env_filter.add_directive(directive); } } } if pattern != "" { - match pattern.parse() { - Ok(directive) => { - env_filter = env_filter.add_directive(directive); - } - // We're not sure if log or tracing is available at this moment, so silently ignore the - // parse error. - Err(_) => (), + // We're not sure if log or tracing is available at this moment, so silently ignore the + // parse error. + if let Ok(directive) = pattern.parse() { + env_filter = env_filter.add_directive(directive); } } @@ -290,18 +283,16 @@ pub fn init_logger( if let Some(tracing_targets) = tracing_targets { let profiling = sc_tracing::ProfilingLayer::new(tracing_receiver, &tracing_targets); - match tracing::subscriber::set_global_default(subscriber.with(profiling)) { - Ok(_) => (), - Err(_) => tracing::warn!( + if tracing::subscriber::set_global_default(subscriber.with(profiling)).is_err() { + tracing::debug!( "💬 Not registering Substrate subscriber, as there is already a global subscriber registered!" - ), + ); } } else { - match tracing::subscriber::set_global_default(subscriber) { - Ok(_) => (), - Err(_) => tracing::warn!( + if tracing::subscriber::set_global_default(subscriber).is_err() { + tracing::warn!( "💬 Not registering Substrate subscriber, as there is already a global subscriber registered!" - ), + ); } } } diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 523849433d2fa..ec692b90dfdec 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -44,9 +44,9 @@ pub mod proxy; #[cfg(feature = "std")] use std::sync::atomic::{AtomicBool, Ordering}; -#[cfg(feature = "std")] /// Try to init a simple tracing subscriber with log compatibility layer. /// Ignores any error. Useful for testing. +#[cfg(feature = "std")] pub fn try_init_simple() { let _ = tracing_subscriber::fmt().with_writer(std::io::stderr).try_init(); } From b3d5b6cf233e9deb028c2a8902b16a52808def11 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Fri, 11 Sep 2020 13:20:00 +0200 Subject: [PATCH 27/29] Fix typo --- client/service/test/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/test/Cargo.toml b/client/service/test/Cargo.toml index 811eb3ffab355..83dfa76b8999e 100644 --- a/client/service/test/Cargo.toml +++ b/client/service/test/Cargo.toml @@ -41,4 +41,4 @@ sc-block-builder = { version = "0.8.0-rc6", path = "../../block-builder" } sc-executor = { version = "0.8.0-rc6", path = "../../executor" } sp-panic-handler = { version = "2.0.0-rc6", path = "../../../primitives/panic-handler" } parity-scale-codec = "1.3.4" -sp-tracing = { version = "2.0.0-rc6\", path = "../../../primitives/tracing" } +sp-tracing = { version = "2.0.0-rc6", path = "../../../primitives/tracing" } From 33ade0127017cff5db29785302886390c1a671c2 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 17 Sep 2020 09:52:42 +0200 Subject: [PATCH 28/29] make logger init error'ing --- client/cli/src/config.rs | 6 ++++-- client/cli/src/lib.rs | 31 +++++++++++++++++-------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index a1f9fd451223b..43b755100244f 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -528,7 +528,7 @@ pub trait CliConfiguration: Sized { Ok(self.shared_params().log_filters().join(",")) } - /// Initialize substrate. This must be done only once. + /// Initialize substrate. This must be done only once per process. /// /// This method: /// @@ -542,7 +542,9 @@ pub trait CliConfiguration: Sized { sp_panic_handler::set(&C::support_url(), &C::impl_version()); - init_logger(&logger_pattern, tracing_receiver, tracing_targets); + if let Err(e) = init_logger(&logger_pattern, tracing_receiver, tracing_targets) { + log::warn!("💬 Problem initializing global logging framework: {:}", e) + } if let Some(new_limit) = fdlimit::raise_fd_limit() { if new_limit < RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT { diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 7bf646f5349ee..f16d02cab51d5 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -226,16 +226,18 @@ pub trait SubstrateCli: Sized { fn native_runtime_version(chain_spec: &Box) -> &'static RuntimeVersion; } -/// Initialize the logger +/// Initialize the global logger +/// +/// This sets various global logging and tracing instances and thus may only be called once. pub fn init_logger( pattern: &str, tracing_receiver: sc_tracing::TracingReceiver, tracing_targets: Option, -) { - if tracing_log::LogTracer::init().is_err() { - log::debug!( - "💬 Not registering Substrate logger, as there is already a global logger registered!" - ) +) -> std::result::Result<(), String> { + if let Err(e) = tracing_log::LogTracer::init() { + return Err(format!( + "Registering Substrate logger failed: {:}!", e + )) } let mut env_filter = tracing_subscriber::EnvFilter::default() @@ -283,16 +285,17 @@ pub fn init_logger( if let Some(tracing_targets) = tracing_targets { let profiling = sc_tracing::ProfilingLayer::new(tracing_receiver, &tracing_targets); - if tracing::subscriber::set_global_default(subscriber.with(profiling)).is_err() { - tracing::debug!( - "💬 Not registering Substrate subscriber, as there is already a global subscriber registered!" - ); + if let Err(e) = tracing::subscriber::set_global_default(subscriber.with(profiling)) { + return Err(format!( + "Registering Substrate tracing subscriber failed: {:}!", e + )) } } else { - if tracing::subscriber::set_global_default(subscriber).is_err() { - tracing::warn!( - "💬 Not registering Substrate subscriber, as there is already a global subscriber registered!" - ); + if let Err(e) = tracing::subscriber::set_global_default(subscriber) { + return Err(format!( + "Registering Substrate tracing subscriber failed: {:}!", e + )) } } + Ok(()) } From 50ed0feba3ac9177ed9d470ad7e578c4bfdb65e6 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 17 Sep 2020 10:08:18 +0200 Subject: [PATCH 29/29] re-fixing the test issue --- frame/support/src/storage/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/storage/mod.rs b/frame/support/src/storage/mod.rs index f673d0cb4851a..5ee144c79c4db 100644 --- a/frame/support/src/storage/mod.rs +++ b/frame/support/src/storage/mod.rs @@ -673,7 +673,7 @@ mod test { unhashed::put(&[&k[..], &vec![1][..]].concat(), &1u32); unhashed::put(&[&k[..], &vec![8][..]].concat(), &2u32); - assert_eq!(MyStorage::iter_values().collect::>(), vec![]); + assert!(MyStorage::iter_values().collect::>().is_empty()); MyStorage::translate_values(|v: u32| Some(v as u64)); assert_eq!(MyStorage::iter_values().collect::>(), vec![1, 2]); MyStorage::remove_all();