Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: dust unbonded for zero existential deposit #4364

Merged
merged 7 commits into from
May 3, 2024

Conversation

krisbitney
Copy link
Contributor

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 #4340

The stashing account reaping conditions have been updated to include cases where the total balance or the ledger total is zero. Previously, checks were only performed for totals falling under the existential deposit. This expanded reaping condition allows accounts with zero balances to be handled more efficiently.
…enario

This commit adds two tests - `reap_stash_works_with_existential_deposit_zero` and `do_withdraw_unbonded_can_kill_stash_with_existential_deposit_zero` - to check staking functionality when existential deposit is set to zero. Also, updated the code to use `is_zero` method for zero balance check, making it more semantically clear and aligning it with other parts of the codebase. This should make the staking module more robust and easier to understand.
@Ank4n Ank4n added T1-FRAME This PR/Issue is related to core FRAME, the framework. T2-pallets This PR/Issue is related to a particular pallet. labels May 3, 2024
@Ank4n Ank4n requested a review from gpestana May 3, 2024 05:56
@bkchr
Copy link
Member

bkchr commented May 3, 2024

bot fmt

@command-bot
Copy link

command-bot bot commented May 3, 2024

@bkchr https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6121902 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 9-74189fcd-c767-4702-a31e-3541c422ab59 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented May 3, 2024

@bkchr Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6121902 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6121902/artifacts/download.

@bkchr bkchr added this pull request to the merge queue May 3, 2024
Merged via the queue into paritytech:master with commit 5198623 May 3, 2024
146 of 147 checks passed
@krisbitney krisbitney deleted the unbond-with-0ed branch May 3, 2024 14:49
dcolley added a commit to metaspan/polkadot-sdk that referenced this pull request May 6, 2024
* 'master' of https://github.com/metaspan/polkadot-sdk: (65 commits)
  Introduces `TypeWithDefault<T, D: Get<T>>` (paritytech#4034)
  Publish `polkadot-sdk-frame`  crate (paritytech#4370)
  Add validate field to prdoc (paritytech#4368)
  State trie migration on asset-hub westend and collectives westend (paritytech#4185)
  Fix: dust unbonded for zero existential deposit (paritytech#4364)
  Bridge: added subcommand to relay single parachain header (paritytech#4365)
  Bridge: fix zombienet tests (paritytech#4367)
  [WIP][CI] Add more GHA jobs (paritytech#4270)
  Allow for 0 existential deposit in benchmarks for `pallet_staking`, `pallet_session`, and `pallet_balances` (paritytech#4346)
  Deprecate `NativeElseWasmExecutor` (paritytech#4329)
  More `xcm::v4` cleanup and `xcm_fee_payment_runtime_api::XcmPaymentApi` nits (paritytech#4355)
  sc-tracing: enable env-filter feature (paritytech#4357)
  deps: update jsonrpsee to v0.22.5 (paritytech#4330)
  Add PoV-reclaim enablement guide to polkadot-sdk-docs (paritytech#4244)
  cargo: Update experimental litep2p to latest version (paritytech#4344)
  Bridge: ignore client errors when calling recently added `*_free_headers_interval` methods (paritytech#4350)
  Make parachain template great again (and async backing ready) (paritytech#4295)
  [Backport] Version bumps and reorg prdocs from 1.11.0 (paritytech#4336)
  HRMP - set `DefaultChannelSizeAndCapacityWithSystem` with dynamic values according to the `ActiveConfig` (paritytech#4332)
  Statement Distribution Per Peer Rate Limit (paritytech#3444)
  ...
TarekkMA pushed a commit to moonbeam-foundation/polkadot-sdk that referenced this pull request Aug 2, 2024
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 paritytech#4340

---------

Co-authored-by: command-bot <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework. T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Persistent Bonding State Issue with Zero Existential Deposit
3 participants