use super::*;
use sp_runtime::{Perbill, Saturating};
#[derive(Clone, RuntimeDebug, TypeInfo, Encode, Decode, PartialEq, Eq)]
pub enum DKGMisbehaviorOffenceType {
SignedProposalNotInQueue,
SignedMalformedProposal,
}
#[derive(Clone, RuntimeDebug, TypeInfo, PartialEq, Eq)]
pub struct DKGMisbehaviourOffence<Offender> {
pub session_index: SessionIndex,
pub validator_set_count: u32,
pub offence: DKGMisbehaviorOffenceType,
pub offenders: Vec<Offender>,
}
impl<Offender: Clone> Offence<Offender> for DKGMisbehaviourOffence<Offender> {
const ID: Kind = *b"im-online:offlin";
type TimeSlot = SessionIndex;
fn offenders(&self) -> Vec<Offender> {
self.offenders.clone()
}
fn session_index(&self) -> SessionIndex {
self.session_index
}
fn validator_set_count(&self) -> u32 {
self.validator_set_count
}
fn time_slot(&self) -> Self::TimeSlot {
self.session_index
}
fn disable_strategy(&self) -> DisableStrategy {
DisableStrategy::Never
}
fn slash_fraction(&self, offenders: u32) -> Perbill {
if let Some(threshold) = offenders.checked_sub(self.validator_set_count / 10 + 1) {
let x = Perbill::from_rational(3 * threshold, self.validator_set_count);
x.saturating_mul(Perbill::from_percent(7))
} else {
Perbill::default()
}
}
}