Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

runtime/disputes: slashing #5535

Merged
merged 95 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
d6a2eb2
disputes: runtime part of slashing
ordian May 6, 2022
fd2194a
disputes: reward winners
ordian May 9, 2022
9f8daef
disputes/slashing: validate_unsigned impl
ordian May 11, 2022
ee46d14
fmt
ordian May 11, 2022
7b158f6
disputes/slashing: report_dispute_lost_unsigned
ordian May 11, 2022
60a82a4
disputes/slashing: separate winners from losers and report winners
ordian May 13, 2022
b303ee4
disputes/slashing: refactoring
ordian May 13, 2022
6f1d724
impl HandleReports
ordian May 16, 2022
4a55be9
enable on Wenstend
ordian May 16, 2022
1941543
fmt
ordian May 16, 2022
04ad120
add slashing pallet to the mock and test runtimes
ordian May 16, 2022
3784591
fix a bug in report_dispute_lost_unsigned
ordian May 16, 2022
f49b55f
fmt
ordian May 16, 2022
cbcf176
disputes: remove new_participants from summary
ordian May 17, 2022
7b82f0d
disputes: remove punish_inconclusive
ordian May 17, 2022
f863baf
impl SlashingHandler for Pallet for type-safety
ordian May 17, 2022
b4fa682
do not impl slashing::Config on mainnets yet
ordian May 17, 2022
2739900
teach spellcheck deduplication
ordian May 17, 2022
62ff14f
simplify interfaces and resolve some TODOs
ordian May 17, 2022
4db3ab8
resolve some more TODOs
ordian May 17, 2022
02c069d
minor typos
ordian May 17, 2022
6fc8f5f
move slashing into a folder
ordian May 18, 2022
7f3ae20
remove unnecessary clone
ordian May 18, 2022
13c7c84
fix validator_set_count calculation
ordian May 18, 2022
5c98289
introduce ValidatorSetCount
ordian May 18, 2022
8263d16
store ValidatorSetCount
ordian May 18, 2022
c073e08
fmt
ordian May 18, 2022
dc3b6de
add the benchmark
ordian Jun 14, 2022
75f256d
fmt
ordian Jun 14, 2022
65851ad
unflatten slashing
ordian Jun 14, 2022
2210bad
post-rebase fixes
ordian Jun 14, 2022
6ab6b48
remove winners eagerly
ordian Jun 14, 2022
6a0ddfc
use real slashing weights for westend
ordian Jun 14, 2022
29376b1
remove bench test suite
ordian Jun 17, 2022
f76a697
Merge branch 'master' into ao-disputes-offences-runtime
ordian Jun 17, 2022
4800be1
zombinet: modify disputes test to check for an offence report
ordian Jun 17, 2022
4c0f83e
zombinet: add a timeout
ordian Jun 17, 2022
3086e26
add slashing pallet to Rococo
ordian Jun 20, 2022
677a262
zombienet: revert back to rococo-local
ordian Jun 20, 2022
e1ff282
Merge branch 'master' into ao-disputes-offences-runtime
ordian Jun 20, 2022
fe7495e
fmt
ordian Jun 20, 2022
461f37f
remove TODOs
ordian Jun 20, 2022
bae9912
revert some accidental changes
ordian Jun 20, 2022
15fcf48
slashing is submodule of disputes
ordian Jun 21, 2022
097d6c1
Merge branch 'master' into ao-disputes-offences-runtime
ordian Jun 21, 2022
65146ca
Merge branch 'master' into ao-disputes-offences-runtime
ordian Jun 28, 2022
650eb19
Merge branch 'master' into ao-disputes-offences-runtime
ordian Jul 5, 2022
95cd87d
Merge branch 'master' into ao-disputes-offences-runtime
ordian Jul 28, 2022
760bdc7
Change the log target
ordian Jul 30, 2022
d3405cc
Merge branch 'master' into ao-disputes-offences-runtime
ordian Aug 1, 2022
d5b3324
Merge branch 'ao-disputes-offences-runtime' of github.com:paritytech/…
ordian Aug 1, 2022
f50aa7d
wrap comments with rustfmt, more docs, constants
ordian Aug 1, 2022
248baa5
use Defensive trait
ordian Aug 3, 2022
b02bcef
cargo update -p sp-io
ordian Aug 3, 2022
e1c87c4
merge offence types, remove rewards for now
ordian Aug 3, 2022
37f9cd7
Merge branch 'master' into ao-disputes-offences-runtime
ordian Aug 3, 2022
b531490
cargo update -p sp-io
ordian Aug 3, 2022
454874f
benchmark fixes
ordian Aug 3, 2022
c0db743
fmt
ordian Aug 3, 2022
9fb1e38
unused var
ordian Aug 3, 2022
9c84b22
fix block_author impl
ordian Aug 3, 2022
19b7c6b
ressurect RewardValidators trait
ordian Aug 3, 2022
784e65e
remove outdated comment
ordian Aug 3, 2022
0c2559c
Merge branch 'master' into ao-disputes-offences-runtime
ordian Aug 4, 2022
3a2858d
Merge branch 'master' into ao-disputes-offences-runtime
ordian Aug 4, 2022
c22a943
more module docs
ordian Aug 5, 2022
884d9d8
introduce BenchmarkingConfig
ordian Aug 5, 2022
df81683
Merge branch 'master' into ao-disputes-offences-runtime
ordian Aug 5, 2022
7101379
typo fix
ordian Aug 5, 2022
ce879df
teach spellcheck unapplied
ordian Aug 5, 2022
b070f34
Merge branch 'master' into ao-disputes-offences-runtime
ordian Aug 31, 2022
563995b
Merge branch 'master' into ao-disputes-offences-runtime
ordian Aug 31, 2022
7d5171c
use Weight::new()
ordian Aug 31, 2022
b436249
fix mocking rewards
ordian Aug 31, 2022
397046e
use RefTimeWeight
ordian Aug 31, 2022
18965e3
".git/.scripts/bench-bot.sh" runtime westend-dev runtime_parachains::…
Aug 31, 2022
7269e18
refactor maybe_identify_validators
ordian Aug 31, 2022
399e0e6
no more ticket in disguise
ordian Aug 31, 2022
89fb5ed
remove outdated comments
ordian Aug 31, 2022
4f34bd7
lower against valid to 0.1%
ordian Sep 1, 2022
0d99787
bump zombienet version for debug
pepoviola Sep 1, 2022
9223d71
use from_perthousand
ordian Sep 1, 2022
c48aa45
Merge branch 'master' into ao-disputes-offences-runtime
ordian Sep 1, 2022
655fe98
post-merge fixes
ordian Sep 1, 2022
81578ff
Merge branch 'master' into ao-disputes-offences-runtime
ordian Sep 2, 2022
c5472c9
another day, another Weight changes
ordian Sep 2, 2022
6e5f372
Revert "bump zombienet version for debug"
ordian Sep 2, 2022
7bf295a
do not reward block authors
ordian Sep 5, 2022
8309493
Merge branch 'master' into ao-disputes-offences-runtime
ordian Sep 5, 2022
cd9aeb8
fix outdated comment
ordian Sep 6, 2022
3fe81e9
merge master once again
ordian Sep 6, 2022
e87cc9c
merge master once again II
ordian Sep 8, 2022
918b4ca
Merge branch 'master' into ao-disputes-offences-runtime
ordian Sep 19, 2022
b453b1a
use Pays from frame_support::dispatch::Pays
pepoviola Sep 19, 2022
65da473
add timeout to is up
pepoviola Sep 20, 2022
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
2 changes: 1 addition & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ impl parachains_initializer::Config for Runtime {
impl parachains_disputes::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RewardValidators = parachains_reward_points::RewardValidatorsWithEraPoints<Runtime>;
type PunishValidators = ();
type SlashingHandler = ();
type WeightInfo = weights::runtime_parachains_disputes::WeightInfo<Runtime>;
}

