mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -40,7 +40,6 @@ use wasm_timer::Instant;
|
||||
///
|
||||
/// Call `InformantDisplay::new` to initialize the state, then regularly call `display` with the
|
||||
/// information to display.
|
||||
///
|
||||
pub struct InformantDisplay<B: BlockT> {
|
||||
/// Head of chain block number from the last time `display` has been called.
|
||||
/// `None` if `display` has never been called.
|
||||
@@ -84,34 +83,32 @@ impl<B: BlockT> InformantDisplay<B> {
|
||||
|
||||
let diff_bytes_inbound = total_bytes_inbound - self.last_total_bytes_inbound;
|
||||
let diff_bytes_outbound = total_bytes_outbound - self.last_total_bytes_outbound;
|
||||
let (avg_bytes_per_sec_inbound, avg_bytes_per_sec_outbound) =
|
||||
if elapsed > 0 {
|
||||
self.last_total_bytes_inbound = total_bytes_inbound;
|
||||
self.last_total_bytes_outbound = total_bytes_outbound;
|
||||
(diff_bytes_inbound / elapsed, diff_bytes_outbound / elapsed)
|
||||
} else {
|
||||
(diff_bytes_inbound, diff_bytes_outbound)
|
||||
};
|
||||
|
||||
let (level, status, target) = match (
|
||||
net_status.sync_state,
|
||||
net_status.best_seen_block,
|
||||
net_status.state_sync
|
||||
) {
|
||||
(_, _, Some(state)) => (
|
||||
"⚙️ ",
|
||||
"Downloading state".into(),
|
||||
format!(", {}%, ({:.2}) Mib", state.percentage, (state.size as f32) / (1024f32 * 1024f32)),
|
||||
),
|
||||
(SyncState::Idle, _, _) => ("💤", "Idle".into(), "".into()),
|
||||
(SyncState::Downloading, None, _) => ("⚙️ ", format!("Preparing{}", speed), "".into()),
|
||||
(SyncState::Downloading, Some(n), None) => (
|
||||
"⚙️ ",
|
||||
format!("Syncing{}", speed),
|
||||
format!(", target=#{}", n),
|
||||
),
|
||||
let (avg_bytes_per_sec_inbound, avg_bytes_per_sec_outbound) = if elapsed > 0 {
|
||||
self.last_total_bytes_inbound = total_bytes_inbound;
|
||||
self.last_total_bytes_outbound = total_bytes_outbound;
|
||||
(diff_bytes_inbound / elapsed, diff_bytes_outbound / elapsed)
|
||||
} else {
|
||||
(diff_bytes_inbound, diff_bytes_outbound)
|
||||
};
|
||||
|
||||
let (level, status, target) =
|
||||
match (net_status.sync_state, net_status.best_seen_block, net_status.state_sync) {
|
||||
(_, _, Some(state)) => (
|
||||
"⚙️ ",
|
||||
"Downloading state".into(),
|
||||
format!(
|
||||
", {}%, ({:.2}) Mib",
|
||||
state.percentage,
|
||||
(state.size as f32) / (1024f32 * 1024f32)
|
||||
),
|
||||
),
|
||||
(SyncState::Idle, _, _) => ("💤", "Idle".into(), "".into()),
|
||||
(SyncState::Downloading, None, _) =>
|
||||
("⚙️ ", format!("Preparing{}", speed), "".into()),
|
||||
(SyncState::Downloading, Some(n), None) =>
|
||||
("⚙️ ", format!("Syncing{}", speed), format!(", target=#{}", n)),
|
||||
};
|
||||
|
||||
if self.format.enable_color {
|
||||
info!(
|
||||
target: "substrate",
|
||||
@@ -151,7 +148,7 @@ impl<B: BlockT> InformantDisplay<B> {
|
||||
fn speed<B: BlockT>(
|
||||
best_number: NumberFor<B>,
|
||||
last_number: Option<NumberFor<B>>,
|
||||
last_update: Instant
|
||||
last_update: Instant,
|
||||
) -> String {
|
||||
// Number of milliseconds elapsed since last time.
|
||||
let elapsed_ms = {
|
||||
@@ -164,25 +161,28 @@ fn speed<B: BlockT>(
|
||||
// Number of blocks that have been imported since last time.
|
||||
let diff = match last_number {
|
||||
None => return String::new(),
|
||||
Some(n) => best_number.saturating_sub(n)
|
||||
Some(n) => best_number.saturating_sub(n),
|
||||
};
|
||||
|
||||
if let Ok(diff) = TryInto::<u128>::try_into(diff) {
|
||||
// If the number of blocks can be converted to a regular integer, then it's easy: just
|
||||
// do the math and turn it into a `f64`.
|
||||
let speed = diff.saturating_mul(10_000).checked_div(u128::from(elapsed_ms))
|
||||
.map_or(0.0, |s| s as f64) / 10.0;
|
||||
let speed = diff
|
||||
.saturating_mul(10_000)
|
||||
.checked_div(u128::from(elapsed_ms))
|
||||
.map_or(0.0, |s| s as f64) /
|
||||
10.0;
|
||||
format!(" {:4.1} bps", speed)
|
||||
|
||||
} else {
|
||||
// If the number of blocks can't be converted to a regular integer, then we need a more
|
||||
// algebraic approach and we stay within the realm of integers.
|
||||
let one_thousand = NumberFor::<B>::from(1_000u32);
|
||||
let elapsed = NumberFor::<B>::from(
|
||||
<u32 as TryFrom<_>>::try_from(elapsed_ms).unwrap_or(u32::MAX)
|
||||
);
|
||||
let elapsed =
|
||||
NumberFor::<B>::from(<u32 as TryFrom<_>>::try_from(elapsed_ms).unwrap_or(u32::MAX));
|
||||
|
||||
let speed = diff.saturating_mul(one_thousand).checked_div(&elapsed)
|
||||
let speed = diff
|
||||
.saturating_mul(one_thousand)
|
||||
.checked_div(&elapsed)
|
||||
.unwrap_or_else(Zero::zero);
|
||||
format!(" {} bps", speed)
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ use log::{info, trace, warn};
|
||||
use parity_util_mem::MallocSizeOf;
|
||||
use sc_client_api::{BlockchainEvents, UsageProvider};
|
||||
use sc_network::NetworkService;
|
||||
use sc_transaction_pool_api::TransactionPool;
|
||||
use sp_blockchain::HeaderMetadata;
|
||||
use sp_runtime::traits::{Block as BlockT, Header};
|
||||
use sc_transaction_pool_api::TransactionPool;
|
||||
use std::{fmt::Display, sync::Arc, time::Duration, collections::VecDeque};
|
||||
use std::{collections::VecDeque, fmt::Display, sync::Arc, time::Duration};
|
||||
|
||||
mod display;
|
||||
|
||||
@@ -48,9 +48,7 @@ pub struct OutputFormat {
|
||||
|
||||
impl Default for OutputFormat {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enable_color: true,
|
||||
}
|
||||
Self { enable_color: true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,8 +72,7 @@ pub async fn build<B: BlockT, C>(
|
||||
network: Arc<NetworkService<B, <B as BlockT>::Hash>>,
|
||||
pool: Arc<impl TransactionPoolAndMaybeMallogSizeOf>,
|
||||
format: OutputFormat,
|
||||
)
|
||||
where
|
||||
) where
|
||||
C: UsageProvider<B> + HeaderMetadata<B> + BlockchainEvents<B>,
|
||||
<C as HeaderMetadata<B>>::Error: Display,
|
||||
{
|
||||
@@ -131,19 +128,19 @@ where
|
||||
client.import_notification_stream().for_each(move |n| {
|
||||
// detect and log reorganizations.
|
||||
if let Some((ref last_num, ref last_hash)) = last_best {
|
||||
if n.header.parent_hash() != last_hash && n.is_new_best {
|
||||
let maybe_ancestor = sp_blockchain::lowest_common_ancestor(
|
||||
&*client,
|
||||
last_hash.clone(),
|
||||
n.hash,
|
||||
);
|
||||
if n.header.parent_hash() != last_hash && n.is_new_best {
|
||||
let maybe_ancestor =
|
||||
sp_blockchain::lowest_common_ancestor(&*client, last_hash.clone(), n.hash);
|
||||
|
||||
match maybe_ancestor {
|
||||
Ok(ref ancestor) if ancestor.hash != *last_hash => info!(
|
||||
"♻️ Reorg on #{},{} to #{},{}, common ancestor #{},{}",
|
||||
Colour::Red.bold().paint(format!("{}", last_num)), last_hash,
|
||||
Colour::Green.bold().paint(format!("{}", n.header.number())), n.hash,
|
||||
Colour::White.bold().paint(format!("{}", ancestor.number)), ancestor.hash,
|
||||
Colour::Red.bold().paint(format!("{}", last_num)),
|
||||
last_hash,
|
||||
Colour::Green.bold().paint(format!("{}", n.header.number())),
|
||||
n.hash,
|
||||
Colour::White.bold().paint(format!("{}", ancestor.number)),
|
||||
ancestor.hash,
|
||||
),
|
||||
Ok(_) => {},
|
||||
Err(e) => warn!("Error computing tree route: {}", e),
|
||||
@@ -155,7 +152,6 @@ where
|
||||
last_best = Some((n.header.number().clone(), n.hash.clone()));
|
||||
}
|
||||
|
||||
|
||||
// If we already printed a message for a given block recently,
|
||||
// we should not print it again.
|
||||
if !last_blocks.contains(&n.hash) {
|
||||
|
||||
Reference in New Issue
Block a user