Skip to content

Commit

Permalink
Remove swork migration and add staking migration (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmyyrroonn authored Nov 12, 2020
1 parent 09f5ad7 commit f05e21b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 48 deletions.
15 changes: 15 additions & 0 deletions cstrml/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use primitives::{
constants::{currency::*, time::*},
traits::TransferrableCurrency
};
use frame_support::storage::migration::remove_storage_prefix;

const DEFAULT_MINIMUM_VALIDATOR_COUNT: u32 = 4;
const MAX_UNLOCKING_CHUNKS: usize = 32;
Expand Down Expand Up @@ -725,6 +726,12 @@ decl_module! {

fn deposit_event() = default;

// upgrade for 0.10.0 and spec 6
fn on_runtime_upgrade() -> Weight {
Self::do_upgrade();
10_000
}

fn on_finalize() {
// Set the start of the first era.
if let Some(mut active_era) = Self::active_era() {
Expand Down Expand Up @@ -2143,6 +2150,14 @@ impl<T: Trait> Module<T> {
elected_stashes
}

/// Upgrade storage to current version to support new MPoW
/// * clear of:
/// * StakeLimit
fn do_upgrade() {
// 1. Kill old storages
remove_storage_prefix(b"Staking", b"StakeLimit", &[]);
}

// fn shuffle_candidates(candidates_stakes: &mut Vec<(T::AccountId, u128)>) {
// // 1. Construct random seed, 👼 bless the randomness
// // seed = [ block_hash, phrase ]
Expand Down
49 changes: 1 addition & 48 deletions cstrml/swork/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ use frame_support::{
storage::IterableStorageMap,
traits::{Currency, ReservableCurrency, Get},
weights::{
DispatchClass, constants::WEIGHT_PER_MICROS, Weight
DispatchClass, constants::WEIGHT_PER_MICROS
}
};
use sp_runtime::traits::Saturating;
use sp_std::{str, convert::TryInto, prelude::*};
use frame_system::{self as system, ensure_root, ensure_signed};

use frame_support::storage::migration::remove_storage_prefix;

#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -203,12 +201,6 @@ decl_module! {
// this is needed only if you are using events in your module
fn deposit_event() = default;

// upgrade for 0.10.0
fn on_runtime_upgrade() -> Weight {
Self::do_upgrade();
10_000
}

/// AB Upgrade, this should only be called by `root` origin
/// Ruled by `sudo/democracy`
///
Expand Down Expand Up @@ -811,45 +803,6 @@ impl<T: Trait> Module<T> {
let current_report_index = current_block_numeric / REPORT_SLOT;
current_report_index * REPORT_SLOT
}

/// Upgrade storage to current version to support new MPoW
/// * removal of:
/// * Identities
/// * WorkReports
/// * ReportedInSlot
/// * Used
/// * Reserved
fn do_upgrade() {
// Deprecated storages used for migration only
mod deprecated {
use crate::Trait;
use frame_support::{decl_module, decl_storage};
use sp_std::prelude::*;

decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
}

decl_storage! {
pub trait Store for Module<T: Trait> as Swork {
/// The used workload, used for calculating stake limit in the end of era
/// default is 0
pub Used: u128;

/// The reserved workload, used for calculating stake limit in the end of era
/// default is 0
pub Reserved: u128;
}
}
}

// 1. Kill old storages
remove_storage_prefix(b"Swork", b"Identities", &[]);
remove_storage_prefix(b"Swork", b"WorkReports", &[]);
remove_storage_prefix(b"Swork", b"ReportedInSlot", &[]);
deprecated::Used::kill();
deprecated::Reserved::kill();
}
}

decl_event!(
Expand Down

0 comments on commit f05e21b

Please sign in to comment.