Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
generic authorid in author inherent
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk committed Jun 19, 2023
1 parent 7e9b2e2 commit feb308a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
25 changes: 14 additions & 11 deletions pallets/author-inherent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use frame_support::traits::{FindAuthor, Get};
use nimbus_primitives::{
AccountLookup, CanAuthor, NimbusId, SlotBeacon, INHERENT_IDENTIFIER, NIMBUS_ENGINE_ID,
};
use parity_scale_codec::{Decode, Encode};
use parity_scale_codec::{Decode, Encode, FullCodec};
use sp_inherents::{InherentIdentifier, IsFatalError};
use sp_runtime::{ConsensusEngineId, RuntimeString};

Expand Down Expand Up @@ -56,17 +56,20 @@ pub mod pallet {

#[pallet::config]
pub trait Config: frame_system::Config {
/// A type to convert between AuthorId and AccountId. This is useful when you want to associate
/// Block authoring behavior with an AccoutId for rewards or slashing. If you do not need to
/// hold an AccountID responsible for authoring use `()` which acts as an identity mapping.
type AccountLookup: AccountLookup<Self::AccountId>;
/// Type used to refer to a block author.
type AuthorId: sp_std::fmt::Debug + PartialEq + Clone + FullCodec + TypeInfo + MaxEncodedLen;

/// A type to convert between NimbusId and AuthorId. This is useful when you want to associate
/// Block authoring behavior with an AuthorId for rewards or slashing. If you do not need to
/// hold an AuthorId responsible for authoring use `()` which acts as an identity mapping.
type AccountLookup: AccountLookup<Self::AuthorId>;

/// The final word on whether the reported author can author at this height.
/// This will be used when executing the inherent. This check is often stricter than the
/// Preliminary check, because it can use more data.
/// If the pallet that implements this trait depends on an inherent, that inherent **must**
/// be included before this one.
type CanAuthor: CanAuthor<Self::AccountId>;
type CanAuthor: CanAuthor<Self::AuthorId>;

/// Some way of determining the current slot for purposes of verifying the author's eligibility
type SlotBeacon: SlotBeacon;
Expand All @@ -90,7 +93,7 @@ pub mod pallet {

/// Author of current block.
#[pallet::storage]
pub type Author<T: Config> = StorageValue<_, T::AccountId, OptionQuery>;
pub type Author<T: Config> = StorageValue<_, T::AuthorId, OptionQuery>;

/// The highest slot that has been seen in the history of this chain.
/// This is a strictly-increasing value.
Expand Down Expand Up @@ -170,8 +173,8 @@ pub mod pallet {
}
}

impl<T: Config> FindAuthor<T::AccountId> for Pallet<T> {
fn find_author<'a, I>(digests: I) -> Option<T::AccountId>
impl<T: Config> FindAuthor<T::AuthorId> for Pallet<T> {
fn find_author<'a, I>(digests: I) -> Option<T::AuthorId>
where
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
{
Expand All @@ -191,8 +194,8 @@ pub mod pallet {
}
}

impl<T: Config> Get<T::AccountId> for Pallet<T> {
fn get() -> T::AccountId {
impl<T: Config> Get<T::AuthorId> for Pallet<T> {
fn get() -> T::AuthorId {
Author::<T>::get().expect("Block author not inserted into Author Inherent Pallet")
}
}
Expand Down
1 change: 1 addition & 0 deletions pallets/author-inherent/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl AccountLookup<u64> for MockAccountLookup {
}

impl pallet_testing::Config for Test {
type AuthorId = u64;
type AccountLookup = MockAccountLookup;
type CanAuthor = ();
type SlotBeacon = DummyBeacon;
Expand Down
1 change: 1 addition & 0 deletions parachain-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ impl cumulus_pallet_dmp_queue::Config for Runtime {
}

impl pallet_author_inherent::Config for Runtime {
type AuthorId = AccountId;
// We start a new slot each time we see a new relay block.
type SlotBeacon = cumulus_pallet_parachain_system::RelaychainDataProvider<Self>;
type AccountLookup = PotentialAuthorSet;
Expand Down

0 comments on commit feb308a

Please sign in to comment.