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

Commit

Permalink
put the validate_unsigned implementation inside the pallet definition (
Browse files Browse the repository at this point in the history
…paritytech#9044)

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
  • Loading branch information
2 people authored and Andrei Navoichyk committed Sep 9, 2022
1 parent 98a7d4a commit c3ea13c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
14 changes: 7 additions & 7 deletions frame/babe/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ where
}
}

/// A `ValidateUnsigned` implementation that restricts calls to `report_equivocation_unsigned`
/// to local calls (i.e. extrinsics generated on this node) or that already in a block. This
/// guarantees that only block authors can include unsigned equivocation reports.
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
/// Methods for the `ValidateUnsigned` implementation:
/// It restricts calls to `report_equivocation_unsigned` to local calls (i.e. extrinsics generated
/// on this node) or that already in a block. This guarantees that only block authors can include
/// unsigned equivocation reports.
impl<T: Config> Pallet<T> {
pub fn validate_unsigned(source: TransactionSource, call: &Call<T>) -> TransactionValidity {
if let Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof) = call {
// discard equivocation report not coming from the local node
match source {
Expand Down Expand Up @@ -221,7 +221,7 @@ impl<T: Config> frame_support::unsigned::ValidateUnsigned for Pallet<T> {
}
}

fn pre_dispatch(call: &Self::Call) -> Result<(), TransactionValidityError> {
pub fn pre_dispatch(call: &Call<T>) -> Result<(), TransactionValidityError> {
if let Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof) = call {
is_known_offence::<T>(equivocation_proof, key_owner_proof)
} else {
Expand Down
12 changes: 12 additions & 0 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,18 @@ pub mod pallet {
Ok(())
}
}

#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
Self::validate_unsigned(source, call)
}

fn pre_dispatch(call: &Self::Call) -> Result<(), TransactionValidityError> {
Self::pre_dispatch(call)
}
}
}

/// A BABE public key
Expand Down
14 changes: 7 additions & 7 deletions frame/grandpa/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ pub struct GrandpaTimeSlot {
pub round: RoundNumber,
}

/// A `ValidateUnsigned` implementation that restricts calls to `report_equivocation_unsigned`
/// to local calls (i.e. extrinsics generated on this node) or that already in a block. This
/// guarantees that only block authors can include unsigned equivocation reports.
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
/// Methods for the `ValidateUnsigned` implementation:
/// It restricts calls to `report_equivocation_unsigned` to local calls (i.e. extrinsics generated
/// on this node) or that already in a block. This guarantees that only block authors can include
/// unsigned equivocation reports.
impl<T: Config> Pallet<T> {
pub fn validate_unsigned(source: TransactionSource, call: &Call<T>) -> TransactionValidity {
if let Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof) = call {
// discard equivocation report not coming from the local node
match source {
Expand Down Expand Up @@ -243,7 +243,7 @@ impl<T: Config> frame_support::unsigned::ValidateUnsigned for Pallet<T> {
}
}

fn pre_dispatch(call: &Self::Call) -> Result<(), TransactionValidityError> {
pub fn pre_dispatch(call: &Call<T>) -> Result<(), TransactionValidityError> {
if let Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof) = call {
is_known_offence::<T>(equivocation_proof, key_owner_proof)
} else {
Expand Down
12 changes: 12 additions & 0 deletions frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,18 @@ pub mod pallet {
Pallet::<T>::initialize(&self.authorities)
}
}

#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
Self::validate_unsigned(source, call)
}

fn pre_dispatch(call: &Self::Call) -> Result<(), TransactionValidityError> {
Self::pre_dispatch(call)
}
}
}

pub trait WeightInfo {
Expand Down

0 comments on commit c3ea13c

Please sign in to comment.