From 52ac56904575de5f37476f667c0857530cce4e53 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 25 Nov 2024 15:13:59 +0800 Subject: [PATCH] Bump storage version --- pallet/staking/src/lib.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/pallet/staking/src/lib.rs b/pallet/staking/src/lib.rs index 057f24adb..6c9451604 100644 --- a/pallet/staking/src/lib.rs +++ b/pallet/staking/src/lib.rs @@ -40,6 +40,20 @@ pub mod migration { where T: Config, { + let ver = StorageVersion::get::>(); + let (mut r, mut w) = (1, 0); + + if ver != 2 { + log::warn!( + "\ + [pallet::staking] skipping v2 to v3 migration: executed on wrong storage version.\ + Expected version 2, found {ver:?}\ + ", + ); + + return (r, w); + } + fn clear(item: &[u8], r: &mut u64, w: &mut u64) { let res = migration::clear_storage_prefix(PALLET, item, &[], None, None); @@ -47,8 +61,6 @@ pub mod migration { *w += res.backend as u64; } - let rw @ (mut r, mut w) = (1, 1); - clear(b"Collators", &mut r, &mut w); clear(b"Nominators", &mut r, &mut w); clear(b"ExposureCacheStates", &mut r, &mut w); @@ -69,9 +81,16 @@ pub mod migration { )>(PALLET, b"AuthoredBlocksCount", &[]) { >::put(abc); + + r += 1; + w += 1; } - rw + StorageVersion::new(3).put::>(); + + w += 1; + + (r, w) } pub fn post_check() @@ -138,6 +157,8 @@ pub mod pallet { // darwinia use crate::*; + const STORAGE_VERSION: StorageVersion = StorageVersion::new(3); + #[pallet::config] pub trait Config: frame_system::Config { /// Override the [`frame_system::Config::RuntimeEvent`]. @@ -256,6 +277,7 @@ pub mod pallet { } #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::hooks] impl Hooks> for Pallet {