diff --git a/pallets/author-inherent/src/lib.rs b/pallets/author-inherent/src/lib.rs index 1a5d2491..dcdc2e9e 100644 --- a/pallets/author-inherent/src/lib.rs +++ b/pallets/author-inherent/src/lib.rs @@ -83,6 +83,11 @@ pub mod pallet { #[pallet::storage] pub type Author = StorageValue<_, T::AccountId, OptionQuery>; + /// The highest slot that has been seen in the history of this chain. + /// This is a strictly-increasing value. + #[pallet::storage] + pub type HighestSlotSeen = StorageValue<_, u32, ValueQuery>; + #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(_: T::BlockNumber) -> Weight { @@ -116,14 +121,24 @@ pub mod pallet { pub fn kick_off_authorship_validation(origin: OriginFor) -> DispatchResultWithPostInfo { ensure_none(origin)?; + // First check that the slot number is valid (greater than the previous highest) + let slot = T::SlotBeacon::slot(); + assert!( + slot > HighestSlotSeen::::get(), + "Block invalid; Supplied slot number is not high enough" + ); + + // Now check that the author is valid in this slot let author = >::get() .expect("Block invalid, no authorship information supplied in preruntime digest."); - assert!( T::CanAuthor::can_author(&author, &T::SlotBeacon::slot()), "Block invalid, supplied author is not eligible." ); + // Once that is validated, update the stored slot number + HighestSlotSeen::::put(slot); + Ok(Pays::No.into()) } }