This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Properly defer slashes #11823
Merged
Merged
Properly defer slashes #11823
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
de769d7
initial draft of fixing slashing
kianenigma f1a4e53
fix test
kianenigma b45331a
Update frame/staking/src/tests.rs
kianenigma 1e0162a
last touches
kianenigma 0475b29
add more detail about unbonding
kianenigma 2f3e342
Merge branch 'kiz-fix-staking-slash' of github.com:paritytech/substra…
kianenigma c831ff8
add migration
kianenigma d1f4c53
Merge remote-tracking branch 'origin/master' into kiz-fix-staking-slash
c07ec9b
fmt
kianenigma 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
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
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 |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ use frame_support::{ | |
| use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; | ||
| use pallet_session::historical; | ||
| use sp_runtime::{ | ||
| traits::{Bounded, Convert, SaturatedConversion, Saturating, StaticLookup, Zero}, | ||
| traits::{Bounded, Convert, One, SaturatedConversion, Saturating, StaticLookup, Zero}, | ||
| Perbill, | ||
| }; | ||
| use sp_staking::{ | ||
|
|
@@ -599,20 +599,17 @@ impl<T: Config> Pallet<T> { | |
|
|
||
| /// Apply previously-unapplied slashes on the beginning of a new era, after a delay. | ||
| fn apply_unapplied_slashes(active_era: EraIndex) { | ||
| let slash_defer_duration = T::SlashDeferDuration::get(); | ||
| <Self as Store>::EarliestUnappliedSlash::mutate(|earliest| { | ||
| if let Some(ref mut earliest) = earliest { | ||
| let keep_from = active_era.saturating_sub(slash_defer_duration); | ||
| for era in (*earliest)..keep_from { | ||
| let era_slashes = <Self as Store>::UnappliedSlashes::take(&era); | ||
| for slash in era_slashes { | ||
| slashing::apply_slash::<T>(slash, era); | ||
| } | ||
| } | ||
|
|
||
| *earliest = (*earliest).max(keep_from) | ||
| } | ||
| }) | ||
| let era_slashes = <Self as Store>::UnappliedSlashes::take(&active_era); | ||
| log!( | ||
| debug, | ||
| "found {} slashes scheduled to be executed in era {:?}", | ||
| era_slashes.len(), | ||
| active_era, | ||
| ); | ||
| for slash in era_slashes { | ||
| let slash_era = active_era.saturating_sub(T::SlashDeferDuration::get()); | ||
| slashing::apply_slash::<T>(slash, slash_era); | ||
| } | ||
| } | ||
|
|
||
| /// Add reward points to validators using their stash account ID. | ||
|
|
@@ -1209,11 +1206,6 @@ where | |
| } | ||
| }; | ||
|
|
||
| <Self as Store>::EarliestUnappliedSlash::mutate(|earliest| { | ||
| if earliest.is_none() { | ||
| *earliest = Some(active_era) | ||
| } | ||
| }); | ||
| add_db_reads_writes(1, 1); | ||
|
|
||
| let slash_defer_duration = T::SlashDeferDuration::get(); | ||
|
|
@@ -1263,9 +1255,18 @@ where | |
| } | ||
| } else { | ||
| // Defer to end of some `slash_defer_duration` from now. | ||
| <Self as Store>::UnappliedSlashes::mutate(active_era, move |for_later| { | ||
| for_later.push(unapplied) | ||
| }); | ||
| log!( | ||
| debug, | ||
| "deferring slash of {:?}% happened in {:?} (reported in {:?}) to {:?}", | ||
| slash_fraction, | ||
| slash_era, | ||
| active_era, | ||
| slash_era + slash_defer_duration + 1, | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| <Self as Store>::UnappliedSlashes::mutate( | ||
| slash_era.saturating_add(slash_defer_duration).saturating_add(One::one()), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe pull the |
||
| move |for_later| for_later.push(unapplied), | ||
| ); | ||
| add_db_reads_writes(1, 1); | ||
| } | ||
| } else { | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.