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
+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,
);