diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index 19334438b817..9b34e5cbf78d 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -167,7 +167,7 @@ pub mod pallet { }; use frame_system::{ensure_root, pallet_prelude::*}; /// The in-code storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] diff --git a/substrate/frame/core-fellowship/src/migration.rs b/substrate/frame/core-fellowship/src/migration.rs index 548b3e00a859..02433794d45c 100644 --- a/substrate/frame/core-fellowship/src/migration.rs +++ b/substrate/frame/core-fellowship/src/migration.rs @@ -1,6 +1,9 @@ use super::*; use frame_support::{ - pallet_prelude::*, storage_alias, traits::{UncheckedOnRuntimeUpgrade, DefensiveTruncateFrom}, BoundedVec, + pallet_prelude::*, + storage_alias, + traits::{DefensiveTruncateFrom, UncheckedOnRuntimeUpgrade}, + BoundedVec, }; #[cfg(feature = "try-runtime")] @@ -45,43 +48,46 @@ mod v0 { StorageValue, ParamsOf, ValueQuery>; } -mod v1 { - use super::*; - - pub struct Migration(PhantomData<(T, I)>); - impl, I: 'static> UncheckedOnRuntimeUpgrade for Migration { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, TryRuntimeError> { - ensure!(T::MaxRank::get() >= v0::RANK_COUNT as u32, "pallet-core-fellowship: new bound should not truncate"); - Ok(Default::default()) - } +pub struct Migration(PhantomData<(T, I)>); +impl, I: 'static> UncheckedOnRuntimeUpgrade for Migration { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, TryRuntimeError> { + ensure!( + T::MaxRank::get() >= v0::RANK_COUNT as u32, + "pallet-core-fellowship: new bound should not truncate" + ); + Ok(Default::default()) + } - fn on_runtime_upgrade() -> frame_support::weights::Weight { - // Read the old value from storage - let old_value = v0::Params::::take(); - // Write the new value to storage - let new = crate::ParamsType { - active_salary: BoundedVec::defensive_truncate_from(old_value.active_salary.to_vec()), - passive_salary: BoundedVec::defensive_truncate_from(old_value.passive_salary.to_vec()), - demotion_period: BoundedVec::defensive_truncate_from(old_value.demotion_period.to_vec()), - min_promotion_period: BoundedVec::defensive_truncate_from(old_value.min_promotion_period.to_vec()), - offboard_timeout: old_value.offboard_timeout, - }; - crate::Params::::put(new); - T::DbWeight::get().reads_writes(1, 1) - } + fn on_runtime_upgrade() -> frame_support::weights::Weight { + // Read the old value from storage + let old_value = v0::Params::::take(); + // Write the new value to storage + let new = crate::ParamsType { + active_salary: BoundedVec::defensive_truncate_from(old_value.active_salary.to_vec()), + passive_salary: BoundedVec::defensive_truncate_from(old_value.passive_salary.to_vec()), + demotion_period: BoundedVec::defensive_truncate_from( + old_value.demotion_period.to_vec(), + ), + min_promotion_period: BoundedVec::defensive_truncate_from( + old_value.min_promotion_period.to_vec(), + ), + offboard_timeout: old_value.offboard_timeout, + }; + crate::Params::::put(new); + T::DbWeight::get().reads_writes(1, 1) } } -/// [`UncheckedOnRuntimeUpgrade`] implementation [`v1::Migration`] wrapped in a +/// [`UncheckedOnRuntimeUpgrade`] implementation [`Migration`] wrapped in a /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), which ensures that: /// - The migration only runs once when the on-chain storage version is 0 -/// - The on-chain storage version is updated to `1` after the migration executes +/// - The on-chain storage version is updated to `2` after the migration executes /// - Reads/Writes from checking/settings the on-chain storage version are accounted for pub type Migrate = frame_support::migrations::VersionedMigration< 0, // The migration will only execute when the on-chain storage version is 0 - 1, // The on-chain storage version will be set to 1 after the migration is complete - v1::Migration, + 2, // The on-chain storage version will be set to 2 after the migration is complete + Migration, crate::pallet::Pallet, ::DbWeight, >;