Skip to content

Commit 81ee0ae

Browse files
committed
PR feedback
1 parent 0a3723f commit 81ee0ae

5 files changed

Lines changed: 45 additions & 52 deletions

File tree

prdoc/pr_8701.prdoc

Lines changed: 0 additions & 18 deletions
This file was deleted.

substrate/frame/staking-async/src/benchmarking.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ mod benchmarks {
229229
// clean up any existing state.
230230
clear_validators_and_nominators::<T>();
231231

232-
let origin_weight = MinNominatorBond::<T>::get().max(asset::existential_deposit::<T>());
232+
let origin_weight = Staking::<T>::min_nominator_bond();
233233

234234
// setup the worst case list scenario.
235235

@@ -318,7 +318,7 @@ mod benchmarks {
318318
// clean up any existing state.
319319
clear_validators_and_nominators::<T>();
320320

321-
let origin_weight = MinNominatorBond::<T>::get().max(asset::existential_deposit::<T>());
321+
let origin_weight = Staking::<T>::min_nominator_bond();
322322

323323
// setup a worst case list scenario. Note that we don't care about the setup of the
324324
// destination position because we are doing a removal from the list but no insert.
@@ -442,7 +442,7 @@ mod benchmarks {
442442
// clean up any existing state.
443443
clear_validators_and_nominators::<T>();
444444

445-
let origin_weight = MinNominatorBond::<T>::get().max(asset::existential_deposit::<T>());
445+
let origin_weight = Staking::<T>::min_nominator_bond();
446446

447447
// setup a worst case list scenario. Note we don't care about the destination position,
448448
// because we are just doing an insert into the origin position.
@@ -475,7 +475,7 @@ mod benchmarks {
475475
// clean up any existing state.
476476
clear_validators_and_nominators::<T>();
477477

478-
let origin_weight = MinNominatorBond::<T>::get().max(asset::existential_deposit::<T>());
478+
let origin_weight = Staking::<T>::min_nominator_bond();
479479

480480
// setup a worst case list scenario. Note that we don't care about the setup of the
481481
// destination position because we are doing a removal from the list but no insert.
@@ -633,7 +633,7 @@ mod benchmarks {
633633
// Clean up any existing state.
634634
clear_validators_and_nominators::<T>();
635635

636-
let origin_weight = MinNominatorBond::<T>::get().max(asset::existential_deposit::<T>());
636+
let origin_weight = Staking::<T>::min_nominator_bond();
637637

638638
// setup a worst case list scenario. Note that we don't care about the setup of the
639639
// destination position because we are doing a removal from the list but no insert.
@@ -734,8 +734,7 @@ mod benchmarks {
734734
// clean up any existing state.
735735
clear_validators_and_nominators::<T>();
736736

737-
let origin_weight = MinNominatorBond::<T>::get()
738-
.max(asset::existential_deposit::<T>())
737+
let origin_weight = Pallet::<T>::min_nominator_bond()
739738
// we use 100 to play friendly with the list threshold values in the mock
740739
.max(100u32.into());
741740

@@ -781,7 +780,7 @@ mod benchmarks {
781780
// clean up any existing state.
782781
clear_validators_and_nominators::<T>();
783782

784-
let origin_weight = MinNominatorBond::<T>::get().max(asset::existential_deposit::<T>());
783+
let origin_weight = Staking::<T>::min_nominator_bond();
785784

786785
// setup a worst case list scenario. Note that we don't care about the setup of the
787786
// destination position because we are doing a removal from the list but no insert.
@@ -858,7 +857,7 @@ mod benchmarks {
858857
// clean up any existing state.
859858
clear_validators_and_nominators::<T>();
860859

861-
let origin_weight = MinNominatorBond::<T>::get().max(asset::existential_deposit::<T>());
860+
let origin_weight = Staking::<T>::min_nominator_bond();
862861

863862
// setup a worst case list scenario. Note that we don't care about the setup of the
864863
// destination position because we are doing a removal from the list but no insert.

substrate/frame/staking-async/src/pallet/impls.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,30 @@ use sp_runtime::TryRuntimeError;
7272
const NPOS_MAX_ITERATIONS_COEFFICIENT: u32 = 2;
7373

7474
impl<T: Config> Pallet<T> {
75-
/// Returns the minimum required bond for participation, considering validators, nominators,
75+
/// Returns the minimum required bond for participation, considering nominators,
7676
/// and the chain’s existential deposit.
7777
///
7878
/// This function computes the smallest allowed bond among `MinValidatorBond` and
7979
/// `MinNominatorBond`, but ensures it is not below the existential deposit required to keep an
8080
/// account alive.
81-
pub(crate) fn min_bond() -> BalanceOf<T> {
81+
pub(crate) fn min_chilled_bond() -> BalanceOf<T> {
8282
MinValidatorBond::<T>::get()
8383
.min(MinNominatorBond::<T>::get())
8484
.max(asset::existential_deposit::<T>())
8585
}
8686

87+
/// Returns the minimum required bond for validators, defaulting to `MinNominatorBond` if not
88+
/// set or less than `MinNominatorBond`.
89+
pub(crate) fn min_validator_bond() -> BalanceOf<T> {
90+
MinValidatorBond::<T>::get().max(Self::min_nominator_bond())
91+
}
92+
93+
/// Returns the minimum required bond for nominators, considering the chain’s existential
94+
/// deposit.
95+
pub(crate) fn min_nominator_bond() -> BalanceOf<T> {
96+
MinNominatorBond::<T>::get().max(asset::existential_deposit::<T>())
97+
}
98+
8799
/// Fetches the ledger associated with a controller or stash account, if any.
88100
pub fn ledger(account: StakingAccount<T::AccountId>) -> Result<StakingLedger<T>, Error<T>> {
89101
StakingLedger::<T>::get(account)
@@ -182,7 +194,7 @@ impl<T: Config> Pallet<T> {
182194
ledger.total = ledger.total.checked_add(&extra).ok_or(ArithmeticError::Overflow)?;
183195
ledger.active = ledger.active.checked_add(&extra).ok_or(ArithmeticError::Overflow)?;
184196
// last check: the new active amount of ledger must be more than min bond.
185-
ensure!(ledger.active >= Self::min_bond(), Error::<T>::InsufficientBond);
197+
ensure!(ledger.active >= Self::min_chilled_bond(), Error::<T>::InsufficientBond);
186198

187199
// NOTE: ledger must be updated prior to calling `Self::weight_of`.
188200
ledger.update()?;
@@ -206,7 +218,7 @@ impl<T: Config> Pallet<T> {
206218
let new_total = ledger.total;
207219

208220
let used_weight = if ledger.unlocking.is_empty() &&
209-
(ledger.active < Self::min_bond() || ledger.active.is_zero())
221+
(ledger.active < Self::min_chilled_bond() || ledger.active.is_zero())
210222
{
211223
// This account must have called `unbond()` with some value that caused the active
212224
// portion to fall below existential deposit + will have no more unlocking chunks
@@ -984,7 +996,7 @@ impl<T: Config> ElectionDataProvider for Pallet<T> {
984996

985997
#[cfg(feature = "runtime-benchmarks")]
986998
fn add_target(target: T::AccountId) {
987-
let stake = (MinValidatorBond::<T>::get() + 1u32.into()) * 100u32.into();
999+
let stake = (Self::min_validator_bond() + 1u32.into()) * 100u32.into();
9881000
<Bonded<T>>::insert(target.clone(), target.clone());
9891001
<Ledger<T>>::insert(target.clone(), StakingLedger::<T>::new(target.clone(), stake));
9901002
Self::do_add_validator(
@@ -1016,7 +1028,7 @@ impl<T: Config> ElectionDataProvider for Pallet<T> {
10161028
targets.into_iter().for_each(|v| {
10171029
let stake: BalanceOf<T> = target_stake
10181030
.and_then(|w| <BalanceOf<T>>::try_from(w).ok())
1019-
.unwrap_or_else(|| MinNominatorBond::<T>::get() * 100u32.into());
1031+
.unwrap_or_else(|| Self::min_nominator_bond() * 100u32.into());
10201032
<Bonded<T>>::insert(v.clone(), v.clone());
10211033
<Ledger<T>>::insert(v.clone(), StakingLedger::<T>::new(v.clone(), stake));
10221034
Self::do_add_validator(
@@ -1437,11 +1449,11 @@ impl<T: Config> StakingInterface for Pallet<T> {
14371449
type CurrencyToVote = T::CurrencyToVote;
14381450

14391451
fn minimum_nominator_bond() -> Self::Balance {
1440-
MinNominatorBond::<T>::get()
1452+
Self::min_nominator_bond()
14411453
}
14421454

14431455
fn minimum_validator_bond() -> Self::Balance {
1444-
MinValidatorBond::<T>::get()
1456+
Self::min_validator_bond()
14451457
}
14461458

14471459
fn stash_by_ctrl(controller: &Self::AccountId) -> Result<Self::AccountId, DispatchError> {

substrate/frame/staking-async/src/pallet/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ pub mod pallet {
11501150
DuplicateIndex,
11511151
/// Slash record not found.
11521152
InvalidSlashRecord,
1153-
/// Cannot have a validator or nominator role, with value less than the minimum defined by
1153+
/// Cannot bond, nominate or validate with value less than the minimum defined by
11541154
/// governance (see `MinValidatorBond` and `MinNominatorBond`). If unbonding is the
11551155
/// intention, `chill` first to remove one's role as validator/nominator.
11561156
InsufficientBond,
@@ -1308,7 +1308,7 @@ pub mod pallet {
13081308
}
13091309

13101310
// Reject a bond which is lower than the minimum bond.
1311-
if value < Self::min_bond() {
1311+
if value < Self::min_chilled_bond() {
13121312
return Err(Error::<T>::InsufficientBond.into());
13131313
}
13141314

@@ -1407,9 +1407,9 @@ pub mod pallet {
14071407
}
14081408

14091409
let min_active_bond = if Nominators::<T>::contains_key(&stash) {
1410-
MinNominatorBond::<T>::get()
1410+
Self::min_nominator_bond()
14111411
} else if Validators::<T>::contains_key(&stash) {
1412-
MinValidatorBond::<T>::get()
1412+
Self::min_validator_bond()
14131413
} else {
14141414
// staker is chilled, no min bond.
14151415
Zero::zero()
@@ -1493,7 +1493,7 @@ pub mod pallet {
14931493

14941494
let ledger = Self::ledger(Controller(controller))?;
14951495

1496-
ensure!(ledger.active >= MinValidatorBond::<T>::get(), Error::<T>::InsufficientBond);
1496+
ensure!(ledger.active >= Self::min_validator_bond(), Error::<T>::InsufficientBond);
14971497
let stash = &ledger.stash;
14981498

14991499
// ensure their commission is correct.
@@ -1534,7 +1534,7 @@ pub mod pallet {
15341534

15351535
let ledger = Self::ledger(StakingAccount::Controller(controller.clone()))?;
15361536

1537-
ensure!(ledger.active >= MinNominatorBond::<T>::get(), Error::<T>::InsufficientBond);
1537+
ensure!(ledger.active >= Self::min_nominator_bond(), Error::<T>::InsufficientBond);
15381538
let stash = &ledger.stash;
15391539

15401540
// Only check limits if they are not already a nominator.
@@ -1889,7 +1889,7 @@ pub mod pallet {
18891889
let initial_unlocking = ledger.unlocking.len() as u32;
18901890
let (ledger, rebonded_value) = ledger.rebond(value);
18911891
// Last check: the new active amount of ledger must be more than min bond.
1892-
ensure!(ledger.active >= Self::min_bond(), Error::<T>::InsufficientBond);
1892+
ensure!(ledger.active >= Self::min_chilled_bond(), Error::<T>::InsufficientBond);
18931893

18941894
Self::deposit_event(Event::<T>::Bonded {
18951895
stash: ledger.stash.clone(),
@@ -1942,13 +1942,13 @@ pub mod pallet {
19421942
// virtual stakers should not be allowed to be reaped.
19431943
ensure!(!Self::is_virtual_staker(&stash), Error::<T>::VirtualStakerNotAllowed);
19441944

1945-
let min_bond = Self::min_bond();
1945+
let min_chilled_bond = Self::min_chilled_bond();
19461946
let origin_balance = asset::total_balance::<T>(&stash);
19471947
let ledger_total =
19481948
Self::ledger(Stash(stash.clone())).map(|l| l.total).unwrap_or_default();
1949-
let reapable = origin_balance < min_bond ||
1949+
let reapable = origin_balance < min_chilled_bond ||
19501950
origin_balance.is_zero() ||
1951-
ledger_total < min_bond ||
1951+
ledger_total < min_chilled_bond ||
19521952
ledger_total.is_zero();
19531953
ensure!(reapable, Error::<T>::FundedTarget);
19541954

@@ -2123,7 +2123,7 @@ pub mod pallet {
21232123
threshold * max_nominator_count < current_nominator_count,
21242124
Error::<T>::CannotChillOther
21252125
);
2126-
MinNominatorBond::<T>::get()
2126+
Self::min_nominator_bond()
21272127
} else if Validators::<T>::contains_key(&stash) {
21282128
let max_validator_count =
21292129
MaxValidatorsCount::<T>::get().ok_or(Error::<T>::CannotChillOther)?;
@@ -2132,7 +2132,7 @@ pub mod pallet {
21322132
threshold * max_validator_count < current_validator_count,
21332133
Error::<T>::CannotChillOther
21342134
);
2135-
MinValidatorBond::<T>::get()
2135+
Self::min_validator_bond()
21362136
} else {
21372137
Zero::zero()
21382138
};

substrate/frame/staking-async/src/session_rotation.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ impl<T: Config> Rotator<T> {
513513

514514
#[cfg(any(feature = "try-runtime", feature = "std", feature = "runtime-benchmarks", test))]
515515
pub fn assert_election_ongoing() {
516-
assert!(Self::planning_era().is_some(), "planning era must exist");
516+
assert!(Self::is_planning().is_some(), "planning era must exist");
517517
assert!(
518518
T::ElectionProvider::status().is_ok(),
519519
"Election provider must be in a good state during election"
@@ -526,7 +526,7 @@ impl<T: Config> Rotator<T> {
526526
/// is underway, but rather the last era that was planned. If `Self::active_era()` is equal to
527527
/// this value, it means that the era is currently active and no new era is planned.
528528
///
529-
/// See [`Self::planning_era()`] to only get the next index that is planned.
529+
/// See [`Self::is_planning()`] to only get the next index if planning in progress.
530530
pub fn planned_era() -> EraIndex {
531531
CurrentEra::<T>::get().unwrap_or(0)
532532
}
@@ -538,7 +538,7 @@ impl<T: Config> Rotator<T> {
538538
/// Next era that is planned to be started.
539539
///
540540
/// Returns None if no era is planned.
541-
pub fn planning_era() -> Option<EraIndex> {
541+
pub fn is_planning() -> Option<EraIndex> {
542542
let (active, planned) = (Self::active_era(), Self::planned_era());
543543
if planned.defensive_saturating_sub(active) > 1 {
544544
defensive!("planned era must always be equal or one more than active");
@@ -553,7 +553,7 @@ impl<T: Config> Rotator<T> {
553553
defensive!("Active era must always be available.");
554554
return;
555555
};
556-
let current_planned_era = Self::planning_era();
556+
let current_planned_era = Self::is_planning();
557557
let starting = end_index + 1;
558558
// the session after the starting session.
559559
let planning = starting + 1;
@@ -605,7 +605,7 @@ impl<T: Config> Rotator<T> {
605605

606606
// Note: we call `planning_era` again, as a new era might have started since we checked
607607
// it last.
608-
let has_pending_era = Self::planning_era().is_some();
608+
let has_pending_era = Self::is_planning().is_some();
609609
match (should_plan_era, has_pending_era) {
610610
(false, _) => {
611611
// nothing to consider

0 commit comments

Comments
 (0)