Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
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
57 changes: 29 additions & 28 deletions frame/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,35 @@ pub mod pallet {
Pallet::<T>::initialize_authorities(&self.authorities);
}
}

#[pallet::inherent]
impl<T: Config> ProvideInherent for Pallet<T> {
type Call = pallet_timestamp::Call<T>;
type Error = MakeFatalError<sp_inherents::Error>;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;

fn create_inherent(_: &InherentData) -> Option<Self::Call> {
None
}

/// Verify the validity of the inherent using the timestamp.
fn check_inherent(call: &Self::Call, data: &InherentData) -> result::Result<(), Self::Error> {
let timestamp = match call {
pallet_timestamp::Call::set(ref timestamp) => timestamp.clone(),
_ => return Ok(()),
};

let timestamp_based_slot = timestamp / Self::slot_duration();

let seal_slot = u64::from(data.aura_inherent_data()?).saturated_into();

if timestamp_based_slot == seal_slot {
Ok(())
} else {
Err(sp_inherents::Error::from("timestamp set in block doesn't match slot in seal").into())
}
}
}
}

impl<T: Config> Pallet<T> {
Expand Down Expand Up @@ -242,31 +271,3 @@ impl<T: Config> OnTimestampSet<T::Moment> for Pallet<T> {
// TODO [#3398] Generate offence report for all authorities that skipped their slots.
}
}

impl<T: Config> ProvideInherent for Pallet<T> {
type Call = pallet_timestamp::Call<T>;
type Error = MakeFatalError<sp_inherents::Error>;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;

fn create_inherent(_: &InherentData) -> Option<Self::Call> {
None
}

/// Verify the validity of the inherent using the timestamp.
fn check_inherent(call: &Self::Call, data: &InherentData) -> result::Result<(), Self::Error> {
let timestamp = match call {
pallet_timestamp::Call::set(ref timestamp) => timestamp.clone(),
_ => return Ok(()),
};

let timestamp_based_slot = timestamp / Self::slot_duration();

let seal_slot = u64::from(data.aura_inherent_data()?).saturated_into();

if timestamp_based_slot == seal_slot {
Ok(())
} else {
Err(sp_inherents::Error::from("timestamp set in block doesn't match slot in seal").into())
}
}
}