Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
merge master and everything works
  • Loading branch information
kianenigma committed Nov 8, 2022
commit 78ce1ea8d4e0ed612a31b906c1e59ae4630dbbaa
3 changes: 2 additions & 1 deletion frame/fast-unstake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ std = [
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-staking/runtime-benchmarks"
"sp-staking/runtime-benchmarks",
"pallet-staking/runtime-benchmarks"
]
try-runtime = ["frame-support/try-runtime"]
43 changes: 17 additions & 26 deletions frame/fast-unstake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ pub mod pallet {
/// This many stashes are processed in each unstake request.
type BatchSize: Get<u32>;

/// The access to staking functionality.
type Staking: StakingInterface<Balance = BalanceOf<Self>, AccountId = Self::AccountId>;

/// The weight information of this pallet.
type WeightInfo: WeightInfo;
}
Expand Down Expand Up @@ -256,16 +259,11 @@ pub mod pallet {
let ctrl = ensure_signed(origin)?;

ensure!(ErasToCheckPerBlock::<T>::get() != 0, <Error<T>>::CallNotAllowed);

let ledger =
pallet_staking::Ledger::<T>::get(&ctrl).ok_or(Error::<T>::NotController)?;
ensure!(!Queue::<T>::contains_key(&ledger.stash), Error::<T>::AlreadyQueued);
ensure!(!Self::is_head(&ledger.stash), Error::<T>::AlreadyHead);
// second part of the && is defensive.
ensure!(
ledger.active == ledger.total && ledger.unlocking.is_empty(),
Error::<T>::NotFullyBonded
);
let stash_account =
T::Staking::stash_by_ctrl(&ctrl).map_err(|_| Error::<T>::NotController)?;
ensure!(!Queue::<T>::contains_key(&stash_account), Error::<T>::AlreadyQueued);
ensure!(!Self::is_head(&stash_account), Error::<T>::AlreadyHead);
ensure!(!T::Staking::is_unbonding(&stash_account)?, Error::<T>::NotFullyBonded);

// chill and fully unstake.
T::Staking::chill(&stash_account)?;
Expand All @@ -291,12 +289,11 @@ pub mod pallet {

ensure!(ErasToCheckPerBlock::<T>::get() != 0, <Error<T>>::CallNotAllowed);

let stash = pallet_staking::Ledger::<T>::get(&ctrl)
.map(|l| l.stash)
.ok_or(Error::<T>::NotController)?;
ensure!(Queue::<T>::contains_key(&stash), Error::<T>::NotQueued);
ensure!(!Self::is_head(&stash), Error::<T>::AlreadyHead);
let deposit = Queue::<T>::take(stash.clone());
let stash_account =
T::Staking::stash_by_ctrl(&ctrl).map_err(|_| Error::<T>::NotController)?;
ensure!(Queue::<T>::contains_key(&stash_account), Error::<T>::NotQueued);
ensure!(!Self::is_head(&stash_account), Error::<T>::AlreadyHead);
let deposit = Queue::<T>::take(stash_account.clone());

if let Some(deposit) = deposit.defensive() {
let remaining = T::Currency::unreserve(&stash_account, deposit);
Expand Down Expand Up @@ -410,8 +407,8 @@ pub mod pallet {
);

// the range that we're allowed to check in this round.
let current_era = pallet_staking::CurrentEra::<T>::get().unwrap_or_default();
let bonding_duration = <T as pallet_staking::Config>::BondingDuration::get();
let current_era = T::Staking::current_era();
let bonding_duration = T::Staking::bonding_duration();

// prune all the old eras that we don't care about. This will help us keep the bound
// of `checked`.
Expand Down Expand Up @@ -447,14 +444,8 @@ pub mod pallet {
);

let unstake_stash = |stash: T::AccountId, deposit| {
let num_slashing_spans = Staking::<T>::slashing_spans(&stash).iter().count() as u32;
let result = pallet_staking::Pallet::<T>::force_unstake(
RawOrigin::Root.into(),
stash.clone(),
num_slashing_spans,
);

let remaining = T::DepositCurrency::unreserve(&stash, deposit);
let result = T::Staking::force_unstake(stash.clone());
let remaining = T::Currency::unreserve(&stash, deposit);
if !remaining.is_zero() {
Self::halt("not enough balance to unreserve");
} else {
Expand Down
3 changes: 2 additions & 1 deletion frame/fast-unstake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ parameter_types! {
impl fast_unstake::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Deposit = Deposit;
type DepositCurrency = Balances;
type Currency = Balances;
type Staking = Staking;
type ControlOrigin = frame_system::EnsureRoot<Self::AccountId>;
type BatchSize = BatchSize;
type WeightInfo = ();
Expand Down
4 changes: 2 additions & 2 deletions frame/fast-unstake/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn deregister_works() {

// Controller account registers for fast unstake.
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
assert_eq!(<T as Config>::DepositCurrency::reserved_balance(&1), Deposit::get());
assert_eq!(<T as Config>::Currency::reserved_balance(&1), Deposit::get());

// Controller then changes mind and deregisters.
assert_ok!(FastUnstake::deregister(RuntimeOrigin::signed(2)));
Expand Down Expand Up @@ -365,7 +365,7 @@ mod on_idle {
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(8)));
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(10)));

assert_eq!(<T as Config>::DepositCurrency::reserved_balance(&1), Deposit::get());
assert_eq!(<T as Config>::Currency::reserved_balance(&1), Deposit::get());

assert_eq!(Queue::<T>::count(), 5);
assert_eq!(Head::<T>::get(), None);
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.