mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
Offences report system rework (#13425)
* Experiments with common equivocation trait * Improved equivocation trait * Fix grandpa equivocation implementation * Remove some cruft * Remove some more cruft * More generic naming * Simplification of offences manipilation * More refactory * Some prograss with the encapsulation of offence report system * Finally unit type works as a universal null report system * Align substrate node code * Further simplification * Fix test utils * Remove not required associated type * Fix benches * Rollback to prev field name * Box big params * Fix typo * Remove new tag computation * Remove default implementations * Better docs * Return 'Result' instead of bool * Change offence report system return types * Some renaming and documentation * Improve documentation * More abstract offence report system * Rename 'consume_evidence' to 'process_evidence' * Further docs refinements * Doc for dummy offence report * Fix rustdoc * Fix after master merge * Apply code review suggestions * Improve docs
This commit is contained in:
@@ -112,10 +112,10 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config, O: Offence<T::IdentificationTuple>>
|
||||
ReportOffence<T::AccountId, T::IdentificationTuple, O> for Pallet<T>
|
||||
impl<T, O> ReportOffence<T::AccountId, T::IdentificationTuple, O> for Pallet<T>
|
||||
where
|
||||
T::IdentificationTuple: Clone,
|
||||
T: Config,
|
||||
O: Offence<T::IdentificationTuple>,
|
||||
{
|
||||
fn report_offence(reporters: Vec<T::AccountId>, offence: O) -> Result<(), OffenceError> {
|
||||
let offenders = offence.offenders();
|
||||
|
||||
@@ -134,17 +134,17 @@ pub fn offence_reports(kind: Kind, time_slot: u128) -> Vec<OffenceDetails<u64, u
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Offence<T> {
|
||||
pub struct Offence {
|
||||
pub validator_set_count: u32,
|
||||
pub offenders: Vec<T>,
|
||||
pub offenders: Vec<u64>,
|
||||
pub time_slot: u128,
|
||||
}
|
||||
|
||||
impl<T: Clone> offence::Offence<T> for Offence<T> {
|
||||
impl offence::Offence<u64> for Offence {
|
||||
const ID: offence::Kind = KIND;
|
||||
type TimeSlot = u128;
|
||||
|
||||
fn offenders(&self) -> Vec<T> {
|
||||
fn offenders(&self) -> Vec<u64> {
|
||||
self.offenders.clone()
|
||||
}
|
||||
|
||||
@@ -167,5 +167,5 @@ impl<T: Clone> offence::Offence<T> for Offence<T> {
|
||||
|
||||
/// Create the report id for the given `offender` and `time_slot` combination.
|
||||
pub fn report_id(time_slot: u128, offender: u64) -> H256 {
|
||||
Offences::report_id::<Offence<u64>>(&time_slot, &offender)
|
||||
Offences::report_id::<Offence>(&time_slot, &offender)
|
||||
}
|
||||
|
||||
@@ -160,20 +160,18 @@ fn doesnt_deposit_event_for_dups() {
|
||||
|
||||
#[test]
|
||||
fn reports_if_an_offence_is_dup() {
|
||||
type TestOffence = Offence<u64>;
|
||||
|
||||
new_test_ext().execute_with(|| {
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
|
||||
let offence =
|
||||
|time_slot, offenders| TestOffence { validator_set_count: 5, time_slot, offenders };
|
||||
|time_slot, offenders| Offence { validator_set_count: 5, time_slot, offenders };
|
||||
|
||||
let mut test_offence = offence(time_slot, vec![0]);
|
||||
|
||||
// the report for authority 0 at time slot 42 should not be a known
|
||||
// offence
|
||||
assert!(!<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
assert!(!<Offences as ReportOffence<_, _, Offence>>::is_known_offence(
|
||||
&test_offence.offenders,
|
||||
&test_offence.time_slot
|
||||
));
|
||||
@@ -182,7 +180,7 @@ fn reports_if_an_offence_is_dup() {
|
||||
Offences::report_offence(vec![], test_offence.clone()).unwrap();
|
||||
|
||||
// the same report should be a known offence now
|
||||
assert!(<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
assert!(<Offences as ReportOffence<_, _, Offence>>::is_known_offence(
|
||||
&test_offence.offenders,
|
||||
&test_offence.time_slot
|
||||
));
|
||||
@@ -197,7 +195,7 @@ fn reports_if_an_offence_is_dup() {
|
||||
test_offence.offenders.push(1);
|
||||
|
||||
// it should not be a known offence anymore
|
||||
assert!(!<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
assert!(!<Offences as ReportOffence<_, _, Offence>>::is_known_offence(
|
||||
&test_offence.offenders,
|
||||
&test_offence.time_slot
|
||||
));
|
||||
@@ -208,7 +206,7 @@ fn reports_if_an_offence_is_dup() {
|
||||
// creating a new offence for the same authorities on the next slot
|
||||
// should be considered a new offence and thefore not known
|
||||
let test_offence_next_slot = offence(time_slot + 1, vec![0, 1]);
|
||||
assert!(!<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
assert!(!<Offences as ReportOffence<_, _, Offence>>::is_known_offence(
|
||||
&test_offence_next_slot.offenders,
|
||||
&test_offence_next_slot.time_slot
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user