Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ed6abea
rename for forInvalid to BackedInvalid and introduction of proper For…
Overkillus Dec 10, 2024
67fd371
punish changes temp
Overkillus Jan 8, 2025
0e909c2
rename Slashing Offence Kinds
Overkillus Jan 27, 2025
9f44ed0
revert slashing handler
Overkillus Jan 27, 2025
f59c8d8
split forInvalid into 2 types
Overkillus Jan 27, 2025
eebd576
Merge branch 'master' into mkz-approval-slashes
Overkillus May 13, 2025
aa6774c
OffenceKind rename
Overkillus May 12, 2025
075fbdf
doc clarification
Overkillus May 12, 2025
4cd1f5c
include dispute in offence name
Overkillus May 12, 2025
8655c71
prdoc
Overkillus May 14, 2025
871e47d
Merge branch 'master' into mkz-approval-slashes
Overkillus May 14, 2025
19fd030
Merge branch 'master' into mkz-approval-slashes
Overkillus May 20, 2025
9adff15
move new OffenceKind to vstaging
Overkillus May 20, 2025
33deaad
vstaging primitives + from impls
Overkillus May 22, 2025
4d556e9
notes
Overkillus May 22, 2025
7ac2fa9
lint
Overkillus May 22, 2025
5f48edf
convert old disputeProofs to new ones on call
Overkillus May 22, 2025
f0ab867
simpler v1-v2 conversion at entry point
Overkillus May 22, 2025
66fe2e3
derives + proper imports
Overkillus May 22, 2025
a2335b4
imports and trait bounds
Overkillus May 22, 2025
45379b4
v1,v2 labels and v2->v1 conversion for sake of old runtime api
Overkillus May 22, 2025
69fc17c
Update prdoc/pr_6827.prdoc
Overkillus May 22, 2025
eaef7c8
fixing double offence report
Overkillus May 23, 2025
0a9dc36
prdoc
Overkillus May 23, 2025
95160df
spammy validators get disabled in zombienet
Overkillus May 23, 2025
531352b
guard for no disputes concluding invalid in zn test
Overkillus May 23, 2025
45edbb7
simple migration
Overkillus May 23, 2025
d4ce7c3
Update polkadot/primitives/src/vstaging/mod.rs
Overkillus May 28, 2025
8b3dd2f
migration removal, decoding is backwards compatible
Overkillus May 30, 2025
03969a6
lazy validators test
Overkillus May 30, 2025
4ff936c
Merge branch 'master' into mkz-approval-slashes
Overkillus May 30, 2025
154be9d
clipper
Overkillus Jun 3, 2025
e97cf7a
rm zombienet tests (need to reimplement using sdk)
ordian Jun 4, 2025
f7f110c
add log and fmt
ordian Jun 4, 2025
c884d29
adjust prdoc
ordian Jun 4, 2025
6fe3648
Merge branch 'master' into mkz-approval-slashes
ordian Jun 4, 2025
3c1825a
fix compilation in slashing bench
ordian Jun 5, 2025
4a5798f
argh
ordian Jun 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion polkadot/primitives/src/v8/slashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ use alloc::{collections::btree_map::BTreeMap, vec::Vec};
use codec::{Decode, DecodeWithMemTracking, Encode};
use scale_info::TypeInfo;

