put the validate_unsigned implementation inside the pallet definition (#9044)

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Guillaume Thiolliere
2021-06-08 22:54:06 +02:00
committed by GitHub
parent c7b9430b7f
commit ea6831e398
4 changed files with 38 additions and 14 deletions
+7 -7
View File
@@ -179,12 +179,12 @@ where
} }
} }
/// A `ValidateUnsigned` implementation that restricts calls to `report_equivocation_unsigned` /// Methods for the `ValidateUnsigned` implementation:
/// to local calls (i.e. extrinsics generated on this node) or that already in a block. This /// It restricts calls to `report_equivocation_unsigned` to local calls (i.e. extrinsics generated
/// guarantees that only block authors can include unsigned equivocation reports. /// on this node) or that already in a block. This guarantees that only block authors can include
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Pallet<T> { /// unsigned equivocation reports.
type Call = Call<T>; impl<T: Config> Pallet<T> {
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity { pub fn validate_unsigned(source: TransactionSource, call: &Call<T>) -> TransactionValidity {
if let Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof) = call { if let Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof) = call {
// discard equivocation report not coming from the local node // discard equivocation report not coming from the local node
match source { match source {
@@ -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 { if let Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof) = call {
is_known_offence::<T>(equivocation_proof, key_owner_proof) is_known_offence::<T>(equivocation_proof, key_owner_proof)
} else { } else {
+12
View File
@@ -407,6 +407,18 @@ pub mod pallet {
Ok(()) 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 /// A BABE public key
+7 -7
View File
@@ -200,12 +200,12 @@ pub struct GrandpaTimeSlot {
pub round: RoundNumber, pub round: RoundNumber,
} }
/// A `ValidateUnsigned` implementation that restricts calls to `report_equivocation_unsigned` /// Methods for the `ValidateUnsigned` implementation:
/// to local calls (i.e. extrinsics generated on this node) or that already in a block. This /// It restricts calls to `report_equivocation_unsigned` to local calls (i.e. extrinsics generated
/// guarantees that only block authors can include unsigned equivocation reports. /// on this node) or that already in a block. This guarantees that only block authors can include
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Pallet<T> { /// unsigned equivocation reports.
type Call = Call<T>; impl<T: Config> Pallet<T> {
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity { pub fn validate_unsigned(source: TransactionSource, call: &Call<T>) -> TransactionValidity {
if let Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof) = call { if let Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof) = call {
// discard equivocation report not coming from the local node // discard equivocation report not coming from the local node
match source { match source {
@@ -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 { if let Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof) = call {
is_known_offence::<T>(equivocation_proof, key_owner_proof) is_known_offence::<T>(equivocation_proof, key_owner_proof)
} else { } else {
+12
View File
@@ -341,6 +341,18 @@ pub mod pallet {
Pallet::<T>::initialize(&self.authorities) 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 { pub trait WeightInfo {