-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[stable2412] Backport #6540 #8355
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0dd5aaf
BACKPORT-CONFLICT
Ank4n a72b348
resolve conflicts
Ank4n f8c413d
fix test
Ank4n 8094590
Merge branch 'stable2412' into backport-6540-to-stable2412
EgorPopelyaev f754af0
Merge branch 'stable2412' into backport-6540-to-stable2412
EgorPopelyaev f9cb2cf
Re-use NotSupported error
ggwpez d776f55
fmt
ggwpez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
| # See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
|
||
| title: Only allow apply slash to be executed if the slash amount is atleast ED | ||
|
|
||
| doc: | ||
| - audience: Runtime User | ||
| description: | | ||
| This change prevents `pools::apply_slash` from being executed when the pending slash amount of the member is lower | ||
| than the ED. With this change, such small slashes will still be applied but only when member funds are withdrawn. | ||
|
|
||
| crates: | ||
| - name: pallet-nomination-pools-runtime-api | ||
| bump: patch | ||
| - name: pallet-nomination-pools | ||
| bump: major | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1944,6 +1944,8 @@ pub mod pallet { | |
| NothingToAdjust, | ||
| /// No slash pending that can be applied to the member. | ||
| NothingToSlash, | ||
| /// The slash amount is too low to be applied. | ||
| SlashTooLow, | ||
|
||
| /// The pool or member delegation has already migrated to delegate stake. | ||
| AlreadyMigrated, | ||
| /// The pool or member delegation has not migrated yet to delegate stake. | ||
|
|
@@ -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) { | ||
| Ok(_) => T::WeightInfo::apply_slash(), | ||
| Err(e) => { | ||
| let no_pending_slash: DispatchResult = Err(Error::<T>::NothingToSlash.into()); | ||
|
|
@@ -2974,8 +2976,10 @@ pub mod pallet { | |
| /// Fails unless [`crate::pallet::Config::StakeAdapter`] is of strategy type: | ||
| /// [`adapter::StakeStrategyType::Delegate`]. | ||
| /// | ||
| /// This call can be dispatched permissionlessly (i.e. by any account). If the member has | ||
| /// slash to be applied, caller may be rewarded with the part of the slash. | ||
| /// The pending slash amount of the member must be equal or more than `ExistentialDeposit`. | ||
| /// This call can be dispatched permissionlessly (i.e. by any account). If the execution | ||
| /// is successful, fee is refunded and caller may be rewarded with a part of the slash | ||
| /// based on the [`crate::pallet::Config::StakeAdapter`] configuration. | ||
| #[pallet::call_index(23)] | ||
| #[pallet::weight(T::WeightInfo::apply_slash())] | ||
| pub fn apply_slash( | ||
|
|
@@ -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)?; | ||
|
|
||
| // If successful, refund the fees. | ||
| Ok(Pays::No.into()) | ||
|
|
@@ -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, | ||
| ) -> DispatchResult { | ||
| let member = PoolMembers::<T>::get(member_account).ok_or(Error::<T>::PoolMemberNotFound)?; | ||
|
|
||
| let pending_slash = | ||
| Self::member_pending_slash(Member::from(member_account.clone()), member.clone())?; | ||
|
|
||
| // if nothing to slash, return error. | ||
| // ensure there is something to slash. | ||
| ensure!(!pending_slash.is_zero(), Error::<T>::NothingToSlash); | ||
|
|
||
| if enforce_min_slash { | ||
| // ensure slashed amount is at least the minimum balance. | ||
| ensure!(pending_slash >= T::Currency::minimum_balance(), Error::<T>::SlashTooLow); | ||
| } | ||
|
|
||
| T::StakeAdapter::member_slash( | ||
| Member::from(member_account.clone()), | ||
| Pool::from(Pallet::<T>::generate_bonded_account(member.pool_id)), | ||
|
|
@@ -3946,6 +3956,9 @@ impl<T: Config> Pallet<T> { | |
| /// Returns the unapplied slash of a member. | ||
| /// | ||
| /// Pending slash is only applicable with [`adapter::DelegateStake`] strategy. | ||
| /// | ||
| /// If pending slash of the member exceeds `ExistentialDeposit`, it can be reported on | ||
| /// chain via [`Call::apply_slash`]. | ||
| pub fn api_member_pending_slash(who: T::AccountId) -> BalanceOf<T> { | ||
| PoolMembers::<T>::get(who.clone()) | ||
| .map(|pool_member| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Major bumps in backports are not permissible anymore. They messed up 2503 and we dont want to mess up any more releases because of them...
There is some rational explained here https://forum.parity.io/t/stable-releases/2142/48
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ggwpez @EgorPopelyaev
The breaking change here is the introduction of a new error. I can rework this PR to avoid adding a new error and make it non-breaking if needed.
However, the same new error has already been introduced in the backport to stable2409, so not including it here would technically be a breaking change relative to that.
The logic change itself is quite small (under 10 LOC), along with some tests and updated rustdocs.
This patch addresses a potential low- to mid-severity security issue, preventing a feeless transactions from being triggered with very small values.
P.S.: I am happy to comply based on your preference, just trying to understand the best path forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go for changing it to not break this release