introduce log-target constant to more frame pallets (#13116)

* introduce log-target constant to more frame pallets

* cargo fmt

* make LOG_TARGET in session public

* Update frame/elections-phragmen/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update frame/elections-phragmen/src/migrations/v3.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update frame/elections-phragmen/src/migrations/v3.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update frame/elections-phragmen/src/migrations/v3.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* move LOG_TARGET=runtime::session_historical to migrations module, where it's actually used

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Anthony Alaribe
2023-01-10 20:18:12 +01:00
committed by GitHub
parent 72f086b795
commit c04e68fd01
18 changed files with 89 additions and 71 deletions
+1
View File
@@ -175,6 +175,7 @@ pub use pallet::*;
pub use weights::WeightInfo;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
const LOG_TARGET: &str = "runtime::assets";
/// Trait with callbacks that are executed after successfull asset creation or destruction.
pub trait AssetsCallback<AssetId, AccountId> {
+10 -2
View File
@@ -75,10 +75,18 @@ pub mod v1 {
Some(old_value.migrate_to_v1())
});
current_version.put::<Pallet<T>>();
log::info!(target: "runtime::assets", "Upgraded {} pools, storage to version {:?}", translated, current_version);
log::info!(
target: LOG_TARGET,
"Upgraded {} pools, storage to version {:?}",
translated,
current_version
);
T::DbWeight::get().reads_writes(translated + 1, translated + 1)
} else {
log::info!(target: "runtime::assets", "Migration did not execute. This probably should be removed");
log::info!(
target: LOG_TARGET,
"Migration did not execute. This probably should be removed"
);
T::DbWeight::get().reads(1)
}
}
+4 -2
View File
@@ -193,6 +193,8 @@ pub use weights::WeightInfo;
pub use pallet::*;
const LOG_TARGET: &str = "runtime::balances";
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
#[frame_support::pallet]
@@ -950,7 +952,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
if locks.len() as u32 > T::MaxLocks::get() {
log::warn!(
target: "runtime::balances",
target: LOG_TARGET,
"Warning: A user has more currency locks than expected. \
A runtime configuration adjustment may be needed."
);
@@ -985,7 +987,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
// since the funds that are under the lock will themselves be stored in the
// account and therefore will need a reference.
log::warn!(
target: "runtime::balances",
target: LOG_TARGET,
"Warning: Attempt to introduce lock consumer reference, yet no providers. \
This is unexpected but should be safe."
);
+10 -4
View File
@@ -40,10 +40,13 @@ fn migrate_v0_to_v1<T: Config<I>, I: 'static>(accounts: &[T::AccountId]) -> Weig
// Set storage version to `1`.
StorageVersion::new(1).put::<Pallet<T, I>>();
log::info!(target: "runtime::balances", "Storage to version 1");
log::info!(target: LOG_TARGET, "Storage to version 1");
T::DbWeight::get().reads_writes(2 + accounts.len() as u64, 3)
} else {
log::info!(target: "runtime::balances", "Migration did not execute. This probably should be removed");
log::info!(
target: LOG_TARGET,
"Migration did not execute. This probably should be removed"
);
T::DbWeight::get().reads(1)
}
}
@@ -87,10 +90,13 @@ impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for ResetInactive<T, I> {
// Set storage version to `0`.
StorageVersion::new(0).put::<Pallet<T, I>>();
log::info!(target: "runtime::balances", "Storage to version 0");
log::info!(target: LOG_TARGET, "Storage to version 0");
T::DbWeight::get().reads_writes(1, 2)
} else {
log::info!(target: "runtime::balances", "Migration did not execute. This probably should be removed");
log::info!(
target: LOG_TARGET,
"Migration did not execute. This probably should be removed"
);
T::DbWeight::get().reads(1)
}
}
+5 -3
View File
@@ -71,6 +71,8 @@ pub mod weights;
pub use pallet::*;
pub use weights::WeightInfo;
const LOG_TARGET: &str = "runtime::collective";
/// Simple index type for proposal counting.
pub type ProposalIndex = u32;
@@ -390,7 +392,7 @@ pub mod pallet {
ensure_root(origin)?;
if new_members.len() > T::MaxMembers::get() as usize {
log::error!(
target: "runtime::collective",
target: LOG_TARGET,
"New members count ({}) exceeds maximum amount of members expected ({}).",
new_members.len(),
T::MaxMembers::get(),
@@ -400,7 +402,7 @@ pub mod pallet {
let old = Members::<T, I>::get();
if old.len() > old_count as usize {
log::warn!(
target: "runtime::collective",
target: LOG_TARGET,
"Wrong count used to estimate set_members weight. expected ({}) vs actual ({})",
old_count,
old.len(),
@@ -1040,7 +1042,7 @@ impl<T: Config<I>, I: 'static> ChangeMembers<T::AccountId> for Pallet<T, I> {
) {
if new.len() > T::MaxMembers::get() as usize {
log::error!(
target: "runtime::collective",
target: LOG_TARGET,
"New members count ({}) exceeds maximum amount of members expected ({}).",
new.len(),
T::MaxMembers::get(),
@@ -17,6 +17,7 @@
use sp_io::hashing::twox_128;
use super::super::LOG_TARGET;
use frame_support::{
traits::{
Get, GetStorageVersion, PalletInfoAccess, StorageVersion,
@@ -42,7 +43,7 @@ pub fn migrate<T: frame_system::Config, P: GetStorageVersion + PalletInfoAccess,
if new_pallet_name == old_pallet_name {
log::info!(
target: "runtime::collective",
target: LOG_TARGET,
"New pallet name is equal to the old pallet name. No migration needs to be done.",
);
return Weight::zero()
@@ -50,7 +51,7 @@ pub fn migrate<T: frame_system::Config, P: GetStorageVersion + PalletInfoAccess,
let on_chain_storage_version = <P as GetStorageVersion>::on_chain_storage_version();
log::info!(
target: "runtime::collective",
target: LOG_TARGET,
"Running migration to v4 for collective with storage version {:?}",
on_chain_storage_version,
);
@@ -66,7 +67,7 @@ pub fn migrate<T: frame_system::Config, P: GetStorageVersion + PalletInfoAccess,
<T as frame_system::Config>::BlockWeights::get().max_block
} else {
log::warn!(
target: "runtime::collective",
target: LOG_TARGET,
"Attempted to apply migration to v4 but failed because storage version is {:?}",
on_chain_storage_version,
);
@@ -138,7 +139,7 @@ pub fn post_migrate<P: GetStorageVersion + PalletInfoAccess, N: AsRef<str>>(old_
fn log_migration(stage: &str, old_pallet_name: &str, new_pallet_name: &str) {
log::info!(
target: "runtime::collective",
target: LOG_TARGET,
"{}, prefix: '{}' ==> '{}'",
stage,
old_pallet_name,
+5 -10
View File
@@ -122,6 +122,8 @@ pub use weights::WeightInfo;
/// All migrations.
pub mod migrations;
const LOG_TARGET: &str = "runtime::elections-phragmen";
/// The maximum votes allowed per voter.
pub const MAXIMUM_VOTE: usize = 16;
@@ -789,10 +791,7 @@ impl<T: Config> Pallet<T> {
} else {
// overlap. This can never happen. If so, it seems like our intended replacement
// is already a member, so not much more to do.
log::error!(
target: "runtime::elections-phragmen",
"A member seems to also be a runner-up.",
);
log::error!(target: LOG_TARGET, "A member seems to also be a runner-up.");
}
next_best
});
@@ -939,7 +938,7 @@ impl<T: Config> Pallet<T> {
Ok(_) => (),
Err(_) => {
log::error!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"Failed to run election. Number of voters exceeded",
);
Self::deposit_event(Event::ElectionError);
@@ -1103,11 +1102,7 @@ impl<T: Config> Pallet<T> {
<ElectionRounds<T>>::mutate(|v| *v += 1);
})
.map_err(|e| {
log::error!(
target: "runtime::elections-phragmen",
"Failed to run election [{:?}].",
e,
);
log::error!(target: LOG_TARGET, "Failed to run election [{:?}].", e,);
Self::deposit_event(Event::ElectionError);
});
@@ -17,6 +17,7 @@
//! Migrations to version [`3.0.0`], as denoted by the changelog.
use super::super::LOG_TARGET;
use crate::{Config, Pallet};
use codec::{Decode, Encode, FullCodec};
use frame_support::{
@@ -88,7 +89,7 @@ pub fn apply<V: V2ToV3, T: Config>(
) -> Weight {
let storage_version = StorageVersion::get::<Pallet<T>>();
log::info!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"Running migration for elections-phragmen with storage version {:?}",
storage_version,
);
@@ -104,7 +105,7 @@ pub fn apply<V: V2ToV3, T: Config>(
Weight::MAX
} else {
log::warn!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"Attempted to apply migration to V3 but failed because storage version is {:?}",
storage_version,
);
@@ -118,22 +119,14 @@ pub fn migrate_voters_to_recorded_deposit<V: V2ToV3, T: Config>(old_deposit: V::
Some(Voter { votes, stake, deposit: old_deposit })
});
log::info!(
target: "runtime::elections-phragmen",
"migrated {} voter accounts.",
<Voting<V, T>>::iter().count(),
);
log::info!(target: LOG_TARGET, "migrated {} voter accounts.", <Voting<V, T>>::iter().count());
}
/// Migrate all candidates to recorded deposit.
pub fn migrate_candidates_to_recorded_deposit<V: V2ToV3, T: Config>(old_deposit: V::Balance) {
let _ = <Candidates<V, T>>::translate::<Vec<V::AccountId>, _>(|maybe_old_candidates| {
maybe_old_candidates.map(|old_candidates| {
log::info!(
target: "runtime::elections-phragmen",
"migrated {} candidate accounts.",
old_candidates.len(),
);
log::info!(target: LOG_TARGET, "migrated {} candidate accounts.", old_candidates.len());
old_candidates.into_iter().map(|c| (c, old_deposit)).collect::<Vec<_>>()
})
});
@@ -143,11 +136,7 @@ pub fn migrate_candidates_to_recorded_deposit<V: V2ToV3, T: Config>(old_deposit:
pub fn migrate_members_to_recorded_deposit<V: V2ToV3, T: Config>(old_deposit: V::Balance) {
let _ = <Members<V, T>>::translate::<Vec<(V::AccountId, V::Balance)>, _>(|maybe_old_members| {
maybe_old_members.map(|old_members| {
log::info!(
target: "runtime::elections-phragmen",
"migrated {} member accounts.",
old_members.len(),
);
log::info!(target: LOG_TARGET, "migrated {} member accounts.", old_members.len());
old_members
.into_iter()
.map(|(who, stake)| SeatHolder { who, stake, deposit: old_deposit })
@@ -162,7 +151,7 @@ pub fn migrate_runners_up_to_recorded_deposit<V: V2ToV3, T: Config>(old_deposit:
|maybe_old_runners_up| {
maybe_old_runners_up.map(|old_runners_up| {
log::info!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"migrated {} runner-up accounts.",
old_runners_up.len(),
);
@@ -17,6 +17,7 @@
//! Migrations to version [`4.0.0`], as denoted by the changelog.
use super::super::LOG_TARGET;
use frame_support::{
traits::{Get, StorageVersion},
weights::Weight,
@@ -35,14 +36,14 @@ pub const OLD_PREFIX: &[u8] = b"PhragmenElection";
pub fn migrate<T: crate::Config, N: AsRef<str>>(new_pallet_name: N) -> Weight {
if new_pallet_name.as_ref().as_bytes() == OLD_PREFIX {
log::info!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"New pallet name is equal to the old prefix. No migration needs to be done.",
);
return Weight::zero()
}
let storage_version = StorageVersion::get::<crate::Pallet<T>>();
log::info!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"Running migration to v4 for elections-phragmen with storage version {:?}",
storage_version,
);
@@ -59,7 +60,7 @@ pub fn migrate<T: crate::Config, N: AsRef<str>>(new_pallet_name: N) -> Weight {
<T as frame_system::Config>::BlockWeights::get().max_block
} else {
log::warn!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"Attempted to apply migration to v4 but failed because storage version is {:?}",
storage_version,
);
+2
View File
@@ -36,6 +36,8 @@ pub mod weights;
pub use pallet::*;
pub use weights::WeightInfo;
const LOG_TARGET: &str = "runtime::membership";
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
#[frame_support::pallet]
@@ -15,6 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use super::super::LOG_TARGET;
use sp_io::hashing::twox_128;
use frame_support::{
@@ -43,7 +44,7 @@ pub fn migrate<T: frame_system::Config, P: GetStorageVersion + PalletInfoAccess,
if new_pallet_name == old_pallet_name {
log::info!(
target: "runtime::membership",
target: LOG_TARGET,
"New pallet name is equal to the old prefix. No migration needs to be done.",
);
return Weight::zero()
@@ -51,7 +52,7 @@ pub fn migrate<T: frame_system::Config, P: GetStorageVersion + PalletInfoAccess,
let on_chain_storage_version = <P as GetStorageVersion>::on_chain_storage_version();
log::info!(
target: "runtime::membership",
target: LOG_TARGET,
"Running migration to v4 for membership with storage version {:?}",
on_chain_storage_version,
);
@@ -67,7 +68,7 @@ pub fn migrate<T: frame_system::Config, P: GetStorageVersion + PalletInfoAccess,
<T as frame_system::Config>::BlockWeights::get().max_block
} else {
log::warn!(
target: "runtime::membership",
target: LOG_TARGET,
"Attempted to apply migration to v4 but failed because storage version is {:?}",
on_chain_storage_version,
);
@@ -139,7 +140,7 @@ pub fn post_migrate<P: GetStorageVersion, N: AsRef<str>>(old_pallet_name: N, new
fn log_migration(stage: &str, old_pallet_name: &str, new_pallet_name: &str) {
log::info!(
target: "runtime::membership",
target: LOG_TARGET,
"{}, prefix: '{}' ==> '{}'",
stage,
old_pallet_name,
+6 -4
View File
@@ -29,6 +29,8 @@ use frame_support::{
use crate::historical as pallet_session_historical;
const LOG_TARGET: &str = "runtime::session_historical";
const OLD_PREFIX: &str = "Session";
/// Migrate the entire storage of this pallet to a new prefix.
@@ -44,7 +46,7 @@ pub fn migrate<T: pallet_session_historical::Config, P: GetStorageVersion + Pall
if new_pallet_name == OLD_PREFIX {
log::info!(
target: "runtime::session_historical",
target: LOG_TARGET,
"New pallet name is equal to the old prefix. No migration needs to be done.",
);
return Weight::zero()
@@ -52,7 +54,7 @@ pub fn migrate<T: pallet_session_historical::Config, P: GetStorageVersion + Pall
let on_chain_storage_version = <P as GetStorageVersion>::on_chain_storage_version();
log::info!(
target: "runtime::session_historical",
target: LOG_TARGET,
"Running migration to v1 for session_historical with storage version {:?}",
on_chain_storage_version,
);
@@ -78,7 +80,7 @@ pub fn migrate<T: pallet_session_historical::Config, P: GetStorageVersion + Pall
<T as frame_system::Config>::BlockWeights::get().max_block
} else {
log::warn!(
target: "runtime::session_historical",
target: LOG_TARGET,
"Attempted to apply migration to v1 but failed because storage version is {:?}",
on_chain_storage_version,
);
@@ -184,7 +186,7 @@ pub fn post_migrate<
fn log_migration(stage: &str, storage_prefix: &[u8], old_pallet_name: &str, new_pallet_name: &str) {
log::info!(
target: "runtime::session_historical",
target: LOG_TARGET,
"{} prefix of storage '{}': '{}' ==> '{}'",
stage,
str::from_utf8(storage_prefix).unwrap_or("<Invalid UTF8>"),
+9 -7
View File
@@ -129,6 +129,8 @@ pub use extensions::check_mortality::CheckMortality as CheckEra;
pub use frame_support::dispatch::RawOrigin;
pub use weights::WeightInfo;
const LOG_TARGET: &str = "runtime::system";
/// Compute the trie root of a list of extrinsics.
///
/// The merkle proof is using the same trie as runtime state with
@@ -1075,7 +1077,7 @@ impl<T: Config> Pallet<T> {
if account.providers == 0 {
// Logic error - cannot decrement beyond zero.
log::error!(
target: "runtime::system",
target: LOG_TARGET,
"Logic error: Unexpected underflow in reducing provider",
);
account.providers = 1;
@@ -1101,7 +1103,7 @@ impl<T: Config> Pallet<T> {
}
} else {
log::error!(
target: "runtime::system",
target: LOG_TARGET,
"Logic error: Account already dead when reducing provider",
);
Ok(DecRefStatus::Reaped)
@@ -1133,7 +1135,7 @@ impl<T: Config> Pallet<T> {
if account.sufficients == 0 {
// Logic error - cannot decrement beyond zero.
log::error!(
target: "runtime::system",
target: LOG_TARGET,
"Logic error: Unexpected underflow in reducing sufficients",
);
}
@@ -1150,7 +1152,7 @@ impl<T: Config> Pallet<T> {
}
} else {
log::error!(
target: "runtime::system",
target: LOG_TARGET,
"Logic error: Account already dead when reducing provider",
);
DecRefStatus::Reaped
@@ -1215,7 +1217,7 @@ impl<T: Config> Pallet<T> {
a.consumers -= 1;
} else {
log::error!(
target: "runtime::system",
target: LOG_TARGET,
"Logic error: Unexpected underflow in reducing consumer",
);
}
@@ -1337,7 +1339,7 @@ impl<T: Config> Pallet<T> {
/// resulting header for this block.
pub fn finalize() -> T::Header {
log::debug!(
target: "runtime::system",
target: LOG_TARGET,
"[{:?}] {} extrinsics, length: {} (normal {}%, op: {}%, mandatory {}%) / normal weight:\
{} ({}%) op weight {} ({}%) / mandatory weight {} ({}%)",
Self::block_number(),
@@ -1547,7 +1549,7 @@ impl<T: Config> Pallet<T> {
Ok(_) => Event::ExtrinsicSuccess { dispatch_info: info },
Err(err) => {
log::trace!(
target: "runtime::system",
target: LOG_TARGET,
"Extrinsic failed at block({:?}): {:?}",
Self::block_number(),
err,
+4 -3
View File
@@ -17,6 +17,7 @@
//! Migrate the reference counting state.
use super::LOG_TARGET;
use crate::{Config, Pallet};
use codec::{Decode, Encode, FullCodec};
use frame_support::{
@@ -75,7 +76,7 @@ pub fn migrate_from_single_u8_to_triple_ref_count<V: V2ToV3, T: Config>() -> Wei
Some(AccountInfo { nonce, consumers: rc as RefCount, providers: 1, sufficients: 0, data })
});
log::info!(
target: "runtime::system",
target: LOG_TARGET,
"Applied migration from single u8 to triple reference counting to {:?} elements.",
translated
);
@@ -94,7 +95,7 @@ pub fn migrate_from_single_to_triple_ref_count<V: V2ToV3, T: Config>() -> Weight
},
);
log::info!(
target: "runtime::system",
target: LOG_TARGET,
"Applied migration from single to triple reference counting to {:?} elements.",
translated
);
@@ -112,7 +113,7 @@ pub fn migrate_from_dual_to_triple_ref_count<V: V2ToV3, T: Config>() -> Weight {
},
);
log::info!(
target: "runtime::system",
target: LOG_TARGET,
"Applied migration from dual to triple reference counting to {:?} elements.",
translated
);
+2
View File
@@ -78,6 +78,8 @@ use frame_support::{
pub use pallet::*;
pub use weights::WeightInfo;
const LOG_TARGET: &str = "runtime::tips";
pub type BalanceOf<T, I = ()> = pallet_treasury::BalanceOf<T, I>;
pub type NegativeImbalanceOf<T, I = ()> = pallet_treasury::NegativeImbalanceOf<T, I>;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
+5 -4
View File
@@ -18,6 +18,7 @@
use sp_io::hashing::twox_128;
use sp_std::str;
use super::super::LOG_TARGET;
use frame_support::{
storage::StoragePrefixedMap,
traits::{
@@ -46,7 +47,7 @@ pub fn migrate<T: pallet_tips::Config, P: GetStorageVersion + PalletInfoAccess,
if new_pallet_name == old_pallet_name {
log::info!(
target: "runtime::tips",
target: LOG_TARGET,
"New pallet name is equal to the old prefix. No migration needs to be done.",
);
return Weight::zero()
@@ -54,7 +55,7 @@ pub fn migrate<T: pallet_tips::Config, P: GetStorageVersion + PalletInfoAccess,
let on_chain_storage_version = <P as GetStorageVersion>::on_chain_storage_version();
log::info!(
target: "runtime::tips",
target: LOG_TARGET,
"Running migration to v4 for tips with storage version {:?}",
on_chain_storage_version,
);
@@ -80,7 +81,7 @@ pub fn migrate<T: pallet_tips::Config, P: GetStorageVersion + PalletInfoAccess,
<T as frame_system::Config>::BlockWeights::get().max_block
} else {
log::warn!(
target: "runtime::tips",
target: LOG_TARGET,
"Attempted to apply migration to v4 but failed because storage version is {:?}",
on_chain_storage_version,
);
@@ -185,7 +186,7 @@ pub fn post_migrate<
fn log_migration(stage: &str, storage_prefix: &[u8], old_pallet_name: &str, new_pallet_name: &str) {
log::info!(
target: "runtime::tips",
target: LOG_TARGET,
"{} prefix of storage '{}': '{}' ==> '{}'",
stage,
str::from_utf8(storage_prefix).unwrap_or("<Invalid UTF8>"),
+2
View File
@@ -60,6 +60,8 @@ pub use pallet::*;
pub use types::*;
pub use weights::WeightInfo;
const LOG_TARGET: &str = "runtime::uniques";
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
#[frame_support::pallet]
+3 -3
View File
@@ -24,7 +24,7 @@ pub fn migrate_to_v1<T: Config<I>, I: 'static, P: GetStorageVersion + PalletInfo
) -> frame_support::weights::Weight {
let on_chain_storage_version = <P as GetStorageVersion>::on_chain_storage_version();
log::info!(
target: "runtime::uniques",
target: LOG_TARGET,
"Running migration storage v1 for uniques with storage version {:?}",
on_chain_storage_version,
);
@@ -37,7 +37,7 @@ pub fn migrate_to_v1<T: Config<I>, I: 'static, P: GetStorageVersion + PalletInfo
}
StorageVersion::new(1).put::<P>();
log::info!(
target: "runtime::uniques",
target: LOG_TARGET,
"Running migration storage v1 for uniques with storage version {:?} was complete",
on_chain_storage_version,
);
@@ -45,7 +45,7 @@ pub fn migrate_to_v1<T: Config<I>, I: 'static, P: GetStorageVersion + PalletInfo
T::DbWeight::get().reads_writes(count as u64 + 1, count as u64 + 1)
} else {
log::warn!(
target: "runtime::uniques",
target: LOG_TARGET,
"Attempted to apply migration to v1 but failed because storage version is {:?}",
on_chain_storage_version,
);