Skip to content

Commit

Permalink
use babe FindAuthor implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
akildemir committed Jun 26, 2024
1 parent 615a248 commit f6883ed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions frame/babe/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<T, R, P, L>
OffenceReportSystem<Option<T::AccountId>, (EquivocationProof<HeaderFor<T>>, T::KeyOwnerProof)>
for EquivocationReportSystem<T, R, P, L>
where
T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
T: Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
R: ReportOffence<
T::AccountId,
P::IdentificationTuple,
Expand Down Expand Up @@ -167,7 +167,7 @@ where
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)
Pallet<T>::find_author(pre_runtime_digests)
});
let offender = equivocation_proof.offender.clone();
let slot = equivocation_proof.slot;
Expand Down
9 changes: 4 additions & 5 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ pub mod pallet {
Option<Self::AccountId>,
(EquivocationProof<HeaderFor<Self>>, Self::KeyOwnerProof),
>;

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

#[pallet::error]
Expand Down Expand Up @@ -487,15 +485,16 @@ pub mod pallet {
}
}

impl<T: Config> FindAuthor<u32> for Pallet<T> {
fn find_author<'a, I>(digests: I) -> Option<u32>
impl<T: Config> FindAuthor<T::AccountId> for Pallet<T> {
fn find_author<'a, I>(digests: I) -> Option<T::AccountId>
where
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
{
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())
}
}

Expand Down
2 changes: 1 addition & 1 deletion frame/grandpa/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<T, R, P, L>
(EquivocationProof<T::Hash, BlockNumberFor<T>>, T::KeyOwnerProof),
> for EquivocationReportSystem<T, R, P, L>
where
T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
T: Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
R: ReportOffence<
T::AccountId,
P::IdentificationTuple,
Expand Down

0 comments on commit f6883ed

Please sign in to comment.