Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d0b6d95
Experiments with common equivocation trait
davxy Feb 13, 2023
5754be6
Improved equivocation trait
davxy Feb 15, 2023
9029a5c
Fix grandpa equivocation implementation
davxy Feb 15, 2023
0e04ca0
Remove some cruft
davxy Feb 16, 2023
d8c2598
Remove some more cruft
davxy Feb 16, 2023
1674a48
More generic naming
davxy Feb 16, 2023
6f0feff
Simplification of offences manipilation
davxy Feb 16, 2023
239bfbb
More refactory
davxy Feb 17, 2023
4ba1a01
Some prograss with the encapsulation of offence report system
davxy Feb 18, 2023
7c1c06d
Finally unit type works as a universal null report system
davxy Feb 20, 2023
1069c9d
Align substrate node code
davxy Feb 20, 2023
e096669
Further simplification
davxy Feb 20, 2023
09850ee
Fix test utils
davxy Feb 20, 2023
020e71c
Remove not required associated type
davxy Feb 20, 2023
4155c88
Fix benches
davxy Feb 20, 2023
2a3ed07
Rollback to prev field name
davxy Feb 20, 2023
5545901
Merge branch 'master' into equivocation-offence-rework
davxy Feb 20, 2023
c8a8eb6
Box big params
davxy Feb 20, 2023
9e959b7
Fix typo
davxy Feb 20, 2023
6e7e11d
Remove new tag computation
davxy Feb 20, 2023
080e82c
Remove default implementations
davxy Feb 21, 2023
3966ef7
Better docs
davxy Feb 21, 2023
5587720
Return 'Result' instead of bool
davxy Feb 23, 2023
52ee367
Change offence report system return types
davxy Feb 24, 2023
8706a6d
Some renaming and documentation
davxy Feb 24, 2023
7bebe84
Improve documentation
davxy Feb 24, 2023
f9a505b
More abstract offence report system
davxy Feb 24, 2023
aa83011
Rename 'consume_evidence' to 'process_evidence'
davxy Feb 24, 2023
0c5a536
Further docs refinements
davxy Feb 24, 2023
46b9f86
Doc for dummy offence report
davxy Feb 24, 2023
f05c4ea
Merge branch 'master' into equivocation-offence-rework
davxy Feb 24, 2023
3ff71d1
Fix rustdoc
davxy Feb 24, 2023
78f0e9f
Merge branch 'master' into equivocation-offence-rework
davxy Mar 7, 2023
d336264
Fix after master merge
davxy Mar 7, 2023
2e1c338
Apply code review suggestions
davxy Mar 7, 2023
643c745
Improve docs
davxy Mar 7, 2023
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
Remove not required associated type
  • Loading branch information
