Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix fast-unstake for accounts with slashing #12963

Merged
merged 11 commits into from
Dec 23, 2022

Conversation

kianenigma
Copy link
Contributor

@kianenigma kianenigma commented Dec 18, 2022

kinda subtle, but kinda ashamed that I made the mistake 🤦

@kianenigma kianenigma added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Dec 18, 2022
@kianenigma
Copy link
Contributor Author

bot fmt

@kianenigma
Copy link
Contributor Author

/cmd queue -c fmt $ 1

@command-bot
Copy link

command-bot bot commented Dec 18, 2022

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

Comment /cmd cancel 116-bf25b68a-c4b2-49ff-a678-b2d6056d6f10 to cancel this command or /cmd cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Dec 18, 2022

@kianenigma Command "$PIPELINE_SCRIPTS_DIR/fmt.sh" 1 has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2172044 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2172044/artifacts/download.

@Ank4n
Copy link
Contributor

Ank4n commented Dec 18, 2022

Similar mistake here
https://github.com/paritytech/substrate/blob/master/frame/staking/src/pallet/mod.rs#L985

@kianenigma
Copy link
Contributor Author

Similar mistake here https://github.com/paritytech/substrate/blob/master/frame/staking/src/pallet/mod.rs#L985

@gpestana can you add a test for this as well?

@kianenigma
Copy link
Contributor Author

we should make sure this goes to the next possible Polkadot release, which will probably be in 2023, would be good to have your tests in here @gpestana soon nonetheless.

@melekes
Copy link
Contributor

melekes commented Dec 22, 2022

kinda subtle, but kinda ashamed that I made the mistake 🤦

can you explain what the issue was? neither issue's title does this nor there's an issue linked to this PR. Thanks 🙏

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (code-wise; don't know enough to reason about business logic)

@gpestana
Copy link
Contributor

@kianenigma with the current flow, there's no path for the calculated real_num_slashing_spans to be used in the fn kill_stash called by fn do_withdraw_unbound. Thus, the slash + unbound + do_witdraw tests are not required/possible.


Explanation:

When calling Call::unbound(), if the controller's max_chunks are filled, the fn do_withdraw_unbond is called:

mod.rs#L984-L986

if unlocking == T::MaxUnlockingChunks::get() as usize {
    let real_num_slashing_spans = Self::slashing_spans(&controller).iter().count();
    Some(Self::do_withdraw_unbonded(&controller, real_num_slashing_spans as u32)?)
}

In the do_withdraw_unbond, the account is checked to see if all the staking related information should be removed (fn kill_stash). The condition is the following:

if ledger.unlocking.is_empty() && ledger.active < T::Currency::minimum_balance() {
    Self::kill_stash(&stash, num_slashing_spans)?;
    // ... 

i.e. the account should be killed iff there's no unlocking chunks and the balance is below the ED.

Thus, the path unbound() -> do_withdraw_unbond() -> kill_stash() is disjoint and can never happen, because the condition to call kill_stash() prevents the do_withdraw_unbond() to be called (no chunks in the slots).

Note: since withdraw_unbond() is an extrinsic, the fn kill_stash() may be called, just not through the fn unbond call.

@kianenigma
Copy link
Contributor Author

kianenigma commented Dec 22, 2022

kinda subtle, but kinda ashamed that I made the mistake 🤦

can you explain what the issue was? neither issue's title does this nor there's an issue linked to this PR. Thanks 🙏

fn slashing_spans returns Option<T> where T implemented Iterator and I expected it check the .count() of this iterator, but, Option<T> also implements Iterator, who's count is 0 or 1.

This is unrelated to any business logic.

@kianenigma
Copy link
Contributor Author

bot rebase

@paritytech-processbot
Copy link

Rebased

@kianenigma
Copy link
Contributor Author

/cmd queue -c fmt

@command-bot
Copy link

command-bot bot commented Dec 22, 2022

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

Comment /cmd cancel 124-14dc6cef-2a84-414a-8b45-9c071519bfc3 to cancel this command or /cmd cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Dec 22, 2022

@kianenigma Command "$PIPELINE_SCRIPTS_DIR/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2188345 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2188345/artifacts/download.

@kianenigma
Copy link
Contributor Author

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 6c65424 into master Dec 23, 2022
@paritytech-processbot paritytech-processbot bot deleted the kiz-correct-slashing-spans branch December 23, 2022 07:04
@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/path-to-fast-unstake-in-polkadot-kusama/1539/1

@kianenigma kianenigma added B7-runtimenoteworthy and removed B0-silent Changes should not be mentioned in any release notes labels Jan 14, 2023
ltfschoen pushed a commit to ltfschoen/substrate that referenced this pull request Feb 22, 2023
* Fix fast-unstake for accounts with slashing

* ".git/.scripts/fmt.sh" 1

* fmt

* fix

* fix weight tracking

* Adds tests for withdraw_unbonded with slashing

* Removes tests for withdraw_unbonded with slashing

* ".git/.scripts/fmt.sh"

* Adds slash spans calculation test for withdraw_unbonded

Co-authored-by: command-bot <>
Co-authored-by: gpestana <g6pestana@gmail.com>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* Fix fast-unstake for accounts with slashing

* ".git/.scripts/fmt.sh" 1

* fmt

* fix

* fix weight tracking

* Adds tests for withdraw_unbonded with slashing

* Removes tests for withdraw_unbonded with slashing

* ".git/.scripts/fmt.sh"

* Adds slash spans calculation test for withdraw_unbonded

Co-authored-by: command-bot <>
Co-authored-by: gpestana <g6pestana@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants