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
+3 -3
View File
@@ -97,7 +97,7 @@ use sp_consensus::{
SelectChain, SlotData, import_queue::{Verifier, BasicQueue, DefaultImportQueue, CacheKeyId},
};
use sp_consensus_babe::inherents::BabeInherentData;
use sp_timestamp::{TimestampInherentData, InherentType as TimestampInherent};
use sp_timestamp::TimestampInherentData;
use sc_client_api::{
backend::AuxStore, BlockchainEvents, ProvideUncles,
};
@@ -919,13 +919,13 @@ impl SlotCompatible for TimeSource {
fn extract_timestamp_and_slot(
&self,
data: &InherentData,
) -> Result<(TimestampInherent, Slot, std::time::Duration), sp_consensus::Error> {
) -> Result<(u64, Slot, std::time::Duration), sp_consensus::Error> {
trace!(target: "babe", "extract timestamp");
data.timestamp_inherent_data()
.and_then(|t| data.babe_inherent_data().map(|a| (t, a)))
.map_err(Into::into)
.map_err(sp_consensus::Error::InherentData)
.map(|(x, y)| (x, y, self.0.lock().0.take().unwrap_or_default()))
.map(|(x, y)| (*x, y, self.0.lock().0.take().unwrap_or_default()))
}
}