From 3bf0ae87e333d3f7101268a2aa5a8c4171921d41 Mon Sep 17 00:00:00 2001 From: Cem Eliguzel Date: Wed, 8 Nov 2023 09:31:34 +0000 Subject: [PATCH 1/5] Fixes the pallet versions. TreasuryCouncilCollective 0 -> 4 OpenTechCommitteeCollective 0 -> 4 Balances 0 -> 1 Referenda 0 -> 1 --- runtime/common/src/migrations.rs | 101 +++++++++++++++++++++++++++---- runtime/moonbase/src/lib.rs | 8 +-- runtime/moonbeam/src/lib.rs | 2 + runtime/moonriver/src/lib.rs | 8 +-- 4 files changed, 96 insertions(+), 23 deletions(-) diff --git a/runtime/common/src/migrations.rs b/runtime/common/src/migrations.rs index b1526fcf04..5d78f91eaf 100644 --- a/runtime/common/src/migrations.rs +++ b/runtime/common/src/migrations.rs @@ -20,8 +20,9 @@ //! the "Migration" trait declared in the pallet-migrations crate. use frame_support::{ + ensure, pallet_prelude::GetStorageVersion, - traits::{Hash as PreimageHash, OnRuntimeUpgrade, PalletInfoAccess}, + traits::{Hash as PreimageHash, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion}, weights::Weight, }; use pallet_author_slot_filter::Config as AuthorSlotFilterConfig; @@ -154,19 +155,79 @@ where } } -pub struct ReferendaMigrations(PhantomData<(Runtime, Council, Tech)>); +pub struct MissingBalancesMigrations(PhantomData); +impl Migration for MissingBalancesMigrations +where + T: pallet_balances::Config, + ::AccountId: Default, +{ + fn friendly_name(&self) -> &str { + "MM_MissingBalancesMigrations" + } + + fn migrate(&self, _available_weight: Weight) -> Weight { + pallet_balances::migration::MigrateToTrackInactive::::on_runtime_upgrade(); + pallet_balances::migration::ResetInactive::::on_runtime_upgrade(); + pallet_balances::migration::MigrateToTrackInactive::::on_runtime_upgrade() + } +} -impl GetMigrations for ReferendaMigrations +pub struct FixIncorrectPalletVersions( + pub PhantomData<(Runtime, Treasury, OpenTech)>, +); +impl Migration + for FixIncorrectPalletVersions where - Runtime: pallet_author_mapping::Config, - Runtime: pallet_parachain_staking::Config, - Runtime: pallet_scheduler::Config, - Runtime: AuthorSlotFilterConfig, - Council: GetStorageVersion + PalletInfoAccess + 'static, - Tech: GetStorageVersion + PalletInfoAccess + 'static, - Runtime: pallet_democracy::Config, - Runtime: pallet_preimage::Config, + Treasury: GetStorageVersion + PalletInfoAccess, + OpenTech: GetStorageVersion + PalletInfoAccess, + Runtime: frame_system::Config, Runtime: pallet_referenda::Config, +{ + fn friendly_name(&self) -> &str { + "MM_SetCollectivePalletVersions" + } + + fn migrate(&self, _available_weight: Weight) -> Weight { + log::info!("Setting collective pallet versions to 4"); + StorageVersion::new(4).put::(); + StorageVersion::new(4).put::(); + log::info!("Setting referenda pallet version to 1"); + StorageVersion::new(1).put::>(); + Runtime::DbWeight::get().writes(2) + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade(&self) -> Result, sp_runtime::DispatchError> { + ensure!( + ::on_chain_storage_version() == 0, + "TreasuryCouncilCollective storage version should be 0" + ); + ensure!( + ::on_chain_storage_version() == 0, + "OpenTechCommitteeCollective storage version should be 0" + ); + Ok(vec![]) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(&self, _state: Vec) -> Result<(), sp_runtime::DispatchError> { + ensure!( + ::on_chain_storage_version() == 4, + "Treasury storage version should be 4" + ); + ensure!( + ::on_chain_storage_version() == 4, + "OpenTech storage version should be 4" + ); + Ok(()) + } +} + +pub struct ReferendaMigrations(PhantomData); + +impl GetMigrations for ReferendaMigrations +where + Runtime: pallet_referenda::Config, { fn get_migrations() -> Vec> { let pallet_referenda_migrate_v0_to_v1 = @@ -175,9 +236,12 @@ where } } -pub struct CommonMigrations(PhantomData<(Runtime, Council, Tech)>); +pub struct CommonMigrations( + PhantomData<(Runtime, Council, Tech, Treasury, OpenTech)>, +); -impl GetMigrations for CommonMigrations +impl GetMigrations + for CommonMigrations where Runtime: pallet_author_mapping::Config, Runtime: pallet_parachain_staking::Config, @@ -185,12 +249,17 @@ where Runtime: AuthorSlotFilterConfig, Council: GetStorageVersion + PalletInfoAccess + 'static, Tech: GetStorageVersion + PalletInfoAccess + 'static, + Treasury: GetStorageVersion + PalletInfoAccess + 'static, + OpenTech: GetStorageVersion + PalletInfoAccess + 'static, Runtime: pallet_democracy::Config, Runtime: pallet_preimage::Config, Runtime: pallet_asset_manager::Config, ::ForeignAssetType: From, Runtime: pallet_xcm_transactor::Config, Runtime: pallet_moonbeam_orbiters::Config, + Runtime: pallet_balances::Config, + Runtime: pallet_referenda::Config, + Runtime::AccountId: Default, { fn get_migrations() -> Vec> { // let migration_author_mapping_twox_to_blake = AuthorMappingTwoXToBlake:: { @@ -258,6 +327,10 @@ where // PalletXcmTransactorMigrateXcmV2ToV3::(Default::default()); let remove_min_bond_for_old_orbiter_collators = RemoveMinBondForOrbiterCollators::(Default::default()); + let missing_balances_migrations = MissingBalancesMigrations::(Default::default()); + let fix_pallet_versions = + FixIncorrectPalletVersions::(Default::default()); + vec![ // completed in runtime 800 // Box::new(migration_author_mapping_twox_to_blake), @@ -305,6 +378,8 @@ where //Box::new(asset_manager_to_xcm_v3), //Box::new(xcm_transactor_to_xcm_v3), Box::new(remove_min_bond_for_old_orbiter_collators), + Box::new(missing_balances_migrations), + Box::new(fix_pallet_versions), ] } } diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 69d853c327..0ad064e803 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1067,12 +1067,10 @@ impl pallet_migrations::Config for Runtime { Runtime, CouncilCollective, TechCommitteeCollective, + TreasuryCouncilCollective, + OpenTechCommitteeCollective, >, - moonbeam_runtime_common::migrations::ReferendaMigrations< - Runtime, - CouncilCollective, - TechCommitteeCollective, - >, + moonbeam_runtime_common::migrations::ReferendaMigrations, TransactorRelayIndexMigration, ); type XcmExecutionManager = XcmExecutionManager; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 48a641e903..f01527505a 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1076,6 +1076,8 @@ impl pallet_migrations::Config for Runtime { Runtime, CouncilCollective, TechCommitteeCollective, + TreasuryCouncilCollective, + OpenTechCommitteeCollective, >, TransactorRelayIndexMigration, ); diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 9c9a1af004..3490ceed30 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1080,12 +1080,10 @@ impl pallet_migrations::Config for Runtime { Runtime, CouncilCollective, TechCommitteeCollective, + TreasuryCouncilCollective, + OpenTechCommitteeCollective, >, - moonbeam_runtime_common::migrations::ReferendaMigrations< - Runtime, - CouncilCollective, - TechCommitteeCollective, - >, + moonbeam_runtime_common::migrations::ReferendaMigrations, TransactorRelayIndexMigration, ); type XcmExecutionManager = XcmExecutionManager; From b0a3c72fbd8ae1317ef53170626f16a3bdd961d1 Mon Sep 17 00:00:00 2001 From: Cem Eliguzel Date: Wed, 8 Nov 2023 09:45:03 +0000 Subject: [PATCH 2/5] Fix the unused import warning --- runtime/common/src/migrations.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/common/src/migrations.rs b/runtime/common/src/migrations.rs index 5d78f91eaf..c9dd2e92ce 100644 --- a/runtime/common/src/migrations.rs +++ b/runtime/common/src/migrations.rs @@ -20,7 +20,6 @@ //! the "Migration" trait declared in the pallet-migrations crate. use frame_support::{ - ensure, pallet_prelude::GetStorageVersion, traits::{Hash as PreimageHash, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion}, weights::Weight, @@ -29,6 +28,8 @@ use pallet_author_slot_filter::Config as AuthorSlotFilterConfig; use pallet_migrations::{GetMigrations, Migration}; use pallet_moonbeam_orbiters::CollatorsPool; #[cfg(feature = "try-runtime")] +use frame_support::ensure; +#[cfg(feature = "try-runtime")] use sp_runtime::traits::Zero; use sp_std::{marker::PhantomData, prelude::*}; From 847c2235aac2e00efe986e200e58b00cb2b2fa59 Mon Sep 17 00:00:00 2001 From: Cem Eliguzel Date: Wed, 8 Nov 2023 09:46:32 +0000 Subject: [PATCH 3/5] Fix the friendly name of the migration --- runtime/common/src/migrations.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/common/src/migrations.rs b/runtime/common/src/migrations.rs index c9dd2e92ce..85e74f54e6 100644 --- a/runtime/common/src/migrations.rs +++ b/runtime/common/src/migrations.rs @@ -185,7 +185,7 @@ where Runtime: pallet_referenda::Config, { fn friendly_name(&self) -> &str { - "MM_SetCollectivePalletVersions" + "MM_FixIncorrectPalletVersions" } fn migrate(&self, _available_weight: Weight) -> Weight { From ca0151ebdbd98f24a046ff390ea63259e10aa7af Mon Sep 17 00:00:00 2001 From: Cem Eliguzel Date: Wed, 8 Nov 2023 09:48:00 +0000 Subject: [PATCH 4/5] Add the pre/post checks for the pallet-referenda --- runtime/common/src/migrations.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/runtime/common/src/migrations.rs b/runtime/common/src/migrations.rs index 85e74f54e6..0167fdde72 100644 --- a/runtime/common/src/migrations.rs +++ b/runtime/common/src/migrations.rs @@ -207,6 +207,10 @@ where ::on_chain_storage_version() == 0, "OpenTechCommitteeCollective storage version should be 0" ); + ensure!( + as GetStorageVersion>::on_chain_storage_version() == 0, + "Referenda storage version should be 0" + ); Ok(vec![]) } @@ -220,6 +224,10 @@ where ::on_chain_storage_version() == 4, "OpenTech storage version should be 4" ); + ensure!( + as GetStorageVersion>::on_chain_storage_version() == 1, + "Referenda storage version should be 1" + ); Ok(()) } } From 84aebf6339c9d079d8b25f59b1c70caf28f554b6 Mon Sep 17 00:00:00 2001 From: Cem Eliguzel Date: Wed, 8 Nov 2023 09:50:50 +0000 Subject: [PATCH 5/5] Fix formatting --- runtime/common/src/migrations.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/runtime/common/src/migrations.rs b/runtime/common/src/migrations.rs index 0167fdde72..7002e02937 100644 --- a/runtime/common/src/migrations.rs +++ b/runtime/common/src/migrations.rs @@ -19,6 +19,8 @@ //! This module acts as a registry where each migration is defined. Each migration should implement //! the "Migration" trait declared in the pallet-migrations crate. +#[cfg(feature = "try-runtime")] +use frame_support::ensure; use frame_support::{ pallet_prelude::GetStorageVersion, traits::{Hash as PreimageHash, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion}, @@ -28,8 +30,6 @@ use pallet_author_slot_filter::Config as AuthorSlotFilterConfig; use pallet_migrations::{GetMigrations, Migration}; use pallet_moonbeam_orbiters::CollatorsPool; #[cfg(feature = "try-runtime")] -use frame_support::ensure; -#[cfg(feature = "try-runtime")] use sp_runtime::traits::Zero; use sp_std::{marker::PhantomData, prelude::*}; @@ -208,7 +208,8 @@ where "OpenTechCommitteeCollective storage version should be 0" ); ensure!( - as GetStorageVersion>::on_chain_storage_version() == 0, + as GetStorageVersion>::on_chain_storage_version() + == 0, "Referenda storage version should be 0" ); Ok(vec![]) @@ -225,7 +226,8 @@ where "OpenTech storage version should be 4" ); ensure!( - as GetStorageVersion>::on_chain_storage_version() == 1, + as GetStorageVersion>::on_chain_storage_version() + == 1, "Referenda storage version should be 1" ); Ok(())