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

BEEFY: introduce offence report system #13564

Merged
merged 5 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 8 additions & 6 deletions frame/babe/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ impl<Offender: Clone> Offence<Offender> for EquivocationOffence<Offender> {
}
}

/// Babe equivocation offence system.
/// BABE equivocation offence report system.
///
/// This type implements `OffenceReportSystem`
/// This type implements `OffenceReportSystem` such that:
/// - Equivocation reports are published on-chain as unsigned extrinsic via
/// `offchain::SendTransactioinsTypes`.
/// - On-chain validity checks and processing are mostly delegated to the user provided generic
/// types implementing `KeyOwnerProofSystem` and `ReportOffence` traits.
/// - Offence reporter for unsigned transactions is fetched via the the authorship pallet.
pub struct EquivocationReportSystem<T, R, P, L>(sp_std::marker::PhantomData<(T, R, P, L)>);

// 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<Option<T::AccountId>, (EquivocationProof<T::Header>, T::KeyOwnerProof)>
for EquivocationReportSystem<T, R, P, L>
Expand Down Expand Up @@ -131,7 +133,7 @@ where
};
let res = SubmitTransaction::<T, Call<T>>::submit_unsigned_transaction(call.into());
match res {
Ok(()) => info!(target: LOG_TARGET, "Submitted equivocation report."),
Ok(_) => info!(target: LOG_TARGET, "Submitted equivocation report"),
Err(e) => error!(target: LOG_TARGET, "Error submitting equivocation report: {:?}", e),
}
res
Expand Down
14 changes: 4 additions & 10 deletions frame/beefy-mmr/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use codec::Encode;
use frame_support::{
construct_runtime, parameter_types,
sp_io::TestExternalities,
traits::{ConstU16, ConstU32, ConstU64, GenesisBuild, KeyOwnerProofSystem},
traits::{ConstU16, ConstU32, ConstU64, GenesisBuild},
BasicExternalities,
};
use sp_consensus_beefy::mmr::MmrLeafVersion;
use sp_core::{crypto::KeyTypeId, Hasher, H256};
use sp_core::{Hasher, H256};
use sp_runtime::{
app_crypto::ecdsa::Public,
impl_opaque_keys,
Expand Down Expand Up @@ -124,18 +124,12 @@ impl pallet_mmr::Config for Test {

impl pallet_beefy::Config for Test {
type BeefyId = BeefyId;
type KeyOwnerProofSystem = ();
type KeyOwnerProof =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, BeefyId)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
BeefyId,
)>>::IdentificationTuple;
type HandleEquivocation = ();
type MaxAuthorities = ConstU32<100>;
type MaxSetIdSessionEntries = ConstU64<100>;
type OnNewValidatorSet = BeefyMmr;
type WeightInfo = ();
type KeyOwnerProof = sp_core::Void;
type EquivocationReportSystem = ();
}

parameter_types! {
Expand Down
Loading