diff --git a/frame/babe/src/equivocation.rs b/frame/babe/src/equivocation.rs index d9a097da76b24..0c8f41b4d6981 100644 --- a/frame/babe/src/equivocation.rs +++ b/frame/babe/src/equivocation.rs @@ -34,7 +34,7 @@ //! that the `ValidateUnsigned` for the BABE pallet is used in the runtime //! definition. -use frame_support::traits::{Get, KeyOwnerProofSystem}; +use frame_support::traits::{Get, KeyOwnerProofSystem, FindAuthor}; use frame_system::pallet_prelude::HeaderFor; use log::{error, info}; @@ -111,7 +111,7 @@ impl OffenceReportSystem, (EquivocationProof>, T::KeyOwnerProof)> for EquivocationReportSystem where - T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes>, + T: Config + frame_system::offchain::SendTransactionTypes>, R: ReportOffence< T::AccountId, P::IdentificationTuple, @@ -164,7 +164,11 @@ where evidence: (EquivocationProof>, T::KeyOwnerProof), ) -> Result<(), DispatchError> { let (equivocation_proof, key_owner_proof) = evidence; - let reporter = reporter.or_else(|| >::author()); + let reporter = reporter.or_else(|| { + let digest = >::digest(); + let pre_runtime_digests = digest.logs.iter().filter_map(|d| d.as_pre_runtime()); + Pallet::::find_author(pre_runtime_digests) + }); let offender = equivocation_proof.offender.clone(); let slot = equivocation_proof.slot; diff --git a/frame/babe/src/lib.rs b/frame/babe/src/lib.rs index 793718146462b..e8909bcae4ad6 100644 --- a/frame/babe/src/lib.rs +++ b/frame/babe/src/lib.rs @@ -37,7 +37,7 @@ use sp_consensus_babe::{ EquivocationProof, Randomness as BabeRandomness, Slot, BABE_ENGINE_ID, RANDOMNESS_LENGTH, RANDOMNESS_VRF_CONTEXT, }; -use sp_core::crypto::Wraps; +use sp_core::{crypto::Wraps, sr25519::Public}; use sp_runtime::{ generic::DigestItem, traits::{IsMember, One, SaturatedConversion, Saturating, Zero}, @@ -120,7 +120,7 @@ pub mod pallet { #[pallet::config] #[pallet::disable_frame_system_supertrait_check] - pub trait Config: pallet_timestamp::Config { + pub trait Config: pallet_timestamp::Config { /// The amount of time, in slots, that each epoch should last. /// NOTE: Currently it is not possible to change the epoch duration after /// the chain has started. Attempting to do so will brick block production. @@ -485,15 +485,16 @@ pub mod pallet { } } -impl FindAuthor for Pallet { - fn find_author<'a, I>(digests: I) -> Option +impl FindAuthor for Pallet { + fn find_author<'a, I>(digests: I) -> Option where I: 'a + IntoIterator, { for (id, mut data) in digests.into_iter() { if id == BABE_ENGINE_ID { let pre_digest: PreDigest = PreDigest::decode(&mut data).ok()?; - return Some(pre_digest.authority_index()) + let index = pre_digest.authority_index(); + return Some(Self::authorities()[index as usize].0.clone().into()) } } diff --git a/frame/grandpa/src/equivocation.rs b/frame/grandpa/src/equivocation.rs index e32886603e8f5..b81d62d3ebc9b 100644 --- a/frame/grandpa/src/equivocation.rs +++ b/frame/grandpa/src/equivocation.rs @@ -37,7 +37,7 @@ //! definition. use codec::{self as codec, Decode, Encode}; -use frame_support::traits::{Get, KeyOwnerProofSystem}; +use frame_support::traits::{Get, KeyOwnerProofSystem, FindAuthor}; use frame_system::pallet_prelude::BlockNumberFor; use log::{error, info}; use sp_consensus_grandpa::{AuthorityId, EquivocationProof, RoundNumber, SetId, KEY_TYPE}; @@ -123,7 +123,7 @@ impl (EquivocationProof>, T::KeyOwnerProof), > for EquivocationReportSystem where - T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes>, + T: Config + frame_system::offchain::SendTransactionTypes>, R: ReportOffence< T::AccountId, P::IdentificationTuple, @@ -177,7 +177,11 @@ where evidence: (EquivocationProof>, T::KeyOwnerProof), ) -> Result<(), DispatchError> { let (equivocation_proof, key_owner_proof) = evidence; - let reporter = reporter.or_else(|| >::author()); + let reporter = reporter.or_else(|| { + let digest = >::digest(); + let pre_runtime_digests = digest.logs.iter().filter_map(|d| d.as_pre_runtime()); + ::FindAuthor::find_author(pre_runtime_digests) + }); let offender = equivocation_proof.offender().clone(); // We check the equivocation within the context of its set id (and diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index a9f0ccfeb7482..475b2d6d8d90a 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -39,7 +39,7 @@ use frame_support::{ dispatch::{DispatchResultWithPostInfo, Pays}, pallet_prelude::Get, storage, - traits::OneSessionHandler, + traits::{OneSessionHandler, FindAuthor}, weights::Weight, WeakBoundedVec, }; @@ -117,6 +117,8 @@ pub mod pallet { Option, (EquivocationProof>, Self::KeyOwnerProof), >; + + type FindAuthor: FindAuthor; } #[pallet::hooks]