Skip to content

Commit

Permalink
Merge branch 'master' into update-from-master-22-jan
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Jan 22, 2024
2 parents 6391978 + bbfff66 commit 37ce47a
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 94 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions prdoc/pr_3009.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: "sc-informant: Respect `--disable-log-color`"

doc:
- audience: Node Operator
description: |
Fixes some places that weren't respecting the `--disable-log-color` CLI flag.

crates:
- name: "sc-informant"
- name: "sc-service"
2 changes: 1 addition & 1 deletion scripts/update-ui-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ export TRYBUILD=overwrite
$RUSTUP_RUN cargo test --manifest-path substrate/primitives/runtime-interface/Cargo.toml ui
$RUSTUP_RUN cargo test -p sp-api-test ui
$RUSTUP_RUN cargo test -p frame-election-provider-solution-type ui
$RUSTUP_RUN cargo test -p frame-support-test ui
$RUSTUP_RUN cargo test -p frame-support-test --features=no-metadata-docs,try-runtime,experimental ui
2 changes: 1 addition & 1 deletion substrate/client/chain-spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] }
memmap2 = "0.5.0"
memmap2 = "0.9.3"
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.111"
sc-client-api = { path = "../api" }
Expand Down
6 changes: 3 additions & 3 deletions substrate/client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use names::{Generator, Name};
use sc_service::{
config::{
BasePath, Configuration, DatabaseSource, KeystoreConfig, NetworkConfiguration,
NodeKeyConfig, OffchainWorkerConfig, PrometheusConfig, PruningMode, Role, RpcMethods,
TelemetryEndpoints, TransactionPoolOptions, WasmExecutionMethod,
NodeKeyConfig, OffchainWorkerConfig, OutputFormat, PrometheusConfig, PruningMode, Role,
RpcMethods, TelemetryEndpoints, TransactionPoolOptions, WasmExecutionMethod,
},
BlocksPruning, ChainSpec, TracingReceiver,
};
Expand Down Expand Up @@ -516,7 +516,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
announce_block: self.announce_block()?,
role,
base_path,
informant_output_format: Default::default(),
informant_output_format: OutputFormat { enable_color: !self.disable_log_color()? },
runtime_cache_size,
})
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/executor/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
thiserror = "1.0.48"
wasm-instrument = "0.3"
wasm-instrument = "0.4"
sc-allocator = { path = "../../allocator" }
sp-maybe-compressed-blob = { path = "../../../primitives/maybe-compressed-blob" }
sp-wasm-interface = { path = "../../../primitives/wasm-interface" }
Expand Down
45 changes: 14 additions & 31 deletions substrate/client/informant/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,37 +142,20 @@ impl<B: BlockT> InformantDisplay<B> {
("⚙️ ", format!("Preparing{}", speed), format!(", target=#{target}")),
};

if self.format.enable_color {
info!(
target: "substrate",
"{} {}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}",
level,
Colour::White.bold().paint(&status),
target,
Colour::White.bold().paint(format!("{}", num_connected_peers)),
Colour::White.bold().paint(format!("{}", best_number)),
best_hash,
Colour::White.bold().paint(format!("{}", finalized_number)),
info.chain.finalized_hash,
Colour::Green.paint(format!("⬇ {}", TransferRateFormat(avg_bytes_per_sec_inbound))),
Colour::Red.paint(format!("⬆ {}", TransferRateFormat(avg_bytes_per_sec_outbound))),
)
} else {
info!(
target: "substrate",
"{} {}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}",
level,
status,
target,
num_connected_peers,
best_number,
best_hash,
finalized_number,
info.chain.finalized_hash,
TransferRateFormat(avg_bytes_per_sec_inbound),
TransferRateFormat(avg_bytes_per_sec_outbound),
)
}
info!(
target: "substrate",
"{} {}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}",
level,
self.format.print_with_color(Colour::White.bold(), status),
target,
self.format.print_with_color(Colour::White.bold(), num_connected_peers),
self.format.print_with_color(Colour::White.bold(), best_number),
best_hash,
self.format.print_with_color(Colour::White.bold(), finalized_number),
info.chain.finalized_hash,
self.format.print_with_color(Colour::Green, format!("⬇ {}", TransferRateFormat(avg_bytes_per_sec_inbound))),
self.format.print_with_color(Colour::Red, format!("⬆ {}", TransferRateFormat(avg_bytes_per_sec_outbound))),
)
}
}