davxy committed Feb 20, 2023
commit 020e71cf24eab157ab0a14b9c6ccdc810dd3d534
18 changes: 7 additions & 11 deletions frame/babe/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ pub struct EquivocationReportSystem<T, R, P, L>(sp_std::marker::PhantomData<(T,
// We use the authorship pallet to fetch the current block author and use
// `offchain::SendTransactionTypes` for unsigned extrinsic creation and
// submission.
impl<T, R, P, L> OffenceReportSystem<T::AccountId, EquivocationProof<T::Header>>
impl<T, R, P, L> OffenceReportSystem<T::AccountId, P::Proof, EquivocationProof<T::Header>>
for EquivocationReportSystem<T, R, P, L>
where
T: Config //<EquivocationProof = EquivocationProof<<T as frame_system::Config>::Header>>
+ pallet_authorship::Config
+ frame_system::offchain::SendTransactionTypes<Call<T>>,
T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
R: ReportOffence<
T::AccountId,
P::IdentificationTuple,
Expand All @@ -121,14 +119,12 @@ where
P::IdentificationTuple: Clone,
L: Get<u64>,
{
type KeyOwnerProof = P::Proof;

type ReportLongevity = L;
type Longevity = L;

fn report_evidence(
reporter: Option<T::AccountId>,
equivocation_proof: EquivocationProof<T::Header>,
key_owner_proof: Self::KeyOwnerProof,
key_owner_proof: T::KeyOwnerProof,
) -> DispatchResult {
let reporter = reporter.or_else(|| <pallet_authorship::Pallet<T>>::author());

Expand Down Expand Up @@ -169,7 +165,7 @@ where

fn check_evidence(
equivocation_proof: &EquivocationProof<T::Header>,
key_owner_proof: &Self::KeyOwnerProof,
key_owner_proof: &T::KeyOwnerProof,
) -> DispatchResult {
// Check the membership proof to extract the offender's id
let key = (sp_consensus_babe::KEY_TYPE, equivocation_proof.offender.clone());
Expand All @@ -186,7 +182,7 @@ where

fn submit_evidence(
equivocation_proof: EquivocationProof<T::Header>,
key_owner_proof: Self::KeyOwnerProof,
key_owner_proof: T::KeyOwnerProof,
) -> bool {
use frame_system::offchain::SubmitTransaction;

Expand Down Expand Up @@ -226,7 +222,7 @@ impl<T: Config> Pallet<T> {
.map_err(|_| InvalidTransaction::Stale)?;

let longevity =
<T::EquivocationReportSystem as OffenceReportSystem<_, _>>::ReportLongevity::get();
<T::EquivocationReportSystem as OffenceReportSystem<_, _, _>>::Longevity::get();
let tag = equivocation_proof.using_encoded(|bytes| sp_io::hashing::blake2_256(bytes));

ValidTransaction::with_tag_prefix("BabeEquivocation")
Expand Down
2 changes: 1 addition & 1 deletion frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ pub mod pallet {
/// definition.
type EquivocationReportSystem: OffenceReportSystem<
Self::AccountId,
Self::KeyOwnerProof,
EquivocationProof<Self::Header>,
KeyOwnerProof = Self::KeyOwnerProof,
>;
}

Expand Down
15 changes: 7 additions & 8 deletions frame/grandpa/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ pub struct EquivocationReportSystem<T, R, P, L>(sp_std::marker::PhantomData<(T,
// We use the authorship pallet to fetch the current block author and use
// `offchain::SendTransactionTypes` for unsigned extrinsic creation and
// submission.
impl<T, R, P, L> OffenceReportSystem<T::AccountId, EquivocationProof<T::Hash, T::BlockNumber>>
impl<T, R, P, L>
OffenceReportSystem<T::AccountId, T::KeyOwnerProof, EquivocationProof<T::Hash, T::BlockNumber>>
for EquivocationReportSystem<T, R, P, L>
where
T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
Expand All @@ -129,14 +130,12 @@ where
P::IdentificationTuple: Clone,
L: Get<u64>,
{
type KeyOwnerProof = T::KeyOwnerProof;

type ReportLongevity = L;
type Longevity = L;

fn report_evidence(
reporter: Option<T::AccountId>,
equivocation_proof: EquivocationProof<T::Hash, T::BlockNumber>,
key_owner_proof: Self::KeyOwnerProof,
key_owner_proof: T::KeyOwnerProof,
) -> DispatchResult {
let reporter = reporter.or_else(|| <pallet_authorship::Pallet<T>>::author());

Expand Down Expand Up @@ -197,7 +196,7 @@ where

fn check_evidence(
equivocation_proof: &EquivocationProof<T::Hash, T::BlockNumber>,
key_owner_proof: &Self::KeyOwnerProof,
key_owner_proof: &T::KeyOwnerProof,
) -> DispatchResult {
// Check the membership proof to extract the offender's id
let key = (sp_finality_grandpa::KEY_TYPE, equivocation_proof.offender().clone());
Expand All @@ -218,7 +217,7 @@ where

fn submit_evidence(
equivocation_proof: EquivocationProof<T::Hash, T::BlockNumber>,
key_owner_proof: Self::KeyOwnerProof,
key_owner_proof: T::KeyOwnerProof,
) -> bool {
use frame_system::offchain::SubmitTransaction;

Expand Down Expand Up @@ -258,7 +257,7 @@ impl<T: Config> Pallet<T> {
.map_err(|_| InvalidTransaction::Stale)?;

let longevity =
<T::EquivocationReportSystem as OffenceReportSystem<_, _>>::ReportLongevity::get();
<T::EquivocationReportSystem as OffenceReportSystem<_, _, _>>::Longevity::get();
// TODO DAVXY: is ok the hash of the serialized structure as an identifier?
// Was: (equivocation_proof.offender(), equivocation_proof.set_id(),
// equivocation_proof.round()) Oterwise we're going to introduce tag()
Expand Down
2 changes: 1 addition & 1 deletion frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ pub mod pallet {
/// definition.
type EquivocationReportSystem: OffenceReportSystem<
Self::AccountId,
Self::KeyOwnerProof,
EquivocationProof<Self::Hash, Self::BlockNumber>,
KeyOwnerProof = Self::KeyOwnerProof,
>;
}

Expand Down
34 changes: 12 additions & 22 deletions primitives/staking/src/offence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,67 +216,57 @@ pub struct OffenceDetails<Reporter, Offender> {
///
/// It is assumed that this subsystem takes care of checking key ownership proof
/// before report submission.
pub trait OffenceReportSystem<Reporter, OffenceProof> {
/// Offender key ownership proof.
/// This can be used by the offence report system to check for evidence validity.
type KeyOwnerProof;

pub trait OffenceReportSystem<Reporter, KeyOwnerProof, OffenceProof> {
/// Longevity, in blocks, for the report validity. When using the staking
/// pallet this should be equal to the bonding duration (in blocks, not eras).
type ReportLongevity: Get<u64>;
type Longevity: Get<u64>;

/// Report offence to the `ReportOffence` handler.
fn report_evidence(
_reporter: Option<Reporter>,
_offence_proof: OffenceProof,
_key_owner_proof: Self::KeyOwnerProof,
_key_owner_proof: KeyOwnerProof,
) -> DispatchResult {
Ok(())
}

/// Check if is a known offence.
fn check_evidence(
_offence_proof: &OffenceProof,
_key_owner_proof: &Self::KeyOwnerProof,
_key_owner_proof: &KeyOwnerProof,
) -> DispatchResult {
Ok(())
}

/// Create and dispatch an offence report extrinsic.
fn submit_evidence(
_offence_proof: OffenceProof,
_key_owner_proof: Self::KeyOwnerProof,
) -> bool {
fn submit_evidence(_offence_proof: OffenceProof, _key_owner_proof: KeyOwnerProof) -> bool {
true
}
}

// Dummy report system.
// Should always give successful results
impl<Reporter, OffenceProof> OffenceReportSystem<Reporter, OffenceProof> for () {
type KeyOwnerProof = sp_core::Void;

type ReportLongevity = ();
impl<Reporter, KeyOwnerProof, OffenceProof>
OffenceReportSystem<Reporter, KeyOwnerProof, OffenceProof> for ()
{
type Longevity = ();

fn report_evidence(
_reporter: Option<Reporter>,
_offence_proof: OffenceProof,
_key_owner_proof: Self::KeyOwnerProof,
_key_owner_proof: KeyOwnerProof,
) -> DispatchResult {
Ok(())
}

fn check_evidence(
_offence_proof: &OffenceProof,
_key_owner_proof: &Self::KeyOwnerProof,
_key_owner_proof: &KeyOwnerProof,
) -> DispatchResult {
Ok(())
}

fn submit_evidence(
_offence_proof: OffenceProof,
_key_owner_proof: Self::KeyOwnerProof,
) -> bool {
fn submit_evidence(_offence_proof: OffenceProof, _key_owner_proof: KeyOwnerProof) -> bool {
true
}
}