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
Only maintain at most 1 UnlockChunk per era
#10670
Merged
paritytech-processbot
merged 21 commits into
master
from
zeke-consolidate-unbonding-chunks
Mar 1, 2022
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d14d0a1
Only maintain at most 1 `UnlockChunk` per era
emostov 54198dc
Bound `unlocking`
emostov 1b6f801
Run cargo +nightly-2021-10-29 fmt
emostov a64c335
Make benchmarks stuff compile
emostov a9c1e19
Update frame/staking/src/lib.rs
emostov c876504
Remove DerefMut; Implement neccesary methods directly
emostov a2638f1
Doc comments for new BoundedVec methods
emostov b28b43e
Try merge origin master
emostov 5d22337
Merge remote-tracking branch 'origin' into zeke-consolidate-unbonding…
emostov fbd9437
Fix benchmarks
emostov c31b8d3
wip bonded_vec macro
emostov c17ea60
merge master + fmt
emostov b088520
Correct rust doc
emostov db7b8c1
Apply suggestions from code review
emostov 72aae74
Update staking::Config impls
emostov 4d9000c
Merge remote-tracking branch 'origin' into zeke-consolidate-unbonding…
emostov 3f5af79
Add MaxUnlockingChunks to more places
emostov d46edb7
Try merge origin master
emostov 7bc0c2a
Use defensive saturating add
emostov f6b22fb
FMT
emostov 1863f36
Merge remote-tracking branch 'origin' into zeke-consolidate-unbonding…
emostov 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
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
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
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
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 |
|---|---|---|
|
|
@@ -21,8 +21,8 @@ use frame_election_provider_support::SortedListProvider; | |
| use frame_support::{ | ||
| pallet_prelude::*, | ||
| traits::{ | ||
| Currency, CurrencyToVote, EnsureOrigin, EstimateNextNewSession, Get, LockIdentifier, | ||
| LockableCurrency, OnUnbalanced, UnixTime, | ||
| Currency, CurrencyToVote, DefensiveSaturating, EnsureOrigin, EstimateNextNewSession, Get, | ||
| LockIdentifier, LockableCurrency, OnUnbalanced, UnixTime, | ||
| }, | ||
| weights::Weight, | ||
| }; | ||
|
|
@@ -40,12 +40,11 @@ pub use impls::*; | |
|
|
||
| use crate::{ | ||
| log, slashing, weights::WeightInfo, ActiveEraInfo, BalanceOf, EraPayout, EraRewardPoints, | ||
| Exposure, Forcing, NegativeImbalanceOf, Nominations, PositiveImbalanceOf, Releases, | ||
| RewardDestination, SessionInterface, StakingLedger, UnappliedSlash, UnlockChunk, | ||
| Exposure, Forcing, MaxUnlockingChunks, NegativeImbalanceOf, Nominations, PositiveImbalanceOf, | ||
| Releases, RewardDestination, SessionInterface, StakingLedger, UnappliedSlash, UnlockChunk, | ||
| ValidatorPrefs, | ||
| }; | ||
|
|
||
| pub const MAX_UNLOCKING_CHUNKS: usize = 32; | ||
| const STAKING_ID: LockIdentifier = *b"staking "; | ||
|
|
||
| #[frame_support::pallet] | ||
|
|
@@ -157,6 +156,10 @@ pub mod pallet { | |
| /// the bags-list is not desired, [`impls::UseNominatorsMap`] is likely the desired option. | ||
| type SortedListProvider: SortedListProvider<Self::AccountId>; | ||
|
|
||
| /// The maximum number of `unlocking` chunks a [`StakingLedger`] can have. Effectively | ||
| /// determines how many unique eras a staker may be unbonding in. | ||
| type MaxUnlockingChunks: Get<u32>; | ||
|
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. should be exposed to metadata.
Contributor
Author
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. I will make a quick PR |
||
|
|
||
| /// Some parameters of the benchmarking. | ||
| type BenchmarkingConfig: BenchmarkingConfig; | ||
|
|
||
|
|
@@ -772,7 +775,7 @@ pub mod pallet { | |
| stash, | ||
| total: value, | ||
| active: value, | ||
| unlocking: vec![], | ||
| unlocking: Default::default(), | ||
| claimed_rewards: (last_reward_era..current_era).collect(), | ||
| }; | ||
| Self::update_ledger(&controller, &item); | ||
|
|
@@ -837,7 +840,7 @@ pub mod pallet { | |
| /// Once the unlock period is done, you can call `withdraw_unbonded` to actually move | ||
| /// the funds out of management ready for transfer. | ||
| /// | ||
| /// No more than a limited number of unlocking chunks (see `MAX_UNLOCKING_CHUNKS`) | ||
| /// No more than a limited number of unlocking chunks (see `MaxUnlockingChunks`) | ||
| /// can co-exists at the same time. In that case, [`Call::withdraw_unbonded`] need | ||
| /// to be called first to remove some of the chunks (if possible). | ||
| /// | ||
|
|
@@ -854,7 +857,10 @@ pub mod pallet { | |
| ) -> DispatchResult { | ||
| let controller = ensure_signed(origin)?; | ||
| let mut ledger = Self::ledger(&controller).ok_or(Error::<T>::NotController)?; | ||
| ensure!(ledger.unlocking.len() < MAX_UNLOCKING_CHUNKS, Error::<T>::NoMoreChunks,); | ||
| ensure!( | ||
| ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, | ||
| Error::<T>::NoMoreChunks, | ||
| ); | ||
|
|
||
| let mut value = value.min(ledger.active); | ||
|
|
||
|
|
@@ -881,7 +887,19 @@ pub mod pallet { | |
|
|
||
| // Note: in case there is no current era it is fine to bond one era more. | ||
| let era = Self::current_era().unwrap_or(0) + T::BondingDuration::get(); | ||
| ledger.unlocking.push(UnlockChunk { value, era }); | ||
| if let Some(mut chunk) = | ||
| ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) | ||
| { | ||
| // To keep the chunk count down, we only keep one chunk per era. Since | ||
| // `unlocking` is a FiFo queue, if a chunk exists for `era` we know that it will | ||
| // be the last one. | ||
| chunk.value = chunk.value.defensive_saturating_add(value) | ||
| } else { | ||
| ledger | ||
| .unlocking | ||
| .try_push(UnlockChunk { value, era }) | ||
| .map_err(|_| Error::<T>::NoMoreChunks)?; | ||
ggwpez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| // NOTE: ledger must be updated prior to calling `Self::weight_of`. | ||
| Self::update_ledger(&controller, &ledger); | ||
|
|
||
|
|
@@ -1348,10 +1366,10 @@ pub mod pallet { | |
| /// | ||
| /// # <weight> | ||
| /// - Time complexity: O(L), where L is unlocking chunks | ||
| /// - Bounded by `MAX_UNLOCKING_CHUNKS`. | ||
| /// - Bounded by `MaxUnlockingChunks`. | ||
| /// - Storage changes: Can't increase storage, only decrease it. | ||
| /// # </weight> | ||
| #[pallet::weight(T::WeightInfo::rebond(MAX_UNLOCKING_CHUNKS as u32))] | ||
| #[pallet::weight(T::WeightInfo::rebond(MaxUnlockingChunks::get() as u32))] | ||
| pub fn rebond( | ||
| origin: OriginFor<T>, | ||
| #[pallet::compact] value: BalanceOf<T>, | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.