Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

Commit

Permalink
upstream patch fixes (#160)
Browse files Browse the repository at this point in the history
* Fixes logging of target names with dashes (#7281)

* Fixes logging of target names with dashes

There was a bug in tracing-core which resulted in not supporting dashes
in target names. This was fixed upstream. Besides that a test was added
to ensure that we don't break this again.

* Extend test

* client: fix log filters (#7241)

* client: fix multiple logger filters

* client: add test for log filters setup

* Fix logging from inside the WASM runtime (#7355)

* Fix logging from inside the WASM runtime

When using `RuntimeLogger` to log something from the runtime, we didn't
set any logging level. So, we actually did not log anything from the
runtime as logging is disabled by default. This pr fixes that by setting
the logging level to `TRACE`. It also adds a test to ensure this does
not break again ;)

* Update frame/support/src/debug.rs

* Print an error if an unregistered notifications protocol is used (#7457)

* Print an error if an nregistered notifications protocol is used

* Print an error if an nregistered notifications protocol is used

* Update client/network/src/service.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Fix wrong outgoing calculation in election (#7384)

* Fix wrong outgoing calculation in election

* Add test.

* Lil bit better naming.

* grandpa: fix tests

* *: Bump async-std to v1.6.5 (#7306)

* *: Bump async-std to v1.6.5

Prevent users from using v1.6.4 which faces issues receiving incoming
TCP connections. See async-rs/async-std#888
for details.

* client/network/src/gossip: Use channel instead of condvar

`async_std::sync::Condvar::wait_timeout` uses
`gloo_timers::callback::Timeout` when compiled for
`wasm32-unknown-unknown`. This timeout implementation does not fulfill
the requirement of being `Send`.

Instead of using a `Condvar` use a `futures::channel::mpsc` to signal
progress from the `QueuedSender` to the background `Future`.

* client/network/Cargo.toml: Remove async-std unstable feature

* client/network/src/gossip: Forward all queued messages

* client/network/gossip: Have QueuedSender methods take &mut self

* client/network/gossip: Move queue_size_limit into QueuedSender

The `queue_size_limit` field is only accessed by `QueuedSender`, thus
there is no need to share it between the background future and the
`QueuedSender`.

* client/network/gossip: Rename background task to future

To be a bit picky the background task is not a task in the sense of an
asynchonous task, but rather a background future in the sense of
`futures::future::Future`.

* client/network: Remove option to disable yamux flow control (#7358)

With the `OnRead` flow control option yamux "send[s] window updates only
when data is read on the receiving end" and not as soon as "a Stream's
receive window drops to 0".

Yamux flow control has proven itself. This commit removes the feature
flag. Yamux flow control is now always enabled.

* Make `queryStorage` and `storagePairs` unsafe RPC functions (#7342)

The RPC calls can be rather expensive and can easily bring a RPC node in
some problems ;)

* consensus: prioritize finality work over block import in queue (#7307)

* consensus: prioritize finality work over block import in queue

* consensus: add test for import queue task priority

* sync: only restart peers not doing finality related requests (#7322)

* sync: only restart peers not doing finality related requests

* sync: add test for sync restart

* sync: add better docs to restart method

* Undo phragmen merge

* grandpa: fix early enactment of forced changes (#7321)

* grandpa: fix early enactment of forced authority set changes

* grandpa: add test for early enactment of forced changes

* grandpa: fix typo in log message

* grandpa: only allow one pending forced change per fork

* grandpa: fix tests

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: André Silva <andrerfosilva@gmail.com>
Co-authored-by: Max Inden <mail@max-inden.de>
  • Loading branch information
7 people authored Nov 11, 2020
1 parent c0ee046 commit d3d9596
Show file tree
Hide file tree
Showing 30 changed files with 1,105 additions and 358 deletions.
193 changes: 130 additions & 63 deletions Cargo.lock

Large diffs are not rendered by default.

86 changes: 83 additions & 3 deletions client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use structopt::{
clap::{self, AppSettings},
StructOpt,
};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::{filter::Directive, layer::SubscriberExt};

/// Substrate client CLI
///
Expand Down Expand Up @@ -234,6 +234,13 @@ pub fn init_logger(
tracing_receiver: sc_tracing::TracingReceiver,
tracing_targets: Option<String>,
) -> std::result::Result<(), String> {
fn parse_directives(dirs: impl AsRef<str>) -> Vec<Directive> {
dirs.as_ref()
.split(',')
.filter_map(|s| s.parse().ok())
.collect()
}

if let Err(e) = tracing_log::LogTracer::init() {
return Err(format!(
"Registering Substrate logger failed: {:}!", e
Expand All @@ -257,7 +264,7 @@ pub fn init_logger(
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() {
for directive in parse_directives(lvl) {
env_filter = env_filter.add_directive(directive);
}
}
Expand All @@ -266,7 +273,7 @@ pub fn init_logger(
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() {
for directive in parse_directives(pattern) {
env_filter = env_filter.add_directive(directive);
}
}
Expand Down Expand Up @@ -299,3 +306,76 @@ pub fn init_logger(
}
Ok(())
}
mod tests {
use super::*;
use tracing::{metadata::Kind, subscriber::Interest, Callsite, Level, Metadata};
use std::{process::Command, env};

#[test]
fn test_logger_filters() {
let test_pattern = "afg=debug,sync=trace,client=warn,telemetry,something-with-dash=error";
init_logger(&test_pattern, Default::default(), Default::default()).unwrap();

tracing::dispatcher::get_default(|dispatcher| {
let test_filter = |target, level| {
struct DummyCallSite;
impl Callsite for DummyCallSite {
fn set_interest(&self, _: Interest) {}
fn metadata(&self) -> &Metadata<'_> {
unreachable!();
}
}

let metadata = tracing::metadata!(
name: "",
target: target,
level: level,
fields: &[],
callsite: &DummyCallSite,
kind: Kind::SPAN,
);

dispatcher.enabled(&metadata)
};

assert!(test_filter("afg", Level::INFO));
assert!(test_filter("afg", Level::DEBUG));
assert!(!test_filter("afg", Level::TRACE));

assert!(test_filter("sync", Level::TRACE));
assert!(test_filter("client", Level::WARN));

assert!(test_filter("telemetry", Level::TRACE));
assert!(test_filter("something-with-dash", Level::ERROR));
});
}

const EXPECTED_LOG_MESSAGE: &'static str = "yeah logging works as expected";

#[test]
fn dash_in_target_name_works() {
let executable = env::current_exe().unwrap();
let output = Command::new(executable)
.env("ENABLE_LOGGING", "1")
.args(&["--nocapture", "log_something_with_dash_target_name"])
.output()
.unwrap();

let output = String::from_utf8(output.stderr).unwrap();
assert!(output.contains(EXPECTED_LOG_MESSAGE));
}

/// This is no actual test, it will be used by the `dash_in_target_name_works` test.
/// The given test will call the test executable to only execute this test that
/// will only print `EXPECTED_LOG_MESSAGE` through logging while using a target
/// name that contains a dash. This ensures that targets names with dashes work.
#[test]
fn log_something_with_dash_target_name() {
if env::var("ENABLE_LOGGING").is_ok() {
let test_pattern = "test-target=info";
init_logger(&test_pattern, Default::default(), Default::default()).unwrap();

log::info!(target: "test-target", "{}", EXPECTED_LOG_MESSAGE);
}
}
}
6 changes: 0 additions & 6 deletions client/cli/src/params/network_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ pub struct NetworkParams {
#[structopt(flatten)]
pub node_key_params: NodeKeyParams,

/// Disable the yamux flow control. This option will be removed in the future once there is
/// enough confidence that this feature is properly working.
#[structopt(long)]
pub no_yamux_flow_control: bool,

/// Enable peer discovery on local networks.
///
/// By default this option is true for `--dev` and false otherwise.
Expand Down Expand Up @@ -158,7 +153,6 @@ impl NetworkParams {
enable_mdns: !is_dev && !self.no_mdns,
allow_private_ipv4: !self.no_private_ipv4,
wasm_external_transport: None,
use_yamux_flow_control: !self.no_yamux_flow_control,
},
max_parallel_downloads: self.max_parallel_downloads,
allow_non_globals_in_dht: self.discover_local || is_dev,
Expand Down
Loading

0 comments on commit d3d9596

Please sign in to comment.