/// The kind of the dispute offence.
/// The kind of the slashing offence (those come from disputes).
///
/// Notes:
/// Will soon be fully eclipsed by the expanded `DisputeOffenceKind` enum.
/// Only kept for backwards compatibility through old runtime apis.
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, DecodeWithMemTracking, TypeInfo, Debug)]
pub enum SlashingOffenceKind {
/// A severe offence when a validator backed an invalid block.
Expand Down Expand Up @@ -54,6 +58,11 @@ impl DisputesTimeSlot {

/// We store most of the information about a lost dispute on chain. This struct
/// is required to identify and verify it.
///
/// Notes:
/// Will soon be fully eclipsed by the expanded vstaging `DisputeProof` struct
/// that uses the newer `DisputeOffenceKind` enum instead.
/// Only kept for backwards compatibility.
#[derive(PartialEq, Eq, Clone, Encode, Decode, DecodeWithMemTracking, TypeInfo, Debug)]
pub struct DisputeProof {
/// Time slot when the dispute occurred.
Expand All @@ -68,6 +77,11 @@ pub struct DisputeProof {

/// Slashes that are waiting to be applied once we have validator key
/// identification.
///
/// Notes:
/// Will soon be fully eclipsed by the expanded vstaging `PendingSlashes` struct
/// that uses the newer `DisputeOffenceKind` enum instead.
/// Only kept for backwards compatibility.
#[derive(Encode, Decode, TypeInfo, Debug, Clone)]
pub struct PendingSlashes {
/// Indices and keys of the validators who lost a dispute and are pending
Expand Down
111 changes: 109 additions & 2 deletions polkadot/primitives/src/vstaging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Staging Primitives.
use crate::{ValidatorIndex, ValidityAttestation};
use crate::{slashing::DisputesTimeSlot, ValidatorId, ValidatorIndex, ValidityAttestation};

// Put any primitives used by staging APIs functions here
use super::{
Expand Down Expand Up @@ -1036,7 +1036,7 @@ pub fn transpose_claim_queue(
}

#[cfg(test)]
mod tests {
mod candidate_receipt_tests {
use super::*;
use crate::{
v8::{
Expand Down Expand Up @@ -1503,3 +1503,110 @@ mod tests {
assert_eq!(old_ccr_hash, new_ccr.hash());
}
}

// Approval Slashes primitives
/// Supercedes the old 'SlashingOffenceKind' enum.
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, DecodeWithMemTracking, TypeInfo, Debug)]
pub enum DisputeOffenceKind {
/// A severe offence when a validator backed an invalid block
/// (backing only)
#[codec(index = 0)]
ForInvalidBacked,
/// A minor offence when a validator disputed a valid block.
/// (approval checking and dispute vote only)
#[codec(index = 1)]
AgainstValid,
/// A medium offence when a validator approved an invalid block
/// (approval checking and dispute vote only)
#[codec(index = 2)]
ForInvalidApproved,
}

/// impl for a conversion from SlashingOffenceKind to DisputeOffenceKind
/// This creates DisputeOffenceKind that never contains ForInvalidApproved since it was not
/// supported in the past
impl From<super::v8::slashing::SlashingOffenceKind> for DisputeOffenceKind {
fn from(value: super::v8::slashing::SlashingOffenceKind) -> Self {
match value {
super::v8::slashing::SlashingOffenceKind::ForInvalid => Self::ForInvalidBacked,
super::v8::slashing::SlashingOffenceKind::AgainstValid => Self::AgainstValid,
}
}
}

/// impl for a tryFrom conversion from DisputeOffenceKind to SlashingOffenceKind
impl TryFrom<DisputeOffenceKind> for super::v8::slashing::SlashingOffenceKind {
type Error = ();

fn try_from(value: DisputeOffenceKind) -> Result<Self, Self::Error> {
match value {
DisputeOffenceKind::ForInvalidBacked => Ok(Self::ForInvalid),
DisputeOffenceKind::AgainstValid => Ok(Self::AgainstValid),
DisputeOffenceKind::ForInvalidApproved => Err(()),
}
}
}

/// Slashes that are waiting to be applied once we have validator key
/// identification.
#[derive(Encode, Decode, TypeInfo, Debug, Clone)]
pub struct PendingSlashes {
/// Indices and keys of the validators who lost a dispute and are pending
/// slashes.
pub keys: BTreeMap<ValidatorIndex, ValidatorId>,
/// The dispute outcome.
pub kind: DisputeOffenceKind,
}

impl From<super::v8::slashing::PendingSlashes> for PendingSlashes {
fn from(old: super::v8::slashing::PendingSlashes) -> Self {
let keys = old.keys;
let kind = old.kind.into();
Self { keys, kind }
}
}

impl TryFrom<PendingSlashes> for super::v8::slashing::PendingSlashes {
type Error = ();

fn try_from(value: PendingSlashes) -> Result<Self, Self::Error> {
Ok(Self { keys: value.keys, kind: value.kind.try_into()? })
}
}

/// We store most of the information about a lost dispute on chain. This struct
/// is required to identify and verify it.
#[derive(PartialEq, Eq, Clone, Encode, Decode, DecodeWithMemTracking, TypeInfo, Debug)]
pub struct DisputeProof {
/// Time slot when the dispute occurred.
pub time_slot: DisputesTimeSlot,
/// The dispute outcome.
pub kind: DisputeOffenceKind,
/// The index of the validator who lost a dispute.
pub validator_index: ValidatorIndex,
/// The parachain session key of the validator.
pub validator_id: ValidatorId,
}

impl From<super::v8::slashing::DisputeProof> for DisputeProof {
fn from(old: super::v8::slashing::DisputeProof) -> Self {
let time_slot = old.time_slot;
let kind = old.kind.into(); // infallible conversion
let validator_index = old.validator_index;
let validator_id = old.validator_id;
Self { time_slot, kind, validator_index, validator_id }
}
}

impl TryFrom<DisputeProof> for super::v8::slashing::DisputeProof {
type Error = ();

fn try_from(value: DisputeProof) -> Result<Self, Self::Error> {
Ok(Self {
time_slot: value.time_slot,
kind: value.kind.try_into()?,
validator_index: value.validator_index,
validator_id: value.validator_id,
})
}
}
9 changes: 5 additions & 4 deletions polkadot/runtime/parachains/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,18 @@ impl RewardValidators for () {

/// Punishment hooks for disputes.
pub trait SlashingHandler<BlockNumber> {
/// Punish a series of validators who were for an invalid parablock. This is
/// expected to be a major punishment.
/// Punish a series of validators who were for an invalid parablock.
/// This is expected to trigger a large punishment for backers
/// and a medium punishment for other approvers.
fn punish_for_invalid(
session: SessionIndex,
candidate_hash: CandidateHash,
losers: impl IntoIterator<Item = ValidatorIndex>,
backers: impl IntoIterator<Item = ValidatorIndex>,
);

/// Punish a series of validators who were against a valid parablock. This
/// is expected to be a minor punishment.
/// Punish a series of validators who were against a valid parablock.
/// This is expected to be a minor punishment.
fn punish_against_valid(
session: SessionIndex,
candidate_hash: CandidateHash,
Expand Down
Loading