Expand description
Clock abstraction shared by Polkadot node subsystems.
Production code uses SystemClock. Tests inject a deterministic mock so subsystems’
time-dependent behavior can be driven and observed without wall-clock dependence.
Subsystems that need time should accept Arc<dyn Clock> rather than reading
Instant::now(), SystemTime::now(), futures_timer::Delay::new(..), or
tokio::time::sleep(..) directly. Consider enforcing this via a crate-level
clippy.toml (see polkadot-collator-protocol for an example).
Note: not every subsystem currently routes all of its time reads through this
trait. In particular, polkadot-node-core-chain-selection,
polkadot-node-core-av-store, and polkadot-node-core-dispute-coordinator
presently use this trait only for their wall-clock reads and continue to call
futures_timer::Delay::new directly for their internal timers. Those call sites
need to be migrated before those subsystems can run under a deterministic test
harness.
Re-exports§
pub use mock::MockClock;
Modules§
Structs§
- System
Clock - Production clock backed by
std::timeandfutures_timer.
Traits§
- Clock
- Abstraction over wall-clock time. See module-level docs.
Functions§
- system_
clock - Convenience constructor returning a thread-safe handle to a
SystemClock.
Type Aliases§
- Boxed
Delay - Boxed future returned by
Clock::delay.