From 6dad16d56f1ef9d668043e939bc6a84ee2cf8ee6 Mon Sep 17 00:00:00 2001 From: girazoki Date: Wed, 8 Jan 2025 10:28:48 +0100 Subject: [PATCH] apply slashes next era --- pallets/external-validator-slashes/src/lib.rs | 9 ++++++--- pallets/external-validator-slashes/src/tests.rs | 6 +++--- solo-chains/runtime/dancelight/src/lib.rs | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pallets/external-validator-slashes/src/lib.rs b/pallets/external-validator-slashes/src/lib.rs index b591cb718..db6977e04 100644 --- a/pallets/external-validator-slashes/src/lib.rs +++ b/pallets/external-validator-slashes/src/lib.rs @@ -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::::mutate(slash_era, move |for_now| for_now.push(slash)); + Slashes::::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::::mutate( slash_era .saturating_add(slash_defer_duration) @@ -499,9 +503,8 @@ impl Pallet { /// 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::::mutate(&active_era, |era_slashes| { + Slashes::::mutate(&active_era, |era_slashes| { let unreported_slashes = UnreportedSlashes::::get(); let free_slashing_space = SLASH_PAGE_SIZE.saturating_sub(unreported_slashes.len()); diff --git a/pallets/external-validator-slashes/src/tests.rs b/pallets/external-validator-slashes/src/tests.rs index 5609346e4..c5e340998 100644 --- a/pallets/external-validator-slashes/src/tests.rs +++ b/pallets/external-validator-slashes/src/tests.rs @@ -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::::get(slash_era), + Slashes::::get(era_to_slash), vec![Slash { validator: 3, percentage: Perbill::from_percent(75), diff --git a/solo-chains/runtime/dancelight/src/lib.rs b/solo-chains/runtime/dancelight/src/lib.rs index e62ede291..fc881780e 100644 --- a/solo-chains/runtime/dancelight/src/lib.rs +++ b/solo-chains/runtime/dancelight/src/lib.rs @@ -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; #[cfg(feature = "runtime-benchmarks")] type Currency = Balances;