Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions integration-tests/ahm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type RcChecks = (
pallet_rc_migrator::vesting::VestingMigrator<Polkadot>,
pallet_rc_migrator::proxy::ProxyProxiesMigrator<Polkadot>,
pallet_rc_migrator::staking::bags_list::BagsListMigrator<Polkadot>,
pallet_rc_migrator::staking::fast_unstake::FastUnstakeMigrator<Polkadot>,
pallet_rc_migrator::conviction_voting::ConvictionVotingMigrator<Polkadot>,
// other pallets go here
ProxiesStillWork,
Expand All @@ -78,6 +79,7 @@ type AhChecks = (
pallet_rc_migrator::vesting::VestingMigrator<AssetHub>,
pallet_rc_migrator::proxy::ProxyProxiesMigrator<AssetHub>,
pallet_rc_migrator::staking::bags_list::BagsListMigrator<AssetHub>,
pallet_rc_migrator::staking::fast_unstake::FastUnstakeMigrator<AssetHub>,
pallet_rc_migrator::conviction_voting::ConvictionVotingMigrator<AssetHub>,
// other pallets go here
ProxiesStillWork,
Expand Down
57 changes: 57 additions & 0 deletions pallets/ah-migrator/src/staking/fast_unstake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! Fast unstake migration logic.

use crate::*;
use pallet_rc_migrator::staking::fast_unstake::{alias, FastUnstakeMigrator, RcFastUnstakeMessage};

impl<T: Config> Pallet<T> {
pub fn do_receive_fast_unstake_messages(
Expand Down Expand Up @@ -66,3 +67,59 @@ impl<T: Config> Pallet<T> {
Ok(())
}
}

#[cfg(feature = "std")]
impl<T: Config> crate::types::AhMigrationCheck for FastUnstakeMigrator<T> {
type RcPrePayload = (Vec<(T::AccountId, alias::BalanceOf<T>)>, u32); // (queue, eras_to_check)
type AhPrePayload = ();

fn pre_check(_: Self::RcPrePayload) -> Self::AhPrePayload {
// AH pre: Verify no entries are present
assert!(
alias::Head::<T>::get().is_none(),
"Assert storage 'FastUnstake::Head::ah_pre::empty'"
);
assert!(
pallet_fast_unstake::Queue::<T>::iter().next().is_none(),
"Assert storage 'FastUnstake::Queue::ah_pre::empty'"
);
assert!(
pallet_fast_unstake::ErasToCheckPerBlock::<T>::get() == 0,
"Assert storage 'FastUnstake::ErasToCheckPerBlock::ah_pre::empty'"
);
}

fn post_check(rc_pre_payload: Self::RcPrePayload, _: Self::AhPrePayload) {
let (queue, eras_to_check) = rc_pre_payload;

// AH post: Verify entries are correctly migrated
let ah_queue: Vec<_> = pallet_fast_unstake::Queue::<T>::iter().collect();
let ah_eras_to_check = pallet_fast_unstake::ErasToCheckPerBlock::<T>::get();

// Verify Head is None
assert!(
alias::Head::<T>::get().is_none(),
"Assert storage 'FastUnstake::Head::ah_post::correct'"
);

// Verify Queue entries
assert_eq!(
queue.len(),
ah_queue.len(),
"Assert storage 'FastUnstake::Queue::ah_post::length'"
);
// Verify Queue values match
for (pre_entry, post_entry) in queue.iter().zip(ah_queue.iter()) {
assert_eq!(
pre_entry, post_entry,
"Assert storage 'FastUnstake::Queue::ah_post::correct'"
);
}

// Verify ErasToCheckPerBlock
assert_eq!(
eras_to_check, ah_eras_to_check,
"Assert storage 'FastUnstake::ErasToCheckPerBlock::ah_post::correct'"
);
}
}
33 changes: 33 additions & 0 deletions pallets/rc-migrator/src/staking/fast_unstake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,39 @@ impl<T: Config> PalletMigration for FastUnstakeMigrator<T> {
}
}

#[cfg(feature = "std")]
impl<T: Config> crate::types::RcMigrationCheck for FastUnstakeMigrator<T> {
type RcPrePayload = (Vec<(T::AccountId, alias::BalanceOf<T>)>, u32); // (queue, eras_to_check)

fn pre_check() -> Self::RcPrePayload {
let queue: Vec<_> = pallet_fast_unstake::Queue::<T>::iter().collect();
let eras_to_check = pallet_fast_unstake::ErasToCheckPerBlock::<T>::get();

assert!(
alias::Head::<T>::get().is_none(),
"Staking Heads must be empty on the relay chain before the migration"
);

(queue, eras_to_check)
}

fn post_check(_: Self::RcPrePayload) {
// RC post: Ensure that entries have been deleted
assert!(
alias::Head::<T>::get().is_none(),
"Assert storage 'FastUnstake::Head::rc_post::empty'"
);
assert!(
pallet_fast_unstake::Queue::<T>::iter().next().is_none(),
"Assert storage 'FastUnstake::Queue::rc_post::empty'"
);
assert!(
pallet_fast_unstake::ErasToCheckPerBlock::<T>::get() == 0,
"Assert storage 'FastUnstake::ErasToCheckPerBlock::rc_post::empty'"
);
}
}

pub mod alias {
use super::*;
use frame_support::traits::Currency;
Expand Down
Loading