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:
Mac L
2026-04-09 12:41:02 +04:00
committed by GitHub
parent fb5a0434d7
commit 7c2dcfc0d6
12 changed files with 60 additions and 60 deletions

View File

@@ -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()
}