Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate pallets old versions #2555

Merged
merged 5 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 99 additions & 13 deletions runtime/common/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
//! 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},
traits::{Hash as PreimageHash, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion},
weights::Weight,
};
use pallet_author_slot_filter::Config as AuthorSlotFilterConfig;
Expand Down Expand Up @@ -154,19 +156,89 @@ where
}
}

pub struct ReferendaMigrations<Runtime, Council, Tech>(PhantomData<(Runtime, Council, Tech)>);
pub struct MissingBalancesMigrations<T>(PhantomData<T>);
impl<T> Migration for MissingBalancesMigrations<T>
where
T: pallet_balances::Config,
<T as frame_system::Config>::AccountId: Default,
{
fn friendly_name(&self) -> &str {
"MM_MissingBalancesMigrations"
}

fn migrate(&self, _available_weight: Weight) -> Weight {
pallet_balances::migration::MigrateToTrackInactive::<T, ()>::on_runtime_upgrade();
pallet_balances::migration::ResetInactive::<T, ()>::on_runtime_upgrade();
pallet_balances::migration::MigrateToTrackInactive::<T, ()>::on_runtime_upgrade()
noandrea marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl<Runtime, Council, Tech> GetMigrations for ReferendaMigrations<Runtime, Council, Tech>
pub struct FixIncorrectPalletVersions<Runtime, Treasury, OpenTech>(
pub PhantomData<(Runtime, Treasury, OpenTech)>,
);
impl<Runtime, Treasury, OpenTech> Migration
for FixIncorrectPalletVersions<Runtime, Treasury, OpenTech>
where
Runtime: pallet_author_mapping::Config,
Runtime: pallet_parachain_staking::Config,
Runtime: pallet_scheduler::Config<Hash = PreimageHash>,
Runtime: AuthorSlotFilterConfig,
Council: GetStorageVersion + PalletInfoAccess + 'static,
Tech: GetStorageVersion + PalletInfoAccess + 'static,
Runtime: pallet_democracy::Config<Hash = PreimageHash>,
Runtime: pallet_preimage::Config<Hash = PreimageHash>,
Treasury: GetStorageVersion + PalletInfoAccess,
OpenTech: GetStorageVersion + PalletInfoAccess,
Runtime: frame_system::Config,
Runtime: pallet_referenda::Config,
{
fn friendly_name(&self) -> &str {
"MM_FixIncorrectPalletVersions"
}

fn migrate(&self, _available_weight: Weight) -> Weight {
log::info!("Setting collective pallet versions to 4");
StorageVersion::new(4).put::<Treasury>();
StorageVersion::new(4).put::<OpenTech>();
log::info!("Setting referenda pallet version to 1");
StorageVersion::new(1).put::<pallet_referenda::Pallet<Runtime>>();
Runtime::DbWeight::get().writes(2)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
ensure!(
<Treasury as GetStorageVersion>::on_chain_storage_version() == 0,
"TreasuryCouncilCollective storage version should be 0"
);
ensure!(
<OpenTech as GetStorageVersion>::on_chain_storage_version() == 0,
"OpenTechCommitteeCollective storage version should be 0"
);
ensure!(
<pallet_referenda::Pallet<Runtime> as GetStorageVersion>::on_chain_storage_version()
== 0,
"Referenda storage version should be 0"
);
Ok(vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
ensure!(
<Treasury as GetStorageVersion>::on_chain_storage_version() == 4,
"Treasury storage version should be 4"
);
ensure!(
<OpenTech as GetStorageVersion>::on_chain_storage_version() == 4,
"OpenTech storage version should be 4"
);
ensure!(
<pallet_referenda::Pallet<Runtime> as GetStorageVersion>::on_chain_storage_version()
== 1,
"Referenda storage version should be 1"
);
Ok(())
}
}

pub struct ReferendaMigrations<Runtime>(PhantomData<Runtime>);

impl<Runtime> GetMigrations for ReferendaMigrations<Runtime>
where
Runtime: pallet_referenda::Config<Hash = PreimageHash>,
{
fn get_migrations() -> Vec<Box<dyn Migration>> {
let pallet_referenda_migrate_v0_to_v1 =
Expand All @@ -175,22 +247,30 @@ where
}
}

pub struct CommonMigrations<Runtime, Council, Tech>(PhantomData<(Runtime, Council, Tech)>);
pub struct CommonMigrations<Runtime, Council, Tech, Treasury, OpenTech>(
PhantomData<(Runtime, Council, Tech, Treasury, OpenTech)>,
);

impl<Runtime, Council, Tech> GetMigrations for CommonMigrations<Runtime, Council, Tech>
impl<Runtime, Council, Tech, Treasury, OpenTech> GetMigrations
for CommonMigrations<Runtime, Council, Tech, Treasury, OpenTech>
where
Runtime: pallet_author_mapping::Config,
Runtime: pallet_parachain_staking::Config,
Runtime: pallet_scheduler::Config<Hash = PreimageHash>,
Runtime: AuthorSlotFilterConfig,
Council: GetStorageVersion + PalletInfoAccess + 'static,
Tech: GetStorageVersion + PalletInfoAccess + 'static,
Treasury: GetStorageVersion + PalletInfoAccess + 'static,
OpenTech: GetStorageVersion + PalletInfoAccess + 'static,
Runtime: pallet_democracy::Config<Hash = PreimageHash>,
Runtime: pallet_preimage::Config<Hash = PreimageHash>,
Runtime: pallet_asset_manager::Config,
<Runtime as pallet_asset_manager::Config>::ForeignAssetType: From<xcm::v3::MultiLocation>,
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<Box<dyn Migration>> {
// let migration_author_mapping_twox_to_blake = AuthorMappingTwoXToBlake::<Runtime> {
Expand Down Expand Up @@ -258,6 +338,10 @@ where
// PalletXcmTransactorMigrateXcmV2ToV3::<Runtime>(Default::default());
let remove_min_bond_for_old_orbiter_collators =
RemoveMinBondForOrbiterCollators::<Runtime>(Default::default());
let missing_balances_migrations = MissingBalancesMigrations::<Runtime>(Default::default());
let fix_pallet_versions =
FixIncorrectPalletVersions::<Runtime, Treasury, OpenTech>(Default::default());

vec![
// completed in runtime 800
// Box::new(migration_author_mapping_twox_to_blake),
Expand Down Expand Up @@ -305,6 +389,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),
]
}
}
8 changes: 3 additions & 5 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime>,
TransactorRelayIndexMigration<Runtime>,
);
type XcmExecutionManager = XcmExecutionManager;
Expand Down
2 changes: 2 additions & 0 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,8 @@ impl pallet_migrations::Config for Runtime {
Runtime,
CouncilCollective,
TechCommitteeCollective,
TreasuryCouncilCollective,
OpenTechCommitteeCollective,
>,
TransactorRelayIndexMigration<Runtime>,
);
Expand Down
8 changes: 3 additions & 5 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime>,
TransactorRelayIndexMigration<Runtime>,
);
type XcmExecutionManager = XcmExecutionManager;
Expand Down
Loading