mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 05:51:02 +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()
|
||||
|
||||
@@ -226,6 +226,11 @@ impl pallet_offences::Config for Test {
|
||||
type WeightSoftLimit = OffencesWeightSoftLimit;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const ReportLongevity: u64 =
|
||||
BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * Period::get();
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
type Event = Event;
|
||||
type Call = Call;
|
||||
@@ -240,7 +245,8 @@ impl Config for Test {
|
||||
AuthorityId,
|
||||
)>>::IdentificationTuple;
|
||||
|
||||
type HandleEquivocation = super::EquivocationHandler<Self::KeyOwnerIdentification, Offences>;
|
||||
type HandleEquivocation =
|
||||
super::EquivocationHandler<Self::KeyOwnerIdentification, Offences, ReportLongevity>;
|
||||
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
@@ -706,8 +706,8 @@ fn report_equivocation_invalid_equivocation_proof() {
|
||||
#[test]
|
||||
fn report_equivocation_validate_unsigned_prevents_duplicates() {
|
||||
use sp_runtime::transaction_validity::{
|
||||
InvalidTransaction, TransactionLongevity, TransactionPriority, TransactionSource,
|
||||
TransactionValidity, ValidTransaction,
|
||||
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
|
||||
ValidTransaction,
|
||||
};
|
||||
|
||||
let authorities = test_authorities();
|
||||
@@ -762,7 +762,7 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() {
|
||||
priority: TransactionPriority::max_value(),
|
||||
requires: vec![],
|
||||
provides: vec![("GrandpaEquivocation", tx_tag).encode()],
|
||||
longevity: TransactionLongevity::max_value(),
|
||||
longevity: ReportLongevity::get(),
|
||||
propagate: false,
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user