Skip to content
Unverified Commit 51986233 authored by Kris Bitney's avatar Kris Bitney Committed by GitHub
Browse files

Fix: dust unbonded for zero existential deposit (#4364)

When a staker unbonds and withdraws, it is possible that their stash
will contain less currency than the existential deposit. If that
happens, their stash is reaped. But if the existential deposit is zero,
the reap is not triggered. This PR adjusts `pallet_staking` to reap a
stash in the special case that the stash value is zero and the
existential deposit is zero.

This change is important for blockchains built on substrate that require
an existential deposit of zero, becuase it conserves valued storage
space.

There are two places in which ledgers are checked to determine if their
value is less than the existential deposit and they should be reaped: in
the methods `do_withdraw_unbonded` and `reap_stash`. When the check is
made, the condition `ledger_total == 0` is also checked. If
`ledger_total` is zero, then it must be below any existential deposit
greater than zero and equal to an existential deposit of 0.

I added a new test for each method to confirm the change behaves as
expected.

Closes https://github.com/paritytech/polkadot-sdk/issues/4340

---------

Co-authored-by: command-bot <>
parent 1680977e
Pipeline #471943 passed with warnings with stages
in 1 hour, 8 minutes, and 46 seconds