Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use FindAuthor in babe & grandpa directly #5

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading