From 02b7dc67d239cf09dee0f9e7e8cf2f0212e39e5f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Apr 2022 10:39:33 +0200 Subject: [PATCH 1/3] Bump tracing-core from 0.1.21 to 0.1.26 (#11258) Bumps [tracing-core](https://github.com/tokio-rs/tracing) from 0.1.21 to 0.1.26. - [Release notes](https://github.com/tokio-rs/tracing/releases) - [Commits](https://github.com/tokio-rs/tracing/compare/tracing-core-0.1.21...tracing-core-0.1.26) --- updated-dependencies: - dependency-name: tracing-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 11 +++++++++-- primitives/io/Cargo.toml | 2 +- primitives/runtime-interface/test/Cargo.toml | 2 +- primitives/tracing/Cargo.toml | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1a23117235e0..486cb083bca99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11383,11 +11383,12 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.21" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f" dependencies = [ "lazy_static", + "valuable", ] [[package]] @@ -11764,6 +11765,12 @@ dependencies = [ "percent-encoding 2.1.0", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "value-bag" version = "1.0.0-alpha.8" diff --git a/primitives/io/Cargo.toml b/primitives/io/Cargo.toml index 9964fe2eea318..6d0ac398e473d 100644 --- a/primitives/io/Cargo.toml +++ b/primitives/io/Cargo.toml @@ -32,7 +32,7 @@ futures = { version = "0.3.21", features = ["thread-pool"], optional = true } parking_lot = { version = "0.12.0", optional = true } secp256k1 = { version = "0.21.2", features = ["recovery", "global-context"], optional = true } tracing = { version = "0.1.29", default-features = false } -tracing-core = { version = "0.1.17", default-features = false} +tracing-core = { version = "0.1.26", default-features = false} [features] default = ["std"] diff --git a/primitives/runtime-interface/test/Cargo.toml b/primitives/runtime-interface/test/Cargo.toml index 3b51088ea3779..60962bb16caf5 100644 --- a/primitives/runtime-interface/test/Cargo.toml +++ b/primitives/runtime-interface/test/Cargo.toml @@ -21,4 +21,4 @@ sp-state-machine = { version = "0.12.0", path = "../../state-machine" } sp-runtime = { version = "6.0.0", path = "../../runtime" } sp-io = { version = "6.0.0", path = "../../io" } tracing = "0.1.29" -tracing-core = "0.1.17" +tracing-core = "0.1.26" diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 3f53cc2e6c5c6..d305b756e2d68 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -23,7 +23,7 @@ codec = { version = "3.0.0", package = "parity-scale-codec", default-features = "derive", ] } tracing = { version = "0.1.29", default-features = false } -tracing-core = { version = "0.1.21", default-features = false } +tracing-core = { version = "0.1.26", default-features = false } tracing-subscriber = { version = "0.2.25", optional = true, features = [ "tracing-log", ] } From 662598908902ec8879fcd6a950324ef6735ea1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 22 Apr 2022 16:58:53 +0200 Subject: [PATCH 2/3] BABE: Fix aux data cleaning (#11263) With the latest optimizations of the `FinalityNotification` generation, the aux data pruning started to print a warning. The problem here was that we printed a warning and stopped the adding of blocks to prune when we hit the `heigh_limit`. This is now wrong, as we could for example have two 512 long forks and then we start finalizing one of them. The second fork head would be part of the stale heads at some point (in the current implementation when we finalize second fork head number + 1), but then we would actually need to go back into the past than `heigh_limit` (which was actually last_finalized - 1). We now go back until we reach the canonical chain. Also fixed some wrong comment that was added by be about the content of the `finalized` blocks in the `FinalityNotification`. --- client/api/src/client.rs | 2 +- client/consensus/babe/src/lib.rs | 59 +++++++++++++++++++----------- client/consensus/babe/src/tests.rs | 9 +++++ 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/client/api/src/client.rs b/client/api/src/client.rs index 183ce610e7b7c..c4b01fbd0abbd 100644 --- a/client/api/src/client.rs +++ b/client/api/src/client.rs @@ -308,7 +308,7 @@ pub struct FinalityNotification { pub header: Block::Header, /// Path from the old finalized to new finalized parent (implicitly finalized blocks). /// - /// This maps to the range `(old_finalized, new_finalized]`. + /// This maps to the range `(old_finalized, new_finalized)`. pub tree_route: Arc<[Block::Hash]>, /// Stale branches heads. pub stale_heads: Arc<[Block::Hash]>, diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index 3d3a7f24df816..be5c2809bd796 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -541,49 +541,66 @@ where // Remove obsolete block's weight data by leveraging finality notifications. // This includes data for all finalized blocks (excluding the most recent one) // and all stale branches. -fn aux_storage_cleanup, Block: BlockT>( +fn aux_storage_cleanup + HeaderBackend, Block: BlockT>( client: &C, notification: &FinalityNotification, ) -> AuxDataOperations { let mut aux_keys = HashSet::new(); - // Cleans data for finalized block's ancestors down to, and including, the previously - // finalized one. - - let first_new_finalized = notification.tree_route.get(0).unwrap_or(¬ification.hash); - match client.header_metadata(*first_new_finalized) { + let first = notification.tree_route.first().unwrap_or(¬ification.hash); + match client.header_metadata(*first) { Ok(meta) => { aux_keys.insert(aux_schema::block_weight_key(meta.parent)); }, - Err(err) => { - warn!(target: "babe", "header lookup fail while cleaning data for block {}: {}", first_new_finalized.to_string(), err.to_string()); - }, + Err(err) => warn!( + target: "babe", + "Failed to lookup metadata for block `{:?}`: {}", + first, + err, + ), } - aux_keys.extend(notification.tree_route.iter().map(aux_schema::block_weight_key)); + // Cleans data for finalized block's ancestors + aux_keys.extend( + notification + .tree_route + .iter() + // Ensure we don't prune latest finalized block. + // This should not happen, but better be safe than sorry! + .filter(|h| **h != notification.hash) + .map(aux_schema::block_weight_key), + ); // Cleans data for stale branches. - // A safenet in case of malformed notification. - let height_limit = notification.header.number().saturating_sub( - notification.tree_route.len().saturated_into::>() + One::one(), - ); for head in notification.stale_heads.iter() { let mut hash = *head; - // Insert stale blocks hashes until canonical chain is not reached. - // Soon or late we should hit an element already present within the `aux_keys` set. + // Insert stale blocks hashes until canonical chain is reached. + // If we reach a block that is already part of the `aux_keys` we can stop the processing the + // head. while aux_keys.insert(aux_schema::block_weight_key(hash)) { match client.header_metadata(hash) { Ok(meta) => { - // This should never happen and must be considered a bug. - if meta.number <= height_limit { - warn!(target: "babe", "unexpected canonical chain state or malformed finality notification"); + hash = meta.parent; + + // If the parent is part of the canonical chain or there doesn't exist a block + // hash for the parent number (bug?!), we can abort adding blocks. + if client + .hash(meta.number.saturating_sub(1u32.into())) + .ok() + .flatten() + .map_or(true, |h| h == hash) + { break } - hash = meta.parent; }, Err(err) => { - warn!(target: "babe", "header lookup fail while cleaning data for block {}: {}", head.to_string(), err.to_string()); + warn!( + target: "babe", + "Header lookup fail while cleaning data for block {:?}: {}", + hash, + err, + ); break }, } diff --git a/client/consensus/babe/src/tests.rs b/client/consensus/babe/src/tests.rs index aa2d824b8ccb9..db19deda06fd8 100644 --- a/client/consensus/babe/src/tests.rs +++ b/client/consensus/babe/src/tests.rs @@ -1043,4 +1043,13 @@ fn obsolete_blocks_aux_data_cleanup() { assert!(aux_data_check(&fork2_hashes, false)); // Present C4, C5 assert!(aux_data_check(&fork3_hashes, true)); + + client.finalize_block(BlockId::Number(4), None, true).unwrap(); + + // Wiped: A3 + assert!(aux_data_check(&fork1_hashes[2..3], false)); + // Present: A4 + assert!(aux_data_check(&fork1_hashes[3..], true)); + // Present C4, C5 + assert!(aux_data_check(&fork3_hashes, true)); } From 52cc538d8e51ca7af1bfa0138b76c1b358c70692 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Mon, 25 Apr 2022 07:16:38 +0300 Subject: [PATCH 3/3] More efficient identity and multiplier weight to fee (#11226) --- frame/support/src/weights.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frame/support/src/weights.rs b/frame/support/src/weights.rs index 4c3fcaa0fd423..5b4a13e7f9457 100644 --- a/frame/support/src/weights.rs +++ b/frame/support/src/weights.rs @@ -710,6 +710,10 @@ where degree: 1, }) } + + fn calc(weight: &Weight) -> Self::Balance { + Self::Balance::saturated_from(*weight) + } } /// Implementor of [`WeightToFeePolynomial`] that uses a constant multiplier. @@ -738,6 +742,10 @@ where degree: 1, }) } + + fn calc(weight: &Weight) -> Self::Balance { + Self::Balance::saturated_from(*weight).saturating_mul(M::get()) + } } /// A struct holding value for each `DispatchClass`.