diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 11f23e528832..9de3a470dd90 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1314,7 +1314,7 @@ impl parachains_initializer::Config for Runtime { impl parachains_disputes::Config for Runtime { type Event = Event; - type PunishValidators = (); + type SlashingHandler = (); type WeightInfo = weights::runtime_parachains_disputes::WeightInfo; } diff --git a/runtime/parachains/src/disputes.rs b/runtime/parachains/src/disputes.rs index 9e2c97a3ad72..2b84e36f8e24 100644 --- a/runtime/parachains/src/disputes.rs +++ b/runtime/parachains/src/disputes.rs @@ -62,7 +62,7 @@ pub enum DisputeResult { } /// Punishment hooks for disputes. -pub trait PunishValidators { +pub trait SlashingHandler { /// Punish a series of validators who were for an invalid parablock. This is expected to be a major /// punishment. fn punish_for_invalid( @@ -80,9 +80,18 @@ pub trait PunishValidators { losers: impl IntoIterator, winners: impl IntoIterator, ); + + /// Called by the initializer to initialize the slashing pallet. + fn initializer_initialize(now: BlockNumber) -> Weight; + + /// Called by the initializer to finalize the slashing pallet. + fn initializer_finalize(); + + /// Called by the initializer to note that a new session has started. + fn initializer_on_new_session(notification: &SessionChangeNotification); } -impl PunishValidators for () { +impl SlashingHandler for () { fn punish_for_invalid( _: SessionIndex, _: CandidateHash, @@ -98,6 +107,14 @@ impl PunishValidators for () { _: impl IntoIterator, ) { } + + fn initializer_initialize(_now: BlockNumber) -> Weight { + 0 + } + + fn initializer_finalize() {} + + fn initializer_on_new_session(_notification: &SessionChangeNotification) {} } /// Binary discriminator to determine if the expensive signature @@ -408,7 +425,7 @@ pub mod pallet { pub trait Config: frame_system::Config + configuration::Config + session_info::Config { type Event: From> + IsType<::Event>; - type PunishValidators: PunishValidators; + type SlashingHandler: SlashingHandler; /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; @@ -1146,7 +1163,7 @@ impl Pallet { // Slash participants on a losing side. { // a valid candidate, according to 2/3. Punish those on the 'against' side. - T::PunishValidators::punish_against_valid( + T::SlashingHandler::punish_against_valid( session, candidate_hash, summary.slash_against, @@ -1154,7 +1171,7 @@ impl Pallet { ); // an invalid candidate, according to 2/3. Punish those on the 'for' side. - T::PunishValidators::punish_for_invalid( + T::SlashingHandler::punish_for_invalid( session, candidate_hash, summary.slash_for, diff --git a/runtime/parachains/src/disputes/slashing.rs b/runtime/parachains/src/disputes/slashing.rs index 6a1d4b4a664c..4f7152417f04 100644 --- a/runtime/parachains/src/disputes/slashing.rs +++ b/runtime/parachains/src/disputes/slashing.rs @@ -105,7 +105,7 @@ where } fn slash_fraction(_offenders: u32, _validator_set_count: u32) -> Perbill { - Perbill::from_percent(100) // TODO + Perbill::from_percent(100) } } @@ -155,7 +155,7 @@ where } fn slash_fraction(_offenders: u32, _validator_set_count: u32) -> Perbill { - Perbill::from_percent(1) // TODO + Perbill::from_percent(1) } } @@ -170,18 +170,9 @@ impl Default for SlashValidatorsForDisputes { } } -impl SlashValidatorsForDisputes +impl SlashValidatorsForDisputes, R> where T: Config + crate::session_info::Config, - R: ReportOffence< - AccountId, - IdentificationTuple, - ForInvalidOffence>, - > + ReportOffence< - AccountId, - IdentificationTuple, - AgainstValidOffence>, - >, { /// If in the current session, returns the identified validators /// along with the validator set count for that session. `None` otherwise. @@ -212,7 +203,7 @@ where } } -impl super::PunishValidators for SlashValidatorsForDisputes +impl super::SlashingHandler for SlashValidatorsForDisputes, R> where T: Config + crate::session_info::Config, // TODO: use HandleReports instead? @@ -299,6 +290,18 @@ where >::insert(session_index, candidate_hash, losers); >::insert(session_index, candidate_hash, winners); } + + fn initializer_initialize(now: T::BlockNumber) -> Weight { + Pallet::::initializer_initialize(now) + } + + fn initializer_finalize() { + Pallet::::initializer_finalize() + } + + fn initializer_on_new_session(notification: &SessionChangeNotification) { + Pallet::::initializer_on_new_session(notification) + } } #[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug, TypeInfo)] @@ -690,17 +693,15 @@ pub mod pallet { impl Pallet { /// Called by the initializer to initialize the disputes slashing module. - pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight { + fn initializer_initialize(_now: T::BlockNumber) -> Weight { 0 } /// Called by the initializer to finalize the disputes slashing pallet. - pub(crate) fn initializer_finalize() {} + fn initializer_finalize() {} /// Called by the initializer to note a new session in the disputes slashing pallet. - pub(crate) fn initializer_on_new_session( - notification: &SessionChangeNotification, - ) { + fn initializer_on_new_session(notification: &SessionChangeNotification) { let config = >::config(); if notification.session_index <= config.dispute_period + 1 { return diff --git a/runtime/parachains/src/initializer.rs b/runtime/parachains/src/initializer.rs index 4137d720732a..aa817499e56e 100644 --- a/runtime/parachains/src/initializer.rs +++ b/runtime/parachains/src/initializer.rs @@ -21,7 +21,7 @@ use crate::{ configuration::{self, HostConfiguration}, - disputes::{self, DisputesHandler}, + disputes::{self, DisputesHandler as _, SlashingHandler as _}, dmp, hrmp, inclusion, paras, scheduler, session_info, shared, ump, }; use frame_support::{ @@ -109,7 +109,7 @@ pub mod pallet { + scheduler::Config + inclusion::Config + session_info::Config - + disputes::slashing::Config + + disputes::Config + dmp::Config + ump::Config + hrmp::Config @@ -164,7 +164,7 @@ pub mod pallet { inclusion::Pallet::::initializer_initialize(now) + session_info::Pallet::::initializer_initialize(now) + T::DisputesHandler::initializer_initialize(now) + - disputes::slashing::Pallet::::initializer_initialize(now) + + T::SlashingHandler::initializer_initialize(now) + dmp::Pallet::::initializer_initialize(now) + ump::Pallet::::initializer_initialize(now) + hrmp::Pallet::::initializer_initialize(now); @@ -179,7 +179,7 @@ pub mod pallet { hrmp::Pallet::::initializer_finalize(); ump::Pallet::::initializer_finalize(); dmp::Pallet::::initializer_finalize(); - disputes::slashing::Pallet::::initializer_finalize(); + T::SlashingHandler::initializer_finalize(); T::DisputesHandler::initializer_finalize(); session_info::Pallet::::initializer_finalize(); inclusion::Pallet::::initializer_finalize(); @@ -263,7 +263,7 @@ impl Pallet { inclusion::Pallet::::initializer_on_new_session(¬ification); session_info::Pallet::::initializer_on_new_session(¬ification); T::DisputesHandler::initializer_on_new_session(¬ification); - disputes::slashing::Pallet::::initializer_on_new_session(¬ification); + T::SlashingHandler::initializer_on_new_session(¬ification); dmp::Pallet::::initializer_on_new_session(¬ification, &outgoing_paras); ump::Pallet::::initializer_on_new_session(¬ification, &outgoing_paras); hrmp::Pallet::::initializer_on_new_session(¬ification, &outgoing_paras); diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index f190a766ba95..81830241e672 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -245,7 +245,7 @@ impl crate::hrmp::Config for Test { impl crate::disputes::Config for Test { type Event = Event; - type PunishValidators = Self; + type SlashingHandler = Self; type WeightInfo = crate::disputes::TestWeightInfo; } @@ -266,7 +266,7 @@ thread_local! { pub static PUNISH_VALIDATORS_AGAINST: RefCell)>> = RefCell::new(Vec::new()); } -impl crate::disputes::PunishValidators for Test { +impl crate::disputes::SlashingHandler for Test { fn punish_for_invalid( session: SessionIndex, _: CandidateHash, @@ -285,6 +285,14 @@ impl crate::disputes::PunishValidators for Test { PUNISH_VALIDATORS_AGAINST .with(|r| r.borrow_mut().push((session, losers.into_iter().collect()))) } + + fn initializer_initialize(_now: BlockNumber) -> Weight { + 0 + } + + fn initializer_finalize() {} + + fn initializer_on_new_session(_: &initializer::SessionChangeNotification) {} } impl crate::scheduler::Config for Test {} diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 6e8f8fe03e85..8fa2ef51b3c3 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -1296,7 +1296,7 @@ impl parachains_initializer::Config for Runtime { impl parachains_disputes::Config for Runtime { type Event = Event; - type PunishValidators = (); + type SlashingHandler = (); type WeightInfo = weights::runtime_parachains_disputes::WeightInfo; } diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index fafae1b1c0f3..a80a0c8f4c91 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -372,7 +372,7 @@ impl pallet_session::historical::Config for Runtime { impl parachains_disputes::Config for Runtime { type Event = Event; - type PunishValidators = (); + type SlashingHandler = (); type WeightInfo = weights::runtime_parachains_disputes::WeightInfo; } diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index 244660fd9be5..907ceb017f2a 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -485,7 +485,7 @@ impl parachains_inclusion::Config for Runtime { impl parachains_disputes::Config for Runtime { type Event = Event; - type PunishValidators = (); + type SlashingHandler = (); type WeightInfo = parachains_disputes::TestWeightInfo; } diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index bd3bd814fa85..5ca044d84384 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -932,7 +932,7 @@ impl assigned_slots::Config for Runtime { impl parachains_disputes::Config for Runtime { type Event = Event; - type PunishValidators = parachains_slashing::SlashValidatorsForDisputes; + type SlashingHandler = parachains_slashing::SlashValidatorsForDisputes; type WeightInfo = weights::runtime_parachains_disputes::WeightInfo; }