Independence of Slot-based algorithms from system Timestamp (#12224)

* Remove timestamp from SlotInfo

* Expose as millis instead of secs

* Nits

* Fix test after field removal

* Yet another test fix

* On the fly timestamp computation

* Removed slot timestamp from logs

* Removed reference to timestamp from slots subsystem

* Slot based algorithm tests do not require timstamp inherent anymore

* Remove junk files

* Further tests cleanup

* Trigger pipeline

* Apply code suggestions

* Trigger pipeline

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Davide Galassi
2022-09-23 19:51:57 +02:00
committed by GitHub
parent 71438160a1
commit bf97f2a702
9 changed files with 56 additions and 97 deletions
+12 -13
View File
@@ -56,6 +56,17 @@ impl Timestamp {
pub fn checked_sub(self, other: Self) -> Option<Self> {
self.0.checked_sub(other.0).map(Self)
}
/// The current timestamp using the system time.
#[cfg(feature = "std")]
pub fn current() -> Self {
use std::time::SystemTime;
let now = SystemTime::now();
now.duration_since(SystemTime::UNIX_EPOCH)
.expect("Current time is always after unix epoch; qed")
.into()
}
}
impl sp_std::ops::Deref for Timestamp {
@@ -165,18 +176,6 @@ impl TimestampInherentData for InherentData {
}
}
/// The current timestamp using the system time.
///
/// This timestamp is the time since the UNIX epoch.
#[cfg(feature = "std")]
fn current_timestamp() -> std::time::Duration {
use std::time::SystemTime;
let now = SystemTime::now();
now.duration_since(SystemTime::UNIX_EPOCH)
.expect("Current time is always after unix epoch; qed")
}
/// Provide duration since unix epoch in millisecond for timestamp inherent.
#[cfg(feature = "std")]
pub struct InherentDataProvider {
@@ -190,7 +189,7 @@ impl InherentDataProvider {
pub fn from_system_time() -> Self {
Self {
max_drift: std::time::Duration::from_secs(60).into(),
timestamp: current_timestamp().into(),
timestamp: Timestamp::current(),
}
}