Use tracing-based subscriber logging (#6825)

* init_logger: switch from log-based to tracing-based and add compatibility layer

* Move tracing profiling subscriber related config realization

* sp-tracing: change profiling to be a layer instead of a subscriber

* Enable profiling layer in cli

* Change all test env_logger init to sp_tracing::try_init_simple

* Remove all local env_logger dependency

* Add missing tracing-subscriber dependency

* frame-sudo: fix tests

* frame-support: fix tests

* Fix frame/pallet and executor tests

* Fix the remaining tests

* Use subscriber's try_init as recommended by @davidbarsky

* Be explict that the tracing-log feature is needed

* Set subscriber writer to stderr

* Shorter line width

* Update cargo lock tracing version

* Fix sc_tracing crate compile

* Fix sc_authority_discovery crate test

* unremove default-features

* Leave enabled to default true

* Warn if global default cannot be set

* Fix unused import

* Remove unused PROXY_TARGET

* Change all reference from rc5 to rc6

* Change all reference of rc2 to rc6

* Fix styling

* Fix typo

* make logger init error'ing

* re-fixing the test issue

Co-authored-by: Benjamin Kampmann <ben@parity.io>
This commit is contained in:
Wei Tang
2020-09-17 11:04:43 +02:00
committed by GitHub
parent ab97e94972
commit 9fdd4672b0
56 changed files with 309 additions and 320 deletions
+18 -15
View File
@@ -3638,6 +3638,7 @@ dependencies = [
"sp-runtime",
"sp-state-machine",
"sp-timestamp",
"sp-tracing",
"sp-transaction-pool",
"sp-trie",
"structopt",
@@ -3830,13 +3831,13 @@ dependencies = [
name = "node-rpc-client"
version = "2.0.0-rc6"
dependencies = [
"env_logger",
"futures 0.1.29",
"hyper 0.12.35",
"jsonrpc-core-client",
"log",
"node-primitives",
"sc-rpc",
"sp-tracing",
]
[[package]]
@@ -4876,7 +4877,6 @@ dependencies = [
name = "pallet-staking"
version = "2.0.0-rc6"
dependencies = [
"env_logger",
"frame-benchmarking",
"frame-support",
"frame-system",
@@ -4898,6 +4898,7 @@ dependencies = [
"sp-staking",
"sp-std",
"sp-storage",
"sp-tracing",
"static_assertions",
"substrate-test-utils",
]
@@ -6242,7 +6243,6 @@ dependencies = [
"bytes 0.5.6",
"derive_more",
"either",
"env_logger",
"futures 0.3.5",
"futures-timer 3.0.2",
"libp2p",
@@ -6262,6 +6262,7 @@ dependencies = [
"sp-blockchain",
"sp-core",
"sp-runtime",
"sp-tracing",
"substrate-prometheus-endpoint",
"substrate-test-runtime-client",
]
@@ -6345,7 +6346,6 @@ dependencies = [
"bip39",
"chrono",
"derive_more",
"env_logger",
"fdlimit",
"futures 0.3.5",
"hex",
@@ -6383,6 +6383,9 @@ dependencies = [
"tempfile",
"time",
"tokio 0.2.22",
"tracing",
"tracing-log",
"tracing-subscriber",
]
[[package]]
@@ -6428,7 +6431,6 @@ name = "sc-client-db"
version = "0.8.0-rc6"
dependencies = [
"blake2-rfc",
"env_logger",
"hash-db",
"kvdb",
"kvdb-memorydb",
@@ -6451,6 +6453,7 @@ dependencies = [
"sp-keyring",
"sp-runtime",
"sp-state-machine",
"sp-tracing",
"sp-trie",
"substrate-prometheus-endpoint",
"substrate-test-runtime-client",
@@ -6472,7 +6475,6 @@ name = "sc-consensus-aura"
version = "0.8.0-rc6"
dependencies = [
"derive_more",
"env_logger",
"futures 0.3.5",
"futures-timer 3.0.2",
"log",
@@ -6499,6 +6501,7 @@ dependencies = [
"sp-keyring",
"sp-runtime",
"sp-timestamp",
"sp-tracing",
"sp-version",
"substrate-prometheus-endpoint",
"substrate-test-runtime-client",
@@ -6510,7 +6513,6 @@ name = "sc-consensus-babe"
version = "0.8.0-rc6"
dependencies = [
"derive_more",
"env_logger",
"fork-tree",
"futures 0.3.5",
"futures-timer 3.0.2",
@@ -6551,6 +6553,7 @@ dependencies = [
"sp-keyring",
"sp-runtime",
"sp-timestamp",
"sp-tracing",
"sp-utils",
"sp-version",
"substrate-prometheus-endpoint",
@@ -6604,7 +6607,6 @@ version = "0.8.0-rc6"
dependencies = [
"assert_matches",
"derive_more",
"env_logger",
"futures 0.3.5",
"jsonrpc-core",
"jsonrpc-core-client",
@@ -6725,6 +6727,7 @@ dependencies = [
"substrate-test-runtime",
"test-case",
"tracing",
"tracing-subscriber",
"wasmi",
"wat",
]
@@ -6783,7 +6786,6 @@ version = "0.8.0-rc6"
dependencies = [
"assert_matches",
"derive_more",
"env_logger",
"finality-grandpa",
"fork-tree",
"futures 0.3.5",
@@ -6815,6 +6817,7 @@ dependencies = [
"sp-keyring",
"sp-runtime",
"sp-state-machine",
"sp-tracing",
"sp-utils",
"substrate-prometheus-endpoint",
"substrate-test-runtime-client",
@@ -6914,7 +6917,6 @@ dependencies = [
"bytes 0.5.6",
"derive_more",
"either",
"env_logger",
"erased-serde",
"fnv",
"fork-tree",
@@ -6951,6 +6953,7 @@ dependencies = [
"sp-keyring",
"sp-runtime",
"sp-test-primitives",
"sp-tracing",
"sp-utils",
"substrate-prometheus-endpoint",
"substrate-test-runtime",
@@ -6985,7 +6988,6 @@ dependencies = [
name = "sc-network-test"
version = "0.8.0-rc6"
dependencies = [
"env_logger",
"futures 0.3.5",
"futures-timer 3.0.2",
"libp2p",
@@ -7002,6 +7004,7 @@ dependencies = [
"sp-consensus-babe",
"sp-core",
"sp-runtime",
"sp-tracing",
"substrate-test-runtime",
"substrate-test-runtime-client",
"tempfile",
@@ -7012,7 +7015,6 @@ name = "sc-offchain"
version = "2.0.0-rc6"
dependencies = [
"bytes 0.5.6",
"env_logger",
"fnv",
"futures 0.3.5",
"futures-timer 3.0.2",
@@ -7033,6 +7035,7 @@ dependencies = [
"sp-core",
"sp-offchain",
"sp-runtime",
"sp-tracing",
"sp-transaction-pool",
"sp-utils",
"substrate-test-runtime-client",
@@ -7221,7 +7224,6 @@ dependencies = [
name = "sc-service-test"
version = "2.0.0-rc6"
dependencies = [
"env_logger",
"fdlimit",
"futures 0.1.29",
"futures 0.3.5",
@@ -7245,6 +7247,7 @@ dependencies = [
"sp-runtime",
"sp-state-machine",
"sp-storage",
"sp-tracing",
"sp-transaction-pool",
"sp-trie",
"substrate-test-runtime",
@@ -7257,7 +7260,6 @@ dependencies = [
name = "sc-state-db"
version = "0.8.0-rc6"
dependencies = [
"env_logger",
"log",
"parity-scale-codec",
"parity-util-mem",
@@ -8432,6 +8434,7 @@ dependencies = [
"log",
"rental",
"tracing",
"tracing-subscriber",
]
[[package]]
@@ -8692,7 +8695,6 @@ dependencies = [
name = "substrate-frame-rpc-system"
version = "2.0.0-rc6"
dependencies = [
"env_logger",
"frame-system-rpc-runtime-api",
"futures 0.3.5",
"jsonrpc-core",
@@ -8709,6 +8711,7 @@ dependencies = [
"sp-blockchain",
"sp-core",
"sp-runtime",
"sp-tracing",
"sp-transaction-pool",
"substrate-test-runtime-client",
]
+1
View File
@@ -31,6 +31,7 @@ sc-basic-authorship = { version = "0.8.0-rc6", path = "../../../client/basic-aut
sp-inherents = { version = "2.0.0-rc6", path = "../../../primitives/inherents" }
sp-finality-tracker = { version = "2.0.0-rc6", default-features = false, path = "../../../primitives/finality-tracker" }
sp-timestamp = { version = "2.0.0-rc6", default-features = false, path = "../../../primitives/timestamp" }
sp-tracing = { version = "2.0.0-rc6", path = "../../../primitives/tracing" }
hash-db = "0.15.2"
tempfile = "3.1.0"
fs_extra = "1"
+1 -1
View File
@@ -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();
+1 -1
View File
@@ -11,10 +11,10 @@ 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"] }
log = "0.4.8"
node-primitives = { version = "2.0.0-rc6", path = "../primitives" }
sp-tracing = { version = "2.0.0-rc6", path = "../../../primitives/tracing" }
sc-rpc = { version = "2.0.0-rc6", path = "../../../client/rpc" }
+1 -1
View File
@@ -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";
@@ -38,7 +38,7 @@ sp-runtime = { version = "2.0.0-rc6", path = "../../primitives/runtime" }
sp-api = { version = "2.0.0-rc6", path = "../../primitives/api" }
[dev-dependencies]
env_logger = "0.7.0"
quickcheck = "0.9.0"
sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" }
sc-peerset = { version = "2.0.0-rc6", path = "../peerset" }
substrate-test-runtime-client = { version = "2.0.0-rc6", path = "../../test-utils/runtime/client"}
@@ -283,7 +283,7 @@ fn new_registers_metrics() {
#[test]
fn 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
@@ -321,7 +321,7 @@ fn triggers_dht_get_query() {
#[test]
fn publish_discover_cycle() {
let _ = ::env_logger::try_init();
sp_tracing::try_init_simple();
// Node A publishing its address.
+3 -1
View File
@@ -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"
@@ -50,6 +49,9 @@ sc-tracing = { version = "2.0.0-rc6", 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"
+6 -2
View File
@@ -528,7 +528,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: 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:
///
@@ -537,10 +537,14 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
/// 3. Raises the FD limit
fn init<C: SubstrateCli>(&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());
init_logger(&logger_pattern);
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 {
+63 -68
View File
@@ -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};
@@ -46,6 +43,7 @@ use structopt::{
clap::{self, AppSettings},
StructOpt,
};
use tracing_subscriber::layer::SubscriberExt;
/// Substrate client CLI
///
@@ -228,79 +226,76 @@ pub trait SubstrateCli: Sized {
fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion;
}
/// 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::Trace);
// Enable info for others.
builder.filter(None, log::LevelFilter::Info);
if let Ok(lvl) = std::env::var("RUST_LOG") {
builder.parse_filters(&lvl);
/// 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<String>,
) -> 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()
// 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=trace".parse().expect("provided directive is valid"))
// Enable info for others.
.add_directive(tracing_subscriber::filter::LevelFilter::INFO.into());
if let Ok(lvl) = std::env::var("RUST_LOG") {
if lvl != "" {
// 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 != "" {
// 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);
}
}
builder.parse_filters(pattern);
let isatty = atty::is(atty::Stream::Stderr);
let enable_color = isatty;
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 subscriber = tracing_subscriber::FmtSubscriber::builder()
.with_env_filter(env_filter)
.with_target(false)
.with_ansi(enable_color)
.with_writer(std::io::stderr)
.compact()
.finish();
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 let Some(tracing_targets) = tracing_targets {
let profiling = sc_tracing::ProfilingLayer::new(tracing_receiver, &tracing_targets);
if !isatty && record.level() <= log::Level::Info && atty::is(atty::Stream::Stdout) {
// duplicate INFO/WARN output to console
println!("{}", output);
if let Err(e) = tracing::subscriber::set_global_default(subscriber.with(profiling)) {
return Err(format!(
"Registering Substrate tracing subscriber failed: {:}!", e
))
}
if !enable_color {
output = kill_color(output.as_ref());
} else {
if let Err(e) = tracing::subscriber::set_global_default(subscriber) {
return Err(format!(
"Registering Substrate tracing subscriber failed: {:}!", e
))
}
writeln!(buf, "{}", output)
});
if builder.try_init().is_err() {
info!("💬 Not registering Substrate logger, as there is already a global logger registered!");
}
}
fn kill_color(s: &str) -> String {
lazy_static! {
static ref RE: Regex = Regex::new("\x1b\\[[^m]+m").expect("Error initializing color regex");
}
RE.replace_all(s, "").to_string()
Ok(())
}
+1 -1
View File
@@ -39,10 +39,10 @@ prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../..
[dev-dependencies]
sp-keyring = { version = "2.0.0-rc6", path = "../../../primitives/keyring" }
sp-tracing = { version = "2.0.0-rc6", path = "../../../primitives/tracing" }
sc-executor = { version = "0.8.0-rc6", path = "../../executor" }
sc-network = { version = "0.8.0-rc6", path = "../../network" }
sc-network-test = { version = "0.8.0-rc6", path = "../../network/test" }
sc-service = { version = "0.8.0-rc6", default-features = false, path = "../../service" }
substrate-test-runtime-client = { version = "2.0.0-rc6", path = "../../../test-utils/runtime/client" }
env_logger = "0.7.0"
tempfile = "3.1.0"
+1 -1
View File
@@ -991,7 +991,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 = &[
+1 -1
View File
@@ -53,13 +53,13 @@ retain_mut = "0.1.1"
[dev-dependencies]
sp-keyring = { version = "2.0.0-rc6", path = "../../../primitives/keyring" }
sp-tracing = { version = "2.0.0-rc6", path = "../../../primitives/tracing" }
sc-executor = { version = "0.8.0-rc6", path = "../../executor" }
sc-network = { version = "0.8.0-rc6", path = "../../network" }
sc-network-test = { version = "0.8.0-rc6", path = "../../network/test" }
sc-service = { version = "0.8.0-rc6", default-features = false, path = "../../service" }
substrate-test-runtime-client = { version = "2.0.0-rc6", path = "../../../test-utils/runtime/client" }
sc-block-builder = { version = "0.8.0-rc6", path = "../../block-builder" }
env_logger = "0.7.0"
rand_chacha = "0.2.2"
tempfile = "3.1.0"
+7 -7
View File
@@ -347,7 +347,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
@@ -360,7 +360,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());
@@ -489,7 +489,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());
@@ -498,14 +498,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());
@@ -514,7 +514,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::<AuthorityPair>("//Alice")
@@ -821,7 +821,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::<AuthorityPair>("//Alice")
@@ -22,28 +22,27 @@ 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"] }
sc-basic-authorship = { path = "../../basic-authorship", version = "0.8.0-rc6" }
substrate-test-runtime-client = { path = "../../../test-utils/runtime/client", version = "2.0.0-rc6" }
substrate-test-runtime-transaction-pool = { path = "../../../test-utils/runtime/transaction-pool", version = "2.0.0-rc6" }
env_logger = "0.7.0"
tempfile = "3.1.0"
+1 -1
View File
@@ -39,8 +39,8 @@ prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.
[dev-dependencies]
sp-keyring = { version = "2.0.0-rc6", path = "../../primitives/keyring" }
sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" }
substrate-test-runtime-client = { version = "2.0.0-rc6", path = "../../test-utils/runtime/client" }
env_logger = "0.7.0"
quickcheck = "0.9"
kvdb-rocksdb = "0.9.1"
tempfile = "3"
+1 -1
View File
@@ -1958,7 +1958,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::<Block>::new_test(1, 0);
+2 -2
View File
@@ -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();
+1
View File
@@ -47,6 +47,7 @@ sp-runtime = { version = "2.0.0-rc6", path = "../../primitives/runtime" }
sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" }
sc-tracing = { version = "2.0.0-rc6", path = "../tracing" }
tracing = "0.1.18"
tracing-subscriber = "0.2.10"
[features]
default = [ "std" ]
@@ -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;
@@ -678,8 +679,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);
+1 -1
View File
@@ -54,7 +54,7 @@ sp-keyring = { version = "2.0.0-rc6", path = "../../primitives/keyring" }
substrate-test-runtime-client = { version = "2.0.0-rc6", path = "../../test-utils/runtime/client" }
sp-consensus-babe = { version = "0.8.0-rc6", path = "../../primitives/consensus/babe" }
sp-state-machine = { version = "0.8.0-rc6", path = "../../primitives/state-machine" }
env_logger = "0.7.0"
sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" }
tokio = { version = "0.2", features = ["rt-core"] }
tempfile = "3.1.0"
sp-api = { version = "2.0.0-rc6", path = "../../primitives/api" }
@@ -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());
@@ -417,7 +417,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);
@@ -522,7 +522,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,
@@ -792,7 +792,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];
@@ -852,7 +852,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 = &[
@@ -1014,7 +1014,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
@@ -1270,7 +1270,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);
@@ -1315,7 +1315,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];
@@ -1345,7 +1345,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.
@@ -1409,7 +1409,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];
+2 -2
View File
@@ -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"
+8 -8
View File
@@ -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 = []
+1 -1
View File
@@ -69,12 +69,12 @@ features = ["identify", "kad", "mdns-async-std", "mplex", "noise", "ping", "requ
[dev-dependencies]
assert_matches = "1.3"
env_logger = "0.7.0"
libp2p = { version = "0.28.1", default-features = false }
quickcheck = "0.9.0"
rand = "0.7.2"
sp-keyring = { version = "2.0.0-rc6", path = "../../primitives/keyring" }
sp-test-primitives = { version = "2.0.0-rc6", path = "../../primitives/test-primitives" }
sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" }
substrate-test-runtime = { version = "2.0.0-rc6", path = "../../test-utils/runtime" }
substrate-test-runtime-client = { version = "2.0.0-rc6", path = "../../test-utils/runtime/client" }
tempfile = "3.1.0"
@@ -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(),
@@ -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::<Block>::new("test");
+1 -1
View File
@@ -28,8 +28,8 @@ sp-runtime = { version = "2.0.0-rc6", path = "../../../primitives/runtime" }
sp-core = { version = "2.0.0-rc6", path = "../../../primitives/core" }
sc-block-builder = { version = "0.8.0-rc6", path = "../../block-builder" }
sp-consensus-babe = { version = "0.8.0-rc6", path = "../../../primitives/consensus/babe" }
env_logger = "0.7.0"
substrate-test-runtime-client = { version = "2.0.0-rc6", path = "../../../test-utils/runtime/client" }
substrate-test-runtime = { version = "2.0.0-rc6", path = "../../../test-utils/runtime" }
tempfile = "3.1.0"
sp-tracing = { version = "2.0.0-rc6", path = "../../../primitives/tracing" }
sc-service = { version = "0.8.0-rc6", default-features = false, features = ["test-helpers"], path = "../../service" }
+26 -26
View File
@@ -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<Block> 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());
+1 -1
View File
@@ -36,10 +36,10 @@ hyper = "0.13.2"
hyper-rustls = "0.21.0"
[dev-dependencies]
env_logger = "0.7.0"
sc-client-db = { version = "0.8.0-rc6", default-features = true, path = "../db/" }
sc-transaction-pool = { version = "2.0.0-rc6", path = "../../client/transaction-pool" }
sp-transaction-pool = { version = "2.0.0-rc6", path = "../../primitives/transaction-pool" }
sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" }
substrate-test-runtime-client = { version = "2.0.0-rc6", path = "../../test-utils/runtime/client" }
tokio = "0.2"
lazy_static = "1.4.0"
+1 -1
View File
@@ -328,7 +328,7 @@ mod tests {
}
fn offchain_api() -> (Api<LocalStorage>, AsyncApi) {
let _ = env_logger::try_init();
sp_tracing::try_init_simple();
let db = LocalStorage::new_test();
let mock = Arc::new(TestNetwork());
let shared_client = SharedClient::new();
+1 -1
View File
@@ -281,7 +281,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();
+1 -1
View File
@@ -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"}
+1 -12
View File
@@ -36,7 +36,7 @@ use sp_consensus::{
use futures::{FutureExt, StreamExt, future::ready, channel::oneshot};
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;
@@ -572,17 +572,6 @@ pub fn spawn_tasks<TBl, TBackend, TExPool, TRpc, TCl>(
))
});
// 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(),
+1 -1
View File
@@ -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.2.0"
parking_lot = "0.10.0"
sc-light = { version = "2.0.0-rc6", path = "../../light" }
@@ -42,3 +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" }
@@ -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
@@ -1855,4 +1855,4 @@ fn reorg_triggers_a_notification_even_for_sources_that_should_not_trigger_notifi
// We should have a tree route of the re-org
let tree_route = notification.tree_route.unwrap();
assert_eq!(tree_route.enacted()[0].hash, b1.hash());
}
}
+1 -1
View File
@@ -289,7 +289,7 @@ impl<G, E, F, L, U> TestNet<G, E, F, L, U> where
)>,
base_port: u16
) -> TestNet<G, E, F, L, U> {
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 {
-3
View File
@@ -19,6 +19,3 @@ sp-core = { version = "2.0.0-rc6", 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"
+1 -2
View File
@@ -21,6 +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" }
+24 -37
View File
@@ -26,7 +26,6 @@
use rustc_hash::FxHashMap;
use std::fmt;
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::{Duration, Instant};
use parking_lot::Mutex;
@@ -35,21 +34,18 @@ use tracing::{
event::Event,
field::{Visit, Field},
Level,
metadata::Metadata,
span::{Attributes, Id, Record},
subscriber::Subscriber,
};
use tracing_subscriber::CurrentSpan;
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};
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 {
next_id: AtomicU64,
pub struct ProfilingLayer {
targets: Vec<(String, Level)>,
trace_handler: Box<dyn TraceHandler>,
span_data: Mutex<FxHashMap<Id, SpanDatum>>,
@@ -216,12 +212,12 @@ impl slog::Value for Values {
}
}
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(
@@ -237,11 +233,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<dyn TraceHandler>, 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()),
@@ -276,25 +271,14 @@ 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
}
}
fn new_span(&self, attrs: &Attributes<'_>) -> Id {
let id = Id::from_u64(self.next_id.fetch_add(1, Ordering::Relaxed));
impl<S: Subscriber> Layer<S> for ProfilingLayer {
fn new_span(&self, attrs: &Attributes<'_>, id: &Id, _ctx: Context<S>) {
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
return
}
}
let span_datum = SpanDatum {
@@ -309,19 +293,16 @@ impl Subscriber for ProfilingSubscriber {
values,
};
self.span_data.lock().insert(id.clone(), span_datum);
id
}
fn record(&self, span: &Id, values: &Record<'_>) {
fn on_record(&self, span: &Id, values: &Record<'_>, _ctx: Context<S>) {
let mut span_data = self.span_data.lock();
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 on_event(&self, event: &Event<'_>, _ctx: Context<S>) {
let mut values = Values::default();
event.record(&mut values);
let trace_event = TraceEvent {
@@ -334,7 +315,7 @@ impl Subscriber for ProfilingSubscriber {
self.trace_handler.handle_event(trace_event);
}
fn enter(&self, span: &Id) {
fn on_enter(&self, span: &Id, _ctx: Context<S>) {
self.current_span.enter(span.clone());
let mut span_data = self.span_data.lock();
let start_time = Instant::now();
@@ -343,7 +324,7 @@ impl Subscriber for ProfilingSubscriber {
}
}
fn exit(&self, span: &Id) {
fn on_exit(&self, span: &Id, _ctx: Context<S>) {
self.current_span.exit();
let end_time = Instant::now();
let mut span_data = self.span_data.lock();
@@ -352,7 +333,7 @@ impl Subscriber for ProfilingSubscriber {
}
}
fn try_close(&self, span: Id) -> bool {
fn on_close(&self, span: Id, _ctx: Context<S>) {
let span_datum = {
let mut span_data = self.span_data.lock();
span_data.remove(&span)
@@ -373,7 +354,6 @@ impl Subscriber for ProfilingSubscriber {
self.trace_handler.handle_span(span_datum);
}
};
true
}
}
@@ -458,6 +438,7 @@ impl TraceHandler for TelemetryTraceHandler {
mod tests {
use super::*;
use std::sync::Arc;
use tracing_subscriber::layer::SubscriberExt;
struct TestTraceHandler {
spans: Arc<Mutex<Vec<SpanDatum>>>,
@@ -474,18 +455,24 @@ mod tests {
}
}
fn setup_subscriber() -> (ProfilingSubscriber, Arc<Mutex<Vec<SpanDatum>>>, Arc<Mutex<Vec<TraceEvent>>>) {
type TestSubscriber = tracing_subscriber::layer::Layered<
ProfilingLayer,
tracing_subscriber::fmt::Subscriber
>;
fn setup_subscriber() -> (TestSubscriber, Arc<Mutex<Vec<SpanDatum>>>, Arc<Mutex<Vec<TraceEvent>>>) {
let spans = Arc::new(Mutex::new(Vec::new()));
let events = Arc::new(Mutex::new(Vec::new()));
let handler = TestTraceHandler {
spans: spans.clone(),
events: events.clone(),
};
let test_subscriber = ProfilingSubscriber::new_with_handler(
let layer = ProfilingLayer::new_with_handler(
Box::new(handler),
"test_target"
);
(test_subscriber, spans, events)
let subscriber = tracing_subscriber::fmt().finish().with(layer);
(subscriber, spans, events)
}
#[test]
+38 -38
View File
@@ -1398,7 +1398,7 @@ mod tests {
assert!(
Elections::members().iter().chain(
Elections::runners_up().iter()
).all(|(_, s)| *s != Zero::zero())
).all(|(_, s)| *s != u64::zero())
);
}
@@ -1453,15 +1453,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!(<Candidates<Test>>::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());
});
}
@@ -1536,16 +1536,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());
});
}
@@ -1588,18 +1588,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());
});
}
@@ -1627,8 +1627,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)),
@@ -1742,7 +1742,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));
});
@@ -1765,7 +1765,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));
@@ -1791,7 +1791,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));
});
@@ -1876,7 +1876,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));
@@ -1898,7 +1898,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::<Test>::MustBeVoter);
});
@@ -2008,7 +2008,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);
@@ -2044,7 +2044,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));
@@ -2072,7 +2072,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));
@@ -2113,9 +2113,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!(<Candidates<Test>>::decode_len(), None);
assert_eq!(Elections::election_rounds(), 1);
@@ -2180,9 +2180,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,
@@ -2293,7 +2293,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));
});
@@ -2378,7 +2378,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]);
};
@@ -2490,7 +2490,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);
});
}
@@ -2658,14 +2658,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());
})
}
@@ -2729,7 +2729,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());
})
}
@@ -2841,7 +2841,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());
})
}
}
+7 -7
View File
@@ -46,14 +46,14 @@ fn params_should_work() {
assert_eq!(Elections::voters(0), Vec::<Option<u64>>::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());
});
}
+1 -1
View File
@@ -843,7 +843,7 @@ mod tests {
WatchDummy::<Test>(PhantomData).validate(&1, &call, &info, 150)
.unwrap()
.priority,
Bounded::max_value(),
u64::max_value(),
);
assert_eq!(
WatchDummy::<Test>(PhantomData).validate(&1, &call, &info, 250),
+1 -1
View File
@@ -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());
});
}
+1 -1
View File
@@ -33,6 +33,7 @@ rand_chacha = { version = "0.2", default-features = false, optional = true }
[dev-dependencies]
sp-core = { version = "2.0.0-rc6", path = "../../primitives/core" }
sp-storage = { version = "2.0.0-rc6", path = "../../primitives/storage" }
sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" }
pallet-balances = { version = "2.0.0-rc6", path = "../balances" }
pallet-timestamp = { version = "2.0.0-rc6", path = "../timestamp" }
pallet-staking-reward-curve = { version = "2.0.0-rc6", path = "../staking/reward-curve" }
@@ -40,7 +41,6 @@ substrate-test-utils = { version = "2.0.0-rc6", path = "../../test-utils" }
frame-benchmarking = { version = "2.0.0-rc6", path = "../benchmarking" }
rand_chacha = { version = "0.2" }
parking_lot = "0.10.2"
env_logger = "0.7.1"
hex = "0.4"
[features]
+1 -1
View File
@@ -452,7 +452,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::<Test>()
+2 -2
View File
@@ -1734,7 +1734,7 @@ fn bond_with_duplicate_vote_should_be_ignored_by_npos_election() {
.collect::<Vec<_>>(),
vec![(31, 1000), (21, 1000), (11, 1000)],
);
assert_eq!(<Nominators<Test>>::iter().map(|(n, _)| n).collect::<Vec<_>>(), vec![]);
assert!(<Nominators<Test>>::iter().map(|(n, _)| n).collect::<Vec<_>>().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<_>>(),
vec![(31, 100), (21, 1000), (11, 1000)],
);
assert_eq!(<Nominators<Test>>::iter().map(|(n, _)| n).collect::<Vec<_>>(), vec![]);
assert!(<Nominators<Test>>::iter().map(|(n, _)| n).collect::<Vec<_>>().is_empty());
// give the man some money
let initial_balance = 1000;
+15 -15
View File
@@ -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::<Test>::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::<Test>::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);
+3 -3
View File
@@ -656,7 +656,7 @@ mod test {
assert_eq!(MyStorage::final_prefix().to_vec(), k);
// test iteration
assert_eq!(MyStorage::iter_values().collect::<Vec<_>>(), vec![]);
assert!(MyStorage::iter_values().collect::<Vec<_>>().is_empty());
unhashed::put(&[&k[..], &vec![1][..]].concat(), &1u64);
unhashed::put(&[&k[..], &vec![1, 1][..]].concat(), &2u64);
@@ -667,13 +667,13 @@ mod test {
// test removal
MyStorage::remove_all();
assert_eq!(MyStorage::iter_values().collect::<Vec<_>>(), vec![]);
assert!(MyStorage::iter_values().collect::<Vec<_>>().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<_>>(), vec![]);
assert!(MyStorage::iter_values().collect::<Vec<_>>().is_empty());
MyStorage::translate_values(|v: u32| Some(v as u64));
assert_eq!(MyStorage::iter_values().collect::<Vec<_>>(), vec![1, 2]);
MyStorage::remove_all();
@@ -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]);
@@ -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"]
+2 -1
View File
@@ -15,7 +15,8 @@ targets = ["x86_64-unknown-linux-gnu"]
tracing = { version = "0.1.18", optional = true }
rental = { version = "0.5.5", optional = true }
log = { version = "0.4.8", optional = true }
tracing-subscriber = { version = "0.2.10", optional = true, features = ["tracing-log"] }
[features]
default = [ "std" ]
std = [ "tracing", "rental", "log" ]
std = [ "tracing", "rental", "log", "tracing-subscriber" ]
+8 -1
View File
@@ -44,6 +44,13 @@ pub mod proxy;
#[cfg(feature = "std")]
use std::sync::atomic::{AtomicBool, Ordering};
/// 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();
}
/// Flag to signal whether to run wasm tracing
#[cfg(feature = "std")]
static WASM_TRACING_ENABLED: AtomicBool = AtomicBool::new(false);
@@ -114,4 +121,4 @@ pub fn wasm_tracing_enabled() -> bool {
#[cfg(feature = "std")]
pub fn set_wasm_tracing(b: bool) {
WASM_TRACING_ENABLED.store(b, Ordering::Relaxed)
}
}
+1 -1
View File
@@ -31,5 +31,5 @@ sc-rpc-api = { version = "0.8.0-rc6", path = "../../../../client/rpc-api" }
[dev-dependencies]
substrate-test-runtime-client = { version = "2.0.0-rc6", path = "../../../../test-utils/runtime/client" }
env_logger = "0.7.0"
sp-tracing = { version = "2.0.0-rc6", path = "../../../../primitives/tracing" }
sc-transaction-pool = { version = "2.0.0-rc6", path = "../../../../client/transaction-pool" }
+4 -4
View File
@@ -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());