Expand Down
58 changes: 51 additions & 7 deletions substrate/client/informant/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

//! Console informant. Prints sync progress and block events. Runs on the calling thread.

use ansi_term::Colour;
use ansi_term::{Colour, Style};
use futures::prelude::*;
use futures_timer::Delay;
use log::{debug, info, trace};
Expand Down Expand Up @@ -51,6 +51,47 @@ impl Default for OutputFormat {
}
}

enum ColorOrStyle {
Color(Colour),
Style(Style),
}

impl From<Colour> for ColorOrStyle {
fn from(value: Colour) -> Self {
Self::Color(value)
}
}

impl From<Style> for ColorOrStyle {
fn from(value: Style) -> Self {
Self::Style(value)
}
}

impl ColorOrStyle {
fn paint(&self, data: String) -> impl Display {
match self {
Self::Color(c) => c.paint(data),
Self::Style(s) => s.paint(data),
}
}
}

impl OutputFormat {
/// Print with color if `self.enable_color == true`.
fn print_with_color(
&self,
color: impl Into<ColorOrStyle>,
data: impl ToString,
) -> impl Display {
if self.enable_color {
color.into().paint(data.to_string()).to_string()
} else {
data.to_string()
}
}
}

/// Builds the informant and returns a `Future` that drives the informant.
pub async fn build<B: BlockT, C, N, S>(client: Arc<C>, network: N, syncing: S, format: OutputFormat)
where
Expand Down Expand Up @@ -89,11 +130,14 @@ where

futures::select! {
() = display_notifications.fuse() => (),
() = display_block_import(client).fuse() => (),
() = display_block_import(client, format).fuse() => (),
};
}

fn display_block_import<B: BlockT, C>(client: Arc<C>) -> impl Future<Output = ()>
fn display_block_import<B: BlockT, C>(
client: Arc<C>,
format: OutputFormat,
) -> impl Future<Output = ()>
where
C: UsageProvider<B> + HeaderMetadata<B> + BlockchainEvents<B>,
<C as HeaderMetadata<B>>::Error: Display,
Expand All @@ -117,11 +161,11 @@ where
match maybe_ancestor {
Ok(ref ancestor) if ancestor.hash != *last_hash => info!(
"♻️ Reorg on #{},{} to #{},{}, common ancestor #{},{}",
Colour::Red.bold().paint(format!("{}", last_num)),
format.print_with_color(Colour::Red.bold(), last_num),
last_hash,
Colour::Green.bold().paint(format!("{}", n.header.number())),
format.print_with_color(Colour::Green.bold(), n.header.number()),
n.hash,
Colour::White.bold().paint(format!("{}", ancestor.number)),
format.print_with_color(Colour::White.bold(), ancestor.number),
ancestor.hash,
),
Ok(_) => {},
Expand All @@ -146,7 +190,7 @@ where
info!(
target: "substrate",
"✨ Imported #{} ({})",
Colour::White.bold().paint(format!("{}", n.header.number())),
format.print_with_color(Colour::White.bold(), n.header.number()),
n.hash,
);
}
Expand Down
8 changes: 4 additions & 4 deletions substrate/client/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@

//! Service configuration.

use prometheus_endpoint::Registry;
use sc_chain_spec::ChainSpec;
pub use sc_client_db::{BlocksPruning, Database, DatabaseSource, PruningMode};
pub use sc_executor::{WasmExecutionMethod, WasmtimeInstantiationStrategy};
pub use sc_informant::OutputFormat;
pub use sc_network::{
config::{
MultiaddrWithPeerId, NetworkConfiguration, NodeKeyConfig, NonDefaultSetConfig, ProtocolId,
Expand All @@ -30,9 +33,6 @@ pub use sc_network::{
},
Multiaddr,
};

use prometheus_endpoint::Registry;
use sc_chain_spec::ChainSpec;
pub use sc_telemetry::TelemetryEndpoints;
pub use sc_transaction_pool::Options as TransactionPoolOptions;
use sp_core::crypto::SecretString;
Expand Down Expand Up @@ -134,7 +134,7 @@ pub struct Configuration {
/// Base path of the configuration. This is shared between chains.
pub base_path: BasePath,
/// Configuration of the output format that the informant uses.
pub informant_output_format: sc_informant::OutputFormat,
pub informant_output_format: OutputFormat,
/// Maximum number of different runtime versions that can be cached.
pub runtime_cache_size: u8,
}
Expand Down
Loading

0 comments on commit 37ce47a

Please sign in to comment.