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:
Kian Paimani
2020-12-14 15:45:49 +00:00
committed by GitHub
parent a9ab45beae
commit 6b08b37bc9
3 changed files with 100 additions and 3 deletions
+11 -1
View File
@@ -579,8 +579,18 @@ fn assert_is_stash(acc: AccountId) {
fn assert_ledger_consistent(ctrl: AccountId) {
// ensures ledger.total == ledger.active + sum(ledger.unlocking).
let ledger = Staking::ledger(ctrl).expect("Not a controller.");
let real_total: Balance = ledger.unlocking.iter().fold(ledger.active, |a, c| a + c.value);
let real_total: Balance = ledger
.unlocking
.iter()
.fold(ledger.active, |a, c| a + c.value);
assert_eq!(real_total, ledger.total);
assert!(
ledger.active >= Balances::minimum_balance() || ledger.active == 0,
"{}: active ledger amount ({}) must be greater than ED {}",
ctrl,
ledger.active,
Balances::minimum_balance()
);
}
pub(crate) fn bond_validator(stash: AccountId, ctrl: AccountId, val: Balance) {