From f13e389922e1ed3982fad1d363ddb85e47be6e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 17 May 2023 16:53:01 +0200 Subject: [PATCH] Ensure all `StorageVersion`s on Polkadot/Kusama are correct (#7199) * Yeah * Fix all the migrations for Kusama & Polkadot --------- Co-authored-by: Liam Aharon --- runtime/common/src/crowdloan/mod.rs | 2 +- runtime/kusama/src/lib.rs | 25 ++++++++++++- runtime/parachains/src/disputes.rs | 4 ++ runtime/parachains/src/disputes/migration.rs | 9 ++--- runtime/parachains/src/ump.rs | 4 +- runtime/parachains/src/ump/migration.rs | 2 - runtime/polkadot/src/lib.rs | 39 ++++++++++++++++++-- xcm/pallet-xcm/src/lib.rs | 4 +- xcm/pallet-xcm/src/migration.rs | 4 +- 9 files changed, 75 insertions(+), 18 deletions(-) diff --git a/runtime/common/src/crowdloan/mod.rs b/runtime/common/src/crowdloan/mod.rs index 737a36989964..49381817554f 100644 --- a/runtime/common/src/crowdloan/mod.rs +++ b/runtime/common/src/crowdloan/mod.rs @@ -183,7 +183,7 @@ pub mod pallet { use frame_system::{ensure_root, ensure_signed, pallet_prelude::*}; /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); #[pallet::pallet] #[pallet::without_storage_info] diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 57659f81cbdb..b0136170a933 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1468,6 +1468,7 @@ pub type Migrations = #[allow(deprecated, missing_docs)] pub mod migrations { use super::*; + use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion}; pub type V0940 = ( pallet_nomination_pools::migration::v4::MigrateToV4< @@ -1484,7 +1485,29 @@ pub mod migrations { ); /// Unreleased migrations. Add new ones here: - pub type Unreleased = (); + pub type Unreleased = SetStorageVersions; + + /// Migrations that set `StorageVersion`s we missed to set. + pub struct SetStorageVersions; + + impl OnRuntimeUpgrade for SetStorageVersions { + fn on_runtime_upgrade() -> Weight { + // The `NisCounterpartBalances` pallet was added to the chain after/with the migration. + // So, the migration never needed to be executed, but we also did not set the proper `StorageVersion`. + let storage_version = NisCounterpartBalances::on_chain_storage_version(); + if storage_version < 1 { + StorageVersion::new(1).put::(); + } + + // Was missed as part of: `runtime_common::session::migration::ClearOldSessionStorage`. + let storage_version = Historical::on_chain_storage_version(); + if storage_version < 1 { + StorageVersion::new(1).put::(); + } + + RocksDbWeight::get().reads_writes(2, 2) + } + } } /// Unchecked extrinsic type as expected by this runtime. diff --git a/runtime/parachains/src/disputes.rs b/runtime/parachains/src/disputes.rs index 6e423bacaa1b..3141c1e24741 100644 --- a/runtime/parachains/src/disputes.rs +++ b/runtime/parachains/src/disputes.rs @@ -446,8 +446,12 @@ pub mod pallet { type WeightInfo: WeightInfo; } + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + #[pallet::pallet] #[pallet::without_storage_info] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); /// The last pruned session, if any. All data stored by this module diff --git a/runtime/parachains/src/disputes/migration.rs b/runtime/parachains/src/disputes/migration.rs index ff9f2ca54d0c..73ef22fb7d01 100644 --- a/runtime/parachains/src/disputes/migration.rs +++ b/runtime/parachains/src/disputes/migration.rs @@ -18,9 +18,6 @@ use frame_support::traits::StorageVersion; -/// The current storage version. -const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); - pub mod v1 { use super::*; use crate::disputes::{Config, Pallet}; @@ -38,10 +35,10 @@ pub mod v1 { fn on_runtime_upgrade() -> Weight { let mut weight: Weight = Weight::zero(); - if StorageVersion::get::>() < STORAGE_VERSION { + if StorageVersion::get::>() < 1 { log::info!(target: crate::disputes::LOG_TARGET, "Migrating disputes storage to v1"); weight += migrate_to_v1::(); - STORAGE_VERSION.put::>(); + StorageVersion::new(1).put::>(); weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); } else { log::info!( @@ -71,7 +68,7 @@ pub mod v1 { fn post_upgrade(_state: Vec) -> Result<(), &'static str> { log::trace!(target: crate::disputes::LOG_TARGET, "Running post_upgrade()"); ensure!( - StorageVersion::get::>() == STORAGE_VERSION, + StorageVersion::get::>() >= 1, "Storage version should be `1` after the migration" ); ensure!( diff --git a/runtime/parachains/src/ump.rs b/runtime/parachains/src/ump.rs index be761b4236a3..eeaf1fca176d 100644 --- a/runtime/parachains/src/ump.rs +++ b/runtime/parachains/src/ump.rs @@ -214,9 +214,11 @@ impl WeightInfo for TestWeightInfo { pub mod pallet { use super::*; + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + #[pallet::pallet] #[pallet::without_storage_info] - #[pallet::storage_version(migration::STORAGE_VERSION)] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::config] diff --git a/runtime/parachains/src/ump/migration.rs b/runtime/parachains/src/ump/migration.rs index d77cf320c60d..22d7b9adca45 100644 --- a/runtime/parachains/src/ump/migration.rs +++ b/runtime/parachains/src/ump/migration.rs @@ -21,8 +21,6 @@ use frame_support::{ weights::Weight, }; -pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); - pub mod v1 { use super::*; diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 7c06ee84901c..8968308c0ed6 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -1437,13 +1437,24 @@ impl Get for NominationPoolsMigrationV4OldPallet { /// /// This contains the combined migrations of the last 10 releases. It allows to skip runtime /// upgrades in case governance decides to do so. THE ORDER IS IMPORTANT. -pub type Migrations = - (migrations::V0940, migrations::V0941, migrations::V0942, migrations::Unreleased); +pub type Migrations = ( + migrations::V0938, + migrations::V0940, + migrations::V0941, + migrations::V0942, + migrations::Unreleased, +); /// The runtime migrations per release. #[allow(deprecated, missing_docs)] pub mod migrations { use super::*; + use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion}; + + pub type V0938 = ( + pallet_xcm::migration::v1::MigrateToV1, + parachains_ump::migration::v1::MigrateToV1, + ); pub type V0940 = ( pallet_nomination_pools::migration::v4::MigrateToV4< @@ -1460,7 +1471,29 @@ pub mod migrations { ); /// Unreleased migrations. Add new ones here: - pub type Unreleased = (); + pub type Unreleased = SetStorageVersions; + + /// Migrations that set `StorageVersion`s we missed to set. + pub struct SetStorageVersions; + + impl OnRuntimeUpgrade for SetStorageVersions { + fn on_runtime_upgrade() -> Weight { + // `Referenda` pallet was added on chain after the migration to version `1` was added. + // Thus, it never required the migration and we just missed to set the correct `StorageVersion`. + let storage_version = Referenda::on_chain_storage_version(); + if storage_version < 1 { + StorageVersion::new(1).put::(); + } + + // Was missed as part of: `runtime_common::session::migration::ClearOldSessionStorage`. + let storage_version = Historical::on_chain_storage_version(); + if storage_version < 1 { + StorageVersion::new(1).put::(); + } + + RocksDbWeight::get().reads_writes(2, 2) + } + } } /// Unchecked extrinsic type as expected by this runtime. diff --git a/xcm/pallet-xcm/src/lib.rs b/xcm/pallet-xcm/src/lib.rs index 16766b7ab90f..58d363665f28 100644 --- a/xcm/pallet-xcm/src/lib.rs +++ b/xcm/pallet-xcm/src/lib.rs @@ -162,8 +162,10 @@ pub mod pallet { pub const CurrentXcmVersion: u32 = XCM_VERSION; } + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + #[pallet::pallet] - #[pallet::storage_version(migration::STORAGE_VERSION)] + #[pallet::storage_version(STORAGE_VERSION)] #[pallet::without_storage_info] pub struct Pallet(_); diff --git a/xcm/pallet-xcm/src/migration.rs b/xcm/pallet-xcm/src/migration.rs index 32bc5e764c57..34d9193fffaa 100644 --- a/xcm/pallet-xcm/src/migration.rs +++ b/xcm/pallet-xcm/src/migration.rs @@ -21,8 +21,6 @@ use frame_support::{ weights::Weight, }; -pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); - const DEFAULT_PROOF_SIZE: u64 = 64 * 1024; pub mod v1 { @@ -51,7 +49,7 @@ pub mod v1 { VersionNotifyTargets::::translate_values(translate); log::info!("v1 applied successfully"); - STORAGE_VERSION.put::>(); + StorageVersion::new(1).put::>(); weight.saturating_add(T::DbWeight::get().writes(1)) } else {