This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[Enhancement] Remove optional Pool subscription from fast-unstake #12344
Merged
paritytech-processbot
merged 6 commits into
master
from
ru/enhacement/unstake-remove-pools
Sep 26, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
39baff8
[Enhancement] Remove optional Pool subscription from fast-unstake
ruseinov bea56fe
remove nomination-pools pallet dependency
ruseinov e6bf2eb
fixes
ruseinov af38af7
more fixes
ruseinov f474788
more fixes
ruseinov 2fa0326
more fixes
ruseinov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,7 @@ | |
| //! | ||
| //! If a nominator is not exposed in any `ErasStakers` (i.e. "has not actively backed any | ||
| //! validators in the last `BondingDuration` days"), then they can register themselves in this | ||
| //! pallet, unstake faster than having to wait an entire bonding duration, and potentially move | ||
| //! into a nomination pool. | ||
| //! pallet, unstake faster than having to wait an entire bonding duration. | ||
| //! | ||
| //! Appearing in the exposure of a validator means being exposed equal to that validator from the | ||
| //! point of view of the staking system. This usually means earning rewards with the validator, and | ||
|
|
@@ -43,8 +42,7 @@ | |
| //! to prevent them from accidentally exposing themselves behind a validator etc. | ||
| //! | ||
| //! Once processed, if successful, no additional fee for the checking process is taken, and the | ||
| //! staker is instantly unbonded. Optionally, if they have asked to join a pool, their *entire* | ||
| //! stake is joined into their pool of choice. | ||
| //! staker is instantly unbonded. | ||
| //! | ||
| //! If unsuccessful, meaning that the staker was exposed sometime in the last `BondingDuration` eras | ||
| //! they will end up being slashed for the amount of wasted work they have inflicted on the chian. | ||
|
|
@@ -85,7 +83,6 @@ pub mod pallet { | |
| use frame_election_provider_support::ElectionProvider; | ||
| use frame_support::pallet_prelude::*; | ||
| use frame_system::{pallet_prelude::*, RawOrigin}; | ||
| use pallet_nomination_pools::PoolId; | ||
| use pallet_staking::Pallet as Staking; | ||
| use sp_runtime::{ | ||
| traits::{Saturating, Zero}, | ||
|
|
@@ -109,12 +106,7 @@ pub mod pallet { | |
| pub struct Pallet<T>(_); | ||
|
|
||
| #[pallet::config] | ||
| pub trait Config: | ||
| frame_system::Config | ||
| + pallet_staking::Config< | ||
| CurrencyBalance = <Self as pallet_nomination_pools::Config>::CurrencyBalance, | ||
| > + pallet_nomination_pools::Config | ||
| { | ||
| pub trait Config: frame_system::Config + pallet_staking::Config { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. much cleaner |
||
| /// The overarching event type. | ||
| type RuntimeEvent: From<Event<Self>> | ||
| + IsType<<Self as frame_system::Config>::RuntimeEvent> | ||
|
|
@@ -139,10 +131,9 @@ pub mod pallet { | |
|
|
||
| /// The map of all accounts wishing to be unstaked. | ||
| /// | ||
| /// Points the `AccountId` wishing to unstake to the optional `PoolId` they wish to join | ||
| /// thereafter. | ||
| /// Keeps track of `AccountId` wishing to unstake. | ||
| #[pallet::storage] | ||
| pub type Queue<T: Config> = CountedStorageMap<_, Twox64Concat, T::AccountId, Option<PoolId>>; | ||
| pub type Queue<T: Config> = CountedStorageMap<_, Twox64Concat, T::AccountId, ()>; | ||
|
|
||
| /// Number of eras to check per block. | ||
| /// | ||
|
|
@@ -158,7 +149,7 @@ pub mod pallet { | |
| #[pallet::generate_deposit(pub(super) fn deposit_event)] | ||
| pub enum Event<T: Config> { | ||
| /// A staker was unstaked. | ||
| Unstaked { stash: T::AccountId, maybe_pool_id: Option<PoolId>, result: DispatchResult }, | ||
| Unstaked { stash: T::AccountId, result: DispatchResult }, | ||
| /// A staker was slashed for requesting fast-unstake whilst being exposed. | ||
| Slashed { stash: T::AccountId, amount: BalanceOf<T> }, | ||
| /// A staker was partially checked for the given eras, but the process did not finish. | ||
|
|
@@ -213,16 +204,13 @@ pub mod pallet { | |
| /// they are guaranteed to remain eligible, because the call will chill them as well. | ||
| /// | ||
| /// If the check works, the entire staking data is removed, i.e. the stash is fully | ||
| /// unstaked, and they potentially join a pool with their entire bonded stake. | ||
| /// unstaked. | ||
| /// | ||
| /// If the check fails, the stash remains chilled and waiting for being unbonded as in with | ||
| /// the normal staking system, but they lose part of their unbonding chunks due to consuming | ||
| /// the chain's resources. | ||
| #[pallet::weight(<T as Config>::WeightInfo::register_fast_unstake())] | ||
| pub fn register_fast_unstake( | ||
| origin: OriginFor<T>, | ||
| maybe_pool_id: Option<PoolId>, | ||
| ) -> DispatchResult { | ||
| pub fn register_fast_unstake(origin: OriginFor<T>) -> DispatchResult { | ||
| let ctrl = ensure_signed(origin)?; | ||
|
|
||
| let ledger = | ||
|
|
@@ -243,12 +231,11 @@ pub mod pallet { | |
| Staking::<T>::unbond(RawOrigin::Signed(ctrl).into(), ledger.total)?; | ||
|
|
||
| // enqueue them. | ||
| Queue::<T>::insert(ledger.stash, maybe_pool_id); | ||
| Queue::<T>::insert(ledger.stash, ()); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Deregister oneself from the fast-unstake (also cancels joining the pool if that was | ||
| /// supplied on `register_fast_unstake` . | ||
| /// Deregister oneself from the fast-unstake. | ||
| /// | ||
| /// This is useful if one is registered, they are still waiting, and they change their mind. | ||
| /// | ||
|
|
@@ -327,17 +314,12 @@ pub mod pallet { | |
| return T::DbWeight::get().reads(2) | ||
| } | ||
|
|
||
| let UnstakeRequest { stash, mut checked, maybe_pool_id } = match Head::<T>::take() | ||
| .or_else(|| { | ||
| // NOTE: there is no order guarantees in `Queue`. | ||
| Queue::<T>::drain() | ||
| .map(|(stash, maybe_pool_id)| UnstakeRequest { | ||
| stash, | ||
| maybe_pool_id, | ||
| checked: Default::default(), | ||
| }) | ||
| .next() | ||
| }) { | ||
| let UnstakeRequest { stash, mut checked } = match Head::<T>::take().or_else(|| { | ||
| // NOTE: there is no order guarantees in `Queue`. | ||
| Queue::<T>::drain() | ||
| .map(|(stash, _)| UnstakeRequest { stash, checked: Default::default() }) | ||
| .next() | ||
| }) { | ||
| None => { | ||
| // There's no `Head` and nothing in the `Queue`, nothing to do here. | ||
| return T::DbWeight::get().reads(4) | ||
|
|
@@ -392,48 +374,15 @@ pub mod pallet { | |
| // `stash` is not exposed in any era now -- we can let go of them now. | ||
| let num_slashing_spans = Staking::<T>::slashing_spans(&stash).iter().count() as u32; | ||
|
|
||
| let ctrl = match pallet_staking::Bonded::<T>::get(&stash) { | ||
| Some(ctrl) => ctrl, | ||
| None => { | ||
| Self::deposit_event(Event::<T>::Errored { stash }); | ||
| return <T as Config>::WeightInfo::on_idle_unstake() | ||
| }, | ||
| }; | ||
|
|
||
| let ledger = match pallet_staking::Ledger::<T>::get(ctrl) { | ||
| Some(ledger) => ledger, | ||
| None => { | ||
| Self::deposit_event(Event::<T>::Errored { stash }); | ||
| return <T as Config>::WeightInfo::on_idle_unstake() | ||
| }, | ||
| }; | ||
|
|
||
| let unstake_result = pallet_staking::Pallet::<T>::force_unstake( | ||
| let result = pallet_staking::Pallet::<T>::force_unstake( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. much simpler now, nice. |
||
| RawOrigin::Root.into(), | ||
| stash.clone(), | ||
| num_slashing_spans, | ||
| ); | ||
|
|
||
| let pool_stake_result = if let Some(pool_id) = maybe_pool_id { | ||
| pallet_nomination_pools::Pallet::<T>::join( | ||
| RawOrigin::Signed(stash.clone()).into(), | ||
| ledger.total, | ||
| pool_id, | ||
| ) | ||
| } else { | ||
| Ok(()) | ||
| }; | ||
| log!(info, "unstaked {:?}, outcome: {:?}", stash, result); | ||
|
|
||
| let result = unstake_result.and(pool_stake_result); | ||
| log!( | ||
| info, | ||
| "unstaked {:?}, maybe_pool {:?}, outcome: {:?}", | ||
| stash, | ||
| maybe_pool_id, | ||
| result | ||
| ); | ||
|
|
||
| Self::deposit_event(Event::<T>::Unstaked { stash, maybe_pool_id, result }); | ||
| Self::deposit_event(Event::<T>::Unstaked { stash, result }); | ||
| <T as Config>::WeightInfo::on_idle_unstake() | ||
| } else { | ||
| // eras remaining to be checked. | ||
|
|
@@ -471,11 +420,7 @@ pub mod pallet { | |
| // Not exposed in these eras. | ||
| match checked.try_extend(unchecked_eras_to_check.clone().into_iter()) { | ||
| Ok(_) => { | ||
| Head::<T>::put(UnstakeRequest { | ||
| stash: stash.clone(), | ||
| checked, | ||
| maybe_pool_id, | ||
| }); | ||
| Head::<T>::put(UnstakeRequest { stash: stash.clone(), checked }); | ||
| Self::deposit_event(Event::<T>::Checking { | ||
| stash, | ||
| eras: unchecked_eras_to_check, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later on, you can also tackle another part of #12337 and implement this via
trait StakingInterface(if it supports all the needed APIs).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do