mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 18:41:05 +00:00
Remove Old Migration Code (#5870)
* remove old migration code * Remove old staking * Remove indices migration * Remove upgrade test in transaction-payment * oops * Revert "Remove old staking" This reverts commit 95262b1ac43c9b5bcf49d2ae80800feabcbbbaa0. * remove migration test in staking * fix warnings
This commit is contained in:
@@ -1246,18 +1246,6 @@ decl_module! {
|
||||
}
|
||||
}
|
||||
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
// For Kusama the type hasn't actually changed as Moment was u64 and was the number of
|
||||
// millisecond since unix epoch.
|
||||
StorageVersion::mutate(|v| {
|
||||
if matches!(v, Releases::V2_0_0) {
|
||||
Self::migrate_last_reward_to_claimed_rewards();
|
||||
}
|
||||
*v = Releases::V3_0_0;
|
||||
});
|
||||
0
|
||||
}
|
||||
|
||||
/// Take the origin account as a stash and lock up `value` of its balance. `controller` will
|
||||
/// be the account that controls it.
|
||||
///
|
||||
@@ -1935,43 +1923,6 @@ decl_module! {
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
/// Migrate `last_reward` to `claimed_rewards`
|
||||
pub fn migrate_last_reward_to_claimed_rewards() {
|
||||
use frame_support::migration::{StorageIterator, put_storage_value};
|
||||
// Migrate from `last_reward` to `claimed_rewards`.
|
||||
// We will construct a vector from `current_era - history_depth` to `last_reward`
|
||||
// for each validator and nominator.
|
||||
//
|
||||
// Old Staking Ledger
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
struct OldStakingLedger<AccountId, Balance: HasCompact> {
|
||||
pub stash: AccountId,
|
||||
#[codec(compact)]
|
||||
pub total: Balance,
|
||||
#[codec(compact)]
|
||||
pub active: Balance,
|
||||
pub unlocking: Vec<UnlockChunk<Balance>>,
|
||||
pub last_reward: Option<EraIndex>,
|
||||
}
|
||||
// Current era and history depth
|
||||
let current_era = Self::current_era().unwrap_or(0);
|
||||
let history_depth = Self::history_depth();
|
||||
let last_payout_era = current_era.saturating_sub(history_depth);
|
||||
// Convert all ledgers to the new format.
|
||||
for (hash, old_ledger) in StorageIterator::<OldStakingLedger<T::AccountId, BalanceOf<T>>>::new(b"Staking", b"Ledger").drain() {
|
||||
let last_reward = old_ledger.last_reward.unwrap_or(0);
|
||||
let new_ledger = StakingLedger {
|
||||
stash: old_ledger.stash,
|
||||
total: old_ledger.total,
|
||||
active: old_ledger.active,
|
||||
unlocking: old_ledger.unlocking,
|
||||
claimed_rewards: (last_payout_era..=last_reward).collect(),
|
||||
};
|
||||
put_storage_value(b"Staking", b"Ledger", &hash, new_ledger);
|
||||
}
|
||||
MigrateEra::put(current_era);
|
||||
}
|
||||
|
||||
/// The total balance that can be slashed from a stash account as of right now.
|
||||
pub fn slashable_balance_of(stash: &T::AccountId) -> BalanceOf<T> {
|
||||
Self::bonded(stash).and_then(Self::ledger).map(|l| l.active).unwrap_or_default()
|
||||
|
||||
@@ -4267,141 +4267,6 @@ fn bond_during_era_correctly_populates_claimed_rewards() {
|
||||
|
||||
/* These migration tests below can be removed once migration code is removed */
|
||||
|
||||
#[test]
|
||||
fn assert_migration_is_noop() {
|
||||
let kusama_active_era = "4a0200000190e2721171010000";
|
||||
let era = ActiveEraInfo::decode(&mut &hex::decode(kusama_active_era).unwrap()[..]).unwrap();
|
||||
assert_eq!(era.index, 586);
|
||||
assert_eq!(era.start, Some(1585135674000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_last_reward_migration() {
|
||||
use sp_storage::Storage;
|
||||
|
||||
let mut s = Storage::default();
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
struct OldStakingLedger<AccountId, Balance: HasCompact> {
|
||||
pub stash: AccountId,
|
||||
#[codec(compact)]
|
||||
pub total: Balance,
|
||||
#[codec(compact)]
|
||||
pub active: Balance,
|
||||
pub unlocking: Vec<UnlockChunk<Balance>>,
|
||||
pub last_reward: Option<EraIndex>,
|
||||
}
|
||||
|
||||
let old_staking10 = OldStakingLedger::<u64, u64> {
|
||||
stash: 0,
|
||||
total: 10,
|
||||
active: 10,
|
||||
unlocking: vec![UnlockChunk{ value: 1234, era: 56}],
|
||||
last_reward: Some(8),
|
||||
};
|
||||
|
||||
let old_staking11 = OldStakingLedger::<u64, u64> {
|
||||
stash: 1,
|
||||
total: 0,
|
||||
active: 0,
|
||||
unlocking: vec![],
|
||||
last_reward: None,
|
||||
};
|
||||
|
||||
let old_staking12 = OldStakingLedger::<u64, u64> {
|
||||
stash: 2,
|
||||
total: 100,
|
||||
active: 100,
|
||||
unlocking: vec![UnlockChunk{ value: 9876, era: 54}, UnlockChunk{ value: 98, era: 76}],
|
||||
last_reward: Some(23),
|
||||
};
|
||||
|
||||
let old_staking13 = OldStakingLedger::<u64, u64> {
|
||||
stash: 3,
|
||||
total: 100,
|
||||
active: 100,
|
||||
unlocking: vec![],
|
||||
last_reward: Some(23),
|
||||
};
|
||||
|
||||
let data = vec![
|
||||
(
|
||||
Ledger::<Test>::hashed_key_for(10),
|
||||
old_staking10.encode().to_vec()
|
||||
),
|
||||
(
|
||||
Ledger::<Test>::hashed_key_for(11),
|
||||
old_staking11.encode().to_vec()
|
||||
),
|
||||
(
|
||||
Ledger::<Test>::hashed_key_for(12),
|
||||
old_staking12.encode().to_vec()
|
||||
),
|
||||
(
|
||||
Ledger::<Test>::hashed_key_for(13),
|
||||
old_staking13.encode().to_vec()
|
||||
),
|
||||
];
|
||||
|
||||
s.top = data.into_iter().collect();
|
||||
sp_io::TestExternalities::new(s).execute_with(|| {
|
||||
HistoryDepth::put(84);
|
||||
CurrentEra::put(99);
|
||||
let nominations = Nominations::<AccountId> {
|
||||
targets: vec![],
|
||||
submitted_in: 0,
|
||||
suppressed: false
|
||||
};
|
||||
Nominators::<Test>::insert(3, nominations);
|
||||
Bonded::<Test>::insert(3, 13);
|
||||
Staking::migrate_last_reward_to_claimed_rewards();
|
||||
// Test staker out of range
|
||||
assert_eq!(
|
||||
Ledger::<Test>::get(10),
|
||||
Some(StakingLedger {
|
||||
stash: 0,
|
||||
total: 10,
|
||||
active: 10,
|
||||
unlocking: vec![UnlockChunk{ value: 1234, era: 56}],
|
||||
claimed_rewards: vec![],
|
||||
})
|
||||
);
|
||||
// Test staker none
|
||||
assert_eq!(
|
||||
Ledger::<Test>::get(11),
|
||||
Some(StakingLedger {
|
||||
stash: 1,
|
||||
total: 0,
|
||||
active: 0,
|
||||
unlocking: vec![],
|
||||
claimed_rewards: vec![],
|
||||
})
|
||||
);
|
||||
// Test staker migration
|
||||
assert_eq!(
|
||||
Ledger::<Test>::get(12),
|
||||
Some(StakingLedger {
|
||||
stash: 2,
|
||||
total: 100,
|
||||
active: 100,
|
||||
unlocking: vec![UnlockChunk{ value: 9876, era: 54}, UnlockChunk{ value: 98, era: 76}],
|
||||
claimed_rewards: vec![15,16,17,18,19,20,21,22,23],
|
||||
})
|
||||
);
|
||||
// Test nominator migration
|
||||
assert_eq!(
|
||||
Ledger::<Test>::get(13),
|
||||
Some(StakingLedger {
|
||||
stash: 3,
|
||||
total: 100,
|
||||
active: 100,
|
||||
unlocking: vec![],
|
||||
claimed_rewards: vec![15,16,17,18,19,20,21,22,23],
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewards_should_work_before_migration() {
|
||||
// should check that before migration:
|
||||
|
||||
Reference in New Issue
Block a user