Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
d6a2eb2
disputes: runtime part of slashing
May 6, 2022
fd2194a
disputes: reward winners
May 9, 2022
9f8daef
disputes/slashing: validate_unsigned impl
May 11, 2022
ee46d14
fmt
May 11, 2022
7b158f6
disputes/slashing: report_dispute_lost_unsigned
May 11, 2022
60a82a4
disputes/slashing: separate winners from losers and report winners
May 13, 2022
b303ee4
disputes/slashing: refactoring
May 13, 2022
6f1d724
impl HandleReports
May 16, 2022
4a55be9
enable on Wenstend
May 16, 2022
1941543
fmt
May 16, 2022
04ad120
add slashing pallet to the mock and test runtimes
May 16, 2022
3784591
fix a bug in report_dispute_lost_unsigned
May 16, 2022
f49b55f
fmt
May 16, 2022
cbcf176
disputes: remove new_participants from summary
May 17, 2022
7b82f0d
disputes: remove punish_inconclusive
May 17, 2022
f863baf
impl SlashingHandler for Pallet for type-safety
May 17, 2022
b4fa682
do not impl slashing::Config on mainnets yet
May 17, 2022
2739900
teach spellcheck deduplication
May 17, 2022
62ff14f
simplify interfaces and resolve some TODOs
May 17, 2022
4db3ab8
resolve some more TODOs
May 17, 2022
02c069d
minor typos
May 17, 2022
6fc8f5f
move slashing into a folder
May 18, 2022
7f3ae20
remove unnecessary clone
May 18, 2022
13c7c84
fix validator_set_count calculation
May 18, 2022
5c98289
introduce ValidatorSetCount
May 18, 2022
8263d16
store ValidatorSetCount
May 18, 2022
c073e08
fmt
May 18, 2022
dc3b6de
add the benchmark
Jun 14, 2022
75f256d
fmt
Jun 14, 2022
65851ad
unflatten slashing
Jun 14, 2022
2210bad
post-rebase fixes
Jun 14, 2022
6ab6b48
remove winners eagerly
Jun 14, 2022
6a0ddfc
use real slashing weights for westend
Jun 14, 2022
29376b1
remove bench test suite
Jun 17, 2022
f76a697
Merge branch 'master' into ao-disputes-offences-runtime
Jun 17, 2022
4800be1
zombinet: modify disputes test to check for an offence report
Jun 17, 2022
4c0f83e
zombinet: add a timeout
Jun 17, 2022
3086e26
add slashing pallet to Rococo
Jun 20, 2022
677a262
zombienet: revert back to rococo-local
Jun 20, 2022
e1ff282
Merge branch 'master' into ao-disputes-offences-runtime
Jun 20, 2022
fe7495e
fmt
Jun 20, 2022
461f37f
remove TODOs
Jun 20, 2022
bae9912
revert some accidental changes
Jun 20, 2022
15fcf48
slashing is submodule of disputes
Jun 21, 2022
097d6c1
Merge branch 'master' into ao-disputes-offences-runtime
Jun 21, 2022
65146ca
Merge branch 'master' into ao-disputes-offences-runtime
Jun 28, 2022
650eb19
Merge branch 'master' into ao-disputes-offences-runtime
Jul 5, 2022
95cd87d
Merge branch 'master' into ao-disputes-offences-runtime
Jul 28, 2022
760bdc7
Change the log target
Jul 30, 2022
d3405cc
Merge branch 'master' into ao-disputes-offences-runtime
Aug 1, 2022
d5b3324
Merge branch 'ao-disputes-offences-runtime' of github.com:paritytech/…
Aug 1, 2022
f50aa7d
wrap comments with rustfmt, more docs, constants
Aug 1, 2022
248baa5
use Defensive trait
Aug 3, 2022
b02bcef
cargo update -p sp-io
Aug 3, 2022
e1c87c4
merge offence types, remove rewards for now
Aug 3, 2022
37f9cd7
Merge branch 'master' into ao-disputes-offences-runtime
Aug 3, 2022
b531490
cargo update -p sp-io
Aug 3, 2022
454874f
benchmark fixes
Aug 3, 2022
c0db743
fmt
Aug 3, 2022
9fb1e38
unused var
Aug 3, 2022
9c84b22
fix block_author impl
Aug 3, 2022
19b7c6b
ressurect RewardValidators trait
Aug 3, 2022
784e65e
remove outdated comment
Aug 3, 2022
0c2559c
Merge branch 'master' into ao-disputes-offences-runtime
Aug 4, 2022
3a2858d
Merge branch 'master' into ao-disputes-offences-runtime
Aug 4, 2022
c22a943
more module docs
Aug 5, 2022
884d9d8
introduce BenchmarkingConfig
Aug 5, 2022
df81683
Merge branch 'master' into ao-disputes-offences-runtime
Aug 5, 2022
7101379
typo fix
Aug 5, 2022
ce879df
teach spellcheck unapplied
Aug 5, 2022
b070f34
Merge branch 'master' into ao-disputes-offences-runtime
Aug 31, 2022
563995b
Merge branch 'master' into ao-disputes-offences-runtime
Aug 31, 2022
7d5171c
use Weight::new()
Aug 31, 2022
b436249
fix mocking rewards
Aug 31, 2022
397046e
use RefTimeWeight
Aug 31, 2022
18965e3
".git/.scripts/bench-bot.sh" runtime westend-dev runtime_parachains::…
Aug 31, 2022
7269e18
refactor maybe_identify_validators
Aug 31, 2022
399e0e6
no more ticket in disguise
Aug 31, 2022
89fb5ed
remove outdated comments
Aug 31, 2022
4f34bd7
lower against valid to 0.1%
Sep 1, 2022
0d99787
bump zombienet version for debug
pepoviola Sep 1, 2022
9223d71
use from_perthousand
Sep 1, 2022
c48aa45
Merge branch 'master' into ao-disputes-offences-runtime
Sep 1, 2022
655fe98
post-merge fixes
Sep 1, 2022
81578ff
Merge branch 'master' into ao-disputes-offences-runtime
Sep 2, 2022
c5472c9
another day, another Weight changes
Sep 2, 2022
6e5f372
Revert "bump zombienet version for debug"
Sep 2, 2022
7bf295a
do not reward block authors
Sep 5, 2022
8309493
Merge branch 'master' into ao-disputes-offences-runtime
Sep 5, 2022
cd9aeb8
fix outdated comment
Sep 6, 2022
3fe81e9
merge master once again
Sep 6, 2022
e87cc9c
merge master once again II
Sep 8, 2022
918b4ca
Merge branch 'master' into ao-disputes-offences-runtime
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
Prev Previous commit
Next Next commit
disputes/slashing: refactoring
  • Loading branch information
