[fix] Bound staking ledger correctly with MaxUnlockingChunks from configuration (#12343)

* used maxunlockingchunks from config

* mhl MaxUnlockingChunks

* no migration needed

* changes as per requested

* fmt

* fix tests

* fix benchmark

* warning in the doc for abrupt changes in the config

* less unnecessary details in the test

* fix tests

Co-authored-by: mrisholukamba <abdulrazzaqlukamba@gmail.com>
Co-authored-by: parity-processbot <>
This commit is contained in:
Ankan
2022-09-27 17:44:16 +02:00
committed by GitHub
parent 249316d87f
commit e6b1aae97f
5 changed files with 80 additions and 22 deletions
+18 -9
View File
@@ -43,9 +43,9 @@ pub use impls::*;
use crate::{
slashing, weights::WeightInfo, AccountIdLookupOf, ActiveEraInfo, BalanceOf, EraPayout,
EraRewardPoints, Exposure, Forcing, MaxUnlockingChunks, NegativeImbalanceOf, Nominations,
PositiveImbalanceOf, Releases, RewardDestination, SessionInterface, StakingLedger,
UnappliedSlash, UnlockChunk, ValidatorPrefs,
EraRewardPoints, Exposure, Forcing, NegativeImbalanceOf, Nominations, PositiveImbalanceOf,
Releases, RewardDestination, SessionInterface, StakingLedger, UnappliedSlash, UnlockChunk,
ValidatorPrefs,
};
const STAKING_ID: LockIdentifier = *b"staking ";
@@ -142,8 +142,9 @@ pub mod pallet {
///
/// Note: `HistoryDepth` is used as the upper bound for the `BoundedVec`
/// item `StakingLedger.claimed_rewards`. Setting this value lower than
/// the existing value can lead to inconsistencies and will need to be
/// handled properly in a migration.
/// the existing value can lead to inconsistencies in the
/// `StakingLedger` and will need to be handled properly in a migration.
/// The test `reducing_history_depth_abrupt` shows this effect.
#[pallet::constant]
type HistoryDepth: Get<u32>;
@@ -237,8 +238,16 @@ pub mod pallet {
/// VALIDATOR.
type TargetList: SortedListProvider<Self::AccountId, Score = BalanceOf<Self>>;
/// The maximum number of `unlocking` chunks a [`StakingLedger`] can have. Effectively
/// determines how many unique eras a staker may be unbonding in.
/// The maximum number of `unlocking` chunks a [`StakingLedger`] can
/// have. Effectively determines how many unique eras a staker may be
/// unbonding in.
///
/// Note: `MaxUnlockingChunks` is used as the upper bound for the
/// `BoundedVec` item `StakingLedger.unlocking`. Setting this value
/// lower than the existing value can lead to inconsistencies in the
/// `StakingLedger` and will need to be handled properly in a runtime
/// migration. The test `reducing_max_unlocking_chunks_abrupt` shows
/// this effect.
#[pallet::constant]
type MaxUnlockingChunks: Get<u32>;
@@ -940,7 +949,7 @@ pub mod pallet {
let controller = ensure_signed(origin)?;
let mut ledger = Self::ledger(&controller).ok_or(Error::<T>::NotController)?;
ensure!(
ledger.unlocking.len() < MaxUnlockingChunks::get() as usize,
ledger.unlocking.len() < T::MaxUnlockingChunks::get() as usize,
Error::<T>::NoMoreChunks,
);
@@ -1454,7 +1463,7 @@ pub mod pallet {
/// - Bounded by `MaxUnlockingChunks`.
/// - Storage changes: Can't increase storage, only decrease it.
/// # </weight>
#[pallet::weight(T::WeightInfo::rebond(MaxUnlockingChunks::get() as u32))]
#[pallet::weight(T::WeightInfo::rebond(T::MaxUnlockingChunks::get() as u32))]
pub fn rebond(
origin: OriginFor<T>,
#[pallet::compact] value: BalanceOf<T>,