Skip to content

Commit

Permalink
apply slashes next era
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki committed Jan 8, 2025
1 parent c2c907f commit 6dad16d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions pallets/external-validator-slashes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,13 @@ where
);

// Cover slash defer duration equal to 0
// Slashes are applied at the end of the current era
if slash_defer_duration == 0 {
Slashes::<T>::mutate(slash_era, move |for_now| for_now.push(slash));
Slashes::<T>::mutate(active_era.saturating_add(One::one()), move |for_now| {
for_now.push(slash)
});
} else {
// Else, slashes are applied after slash_defer_period since the slashed era
Slashes::<T>::mutate(
slash_era
.saturating_add(slash_defer_duration)
Expand Down Expand Up @@ -499,9 +503,8 @@ impl<T: Config> Pallet<T> {
/// In this case, we also send (or schedule for sending) slashes to ethereum
fn confirm_unconfirmed_slashes(active_era: EraIndex) {
const SLASH_PAGE_SIZE: usize = 20;

Slashes::<T>::mutate(&active_era, |era_slashes| {

Slashes::<T>::mutate(&active_era, |era_slashes| {
let unreported_slashes = UnreportedSlashes::<T>::get();

let free_slashing_space = SLASH_PAGE_SIZE.saturating_sub(unreported_slashes.len());
Expand Down
6 changes: 3 additions & 3 deletions pallets/external-validator-slashes/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ fn test_on_offence_defer_period_0() {
0,
);

let slash_era = 0;

// The era in which it is going to be slashed should be the active era +1
let era_to_slash = 2;
assert_eq!(
Slashes::<Test>::get(slash_era),
Slashes::<Test>::get(era_to_slash),
vec![Slash {
validator: 3,
percentage: Perbill::from_percent(75),
Expand Down
2 changes: 1 addition & 1 deletion solo-chains/runtime/dancelight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ impl pallet_external_validators::Config for Runtime {
type UnixTime = Timestamp;
type SessionsPerEra = SessionsPerEra;
type OnEraStart = (ExternalValidatorSlashes, ExternalValidatorsRewards);
type OnEraEnd = (ExternalValidatorSlashes, ExternalValidatorsRewards);
type OnEraEnd = ExternalValidatorsRewards;
type WeightInfo = weights::pallet_external_validators::SubstrateWeight<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type Currency = Balances;
Expand Down

0 comments on commit 6dad16d

Please sign in to comment.