Skip to content

Commit

Permalink
Removes already applied migrations (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr authored Jan 5, 2024
1 parent 101882e commit 3caec69
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 247 deletions.
89 changes: 3 additions & 86 deletions relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ use frame_support::{
genesis_builder_helper::{build_config, create_default_config},
parameter_types,
traits::{
fungible::HoldConsideration, ConstU32, Contains, EitherOf, EitherOfDiverse, Get,
InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage,
ProcessMessageError, WithdrawReasons,
fungible::HoldConsideration, ConstU32, EitherOf, EitherOfDiverse, Get, InstanceFilter,
KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage, ProcessMessageError,
WithdrawReasons,
},
weights::{ConstantMultiplier, WeightMeter},
PalletId,
Expand Down Expand Up @@ -1688,51 +1688,6 @@ pub type Migrations = migrations::Unreleased;
#[allow(deprecated, missing_docs)]
pub mod migrations {
use super::*;
use frame_support::traits::LockIdentifier;
use frame_system::pallet_prelude::BlockNumberFor;

parameter_types! {
pub const DemocracyPalletName: &'static str = "Democracy";
pub const CouncilPalletName: &'static str = "Council";
pub const TechnicalCommitteePalletName: &'static str = "TechnicalCommittee";
pub const PhragmenElectionPalletName: &'static str = "PhragmenElection";
pub const TechnicalMembershipPalletName: &'static str = "TechnicalMembership";
pub const TipsPalletName: &'static str = "Tips";
pub const PhragmenElectionPalletId: LockIdentifier = *b"phrelect";
}

// Special Config for Gov V1 pallets, allowing us to run migrations for them without
// implementing their configs on [`Runtime`].
pub struct UnlockConfig;
impl pallet_democracy::migrations::unlock_and_unreserve_all_funds::UnlockConfig for UnlockConfig {
type Currency = Balances;
type MaxVotes = ConstU32<100>;
type MaxDeposits = ConstU32<100>;
type AccountId = AccountId;
type BlockNumber = BlockNumberFor<Runtime>;
type DbWeight = <Runtime as frame_system::Config>::DbWeight;
type PalletName = DemocracyPalletName;
}
impl pallet_elections_phragmen::migrations::unlock_and_unreserve_all_funds::UnlockConfig
for UnlockConfig
{
type Currency = Balances;
type MaxVotesPerVoter = ConstU32<16>;
type PalletId = PhragmenElectionPalletId;
type AccountId = AccountId;
type DbWeight = <Runtime as frame_system::Config>::DbWeight;
type PalletName = PhragmenElectionPalletName;
}
impl pallet_tips::migrations::unreserve_deposits::UnlockConfig<()> for UnlockConfig {
type Currency = Balances;
type Hash = Hash;
type DataDepositPerByte = DataDepositPerByte;
type TipReportDepositBase = TipReportDepositBase;
type AccountId = AccountId;
type BlockNumber = BlockNumberFor<Runtime>;
type DbWeight = <Runtime as frame_system::Config>::DbWeight;
type PalletName = TipsPalletName;
}

/// Upgrade Session keys to include BEEFY key.
/// When this is removed, should also remove `OldSessionKeys`.
Expand All @@ -1744,50 +1699,12 @@ pub mod migrations {
}
}

pub struct ParachainsToUnlock;
impl Contains<ParaId> for ParachainsToUnlock {
fn contains(id: &ParaId) -> bool {
let id: u32 = (*id).into();
// polkadot parachains/parathreads that are locked and never produced block
match id {
2003 | 2015 | 2017 | 2018 | 2025 | 2028 | 2036 | 2038 | 2053 | 2055 | 2090 |
2097 | 2106 | 3336 | 3338 | 3342 => true,
_ => false,
}
}
}

/// Unreleased migrations. Add new ones here:
pub type Unreleased = (
pallet_im_online::migration::v1::Migration<Runtime>,
parachains_configuration::migration::v7::MigrateToV7<Runtime>,
parachains_configuration::migration::v8::MigrateToV8<Runtime>,

// Gov v1 storage migrations
// https://github.com/paritytech/polkadot/issues/6749
pallet_elections_phragmen::migrations::unlock_and_unreserve_all_funds::UnlockAndUnreserveAllFunds<UnlockConfig>,
pallet_democracy::migrations::unlock_and_unreserve_all_funds::UnlockAndUnreserveAllFunds<UnlockConfig>,
pallet_tips::migrations::unreserve_deposits::UnreserveDeposits<UnlockConfig, ()>,

// Delete all Gov v1 pallet storage key/values.
frame_support::migrations::RemovePallet<DemocracyPalletName, <Runtime as frame_system::Config>::DbWeight>,
frame_support::migrations::RemovePallet<CouncilPalletName, <Runtime as frame_system::Config>::DbWeight>,
frame_support::migrations::RemovePallet<TechnicalCommitteePalletName, <Runtime as frame_system::Config>::DbWeight>,
frame_support::migrations::RemovePallet<PhragmenElectionPalletName, <Runtime as frame_system::Config>::DbWeight>,
frame_support::migrations::RemovePallet<TechnicalMembershipPalletName, <Runtime as frame_system::Config>::DbWeight>,
frame_support::migrations::RemovePallet<TipsPalletName, <Runtime as frame_system::Config>::DbWeight>,

parachains_configuration::migration::v9::MigrateToV9<Runtime>,
// Migrate parachain info format
paras_registrar::migration::VersionCheckedMigrateToV1<Runtime, ParachainsToUnlock>,

// Upgrade SessionKeys to include BEEFY key
UpgradeSessionKeys,

pallet_nomination_pools::migration::versioned_migrations::V5toV6<Runtime>,
pallet_nomination_pools::migration::versioned_migrations::V6ToV7<Runtime>,

runtime_parachains::scheduler::migration::v1::MigrateToV1<Runtime>
);
}

Expand Down
45 changes: 1 addition & 44 deletions system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,50 +910,7 @@ pub type SignedExtra = (
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
/// Migrations to apply on runtime upgrade.
pub type Migrations = (
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
pallet_multisig::migrations::v1::MigrateToV1<Runtime>,
InitStorageVersions,
);

/// Migration to initialize storage versions for pallets added after genesis.
///
/// Ideally this would be done automatically (see
/// <https://github.com/paritytech/polkadot-sdk/pull/1297>), but it probably won't be ready for some
/// time and it's beneficial to get storage version issues smoothed over before merging
/// <https://github.com/polkadot-fellows/runtimes/pull/28> so we're just setting them manually.
pub struct InitStorageVersions;

impl frame_support::traits::OnRuntimeUpgrade for InitStorageVersions {
fn on_runtime_upgrade() -> Weight {
use frame_support::traits::{GetStorageVersion, StorageVersion};
use sp_runtime::traits::Saturating;

let mut writes = 0;

if PolkadotXcm::on_chain_storage_version() == StorageVersion::new(0) {
PolkadotXcm::current_storage_version().put::<PolkadotXcm>();
writes.saturating_inc();
}

if Nfts::on_chain_storage_version() == StorageVersion::new(0) {
Nfts::current_storage_version().put::<Nfts>();
writes.saturating_inc();
}

if ForeignAssets::on_chain_storage_version() == StorageVersion::new(0) {
ForeignAssets::current_storage_version().put::<ForeignAssets>();
writes.saturating_inc();
}

if PoolAssets::on_chain_storage_version() == StorageVersion::new(0) {
PoolAssets::current_storage_version().put::<PoolAssets>();
writes.saturating_inc();
}

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(4, writes)
}
}
pub type Migrations = ();

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Expand Down
47 changes: 6 additions & 41 deletions system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ use frame_support::{
parameter_types,
traits::{
AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse,
InstanceFilter,
InstanceFilter, OnRuntimeUpgrade,
},
weights::{ConstantMultiplier, Weight},
PalletId,
Expand Down Expand Up @@ -820,49 +820,14 @@ pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
/// Migrations to apply on runtime upgrade.
pub type Migrations =
(pallet_collator_selection::migration::v1::MigrateToV1<Runtime>, InitStorageVersions);
frame_support::migrations::VersionedMigration<0, 1, UniquesMigration, Uniques, RocksDbWeight>;

/// Migration to initialize storage versions for pallets added after genesis.
///
/// Ideally this would be done automatically (see
/// <https://github.com/paritytech/polkadot-sdk/pull/1297>), but it probably won't be ready for some
/// time and it's beneficial to get storage version issues smoothed over before merging
/// <https://github.com/polkadot-fellows/runtimes/pull/28> so we're just setting them manually.
pub struct InitStorageVersions;
/// Migration for Uniques to V1
pub struct UniquesMigration;

impl frame_support::traits::OnRuntimeUpgrade for InitStorageVersions {
impl OnRuntimeUpgrade for UniquesMigration {
fn on_runtime_upgrade() -> Weight {
use frame_support::traits::{GetStorageVersion, StorageVersion};
use sp_runtime::traits::Saturating;

let mut writes = 0;

if Multisig::on_chain_storage_version() == StorageVersion::new(0) {
Multisig::current_storage_version().put::<Multisig>();
writes.saturating_inc();
}

if PolkadotXcm::on_chain_storage_version() == StorageVersion::new(0) {
PolkadotXcm::current_storage_version().put::<PolkadotXcm>();
writes.saturating_inc();
}

if Nfts::on_chain_storage_version() == StorageVersion::new(0) {
Nfts::current_storage_version().put::<Nfts>();
writes.saturating_inc();
}

if ForeignAssets::on_chain_storage_version() == StorageVersion::new(0) {
ForeignAssets::current_storage_version().put::<ForeignAssets>();
writes.saturating_inc();
}

if Uniques::on_chain_storage_version() == StorageVersion::new(0) {
Uniques::current_storage_version().put::<Uniques>();
writes.saturating_inc();
}

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(4, writes)
pallet_uniques::migration::migrate_to_v1::<Runtime, (), pallet_uniques::Pallet<Runtime>>()
}
}

Expand Down
27 changes: 1 addition & 26 deletions system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,7 @@ pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

/// Migrations to apply on runtime upgrade.
pub type Migrations =
(pallet_collator_selection::migration::v1::MigrateToV1<Runtime>, InitStorageVersions);

/// Migration to initialize storage versions for pallets added after genesis.
///
/// Ideally this would be done automatically (see
/// <https://github.com/paritytech/polkadot-sdk/pull/1297>), but it probably won't be ready for some
/// time and it's beneficial to get storage version issues smoothed over before merging
/// <https://github.com/polkadot-fellows/runtimes/pull/28> so we're just setting them manually.
pub struct InitStorageVersions;

impl frame_support::traits::OnRuntimeUpgrade for InitStorageVersions {
fn on_runtime_upgrade() -> Weight {
use frame_support::traits::{GetStorageVersion, StorageVersion};
use sp_runtime::traits::Saturating;

let mut writes = 0;

if PolkadotXcm::on_chain_storage_version() == StorageVersion::new(0) {
PolkadotXcm::current_storage_version().put::<PolkadotXcm>();
writes.saturating_inc();
}

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, writes)
}
}
pub type Migrations = ();

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

/// Migrations to apply on runtime upgrade.
pub type Migrations = (pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,);
pub type Migrations = ();

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Expand Down
50 changes: 1 addition & 49 deletions system-parachains/collectives/collectives-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,55 +683,7 @@ pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
/// All migrations executed on runtime upgrade as a nested tuple of types implementing
/// `OnRuntimeUpgrade`. Included migrations must be idempotent.
type Migrations = (
// unreleased
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
InitStorageVersions,
);

/// Migration to initialize storage versions for pallets added after genesis.
///
/// Ideally this would be done automatically (see
/// <https://github.com/paritytech/polkadot-sdk/pull/1297>), but it probably won't be ready for some
/// time and it's beneficial to get storage version issues smoothed over before merging
/// <https://github.com/polkadot-fellows/runtimes/pull/28> so we're just setting them manually.
pub struct InitStorageVersions;

impl frame_support::traits::OnRuntimeUpgrade for InitStorageVersions {
fn on_runtime_upgrade() -> Weight {
use frame_support::traits::{GetStorageVersion, StorageVersion};
use sp_runtime::traits::Saturating;

let mut writes = 0;

if Multisig::on_chain_storage_version() == StorageVersion::new(0) {
Multisig::current_storage_version().put::<Multisig>();
writes.saturating_inc();
}

if PolkadotXcm::on_chain_storage_version() == StorageVersion::new(0) {
PolkadotXcm::current_storage_version().put::<PolkadotXcm>();
writes.saturating_inc();
}

if Preimage::on_chain_storage_version() == StorageVersion::new(0) {
Preimage::current_storage_version().put::<Preimage>();
writes.saturating_inc();
}

if Scheduler::on_chain_storage_version() == StorageVersion::new(0) {
Scheduler::current_storage_version().put::<Scheduler>();
writes.saturating_inc();
}

if FellowshipReferenda::on_chain_storage_version() == StorageVersion::new(0) {
FellowshipReferenda::current_storage_version().put::<FellowshipReferenda>();
writes.saturating_inc();
}

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(5, writes)
}
}
type Migrations = ();

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Expand Down

0 comments on commit 3caec69

Please sign in to comment.