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

Commit

Permalink
keep releases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ank4n committed Nov 19, 2022
1 parent 2a8dcc1 commit b592459
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
35 changes: 27 additions & 8 deletions frame/staking/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,53 @@ use frame_election_provider_support::SortedListProvider;
use frame_support::traits::OnRuntimeUpgrade;
use frame_support::dispatch::GetStorageVersion;

#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
enum OldReleases {
V1_0_0Ancient,
V2_0_0,
V3_0_0,
V4_0_0,
V5_0_0, // blockable validators.
V6_0_0, // removal of all storage associated with offchain phragmen.
V7_0_0, // keep track of number of nominators / validators in map
V8_0_0, // populate `VoterList`.
V9_0_0, // inject validators into `VoterList` as well.
V10_0_0, // remove `EarliestUnappliedSlash`.
V11_0_0, // Move pallet storage prefix, e.g. BagsList -> VoterBagsList
V12_0_0, // remove `HistoryDepth`.
}

impl Default for OldReleases {
fn default() -> Self {
OldReleases::V11_0_0
}
}

pub mod v13 {
use super::*;
use frame_support::{pallet_prelude::ValueQuery, storage_alias};

#[storage_alias]
type StorageVersion<T: Config> = StorageValue<Pallet<T>, Releases, ValueQuery>;
type StorageVersion<T: Config> = StorageValue<Pallet<T>, OldReleases, ValueQuery>;


#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
enum Releases {
V12_0_0,
}
pub struct MigrateToV13<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV13<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
frame_support::ensure!(
StorageVersion::<T>::get() == Releases::V12_0_0,
StorageVersion::<T>::get() == OldReleases::V12_0_0,
"Required v12 before upgrading to v13"
);

Ok(Default::default())
}

fn on_runtime_upgrade() -> frame_support::weights::Weight {
fn on_runtime_upgrade() -> Weight {
let current = Pallet::<T>::current_storage_version();
let onchain = StorageVersion::<T>::get();

if current == 13 && onchain == Releases::V12_0_0 {
if current == 13 && onchain == OldReleases::V12_0_0 {
StorageVersion::<T>::kill();
current.put::<Pallet<T>>();

Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub mod pallet {
use super::*;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(12);
const STORAGE_VERSION: StorageVersion = StorageVersion::new(13);

#[pallet::pallet]
#[pallet::generate_store(pub(crate) trait Store)]
Expand Down

0 comments on commit b592459

Please sign in to comment.