Skip to content

Commit

Permalink
staking migration changes
Browse files Browse the repository at this point in the history
Signed-off-by: R.Rajeshkumar <rajesh@nodle.com>
  • Loading branch information
R.Rajeshkumar committed Jul 27, 2022
1 parent b49204b commit e39c9f1
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 188 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pallets/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ std = [
"sp-staking/std",
"pallet-authorship/std",
"pallet-session/std",
"pallet-membership/std",
"frame-benchmarking/std",
"log/std",
]
Expand Down Expand Up @@ -55,4 +56,4 @@ sp-io = { git = "https://github.com/paritytech/substrate", default-features = fa
sp-tracing = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.20" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.20" }
substrate-test-utils = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.20" }
pallet-poa = { default-features = false, path = "../poa" }
pallet-membership = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.20" }
56 changes: 37 additions & 19 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ mod tests;
mod set;
pub mod weights;

use frame_support::pallet;
pub(crate) mod hooks;

// TODO:: Take it part of PR621
// mod migrations;
use codec::{Decode, Encode};
use frame_support::{pallet, pallet_prelude::MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;

pub(crate) mod hooks;
mod migrations;
pub(crate) mod slashing;
pub(crate) mod types;

Expand All @@ -46,6 +47,21 @@ use frame_support::traits::GenesisBuild;

pub use pallet::*;

// A value placed in storage that represents the current version of the POA storage.
// This value is used by the `on_runtime_upgrade` logic to determine whether we run storage
// migration logic. This should match directly with the semantic versions of the Rust crate.
#[derive(Encode, MaxEncodedLen, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)]
enum Releases {
V0, // Legacy version
V1, // Adds storage info
}

impl Default for Releases {
fn default() -> Self {
Releases::V0
}
}

#[pallet]
pub mod pallet {
use super::*;
Expand Down Expand Up @@ -144,20 +160,19 @@ pub mod pallet {

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
// TODO:: Take it part of PR621
// #[cfg(feature = "try-runtime")]
// fn pre_upgrade() -> Result<(), &'static str> {
// migrations::v1::PoAToStaking::<T>::pre_upgrade()
// }

// fn on_runtime_upgrade() -> frame_support::weights::Weight {
// migrations::v1::PoAToStaking::<T>::on_runtime_upgrade()
// }

// #[cfg(feature = "try-runtime")]
// fn post_upgrade() -> Result<(), &'static str> {
// migrations::v1::PoAToStaking::<T>::post_upgrade()
// }
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
migrations::v1::pre_upgrade::<T>()
}

fn on_runtime_upgrade() -> frame_support::weights::Weight {
migrations::v1::on_runtime_upgrade::<T>()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
migrations::v1::post_upgrade::<T>()
}
}

#[pallet::call]
Expand Down Expand Up @@ -1091,6 +1106,9 @@ pub mod pallet {
Withdrawn(T::AccountId, BalanceOf<T>),
}

#[pallet::storage]
pub(crate) type StorageVersion<T: Config> = StorageValue<_, Releases, ValueQuery>;

/// Any validators that may never be slashed or forcibly kicked. It's a Vec since they're
/// easy to initialize and the performance hit is minimal (we expect no more than four
/// invulnerables) and restricted to testnets.
Expand Down

0 comments on commit e39c9f1

Please sign in to comment.