Andronik committed Jun 14, 2022
commit b303ee481f89c1207084da896779e4b571c9c97c
139 changes: 62 additions & 77 deletions runtime/parachains/src/disputes/slashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,28 +189,26 @@ where
/// along with the validator set count for that session. `None` otherwise.
fn maybe_identify_validators(
session_index: SessionIndex,
account_ids: &[AccountId<T>],
validators: impl IntoIterator<Item = ValidatorIndex>,
) -> Option<(Vec<IdentificationTuple<T>>, Vec<AccountId<T>>, u32)> {
) -> Option<(Vec<IdentificationTuple<T>>, u32)> {
// We use `ValidatorSet::session_index` and not `shared::Pallet<T>::session_index()`
// because at the first block of a new era, the `IdentificationOf` of a validator
// in the previous session might be missing, while `shared` pallet would return
// the same session index as being updated at the end of the block.
let current_session = T::ValidatorSet::session_index();
if session_index == current_session {
if let Some(account_ids) = crate::session_info::Pallet::<T>::account_keys(session_index)
{
let validator_set_count = account_ids.len() as u32;
let fully_identified = validators
.into_iter()
.flat_map(|i| account_ids.get(i.0 as usize).cloned())
.filter_map(|id| {
<T::ValidatorSet as ValidatorSetWithIdentification<T::AccountId>>::IdentificationOf::convert(
id.clone()
).map(|full_id| (id, full_id))
})
.collect::<Vec<IdentificationTuple<T>>>();
return Some((fully_identified, account_ids, validator_set_count))
}
let validator_set_count = account_ids.len() as u32;
let fully_identified = validators
.into_iter()
.flat_map(|i| account_ids.get(i.0 as usize).cloned())
.filter_map(|id| {
<T::ValidatorSet as ValidatorSetWithIdentification<T::AccountId>>::IdentificationOf::convert(
id.clone()
).map(|full_id| (id, full_id))
})
.collect::<Vec<IdentificationTuple<T>>>();
return Some((fully_identified, validator_set_count))
}
None
}
Expand All @@ -236,27 +234,28 @@ where
winners: impl IntoIterator<Item = ValidatorIndex>,
) {
let losers: Losers = losers.into_iter().collect();
let maybe = Self::maybe_identify_validators(session_index, losers.iter().cloned());
if let Some((offenders, account_ids, validator_set_count)) = maybe {
let reporters = winners
.into_iter()
.filter_map(|i| account_ids.get(i.0 as usize).cloned())
.collect();
let account_keys = crate::session_info::Pallet::<T>::account_keys(session_index);
let account_ids = match account_keys {
Some(account_keys) => account_keys,
None => {
// TODO: warn
return
},
};
let winners: Winners<T> = winners
.into_iter()
.filter_map(|i| account_ids.get(i.0 as usize).cloned())
.collect();
let maybe =
Self::maybe_identify_validators(session_index, &account_ids, losers.iter().cloned());
if let Some((offenders, validator_set_count)) = maybe {
let time_slot = DisputesTimeSlot::new(session_index, candidate_hash);
let offence = ForInvalidOffence { validator_set_count, time_slot, offenders };
// TODO: log error?
let _ = R::report_offence(reporters, offence);
let _ = R::report_offence(winners, offence);
return
}
let winners: Winners<T> = if let Some(account_ids) = crate::session_info::Pallet::<T>::account_keys(session_index) {
winners
.into_iter()
.filter_map(|i| account_ids.get(i.0 as usize).cloned())
.collect()
} else {
// Shouldn't really happen
Default::default()
};

<PendingForInvalidLosers<T>>::insert(session_index, candidate_hash, losers);
<ForInvalidWinners<T>>::insert(session_index, candidate_hash, winners);
}
Expand All @@ -268,28 +267,28 @@ where
winners: impl IntoIterator<Item = ValidatorIndex>,
) {
let losers: Losers = losers.into_iter().collect();
let maybe = Self::maybe_identify_validators(session_index, losers.iter().cloned());
if let Some((offenders, account_ids, validator_set_count)) = maybe {
let reporters = winners
.into_iter()
.filter_map(|i| account_ids.get(i.0 as usize).cloned())
.collect();
let account_keys = crate::session_info::Pallet::<T>::account_keys(session_index);
let account_ids = match account_keys {
Some(account_keys) => account_keys,
None => {
// TODO: warn
return
},
};
let winners: Winners<T> = winners
.into_iter()
.filter_map(|i| account_ids.get(i.0 as usize).cloned())
.collect();
let maybe =
Self::maybe_identify_validators(session_index, &account_ids, losers.iter().cloned());
if let Some((offenders, validator_set_count)) = maybe {
let time_slot = DisputesTimeSlot::new(session_index, candidate_hash);
let offence = AgainstValidOffence { validator_set_count, time_slot, offenders };
// TODO: log error?
let _ = R::report_offence(reporters, offence);
let _ = R::report_offence(winners, offence);
return
}

let winners: Winners<T> = if let Some(account_ids) = crate::session_info::Pallet::<T>::account_keys(session_index) {
winners
.into_iter()
.filter_map(|i| account_ids.get(i.0 as usize).cloned())
.collect()
} else {
// Shouldn't really happen
Default::default()
};
<PendingAgainstValidLosers<T>>::insert(session_index, candidate_hash, losers);
<AgainstValidWinners<T>>::insert(session_index, candidate_hash, winners);
}
Expand Down Expand Up @@ -530,14 +529,8 @@ pub mod pallet {

/// Indices of the validators pending "for invalid" dispute slashes.
#[pallet::storage]
pub(super) type PendingForInvalidLosers<T> = StorageDoubleMap<
_,
Twox64Concat,
SessionIndex,
Blake2_128Concat,
CandidateHash,
Losers,
>;
pub(super) type PendingForInvalidLosers<T> =
StorageDoubleMap<_, Twox64Concat, SessionIndex, Blake2_128Concat, CandidateHash, Losers>;

/// Indices of the validators who won in "for invalid" disputes.
#[pallet::storage]
Expand All @@ -552,14 +545,8 @@ pub mod pallet {

/// Indices of the validators pending "against valid" dispute slashes.
#[pallet::storage]
pub(super) type PendingAgainstValidLosers<T> = StorageDoubleMap<
_,
Twox64Concat,
SessionIndex,
Blake2_128Concat,
CandidateHash,
Losers,
>;
pub(super) type PendingAgainstValidLosers<T> =
StorageDoubleMap<_, Twox64Concat, SessionIndex, Blake2_128Concat, CandidateHash, Losers>;

/// Indices of the validators who won in "against valid" disputes.
#[pallet::storage]
Expand Down Expand Up @@ -645,10 +632,8 @@ pub mod pallet {
try_remove,
)?;

let winners = <ForInvalidWinners<T>>::get(
&session_index,
&candidate_hash,
).unwrap_or_default();
let winners = <ForInvalidWinners<T>>::get(&session_index, &candidate_hash)
.unwrap_or_default();

let offence = <T::HandleReports as HandleReports<T>>::OffenceForInvalid::new(
session_index,
Expand All @@ -660,9 +645,9 @@ pub mod pallet {
// We can't really submit a duplicate report
// unless there's a bug.
<T::HandleReports as HandleReports<T>>::report_for_invalid_offence(
winners,
offence,
).map_err(|_| Error::<T>::DuplicateSlashingReport)?;
winners, offence,
)
.map_err(|_| Error::<T>::DuplicateSlashingReport)?;
},
SlashingOffenceKind::AgainstValid => {
<PendingAgainstValidLosers<T>>::try_mutate_exists(
Expand All @@ -671,10 +656,8 @@ pub mod pallet {
try_remove,
)?;

let winners = <ForInvalidWinners<T>>::get(
&session_index,
&candidate_hash,
).unwrap_or_default();
let winners = <ForInvalidWinners<T>>::get(&session_index, &candidate_hash)
.unwrap_or_default();

// submit an offence report
let offence = <T::HandleReports as HandleReports<T>>::OffenceAgainstValid::new(
Expand All @@ -686,9 +669,9 @@ pub mod pallet {
// We can't really submit a duplicate report
// unless there's a bug.
<T::HandleReports as HandleReports<T>>::report_against_valid_offence(
winners,
offence,
).map_err(|_| Error::<T>::DuplicateSlashingReport)?;
winners, offence,
)
.map_err(|_| Error::<T>::DuplicateSlashingReport)?;
},
}

Expand Down Expand Up @@ -716,6 +699,8 @@ impl<T: Config> Pallet<T> {
}

let old_session = notification.session_index - config.dispute_period - 1;

// TODO: warn if there were pending slashes?
<PendingForInvalidLosers<T>>::remove_prefix(old_session, None);
<PendingAgainstValidLosers<T>>::remove_prefix(old_session, None);
<ForInvalidWinners<T>>::remove_prefix(old_session, None);
Expand Down