Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit f13e389

Browse files
bkchrliamaharon
andauthored
Ensure all StorageVersions on Polkadot/Kusama are correct (#7199)
* Yeah * Fix all the migrations for Kusama & Polkadot --------- Co-authored-by: Liam Aharon <[email protected]>
1 parent e260da4 commit f13e389

File tree

9 files changed

+75
-18
lines changed

9 files changed

+75
-18
lines changed

runtime/common/src/crowdloan/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub mod pallet {
183183
use frame_system::{ensure_root, ensure_signed, pallet_prelude::*};
184184

185185
/// The current storage version.
186-
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
186+
const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);
187187

188188
#[pallet::pallet]
189189
#[pallet::without_storage_info]

runtime/kusama/src/lib.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,7 @@ pub type Migrations =
14681468
#[allow(deprecated, missing_docs)]
14691469
pub mod migrations {
14701470
use super::*;
1471+
use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion};
14711472

14721473
pub type V0940 = (
14731474
pallet_nomination_pools::migration::v4::MigrateToV4<
@@ -1484,7 +1485,29 @@ pub mod migrations {
14841485
);
14851486

14861487
/// Unreleased migrations. Add new ones here:
1487-
pub type Unreleased = ();
1488+
pub type Unreleased = SetStorageVersions;
1489+
1490+
/// Migrations that set `StorageVersion`s we missed to set.
1491+
pub struct SetStorageVersions;
1492+
1493+
impl OnRuntimeUpgrade for SetStorageVersions {
1494+
fn on_runtime_upgrade() -> Weight {
1495+
// The `NisCounterpartBalances` pallet was added to the chain after/with the migration.
1496+
// So, the migration never needed to be executed, but we also did not set the proper `StorageVersion`.
1497+
let storage_version = NisCounterpartBalances::on_chain_storage_version();
1498+
if storage_version < 1 {
1499+
StorageVersion::new(1).put::<NisCounterpartBalances>();
1500+
}
1501+
1502+
// Was missed as part of: `runtime_common::session::migration::ClearOldSessionStorage<Runtime>`.
1503+
let storage_version = Historical::on_chain_storage_version();
1504+
if storage_version < 1 {
1505+
StorageVersion::new(1).put::<Historical>();
1506+
}
1507+
1508+
RocksDbWeight::get().reads_writes(2, 2)
1509+
}
1510+
}
14881511
}
14891512

14901513
/// Unchecked extrinsic type as expected by this runtime.

runtime/parachains/src/disputes.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,12 @@ pub mod pallet {
446446
type WeightInfo: WeightInfo;
447447
}
448448

449+
/// The current storage version.
450+
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
451+
449452
#[pallet::pallet]
450453
#[pallet::without_storage_info]
454+
#[pallet::storage_version(STORAGE_VERSION)]
451455
pub struct Pallet<T>(_);
452456

453457
/// The last pruned session, if any. All data stored by this module

runtime/parachains/src/disputes/migration.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
1919
use frame_support::traits::StorageVersion;
2020

21-
/// The current storage version.
22-
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
23-
2421
pub mod v1 {
2522
use super::*;
2623
use crate::disputes::{Config, Pallet};
@@ -38,10 +35,10 @@ pub mod v1 {
3835
fn on_runtime_upgrade() -> Weight {
3936
let mut weight: Weight = Weight::zero();
4037

41-
if StorageVersion::get::<Pallet<T>>() < STORAGE_VERSION {
38+
if StorageVersion::get::<Pallet<T>>() < 1 {
4239
log::info!(target: crate::disputes::LOG_TARGET, "Migrating disputes storage to v1");
4340
weight += migrate_to_v1::<T>();
44-
STORAGE_VERSION.put::<Pallet<T>>();
41+
StorageVersion::new(1).put::<Pallet<T>>();
4542
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
4643
} else {
4744
log::info!(
@@ -71,7 +68,7 @@ pub mod v1 {
7168
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
7269
log::trace!(target: crate::disputes::LOG_TARGET, "Running post_upgrade()");
7370
ensure!(
74-
StorageVersion::get::<Pallet<T>>() == STORAGE_VERSION,
71+
StorageVersion::get::<Pallet<T>>() >= 1,
7572
"Storage version should be `1` after the migration"
7673
);
7774
ensure!(

runtime/parachains/src/ump.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,11 @@ impl WeightInfo for TestWeightInfo {
214214
pub mod pallet {
215215
use super::*;
216216

217+
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
218+
217219
#[pallet::pallet]
218220
#[pallet::without_storage_info]
219-
#[pallet::storage_version(migration::STORAGE_VERSION)]
221+
#[pallet::storage_version(STORAGE_VERSION)]
220222
pub struct Pallet<T>(_);
221223

222224
#[pallet::config]

runtime/parachains/src/ump/migration.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ use frame_support::{
2121
weights::Weight,
2222
};
2323

24-
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
25-
2624
pub mod v1 {
2725
use super::*;
2826

runtime/polkadot/src/lib.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,13 +1437,24 @@ impl Get<Perbill> for NominationPoolsMigrationV4OldPallet {
14371437
///
14381438
/// This contains the combined migrations of the last 10 releases. It allows to skip runtime
14391439
/// upgrades in case governance decides to do so. THE ORDER IS IMPORTANT.
1440-
pub type Migrations =
1441-
(migrations::V0940, migrations::V0941, migrations::V0942, migrations::Unreleased);
1440+
pub type Migrations = (
1441+
migrations::V0938,
1442+
migrations::V0940,
1443+
migrations::V0941,
1444+
migrations::V0942,
1445+
migrations::Unreleased,
1446+
);
14421447

14431448
/// The runtime migrations per release.
14441449
#[allow(deprecated, missing_docs)]
14451450
pub mod migrations {
14461451
use super::*;
1452+
use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion};
1453+
1454+
pub type V0938 = (
1455+
pallet_xcm::migration::v1::MigrateToV1<Runtime>,
1456+
parachains_ump::migration::v1::MigrateToV1<Runtime>,
1457+
);
14471458

14481459
pub type V0940 = (
14491460
pallet_nomination_pools::migration::v4::MigrateToV4<
@@ -1460,7 +1471,29 @@ pub mod migrations {
14601471
);
14611472

14621473
/// Unreleased migrations. Add new ones here:
1463-
pub type Unreleased = ();
1474+
pub type Unreleased = SetStorageVersions;
1475+
1476+
/// Migrations that set `StorageVersion`s we missed to set.
1477+
pub struct SetStorageVersions;
1478+
1479+
impl OnRuntimeUpgrade for SetStorageVersions {
1480+
fn on_runtime_upgrade() -> Weight {
1481+
// `Referenda` pallet was added on chain after the migration to version `1` was added.
1482+
// Thus, it never required the migration and we just missed to set the correct `StorageVersion`.
1483+
let storage_version = Referenda::on_chain_storage_version();
1484+
if storage_version < 1 {
1485+
StorageVersion::new(1).put::<Referenda>();
1486+
}
1487+
1488+
// Was missed as part of: `runtime_common::session::migration::ClearOldSessionStorage<Runtime>`.
1489+
let storage_version = Historical::on_chain_storage_version();
1490+
if storage_version < 1 {
1491+
StorageVersion::new(1).put::<Historical>();
1492+
}
1493+
1494+
RocksDbWeight::get().reads_writes(2, 2)
1495+
}
1496+
}
14641497
}
14651498

14661499
/// Unchecked extrinsic type as expected by this runtime.

xcm/pallet-xcm/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ pub mod pallet {
162162
pub const CurrentXcmVersion: u32 = XCM_VERSION;
163163
}
164164

165+
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
166+
165167
#[pallet::pallet]
166-
#[pallet::storage_version(migration::STORAGE_VERSION)]
168+
#[pallet::storage_version(STORAGE_VERSION)]
167169
#[pallet::without_storage_info]
168170
pub struct Pallet<T>(_);
169171

xcm/pallet-xcm/src/migration.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ use frame_support::{
2121
weights::Weight,
2222
};
2323

24-
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
25-
2624
const DEFAULT_PROOF_SIZE: u64 = 64 * 1024;
2725

2826
pub mod v1 {
@@ -51,7 +49,7 @@ pub mod v1 {
5149
VersionNotifyTargets::<T>::translate_values(translate);
5250

5351
log::info!("v1 applied successfully");
54-
STORAGE_VERSION.put::<Pallet<T>>();
52+
StorageVersion::new(1).put::<Pallet<T>>();
5553

5654
weight.saturating_add(T::DbWeight::get().writes(1))
5755
} else {

0 commit comments

Comments
 (0)