mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
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:
@@ -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.
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 = &[
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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"}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user