From 4c49b6da36022f14a78b4c3ee0140486b86d7763 Mon Sep 17 00:00:00 2001 From: Marcin Date: Tue, 30 May 2023 12:29:58 +0200 Subject: [PATCH] =?UTF-8?q?A0-2586:=20Add=20storage=20version=20checks=20t?= =?UTF-8?q?o=20migrations.=20Bump=20pallet=20committee=20manag=E2=80=A6=20?= =?UTF-8?q?(#1236)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description In order to have the same version of the code for Testnet and Mainnet, we need to bump the storage version for pallet committee management to 1, and add if-conditions in pallet elections for storage versions This makes it possible to upload this runtime from 62 to 64, and also upload 64 alone on itself. In both cases, migrations would be run only once. We need to bump spec_version since runtime that is in `r-11.1-rc1` has 63, so we can't upload this without spec_version bump as it will cause wasm/native conflict. ## Type of change Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue --- bin/runtime/src/lib.rs | 2 +- pallets/committee-management/src/migration.rs | 8 ++++++-- pallets/elections/src/migration.rs | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/bin/runtime/src/lib.rs b/bin/runtime/src/lib.rs index cc9764d043..ae026caccd 100644 --- a/bin/runtime/src/lib.rs +++ b/bin/runtime/src/lib.rs @@ -110,7 +110,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("aleph-node"), impl_name: create_runtime_str!("aleph-node"), authoring_version: 1, - spec_version: 63, + spec_version: 64, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 14, diff --git a/pallets/committee-management/src/migration.rs b/pallets/committee-management/src/migration.rs index 32de1e620d..c2876b7f2e 100644 --- a/pallets/committee-management/src/migration.rs +++ b/pallets/committee-management/src/migration.rs @@ -61,7 +61,11 @@ pub struct PrefixMigration(sp_std::marker::PhantomData); impl OnRuntimeUpgrade for PrefixMigration { fn on_runtime_upgrade() -> Weight { if StorageVersion::get::>() != StorageVersion::new(0) { - return Weight::zero(); + info!( + target: LOG_TARGET, + "Skipping migrations from STORAGE_VERSION 0 to 1 for pallet committee management" + ); + return T::DbWeight::get().reads(1); }; let pallet_name = Pallet::::name(); @@ -89,7 +93,7 @@ impl OnRuntimeUpgrade for PrefixMigration { move_storage_from_pallet(prefix, OLD_PREFIX.as_bytes(), pallet_name.as_bytes()); info!(target: LOG_TARGET, "Migrated Banned"); - StorageVersion::new(0).put::>(); + StorageVersion::new(1).put::>(); ::BlockWeights::get().max_block } diff --git a/pallets/elections/src/migration.rs b/pallets/elections/src/migration.rs index 5a98cb42b6..44e07933d3 100644 --- a/pallets/elections/src/migration.rs +++ b/pallets/elections/src/migration.rs @@ -20,6 +20,14 @@ pub mod v4 { impl OnRuntimeUpgrade for Migration { fn on_runtime_upgrade() -> Weight { + if StorageVersion::get::>() != StorageVersion::new(3) { + log::info!( + target: LOG_TARGET, + "Skipping migrations from STORAGE_VERSION 3 to 4 for pallet elections" + ); + return T::DbWeight::get().reads(1); + }; + log::info!( target: LOG_TARGET, "Running migration from STORAGE_VERSION 3 to 4 for pallet elections" @@ -62,6 +70,14 @@ pub mod v5 { impl OnRuntimeUpgrade for Migration { fn on_runtime_upgrade() -> Weight { + if StorageVersion::get::>() != StorageVersion::new(4) { + log::info!( + target: LOG_TARGET, + "Skipping migrations from STORAGE_VERSION 4 to 5 for pallet elections" + ); + return T::DbWeight::get().reads(1); + }; + log::info!( target: LOG_TARGET, "Running migration from STORAGE_VERSION 4 to 5 for pallet elections"