Expand Down
1 change: 1 addition & 0 deletions runtime/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"primitives/runtime-benchmarks",
"static_assertions",
"sp-application-crypto",
Expand Down
78 changes: 49 additions & 29 deletions runtime/parachains/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use sp_std::{cmp::Ordering, prelude::*};
#[allow(unused_imports)]
pub(crate) use self::tests::run_to_block;

pub mod slashing;
#[cfg(test)]
mod tests;

Expand Down Expand Up @@ -73,35 +74,55 @@ impl RewardValidators for () {
}

/// Punishment hooks for disputes.
pub trait PunishValidators {
/// Punish a series of validators who were for an invalid parablock. This is expected to be a major
/// punishment.
pub trait SlashingHandler<BlockNumber> {
/// Punish a series of validators who were for an invalid parablock. This is
/// expected to be a major punishment.
fn punish_for_invalid(
session: SessionIndex,
validators: impl IntoIterator<Item = ValidatorIndex>,
candidate_hash: CandidateHash,
losers: 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,
validators: impl IntoIterator<Item = ValidatorIndex>,
candidate_hash: CandidateHash,
losers: impl IntoIterator<Item = ValidatorIndex>,
);

/// Punish a series of validators who were part of a dispute which never concluded. This is expected
/// to be a minor punishment.
fn punish_inconclusive(
session: SessionIndex,
validators: impl IntoIterator<Item = ValidatorIndex>,
);
/// 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(session_index: SessionIndex);
}

impl PunishValidators for () {
fn punish_for_invalid(_: SessionIndex, _: impl IntoIterator<Item = ValidatorIndex>) {}
impl<BlockNumber> SlashingHandler<BlockNumber> for () {
fn punish_for_invalid(
_: SessionIndex,
_: CandidateHash,
_: impl IntoIterator<Item = ValidatorIndex>,
) {
}

fn punish_against_valid(
_: SessionIndex,
_: CandidateHash,
_: impl IntoIterator<Item = ValidatorIndex>,
) {
}

fn punish_against_valid(_: SessionIndex, _: impl IntoIterator<Item = ValidatorIndex>) {}
fn initializer_initialize(_now: BlockNumber) -> Weight {
Weight::zero()
}

fn initializer_finalize() {}

fn punish_inconclusive(_: SessionIndex, _: impl IntoIterator<Item = ValidatorIndex>) {}
fn initializer_on_new_session(_: SessionIndex) {}
}

/// Binary discriminator to determine if the expensive signature
Expand Down Expand Up @@ -412,7 +433,7 @@ pub mod pallet {
pub trait Config: frame_system::Config + configuration::Config + session_info::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type RewardValidators: RewardValidators;
type PunishValidators: PunishValidators;
type SlashingHandler: SlashingHandler<Self::BlockNumber>;

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
Expand Down Expand Up @@ -831,14 +852,7 @@ impl<T: Config> Pallet<T> {
// it would be unexpected for any change here to occur when the dispute has not concluded
// in time, as a dispute guaranteed to have at least one honest participant should
// conclude quickly.
let participating = decrement_spam(spam_slots, &dispute);

// Slight punishment as these validators have failed to make data available to
// others in a timely manner.
T::PunishValidators::punish_inconclusive(
session_index,
participating.iter_ones().map(|i| ValidatorIndex(i as _)),
);
let _participating = decrement_spam(spam_slots, &dispute);
});

weight += T::DbWeight::get().reads_writes(2, 2);
Expand Down Expand Up @@ -1187,7 +1201,9 @@ impl<T: Config> Pallet<T> {
Error::<T>::SingleSidedDispute,
);

let DisputeStatementSet { session, candidate_hash, .. } = set.clone();
let DisputeStatementSet { ref session, ref candidate_hash, .. } = set;
let session = *session;
let candidate_hash = *candidate_hash;

// we can omit spam slot checks, `fn filter_disputes_data` is
// always called before calling this `fn`.
Expand Down Expand Up @@ -1227,10 +1243,14 @@ impl<T: Config> Pallet<T> {
// Slash participants on a losing side.
{
// a valid candidate, according to 2/3. Punish those on the 'against' side.
T::PunishValidators::punish_against_valid(session, summary.slash_against);
T::SlashingHandler::punish_against_valid(
session,
candidate_hash,
summary.slash_against,
);

// an invalid candidate, according to 2/3. Punish those on the 'for' side.
T::PunishValidators::punish_for_invalid(session, summary.slash_for);
T::SlashingHandler::punish_for_invalid(session, candidate_hash, summary.slash_for);
}

<Disputes<T>>::insert(&session, &candidate_hash, &summary.state);
Expand Down
Loading