From 2eaf389fca3bd37f19f496c9ee77bb9302810d44 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Thu, 18 May 2023 12:23:30 +0400 Subject: [PATCH 01/13] set fastunstake storage version --- runtime/westend/src/lib.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 538900f83a78..f02389a506db 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1220,6 +1220,8 @@ pub type Migrations = /// The runtime migrations per release. #[allow(deprecated, missing_docs)] pub mod migrations { + use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion}; + use super::*; pub type V0940 = ( @@ -1237,7 +1239,21 @@ 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 { + let storage_version = FastUnstake::on_chain_storage_version(); + if storage_version < 1 { + StorageVersion::new(1).put::(); + } + + RocksDbWeight::get().reads_writes(1, 1) + } + } } /// Unchecked extrinsic type as expected by this runtime. From 5b5dc80036a53ce119fef525764e6b93f538b43e Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Thu, 18 May 2023 14:50:39 +0400 Subject: [PATCH 02/13] fix configration migration hooks --- runtime/parachains/src/configuration.rs | 4 +++- .../parachains/src/configuration/migration.rs | 16 +++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index 380ae4770851..482715667e32 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -485,8 +485,10 @@ impl WeightInfo for TestWeightInfo { pub mod pallet { use super::*; + const STORAGE_VERSION: StorageVersion = StorageVersion::new(5); + #[pallet::pallet] - #[pallet::storage_version(migration::STORAGE_VERSION)] + #[pallet::storage_version(STORAGE_VERSION)] #[pallet::without_storage_info] pub struct Pallet(_); diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index 3aef1761117b..cc5062e9696c 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -31,7 +31,6 @@ use sp_std::vec::Vec; /// v4-v5: /// + /// + -pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(5); pub mod v5 { use super::*; @@ -144,9 +143,12 @@ pub mod v5 { impl OnRuntimeUpgrade for MigrateToV5 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { - log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()"); + log::trace!(target: configuration::LOG_TARGET, "Running pre_upgrade()"); - ensure!(StorageVersion::get::>() == 4, "The migration requires version 4"); + ensure!( + Pallet::::current_storage_version() >= Pallet::::on_chain_storage_version(), + "configuration::migration::v5: on_chain version is greater than current version" + ); Ok(Vec::new()) } @@ -155,11 +157,11 @@ pub mod v5 { let weight_consumed = migrate_to_v5::(); log::info!(target: configuration::LOG_TARGET, "MigrateToV5 executed successfully"); - STORAGE_VERSION.put::>(); + StorageVersion::new(5).put::>(); weight_consumed } else { - log::warn!(target: configuration::LOG_TARGET, "MigrateToV5 should be removed."); + log::warn!(target: configuration::LOG_TARGET, "MigrateToV5 can be removed."); T::DbWeight::get().reads(1) } } @@ -168,8 +170,8 @@ pub mod v5 { fn post_upgrade(_state: Vec) -> Result<(), &'static str> { log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()"); ensure!( - StorageVersion::get::>() == STORAGE_VERSION, - "Storage version should be 5 after the migration" + StorageVersion::get::>() == StorageVersion::new(5), + "Storage version must be 5 after the migration" ); Ok(()) From d4e0926a8a950b2f947192d8085876064658e925 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Thu, 18 May 2023 16:47:16 +0400 Subject: [PATCH 03/13] set missing rococo versions --- runtime/rococo/src/lib.rs | 103 +++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 0f2c63e22a6e..0f58a245f773 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1486,6 +1486,7 @@ pub type Migrations = #[allow(deprecated, missing_docs)] pub mod migrations { use super::*; + use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion}; pub type V0940 = (); pub type V0941 = (); // Node only release - no migrations. @@ -1495,7 +1496,107 @@ 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. + /// + /// It's *possible* that these pallets have not in fact been migrated to the versions being set, + /// which we should keep in mind in the future if we notice any strange behavior. + /// We opted to not check exactly what on-chain versions each pallet is at, since it would be + /// an involved effort, this is testnet, and no one has complained + /// (https://github.com/paritytech/polkadot/issues/6657#issuecomment-1552956439). + pub struct SetStorageVersions; + + impl OnRuntimeUpgrade for SetStorageVersions { + fn on_runtime_upgrade() -> Weight { + let mut writes = 0; + let mut reads = 0; + + // Council + let storage_version = Council::on_chain_storage_version(); + if storage_version < 4 { + // Safe to assume Council was created with V4 pallet. + StorageVersion::new(4).put::(); + writes += 1; + } + reads += 1; + + // Technical Committee + let storage_version = TechnicalCommittee::on_chain_storage_version(); + if storage_version < 4 { + StorageVersion::new(4).put::(); + writes += 1; + } + reads += 1; + + // PhragmenElection + let storage_version = PhragmenElection::on_chain_storage_version(); + if storage_version < 4 { + StorageVersion::new(4).put::(); + writes += 1; + } + reads += 1; + + // TechnicalMembership + let storage_version = TechnicalMembership::on_chain_storage_version(); + if storage_version < 4 { + // Did not miss V4 upgrade because version would have been set in storage, qed. + StorageVersion::new(4).put::(); + writes += 1; + } + reads += 1; + + // Scheduler + let storage_version = Scheduler::on_chain_storage_version(); + if storage_version < 4 { + StorageVersion::new(4).put::(); + writes += 1; + } + reads += 1; + + // Bounties + let storage_version = Bounties::on_chain_storage_version(); + if storage_version < 4 { + StorageVersion::new(4).put::(); + writes += 1; + } + reads += 1; + + // Tips + let storage_version = Tips::on_chain_storage_version(); + if storage_version < 4 { + StorageVersion::new(4).put::(); + writes += 1; + } + reads += 1; + + // NisCounterpartBalances + let storage_version = NisCounterpartBalances::on_chain_storage_version(); + if storage_version < 1 { + StorageVersion::new(1).put::(); + writes += 1; + } + reads += 1; + + // Crowdloan + let storage_version = Crowdloan::on_chain_storage_version(); + if storage_version < 2 { + StorageVersion::new(2).put::(); + writes += 1; + } + reads += 1; + + // ChildBounties + let storage_version = ChildBounties::on_chain_storage_version(); + if storage_version < 1 { + StorageVersion::new(1).put::(); + writes += 1; + } + reads += 1; + + RocksDbWeight::get().reads_writes(reads, writes) + } + } } /// Executive: handles dispatch to the various modules. From b2efa1c711bb5ff94f5926cf5dee5000354295e2 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Thu, 18 May 2023 16:56:41 +0400 Subject: [PATCH 04/13] remove child bounties version set --- runtime/rococo/src/lib.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 0f58a245f773..114a68b0b51b 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1586,14 +1586,6 @@ pub mod migrations { } reads += 1; - // ChildBounties - let storage_version = ChildBounties::on_chain_storage_version(); - if storage_version < 1 { - StorageVersion::new(1).put::(); - writes += 1; - } - reads += 1; - RocksDbWeight::get().reads_writes(reads, writes) } } From 7942d56e269a13cf01ca350b824917fa6ef2ee8e Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Thu, 18 May 2023 17:01:53 +0400 Subject: [PATCH 05/13] future proof this configuration migration --- runtime/parachains/src/configuration/migration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index cc5062e9696c..b67088af2890 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -170,8 +170,8 @@ pub mod v5 { fn post_upgrade(_state: Vec) -> Result<(), &'static str> { log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()"); ensure!( - StorageVersion::get::>() == StorageVersion::new(5), - "Storage version must be 5 after the migration" + StorageVersion::get::>() >= StorageVersion::new(5), + "Storage version must at least 5 after this migration" ); Ok(()) From b59da2daf2e4c55d4b6ce2ceb58bd712a64a09c6 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Thu, 18 May 2023 17:03:44 +0400 Subject: [PATCH 06/13] simplify rococo migration --- runtime/rococo/src/lib.rs | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 114a68b0b51b..60a5f731ae93 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1513,8 +1513,7 @@ pub mod migrations { let mut reads = 0; // Council - let storage_version = Council::on_chain_storage_version(); - if storage_version < 4 { + if Council::on_chain_storage_version() < 4 { // Safe to assume Council was created with V4 pallet. StorageVersion::new(4).put::(); writes += 1; @@ -1522,24 +1521,21 @@ pub mod migrations { reads += 1; // Technical Committee - let storage_version = TechnicalCommittee::on_chain_storage_version(); - if storage_version < 4 { + if TechnicalCommittee::on_chain_storage_version() < 4 { StorageVersion::new(4).put::(); writes += 1; } reads += 1; // PhragmenElection - let storage_version = PhragmenElection::on_chain_storage_version(); - if storage_version < 4 { + if PhragmenElection::on_chain_storage_version() < 4 { StorageVersion::new(4).put::(); writes += 1; } reads += 1; // TechnicalMembership - let storage_version = TechnicalMembership::on_chain_storage_version(); - if storage_version < 4 { + if TechnicalMembership::on_chain_storage_version() < 4 { // Did not miss V4 upgrade because version would have been set in storage, qed. StorageVersion::new(4).put::(); writes += 1; @@ -1547,40 +1543,35 @@ pub mod migrations { reads += 1; // Scheduler - let storage_version = Scheduler::on_chain_storage_version(); - if storage_version < 4 { + if Scheduler::on_chain_storage_version() < 4 { StorageVersion::new(4).put::(); writes += 1; } reads += 1; // Bounties - let storage_version = Bounties::on_chain_storage_version(); - if storage_version < 4 { + if Bounties::on_chain_storage_version() < 4 { StorageVersion::new(4).put::(); writes += 1; } reads += 1; // Tips - let storage_version = Tips::on_chain_storage_version(); - if storage_version < 4 { + if Tips::on_chain_storage_version() < 4 { StorageVersion::new(4).put::(); writes += 1; } reads += 1; // NisCounterpartBalances - let storage_version = NisCounterpartBalances::on_chain_storage_version(); - if storage_version < 1 { + if NisCounterpartBalances::on_chain_storage_version() < 1 { StorageVersion::new(1).put::(); writes += 1; } reads += 1; // Crowdloan - let storage_version = Crowdloan::on_chain_storage_version(); - if storage_version < 2 { + if Crowdloan::on_chain_storage_version() < 2 { StorageVersion::new(2).put::(); writes += 1; } From 1d225f4d9614a3850668284df81ac146db02d122 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Thu, 18 May 2023 17:07:46 +0400 Subject: [PATCH 07/13] simplify westend version migration --- runtime/westend/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index f02389a506db..87e679c995fe 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1246,12 +1246,12 @@ pub mod migrations { impl OnRuntimeUpgrade for SetStorageVersions { fn on_runtime_upgrade() -> Weight { - let storage_version = FastUnstake::on_chain_storage_version(); - if storage_version < 1 { + if FastUnstake::on_chain_storage_version() < 1 { StorageVersion::new(1).put::(); + return RocksDbWeight::get().reads_writes(1, 1) } - RocksDbWeight::get().reads_writes(1, 1) + RocksDbWeight::get().reads(1) } } } From 349255ccdeb18165022e184d6158c9dc3a9eb00e Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Thu, 18 May 2023 17:10:11 +0400 Subject: [PATCH 08/13] typo --- runtime/parachains/src/configuration/migration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index b67088af2890..6e27f16991bd 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -171,7 +171,7 @@ pub mod v5 { log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()"); ensure!( StorageVersion::get::>() >= StorageVersion::new(5), - "Storage version must at least 5 after this migration" + "Storage version must be at least 5 after this migration" ); Ok(()) From f01e098458063ee367fff2f04ba76aca8dc75a61 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Mon, 22 May 2023 12:26:33 +0400 Subject: [PATCH 09/13] restore missing comments --- runtime/rococo/src/lib.rs | 2 ++ runtime/westend/src/lib.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 587475a60c75..3498f2b68b53 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1618,6 +1618,8 @@ pub mod migrations { RocksDbWeight::get().reads_writes(reads, writes) } } + + /// Unreleased migrations. Add new ones here: pub type Unreleased = ( SetStorageVersions, // Remove UMP dispatch queue diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 1dcebd61af34..0560b9eb923e 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1299,6 +1299,7 @@ pub mod migrations { } } + /// Unreleased migrations. Add new ones here: pub type Unreleased = ( SetStorageVersions, // Remove UMP dispatch queue From 596e2a482120fd079072d5ec19ca5d83e3a80e57 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Mon, 22 May 2023 12:28:51 +0400 Subject: [PATCH 10/13] set configuration storage version correctly --- runtime/parachains/src/configuration.rs | 12 +++++++++++- runtime/parachains/src/configuration/migration.rs | 13 ------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index dab58a1c00f3..05b0ca1fc538 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -473,7 +473,17 @@ impl WeightInfo for TestWeightInfo { pub mod pallet { use super::*; - const STORAGE_VERSION: StorageVersion = StorageVersion::new(5); + /// The current storage version. + /// + /// v0-v1: + /// v1-v2: + /// v2-v3: + /// v3-v4: + /// v4-v5: + /// + + /// + + /// v5-v6: (remove UMP dispatch queue) + const STORAGE_VERSION: StorageVersion = StorageVersion::new(6); #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index c41d4f3055b7..e499854e1188 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -16,20 +16,7 @@ //! A module that is responsible for migration of storage. -use frame_support::traits::StorageVersion; use primitives::ExecutorParams; -/// The current storage version. -/// -/// v0-v1: -/// v1-v2: -/// v2-v3: -/// v3-v4: -/// v4-v5: -/// + -/// + -/// v5-v6: (remove UMP dispatch queue) -pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(6); - pub mod v5; pub mod v6; From 4e76341b68f836d275b55a7d7e1bdecf3dd28e17 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Mon, 22 May 2023 12:52:01 +0400 Subject: [PATCH 11/13] remove redundant preupgrade version check --- runtime/parachains/src/configuration/migration/v5.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/parachains/src/configuration/migration/v5.rs b/runtime/parachains/src/configuration/migration/v5.rs index 8cb17408878e..5327686ddac0 100644 --- a/runtime/parachains/src/configuration/migration/v5.rs +++ b/runtime/parachains/src/configuration/migration/v5.rs @@ -262,8 +262,6 @@ impl OnRuntimeUpgrade for MigrateToV5 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()"); - - ensure!(StorageVersion::get::>() == 4, "The migration requires version 4"); Ok(Vec::new()) } @@ -285,8 +283,8 @@ impl OnRuntimeUpgrade for MigrateToV5 { fn post_upgrade(_state: Vec) -> Result<(), &'static str> { log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()"); ensure!( - StorageVersion::get::>() == 5, - "Storage version should be 5 after the migration" + StorageVersion::get::>() >= 5, + "Storage version should be greater or equal to 5 after the migration" ); Ok(()) From 903660b0ff88dcba910e843ba4304698cc3e2de4 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Mon, 22 May 2023 12:57:15 +0400 Subject: [PATCH 12/13] fix version checks --- runtime/parachains/src/configuration/migration/v6.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/parachains/src/configuration/migration/v6.rs b/runtime/parachains/src/configuration/migration/v6.rs index 44acaee71f49..db82dad87c5f 100644 --- a/runtime/parachains/src/configuration/migration/v6.rs +++ b/runtime/parachains/src/configuration/migration/v6.rs @@ -61,8 +61,6 @@ impl OnRuntimeUpgrade for MigrateToV6 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()"); - - ensure!(StorageVersion::get::>() == 5, "The migration requires version 4"); Ok(Vec::new()) } @@ -84,8 +82,8 @@ impl OnRuntimeUpgrade for MigrateToV6 { fn post_upgrade(_state: Vec) -> Result<(), &'static str> { log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()"); ensure!( - StorageVersion::get::>() == 6, - "Storage version should be 6 after the migration" + StorageVersion::get::>() >= 6, + "Storage version should be >= 6 after the migration" ); Ok(()) From 01d4e2f0f4bf659ad246d4850a6ee2ce908f5e2f Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Tue, 23 May 2023 12:09:10 +0400 Subject: [PATCH 13/13] remove redundant comment --- runtime/rococo/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 3498f2b68b53..a0b05aef8d9a 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1574,7 +1574,6 @@ pub mod migrations { // TechnicalMembership if TechnicalMembership::on_chain_storage_version() < 4 { - // Did not miss V4 upgrade because version would have been set in storage, qed. StorageVersion::new(4).put::(); writes += 1; }