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

Ensure slot number is strictly increasing #41

Merged
Changes from 2 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
15 changes: 15 additions & 0 deletions pallets/author-inherent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ pub mod pallet {
#[pallet::storage]
pub type Author<T: Config> = 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<T: Config> = StorageValue<_, u32, ValueQuery>;
4meta5 marked this conversation as resolved.
Show resolved Hide resolved

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: T::BlockNumber) -> Weight {
Expand Down Expand Up @@ -116,6 +121,16 @@ pub mod pallet {
pub fn kick_off_authorship_validation(origin: OriginFor<T>) -> 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::<T>::get(),
"Block invalid; Supplied slot number is not high enough"
);

HighestSlotSeen::<T>::put(slot);
JoshOrndorff marked this conversation as resolved.
Show resolved Hide resolved

// Now check that the author is valid in this slot
let author = <Author<T>>::get()
.expect("Block invalid, no authorship information supplied in preruntime digest.");

Expand Down