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

Offences reporting and slashing #3322

Merged
merged 119 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
4f24928
Remove offline slashing logic from staking.
tomusdrw Aug 6, 2019
9f1cad1
Initial version of reworked offence module, can report offences
folsen Aug 6, 2019
3fc6eaa
Merge branch 'retreat-slashing' of github.com:paritytech/substrate in…
tomusdrw Aug 6, 2019
89e623b
Clean up staking example.
tomusdrw Aug 6, 2019
0e1d398
Commit SlashingOffence
pepyakin Aug 6, 2019
d5c9cd1
Force new era on slash.
tomusdrw Aug 6, 2019
45e5907
Add offenders in the SlashingOffence trait.
pepyakin Aug 6, 2019
b93118f
Introduce the ReportOffence trait.
pepyakin Aug 6, 2019
051001a
Rename `Offence`.
pepyakin Aug 6, 2019
2dae936
Add on_before_session_ending handler.
tomusdrw Aug 6, 2019
5c3a249
Move offence related stuff under sr-primitives.
pepyakin Aug 6, 2019
aaa8159
Fix cargo check.
tomusdrw Aug 6, 2019
06ee813
Import new im-online implementation.
tomusdrw Aug 6, 2019
a807dae
Adding validator count to historical session storage as it's needed f…
folsen Aug 6, 2019
32cba20
Add a comment about offence.
pepyakin Aug 6, 2019
39f7ed0
Add BabeEquivocationOffence
pepyakin Aug 6, 2019
c5579b3
GrandpaEquivocationOffence
pepyakin Aug 6, 2019
ecd8d81
slash_fraction and fix
pepyakin Aug 6, 2019
cfe194d
current_era_start_session_index
pepyakin Aug 6, 2019
4cb0bfe
UnresponsivnessOffence
pepyakin Aug 7, 2019
7ede025
Finalise OnOffenceHandler traits, and stub impl for staking.
tomusdrw Aug 7, 2019
a56a7b4
slash_fraction doesn't really need &self
pepyakin Aug 7, 2019
da2cc83
Note that offenders count is greater than 0
pepyakin Aug 7, 2019
0e2047a
Merge branch 'master' into retreat-slashing
tomusdrw Aug 7, 2019
61c6c22
Add a test to ensure that I got the math right
pepyakin Aug 7, 2019
c94f253
Merge remote-tracking branch 'origin/retreat-slashing' into retreat-s…
tomusdrw Aug 7, 2019
f7a8711
Use FullIdentification in offences.
tomusdrw Aug 7, 2019
7b14a37
Use FullIndentification.
tomusdrw Aug 7, 2019
cea7edc
Hook up the offences module.
pepyakin Aug 7, 2019
da01b46
Report unresponsive validators
pepyakin Aug 7, 2019
e25b43a
Make sure eras have the same length.
tomusdrw Aug 7, 2019
55aeff5
Slashing and rewards.
tomusdrw Aug 7, 2019
0c8b03f
Fix compilation.
tomusdrw Aug 7, 2019
382ffa3
Distribute rewards.
tomusdrw Aug 7, 2019
ac05b4f
Merge branch 'master' into retreat-slashing
tomusdrw Aug 7, 2019
ea68a83
Supply validators_count
pepyakin Aug 7, 2019
fae60b9
Use identificationTuple in Unresponsivness report
pepyakin Aug 7, 2019
6af9ffc
Fix merge.
pepyakin Aug 7, 2019
f2f91ab
Make sure we don't slash if amount is zero.
tomusdrw Aug 7, 2019
9c91502
We don't return an error from report_offence anymo
pepyakin Aug 7, 2019
fdbc3bd
We actually can use vec!
pepyakin Aug 7, 2019
c101666
Prevent division by zero if the reporters is empty
pepyakin Aug 7, 2019
2d1d103
offence_forces_new_era/nominators_also_get_slashed
pepyakin Aug 7, 2019
b7989c9
advance_session
pepyakin Aug 7, 2019
21c1131
Fix tests.
pepyakin Aug 7, 2019
a60252e
Merge branch 'master' into retreat-slashing
tomusdrw Aug 7, 2019
0db09ad
Merge remote-tracking branch 'origin/retreat-slashing' into retreat-s…
tomusdrw Aug 7, 2019
e9029f8
Update srml/staking/src/lib.rs
tomusdrw Aug 7, 2019
e40e448
slashing_performed_according_exposure
pepyakin Aug 7, 2019
63f08a0
Check that reporters receive their slice.
pepyakin Aug 7, 2019
fdb9d15
Small clean-up.
tomusdrw Aug 7, 2019
108869c
Merge branch 'retreat-slashing' of github.com:paritytech/substrate in…
tomusdrw Aug 7, 2019
39cdeb6
invulnerables_are_not_slashed
pepyakin Aug 7, 2019
67b0a50
Minor clean ups.
pepyakin Aug 7, 2019
763d32d
Improve docs.
pepyakin Aug 7, 2019
9c43140
dont_slash_if_fraction_is_zero
pepyakin Aug 7, 2019
c65854c
Remove session dependency from offences.
tomusdrw Aug 7, 2019
77c23dc
Introduce sr-staking-primitives
pepyakin Aug 7, 2019
4384e6c
Move offence under sr_staking_primitives
pepyakin Aug 7, 2019
7d94eaf
rename session_index
pepyakin Aug 7, 2019
97d4f5c
Resolves todos re using SessionIndex
pepyakin Aug 7, 2019
b8f65a8
Fix staking tests.
pepyakin Aug 7, 2019
fe75ebe
Properly scale denominator.
pepyakin Aug 7, 2019
2ff220b
Fix UnresponsivnessOffence
pepyakin Aug 7, 2019
00a8506
Fix compilation.
tomusdrw Aug 8, 2019
eb790f2
Tests for offences.
tomusdrw Aug 8, 2019
bdf5177
Merge branch 'master' into retreat-slashing
tomusdrw Aug 8, 2019
2d0881a
Clean offences tests.
pepyakin Aug 8, 2019
8b4cd8e
Fix staking doc test.
tomusdrw Aug 8, 2019
b90e397
Merge branch 'retreat-slashing' of github.com:paritytech/substrate in…
tomusdrw Aug 8, 2019
b9fa71b
Bump spec version
tomusdrw Aug 8, 2019
6eb6cab
Fix aura tests.
tomusdrw Aug 8, 2019
9e7e8ce
Fix node_executor
pepyakin Aug 8, 2019
f23b2f3
Deposit an event on offence.
pepyakin Aug 8, 2019
2de1c86
Fix compilation of node-runtime
pepyakin Aug 8, 2019
6420e80
Remove aura slashing logic.
tomusdrw Aug 8, 2019
591fa51
Remove HandleReport
pepyakin Aug 8, 2019
0c4760f
Update docs for timeslot.
pepyakin Aug 8, 2019
48a3366
rename with_on_offence_fractions
pepyakin Aug 8, 2019
4bc4e6c
Add should_properly_count_offences
pepyakin Aug 8, 2019
eb1de19
Replace ValidatorIdByIndex with CurrentElectedSet
pepyakin Aug 9, 2019
b015094
Clarify babe equivocation
pepyakin Aug 12, 2019
04ac719
Merge master
pepyakin Aug 12, 2019
1facbf8
Fix offences.
pepyakin Aug 12, 2019
57bc7a2
Rename validators_count to validator_set_count
tomusdrw Aug 13, 2019
0b57b0d
Fix squaring.
pepyakin Aug 14, 2019
12baeda
Update core/sr-staking-primitives/src/offence.rs
tomusdrw Aug 14, 2019
a88c5ac
Docs for CurrentElectedSet.
pepyakin Aug 14, 2019
53b2c64
Don't punish only invulnerables
pepyakin Aug 14, 2019
2b81cc2
Merge 'origin/master' into retreat-slashing
pepyakin Aug 14, 2019
2c30785
Use `get/insert` instead of `mutate`.
pepyakin Aug 14, 2019
fa1d88e
Fix compilation
pepyakin Aug 14, 2019
192e811
Update core/sr-staking-primitives/src/offence.rs
tomusdrw Aug 14, 2019
455dcac
Update srml/offences/src/lib.rs
tomusdrw Aug 14, 2019
3c46391
Update srml/im-online/src/lib.rs
tomusdrw Aug 14, 2019
7257ca9
Update srml/im-online/src/lib.rs
tomusdrw Aug 14, 2019
542de32
Update srml/im-online/src/lib.rs
tomusdrw Aug 14, 2019
e02ef2f
Update srml/babe/src/lib.rs
tomusdrw Aug 14, 2019
08366c0
Update core/sr-staking-primitives/src/offence.rs
tomusdrw Aug 14, 2019
3f398c4
Update core/sr-staking-primitives/src/offence.rs
tomusdrw Aug 14, 2019
fe3094c
Update core/sr-staking-primitives/src/offence.rs
tomusdrw Aug 14, 2019
9b4263c
Update core/sr-staking-primitives/src/offence.rs
tomusdrw Aug 14, 2019
ce5e8ed
Update core/sr-staking-primitives/src/offence.rs
tomusdrw Aug 14, 2019
758a1ec
Add aura todo.
tomusdrw Aug 14, 2019
d58208b
Allow multiple reports for single offence report.
tomusdrw Aug 14, 2019
4feb6e3
Fix slash_fraction calculation.
tomusdrw Aug 14, 2019
dd58c06
Fix typos.
tomusdrw Aug 14, 2019
0c65697
Fix compilation and tests.
tomusdrw Aug 14, 2019
fc927d1
Fix staking tests.
tomusdrw Aug 14, 2019
f3a2d68
Update srml/im-online/src/lib.rs
tomusdrw Aug 14, 2019
b7f44fc
Fix doc on time_slot
pepyakin Aug 15, 2019
2d0fe68
Allow slashing only on current era (#3411)
rphmeier Aug 16, 2019
6d2b7f8
Pave the way for pruning
pepyakin Aug 15, 2019
03734e8
Merge 'origin/master' into retreat-slashing
pepyakin Aug 16, 2019
7781bc9
Address issues.
pepyakin Aug 16, 2019
967ca96
Try to refactor collect_offence_reports
pepyakin Aug 16, 2019
6bc58a8
Other fixes.
pepyakin Aug 16, 2019
bbc837b
More fixes.
pepyakin Aug 16, 2019
9430a2d
Merge 'origin/master' into retreat-slashing
pepyakin Aug 16, 2019
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: 9 additions & 7 deletions core/sr-staking-primitives/src/offence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ pub type Kind = [u8; 16];
/// so that we can slash it accordingly.
pub type OffenceCount = u32;

/// A type that represents a point in time on an abstract timescale.
///
/// See `Offence::time_slot` for details. The only requirement is that such timescale could be
/// represented by a single `u128` value.
pub type TimeSlot = u128;

/// A trait implemented by an offence report.
///
/// This trait assumes that the offence is legitimate and was validated already.
Expand All @@ -53,13 +47,21 @@ pub trait Offence<Offender> {
/// Identifier which is unique for this kind of an offence.
const ID: Kind;

/// A type that represents a point in time on an abstract timescale.
///
/// See `Offence::time_slot` for details. The only requirement is that such timescale could be
/// represented by a single `u128` value.
type TimeSlot: Clone + codec::Codec + Ord;

/// The list of all offenders involved in this incident.
///
/// The list has no duplicates, so it is rather a set.
fn offenders(&self) -> Vec<Offender>;

/// The session index that is used for querying the validator set for the `slash_fraction`
/// function.
///
/// This is used for filtering historical sessions.
fn session_index(&self) -> SessionIndex;

/// Return a validator set count at the time when the offence took place.
Expand All @@ -76,7 +78,7 @@ pub trait Offence<Offender> {
///
/// As an example, for GRANDPA timescale could be a round number and for BABE it could be a slot
/// number. Note that for GRANDPA the round number is reset each epoch.
fn time_slot(&self) -> TimeSlot;
fn time_slot(&self) -> Self::TimeSlot;

/// A slash fraction of the total exposure that should be slashed for this
/// particular offence kind for the given parameters that happened at a singular `TimeSlot`.
Expand Down
7 changes: 4 additions & 3 deletions srml/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use sr_primitives::{generic::DigestItem, ConsensusEngineId, Perbill};
use sr_primitives::traits::{IsMember, SaturatedConversion, Saturating, RandomnessBeacon, Convert};
use sr_staking_primitives::{
SessionIndex,
offence::{Offence, TimeSlot, Kind},
offence::{Offence, Kind},
};
#[cfg(feature = "std")]
use timestamp::TimestampInherentData;
Expand Down Expand Up @@ -266,6 +266,7 @@ struct BabeEquivocationOffence<FullIdentification> {

impl<FullIdentification: Clone> Offence<FullIdentification> for BabeEquivocationOffence<FullIdentification> {
const ID: Kind = *b"babe:equivocatio";
type TimeSlot = u64;

fn offenders(&self) -> Vec<FullIdentification> {
vec![self.offender.clone()]
Expand All @@ -279,8 +280,8 @@ impl<FullIdentification: Clone> Offence<FullIdentification> for BabeEquivocation
self.validator_set_count
}

fn time_slot(&self) -> TimeSlot {
self.slot as TimeSlot
fn time_slot(&self) -> u64 {
pepyakin marked this conversation as resolved.
Show resolved Hide resolved
self.slot
}

fn slash_fraction(
Expand Down
19 changes: 14 additions & 5 deletions srml/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use sr_primitives::{
};
use sr_staking_primitives::{
SessionIndex,
offence::{TimeSlot, Offence, Kind},
offence::{Offence, Kind},
};
use fg_primitives::{ScheduledChange, ConsensusLog, GRANDPA_ENGINE_ID};
pub use fg_primitives::{AuthorityId, AuthorityWeight};
Expand Down Expand Up @@ -382,12 +382,20 @@ impl<T: Trait> finality_tracker::OnFinalizationStalled<T::BlockNumber> for Modul
}
}

/// A round number and set id which point on the time of an offence.
#[derive(Copy, Clone, PartialOrd, Ord, Eq, PartialEq, Encode, Decode)]
struct GrandpaTimeSlot {
// The order of these matters for `derive(Ord)`.
set_id: u64,
round: u64,
}

// TODO [slashing]: Integrate this.
/// A grandpa equivocation offence report.
#[allow(dead_code)]
struct GrandpaEquivocationOffence<FullIdentification> {
/// A round in which the incident happened.
round: u64,
/// Time slot at which this incident happened.
time_slot: GrandpaTimeSlot,
/// The session index in which the incident happened.
session_index: SessionIndex,
/// The size of the validator set at the time of the offence.
Expand All @@ -398,6 +406,7 @@ struct GrandpaEquivocationOffence<FullIdentification> {

impl<FullIdentification: Clone> Offence<FullIdentification> for GrandpaEquivocationOffence<FullIdentification> {
const ID: Kind = *b"grandpa:equivoca";
type TimeSlot = GrandpaTimeSlot;

fn offenders(&self) -> Vec<FullIdentification> {
vec![self.offender.clone()]
Expand All @@ -411,8 +420,8 @@ impl<FullIdentification: Clone> Offence<FullIdentification> for GrandpaEquivocat
self.validator_set_count
}

fn time_slot(&self) -> TimeSlot {
self.round as TimeSlot
fn time_slot(&self) -> GrandpaTimeSlot {
pepyakin marked this conversation as resolved.
Show resolved Hide resolved
self.time_slot
}

fn slash_fraction(
Expand Down
28 changes: 28 additions & 0 deletions srml/grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,31 @@ fn schedule_resume_only_when_paused() {
);
});
}

#[test]
fn time_slot_have_sane_ord() {
// Ensure that `Ord` implementation is sane.
const FIXTURE: &[GrandpaTimeSlot] = &[
GrandpaTimeSlot {
set_id: 0,
round: 0,
},
GrandpaTimeSlot {
set_id: 0,
round: 1,
},
GrandpaTimeSlot {
set_id: 1,
round: 0,
},
GrandpaTimeSlot {
set_id: 1,
round: 1,
},
GrandpaTimeSlot {
set_id: 1,
round: 2,
}
];
assert!(FIXTURE.windows(2).all(|f| f[0] < f[1]));
}
7 changes: 4 additions & 3 deletions srml/im-online/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use sr_primitives::{
};
use sr_staking_primitives::{
SessionIndex, CurrentElectedSet,
offence::{ReportOffence, Offence, TimeSlot, Kind},
offence::{ReportOffence, Offence, Kind},
};
use srml_support::{
StorageValue, decl_module, decl_event, decl_storage, StorageDoubleMap, print,
Expand Down Expand Up @@ -493,6 +493,7 @@ pub struct UnresponsivenessOffence<Offender> {

impl<Offender: Clone> Offence<Offender> for UnresponsivenessOffence<Offender> {
const ID: Kind = *b"im-online:offlin";
type TimeSlot = SessionIndex;

fn offenders(&self) -> Vec<Offender> {
self.offenders.clone()
Expand All @@ -506,8 +507,8 @@ impl<Offender: Clone> Offence<Offender> for UnresponsivenessOffence<Offender> {
self.validator_set_count
}

fn time_slot(&self) -> TimeSlot {
self.session_index as TimeSlot
fn time_slot(&self) -> SessionIndex {
pepyakin marked this conversation as resolved.
Show resolved Hide resolved
self.session_index as SessionIndex
}

fn slash_fraction(offenders: u32, validator_set_count: u32) -> Perbill {
Expand Down
Loading