mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
babe, grandpa: set longevity for equivocation report transactions (#8076)
* babe: set longevity for equivocation report transactions * grandpa: set longevity for equivocation report transaction * babe, grandpa: fix tests * node: add ReportLongevity to babe and grandpa modules * node: bump spec_version
This commit is contained in:
@@ -40,7 +40,10 @@
|
||||
use sp_std::prelude::*;
|
||||
|
||||
use codec::{self as codec, Decode, Encode};
|
||||
use frame_support::{debug, traits::KeyOwnerProofSystem};
|
||||
use frame_support::{
|
||||
debug,
|
||||
traits::{Get, KeyOwnerProofSystem},
|
||||
};
|
||||
use sp_finality_grandpa::{EquivocationProof, RoundNumber, SetId};
|
||||
use sp_runtime::{
|
||||
transaction_validity::{
|
||||
@@ -64,6 +67,10 @@ pub trait HandleEquivocation<T: Config> {
|
||||
/// The offence type used for reporting offences on valid equivocation reports.
|
||||
type Offence: GrandpaOffence<T::KeyOwnerIdentification>;
|
||||
|
||||
/// The longevity, in blocks, that the equivocation report is valid for. When using the staking
|
||||
/// pallet this should be equal to the bonding duration (in blocks, not eras).
|
||||
type ReportLongevity: Get<u64>;
|
||||
|
||||
/// Report an offence proved by the given reporters.
|
||||
fn report_offence(
|
||||
reporters: Vec<T::AccountId>,
|
||||
@@ -88,6 +95,7 @@ pub trait HandleEquivocation<T: Config> {
|
||||
|
||||
impl<T: Config> HandleEquivocation<T> for () {
|
||||
type Offence = GrandpaEquivocationOffence<T::KeyOwnerIdentification>;
|
||||
type ReportLongevity = ();
|
||||
|
||||
fn report_offence(
|
||||
_reporters: Vec<T::AccountId>,
|
||||
@@ -119,11 +127,11 @@ impl<T: Config> HandleEquivocation<T> for () {
|
||||
/// using existing subsystems that are part of frame (type bounds described
|
||||
/// below) and will dispatch to them directly, it's only purpose is to wire all
|
||||
/// subsystems together.
|
||||
pub struct EquivocationHandler<I, R, O = GrandpaEquivocationOffence<I>> {
|
||||
_phantom: sp_std::marker::PhantomData<(I, R, O)>,
|
||||
pub struct EquivocationHandler<I, R, L, O = GrandpaEquivocationOffence<I>> {
|
||||
_phantom: sp_std::marker::PhantomData<(I, R, L, O)>,
|
||||
}
|
||||
|
||||
impl<I, R, O> Default for EquivocationHandler<I, R, O> {
|
||||
impl<I, R, L, O> Default for EquivocationHandler<I, R, L, O> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
_phantom: Default::default(),
|
||||
@@ -131,7 +139,7 @@ impl<I, R, O> Default for EquivocationHandler<I, R, O> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, R, O> HandleEquivocation<T> for EquivocationHandler<T::KeyOwnerIdentification, R, O>
|
||||
impl<T, R, L, O> HandleEquivocation<T> for EquivocationHandler<T::KeyOwnerIdentification, R, L, O>
|
||||
where
|
||||
// We use the authorship pallet to fetch the current block author and use
|
||||
// `offchain::SendTransactionTypes` for unsigned extrinsic creation and
|
||||
@@ -140,10 +148,14 @@ where
|
||||
// A system for reporting offences after valid equivocation reports are
|
||||
// processed.
|
||||
R: ReportOffence<T::AccountId, T::KeyOwnerIdentification, O>,
|
||||
// The longevity (in blocks) that the equivocation report is valid for. When using the staking
|
||||
// pallet this should be the bonding duration.
|
||||
L: Get<u64>,
|
||||
// The offence type that should be used when reporting.
|
||||
O: GrandpaOffence<T::KeyOwnerIdentification>,
|
||||
{
|
||||
type Offence = O;
|
||||
type ReportLongevity = L;
|
||||
|
||||
fn report_offence(reporters: Vec<T::AccountId>, offence: O) -> Result<(), OffenceError> {
|
||||
R::report_offence(reporters, offence)
|
||||
@@ -207,6 +219,8 @@ impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
|
||||
// check report staleness
|
||||
is_known_offence::<T>(equivocation_proof, key_owner_proof)?;
|
||||
|
||||
let longevity = <T::HandleEquivocation as HandleEquivocation<T>>::ReportLongevity::get();
|
||||
|
||||
ValidTransaction::with_tag_prefix("GrandpaEquivocation")
|
||||
// We assign the maximum priority for any equivocation report.
|
||||
.priority(TransactionPriority::max_value())
|
||||
@@ -216,6 +230,7 @@ impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
|
||||
equivocation_proof.set_id(),
|
||||
equivocation_proof.round(),
|
||||
))
|
||||
.longevity(longevity)
|
||||
// We don't propagate this. This can never be included on a remote node.
|
||||
.propagate(false)
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user