From c37b733b2eba2d2f41e719e7b635c8fac5587c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= <123550+andresilva@users.noreply.github.com> Date: Thu, 5 Jan 2023 12:33:08 +0000 Subject: [PATCH] grandpa: remove deprecated afg log target (#13064) * grandpa: remove deprecated afg log target * grandpa: define log targets in primitives --- client/finality-grandpa/src/lib.rs | 6 +++--- client/tracing/src/logging/mod.rs | 8 ++++---- frame/grandpa/src/lib.rs | 4 +--- primitives/finality-grandpa/Cargo.toml | 4 ++-- primitives/finality-grandpa/src/lib.rs | 11 +++++++---- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index 1597e60bd6061..8758efef6037f 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -76,6 +76,9 @@ use sp_application_crypto::AppKey; use sp_blockchain::{Error as ClientError, HeaderBackend, HeaderMetadata, Result as ClientResult}; use sp_consensus::SelectChain; use sp_core::crypto::ByteArray; +use sp_finality_grandpa::{ + AuthorityList, AuthoritySignature, SetId, CLIENT_LOG_TARGET as LOG_TARGET, +}; use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr}; use sp_runtime::{ generic::BlockId, @@ -93,8 +96,6 @@ use std::{ time::Duration, }; -const LOG_TARGET: &str = "grandpa"; - // utility logging macro that takes as first argument a conditional to // decide whether to log under debug or info level (useful to restrict // logging under initial sync). @@ -142,7 +143,6 @@ pub use voting_rule::{ use aux_schema::PersistentData; use communication::{Network as NetworkT, NetworkBridge}; use environment::{Environment, VoterSetState}; -use sp_finality_grandpa::{AuthorityList, AuthoritySignature, SetId}; use until_imported::UntilGlobalMessageBlocksImported; // Re-export these two because it's just so damn convenient. diff --git a/client/tracing/src/logging/mod.rs b/client/tracing/src/logging/mod.rs index 978e24df68d78..77307ad999daf 100644 --- a/client/tracing/src/logging/mod.rs +++ b/client/tracing/src/logging/mod.rs @@ -377,7 +377,7 @@ mod tests { fn test_logger_filters() { run_test_in_another_process("test_logger_filters", || { let test_directives = - "afg=debug,sync=trace,client=warn,telemetry,something-with-dash=error"; + "grandpa=debug,sync=trace,client=warn,telemetry,something-with-dash=error"; init_logger(&test_directives); tracing::dispatcher::get_default(|dispatcher| { @@ -402,9 +402,9 @@ mod tests { dispatcher.enabled(&metadata) }; - assert!(test_filter("afg", Level::INFO)); - assert!(test_filter("afg", Level::DEBUG)); - assert!(!test_filter("afg", Level::TRACE)); + assert!(test_filter("grandpa", Level::INFO)); + assert!(test_filter("grandpa", Level::DEBUG)); + assert!(!test_filter("grandpa", Level::TRACE)); assert!(test_filter("sync", Level::TRACE)); assert!(test_filter("client", Level::WARN)); diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 716cf54865773..aa09b445c6bdd 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -37,7 +37,7 @@ use codec::{self as codec, Decode, Encode, MaxEncodedLen}; pub use fg_primitives::{AuthorityId, AuthorityList, AuthorityWeight, VersionedAuthorityList}; use fg_primitives::{ ConsensusLog, EquivocationProof, ScheduledChange, SetId, GRANDPA_AUTHORITIES_KEY, - GRANDPA_ENGINE_ID, + GRANDPA_ENGINE_ID, RUNTIME_LOG_TARGET as LOG_TARGET, }; use frame_support::{ dispatch::{DispatchResultWithPostInfo, Pays}, @@ -70,8 +70,6 @@ pub use equivocation::{ pub use pallet::*; -const LOG_TARGET: &str = "runtime::grandpa"; - #[frame_support::pallet] pub mod pallet { use super::*; diff --git a/primitives/finality-grandpa/Cargo.toml b/primitives/finality-grandpa/Cargo.toml index 1c8011ff764e3..de8de99eed891 100644 --- a/primitives/finality-grandpa/Cargo.toml +++ b/primitives/finality-grandpa/Cargo.toml @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } grandpa = { package = "finality-grandpa", version = "0.16.0", default-features = false, features = ["derive-codec"] } -log = { version = "0.4.17", optional = true } +log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } serde = { version = "1.0.136", features = ["derive"], optional = true } sp-api = { version = "4.0.0-dev", default-features = false, path = "../api" } @@ -31,7 +31,7 @@ default = ["std"] std = [ "codec/std", "grandpa/std", - "log", + "log/std", "scale-info/std", "serde", "sp-api/std", diff --git a/primitives/finality-grandpa/src/lib.rs b/primitives/finality-grandpa/src/lib.rs index f92fee4f12963..7b3b55f49cee0 100644 --- a/primitives/finality-grandpa/src/lib.rs +++ b/primitives/finality-grandpa/src/lib.rs @@ -35,8 +35,10 @@ use sp_runtime::{ }; use sp_std::{borrow::Cow, vec::Vec}; -#[cfg(feature = "std")] -use log::debug; +/// The log target to be used by client code. +pub const CLIENT_LOG_TARGET: &str = "grandpa"; +/// The log target to be used by runtime code. +pub const RUNTIME_LOG_TARGET: &str = "runtime::grandpa"; /// Key type for GRANDPA module. pub const KEY_TYPE: sp_core::crypto::KeyTypeId = sp_application_crypto::key_types::GRANDPA; @@ -428,8 +430,9 @@ where let valid = id.verify(&buf, signature); if !valid { - #[cfg(feature = "std")] - debug!(target: "afg", "Bad signature on message from {:?}", id); + let log_target = if cfg!(feature = "std") { CLIENT_LOG_TARGET } else { RUNTIME_LOG_TARGET }; + + log::debug!(target: log_target, "Bad signature on message from {:?}", id); } valid