mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 21:08:32 +00:00
Refactor timestamp_now (#9094)
#9077 Where possible replaces all instances of `validator_monitor::timestamp_now` with `chain.slot_clock.now_duration().unwrap_or_default()`. Where chain/slot_clock is not available, instead replace it with a convenience function `slot_clock::timestamp_now`. Remove the `validator_monitor::timestamp_now` function. Co-Authored-By: Mac L <mjladson@pm.me>
This commit is contained in:
@@ -2,7 +2,7 @@ mod manual_slot_clock;
|
||||
mod metrics;
|
||||
mod system_time_slot_clock;
|
||||
|
||||
use std::time::Duration;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub use crate::manual_slot_clock::ManualSlotClock as TestingSlotClock;
|
||||
pub use crate::manual_slot_clock::ManualSlotClock;
|
||||
@@ -110,3 +110,13 @@ pub trait SlotClock: Send + Sync + Sized + Clone {
|
||||
slot_clock
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the current system time as a duration since the UNIX epoch.
|
||||
///
|
||||
/// This is a convenience function for recording timestamps when `SlotClock` is not available.
|
||||
/// Prefer `SlotClock::now_duration` if available.
|
||||
pub fn timestamp_now() -> Duration {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user