Convert timestamp to unit type wrapper (#8333)

The timestamp inherent type was up to now just a simple `u64`. This
worked, but doesn't give you that much guarantees at compile time about
the type. This pr changes that by converting this type to a unit type
wrapper, similar to what we have done for `Slot`.

This is required for some future pr that touches quite a lot of the
inherents stuff :)

Besides this unit wrapper type, this pr also moves the `OnTimestampSet`
trait to `frame_support::traits`.
This commit is contained in:
Bastian Köcher
2021-03-11 23:33:34 +01:00
committed by GitHub
parent 39f3b77f4b
commit 5d73e960da
17 changed files with 113 additions and 43 deletions
@@ -221,7 +221,7 @@ impl<B, C> ConsensusDataProvider<B> for BabeConsensusDataProvider<B, C>
if !has_authority {
log::info!(target: "manual-seal", "authority not found");
let slot = inherents.timestamp_inherent_data()? / self.config.slot_duration;
let slot = *inherents.timestamp_inherent_data()? / self.config.slot_duration;
// manually hard code epoch descriptor
epoch_descriptor = match epoch_descriptor {
ViableEpochDescriptor::Signaled(identifier, _header) => {
@@ -293,7 +293,10 @@ impl ProvideInherentData for SlotTimestampProvider {
fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), sp_inherents::Error> {
// we update the time here.
let duration: InherentType = self.time.fetch_add(self.slot_duration, atomic::Ordering::SeqCst);
let duration: InherentType = self.time.fetch_add(
self.slot_duration,
atomic::Ordering::SeqCst,
).into();
inherent_data.put_data(INHERENT_IDENTIFIER, &duration)?;
Ok(())
}