Skip to content

Commit

Permalink
use FindAuthor in babe & grandpa directly
Browse files Browse the repository at this point in the history
  • Loading branch information
akildemir committed Jun 25, 2024
1 parent 6e3f07b commit 615a248
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions frame/babe/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -164,7 +164,11 @@ where
evidence: (EquivocationProof<HeaderFor<T>>, T::KeyOwnerProof),
) -> Result<(), DispatchError> {
let (equivocation_proof, key_owner_proof) = evidence;
let reporter = reporter.or_else(|| <pallet_authorship::Pallet<T>>::author());
let reporter = reporter.or_else(|| {
let digest = <frame_system::Pallet<T>>::digest();
let pre_runtime_digests = digest.logs.iter().filter_map(|d| d.as_pre_runtime());
<T as Config>::FindAuthor::find_author(pre_runtime_digests)
});
let offender = equivocation_proof.offender.clone();
let slot = equivocation_proof.slot;

Expand Down
2 changes: 2 additions & 0 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ pub mod pallet {
Option<Self::AccountId>,
(EquivocationProof<HeaderFor<Self>>, Self::KeyOwnerProof),
>;

type FindAuthor: FindAuthor<Self::AccountId>;
}

#[pallet::error]
Expand Down
8 changes: 6 additions & 2 deletions frame/grandpa/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -177,7 +177,11 @@ where
evidence: (EquivocationProof<T::Hash, BlockNumberFor<T>>, T::KeyOwnerProof),
) -> Result<(), DispatchError> {
let (equivocation_proof, key_owner_proof) = evidence;
let reporter = reporter.or_else(|| <pallet_authorship::Pallet<T>>::author());
let reporter = reporter.or_else(|| {
let digest = <frame_system::Pallet<T>>::digest();
let pre_runtime_digests = digest.logs.iter().filter_map(|d| d.as_pre_runtime());
<T as Config>::FindAuthor::find_author(pre_runtime_digests)
});
let offender = equivocation_proof.offender().clone();

// We check the equivocation within the context of its set id (and
Expand Down
4 changes: 3 additions & 1 deletion frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use frame_support::{
dispatch::{DispatchResultWithPostInfo, Pays},
pallet_prelude::Get,
storage,
traits::OneSessionHandler,
traits::{OneSessionHandler, FindAuthor},
weights::Weight,
WeakBoundedVec,
};
Expand Down Expand Up @@ -117,6 +117,8 @@ pub mod pallet {
Option<Self::AccountId>,
(EquivocationProof<Self::Hash, BlockNumberFor<Self>>, Self::KeyOwnerProof),
>;

type FindAuthor: FindAuthor<Self::AccountId>;
}

#[pallet::hooks]
Expand Down

0 comments on commit 615a248

Please sign in to comment.