Skip to content

Commit

Permalink
Bump storage version
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Nov 25, 2024
1 parent 1f85158 commit 52ac569
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions pallet/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,27 @@ pub mod migration {
where
T: Config,
{
let ver = StorageVersion::get::<Pallet<T>>();
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);

*r += res.loops as u64;
*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);
Expand All @@ -69,9 +81,16 @@ pub mod migration {
)>(PALLET, b"AuthoredBlocksCount", &[])
{
<AuthoredBlockCount<T>>::put(abc);

r += 1;
w += 1;
}

rw
StorageVersion::new(3).put::<Pallet<T>>();

w += 1;

(r, w)
}

pub fn post_check<T>()
Expand Down Expand Up @@ -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`].
Expand Down Expand Up @@ -256,6 +277,7 @@ pub mod pallet {
}

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
Expand Down

0 comments on commit 52ac569

Please sign in to comment.