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|NominationPools] Only allow apply slash to be executed if the slash amount is atleast ED #6540

Merged
merged 11 commits into from
Nov 21, 2024

Conversation

Ank4n
Copy link
Contributor

@Ank4n Ank4n commented Nov 19, 2024

This change prevents pools::apply_slash from being executed when the pending slash amount of the member is lower than the ED.

The issue came to light with the failing benchmark test in Kusama. The problem arises from the inexact conversion between points and balance. Specifically, when points are converted to balance and then back to points, rounding can introduce a small discrepancy between the input and the resulting value. This issue surfaced in Kusama due to its ED being different from Westend and Polkadot (1 UNIT/300), making the rounding issue noticeable.

This fix is also significant because applying a slash is feeless and permissionless. Allowing super small slash amounts to be applied without a fee is undesirable. With this change, such small slashes will still be applied but only when member funds are withdrawn.

@Ank4n Ank4n added T2-pallets This PR/Issue is related to a particular pallet. A4-needs-backport Pull request must be backported to all maintained releases. labels Nov 19, 2024
@Ank4n Ank4n requested a review from gpestana November 19, 2024 15:01
@Ank4n Ank4n requested a review from a team as a code owner November 19, 2024 15:01
@@ -2989,7 +2993,7 @@ pub mod pallet {

let who = ensure_signed(origin)?;
let member_account = T::Lookup::lookup(member_account)?;
Self::do_apply_slash(&member_account, Some(who))?;
Self::do_apply_slash(&member_account, Some(who), true)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we want to to avoid slashing below the ED here (pub fn apply_slash)?

@gui1117
Copy link
Contributor

gui1117 commented Nov 19, 2024

This fix is also significant because applying a slash is feeless and permissionless. Allowing super small slash amounts to be applied without a fee is undesirable. With this change, such small slashes will still be applied but only when member funds are withdrawn.

I don't think this is an issue, slash are applied for rare circumstances no?

@@ -2300,7 +2302,7 @@ pub mod pallet {

let slash_weight =
// apply slash if any before withdraw.
match Self::do_apply_slash(&member_account, None) {
match Self::do_apply_slash(&member_account, None, false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

My previous comment only made sense when taken with another made to this line, which asked: why don't we want to enforce the ED checks here?

Sorry, I had the GH open for a while, it might have been lost when I refreshed the browser.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point, a gas fee is charged for slashing. Additionally, we need to clean up all bookkeeping before a member withdraws.

@Ank4n
Copy link
Contributor Author

Ank4n commented Nov 20, 2024

This fix is also significant because applying a slash is feeless and permissionless. Allowing super small slash amounts to be applied without a fee is undesirable. With this change, such small slashes will still be applied but only when member funds are withdrawn.

I don't think this is an issue, slash are applied for rare circumstances no?

Single slash can affect unbounded number of pool members. The slashes are applied per member and if that is too small, is it worth to provide free compute for it?

@Ank4n Ank4n requested a review from kianenigma November 20, 2024 08:24
@@ -3574,15 +3578,21 @@ impl<T: Config> Pallet<T> {
fn do_apply_slash(
member_account: &T::AccountId,
reporter: Option<T::AccountId>,
enforce_min_slash: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit but in order to prevent spreading do_apply_slash(..., bool) across the code which is not very readable, how about creating an enum that helps with readability? something along the lines of

enum SlashConfig {
 EnforceMinimum,
 DoNotEnforceMinimuim
}

Not sure about the enum and variant names, but in general

// reads better
do_apply_slash(..., SlashConfig::EnforceMinimum);

// than this
do_apply_slash(..., true);

prdoc/pr_6540.prdoc Outdated Show resolved Hide resolved
Co-authored-by: Dónal Murray <donal.murray@parity.io>
@Ank4n Ank4n enabled auto-merge November 21, 2024 14:00
@Ank4n Ank4n added this pull request to the merge queue Nov 21, 2024
Merged via the queue into master with commit bf20a9e Nov 21, 2024
194 of 198 checks passed
@Ank4n Ank4n deleted the ankan/fix/pool-min-slash-check branch November 21, 2024 15:56
@paritytech-cmd-bot-polkadot-sdk

Created backport PR for stable2407:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-6540-to-stable2407
git worktree add --checkout .worktree/backport-6540-to-stable2407 backport-6540-to-stable2407
cd .worktree/backport-6540-to-stable2407
git reset --hard HEAD^
git cherry-pick -x bf20a9ee18f7215210bbbabf79e955c8c35b3360
git push --force-with-lease

@paritytech-cmd-bot-polkadot-sdk

Created backport PR for stable2409:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-6540-to-stable2409
git worktree add --checkout .worktree/backport-6540-to-stable2409 backport-6540-to-stable2409
cd .worktree/backport-6540-to-stable2409
git reset --hard HEAD^
git cherry-pick -x bf20a9ee18f7215210bbbabf79e955c8c35b3360
git push --force-with-lease

Ank4n added a commit that referenced this pull request Nov 21, 2024
…ash amount is atleast ED (#6540)

This change prevents `pools::apply_slash` from being executed when the
pending slash amount of the member is lower than the ED.

The issue came to light with the failing [benchmark
test](https://github.com/polkadot-fellows/runtimes/actions/runs/11879471717/job/33101445269?pr=490#step:11:765)
in Kusama. The problem arises from the inexact conversion between points
and balance. Specifically, when points are converted to balance and then
back to points, rounding can introduce a small discrepancy between the
input and the resulting value. This issue surfaced in Kusama due to its
ED being different from Westend and Polkadot (1 UNIT/300), making the
rounding issue noticeable.

This fix is also significant because applying a slash is feeless and
permissionless. Allowing super small slash amounts to be applied without
a fee is undesirable. With this change, such small slashes will still be
applied but only when member funds are withdrawn.

---------

Co-authored-by: Dónal Murray <donal.murray@parity.io>
(cherry picked from commit bf20a9e)
EgorPopelyaev added a commit that referenced this pull request Dec 4, 2024
Backport #6540 into `stable2407` from Ank4n.

See the
[documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md)
on how to use this bot.

<!--
  # To be used by other automation, do not modify:
  original-pr-number: #${pull_number}
-->

Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
Co-authored-by: Egor_P <egor@parity.io>
EgorPopelyaev pushed a commit that referenced this pull request Dec 9, 2024
Backport #6540 into `stable2409` from Ank4n.

See the
[documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md)
on how to use this bot.

<!--
  # To be used by other automation, do not modify:
  original-pr-number: #${pull_number}
-->

---------

Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
Co-authored-by: Ankan <ankan.anurag@gmail.com>
Krayt78 pushed a commit to Krayt78/polkadot-sdk that referenced this pull request Dec 18, 2024
…ash amount is atleast ED (paritytech#6540)

This change prevents `pools::apply_slash` from being executed when the
pending slash amount of the member is lower than the ED.

The issue came to light with the failing [benchmark
test](https://github.com/polkadot-fellows/runtimes/actions/runs/11879471717/job/33101445269?pr=490#step:11:765)
in Kusama. The problem arises from the inexact conversion between points
and balance. Specifically, when points are converted to balance and then
back to points, rounding can introduce a small discrepancy between the
input and the resulting value. This issue surfaced in Kusama due to its
ED being different from Westend and Polkadot (1 UNIT/300), making the
rounding issue noticeable.

This fix is also significant because applying a slash is feeless and
permissionless. Allowing super small slash amounts to be applied without
a fee is undesirable. With this change, such small slashes will still be
applied but only when member funds are withdrawn.

---------

Co-authored-by: Dónal Murray <donal.murray@parity.io>
dudo50 pushed a commit to paraspell-research/polkadot-sdk that referenced this pull request Jan 4, 2025
…ash amount is atleast ED (paritytech#6540)

This change prevents `pools::apply_slash` from being executed when the
pending slash amount of the member is lower than the ED.

The issue came to light with the failing [benchmark
test](https://github.com/polkadot-fellows/runtimes/actions/runs/11879471717/job/33101445269?pr=490#step:11:765)
in Kusama. The problem arises from the inexact conversion between points
and balance. Specifically, when points are converted to balance and then
back to points, rounding can introduce a small discrepancy between the
input and the resulting value. This issue surfaced in Kusama due to its
ED being different from Westend and Polkadot (1 UNIT/300), making the
rounding issue noticeable.

This fix is also significant because applying a slash is feeless and
permissionless. Allowing super small slash amounts to be applied without
a fee is undesirable. With this change, such small slashes will still be
applied but only when member funds are withdrawn.

---------

Co-authored-by: Dónal Murray <donal.murray@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A4-needs-backport Pull request must be backported to all maintained releases. T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants