mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 08:21:03 +00:00
Prevent dust in staking by disallowing cheap bond_extra (#7718)
* prevent bond_extra to cause staking actve lower than ed * prevent bond_extra to cause staking actve lower than ed * Check in post conditions. * check rebond as well. * also change withdraw_unbonded. * Fix build * change check format. * Apply suggestions from code review Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -1474,11 +1474,13 @@ decl_module! {
|
||||
let mut ledger = Self::ledger(&controller).ok_or(Error::<T>::NotController)?;
|
||||
|
||||
let stash_balance = T::Currency::free_balance(&stash);
|
||||
|
||||
if let Some(extra) = stash_balance.checked_sub(&ledger.total) {
|
||||
let extra = extra.min(max_additional);
|
||||
ledger.total += extra;
|
||||
ledger.active += extra;
|
||||
// last check: the new active amount of ledger must be more than ED.
|
||||
ensure!(ledger.active >= T::Currency::minimum_balance(), Error::<T>::InsufficientValue);
|
||||
|
||||
Self::deposit_event(RawEvent::Bonded(stash, extra));
|
||||
Self::update_ledger(&controller, &ledger);
|
||||
}
|
||||
@@ -1586,7 +1588,7 @@ decl_module! {
|
||||
ledger = ledger.consolidate_unlocked(current_era)
|
||||
}
|
||||
|
||||
let post_info_weight = if ledger.unlocking.is_empty() && ledger.active.is_zero() {
|
||||
let post_info_weight = if ledger.unlocking.is_empty() && ledger.active <= T::Currency::minimum_balance() {
|
||||
// This account must have called `unbond()` with some value that caused the active
|
||||
// portion to fall below existential deposit + will have no more unlocking chunks
|
||||
// left. We can now safely remove all staking-related information.
|
||||
@@ -1973,6 +1975,9 @@ decl_module! {
|
||||
ensure!(!ledger.unlocking.is_empty(), Error::<T>::NoUnlockChunk);
|
||||
|
||||
let ledger = ledger.rebond(value);
|
||||
// last check: the new active amount of ledger must be more than ED.
|
||||
ensure!(ledger.active >= T::Currency::minimum_balance(), Error::<T>::InsufficientValue);
|
||||
|
||||
Self::update_ledger(&controller, &ledger);
|
||||
Ok(Some(
|
||||
35 * WEIGHT_PER_MICROS
|
||||
|
||||
Reference in New Issue
Block a user