pub struct HybridClock { /* private fields */ }Expand description
A Hybrid Logical Clock instance.
Each node in the EXOCHAIN network maintains its own HybridClock.
The clock is driven by a deterministic physical source and a logical
counter. The default constructor does not read host time; runtime adapters
that need deployment-specific physical metadata must inject an explicit HLC
source.
Implementations§
Source§impl HybridClock
impl HybridClock
Sourcepub fn with_wall_clock(
physical_source: impl Fn() -> u64 + Send + 'static,
) -> Self
pub fn with_wall_clock( physical_source: impl Fn() -> u64 + Send + 'static, ) -> Self
Create a clock with a custom physical source.
Sourcepub fn with_wall_clock_and_max_drift(
physical_source: impl Fn() -> u64 + Send + 'static,
max_drift_ms: u64,
) -> Self
pub fn with_wall_clock_and_max_drift( physical_source: impl Fn() -> u64 + Send + 'static, max_drift_ms: u64, ) -> Self
Create a clock with a custom physical source and drift tolerance.
Sourcepub fn with_fallible_wall_clock(
physical_source: impl Fn() -> Result<u64> + Send + 'static,
) -> Self
pub fn with_fallible_wall_clock( physical_source: impl Fn() -> Result<u64> + Send + 'static, ) -> Self
Create a clock with a fallible physical source.
Sourcepub fn with_fallible_wall_clock_and_max_drift(
physical_source: impl Fn() -> Result<u64> + Send + 'static,
max_drift_ms: u64,
) -> Self
pub fn with_fallible_wall_clock_and_max_drift( physical_source: impl Fn() -> Result<u64> + Send + 'static, max_drift_ms: u64, ) -> Self
Create a clock with a fallible physical source and drift tolerance.
Sourcepub fn max_drift_ms(&self) -> u64
pub fn max_drift_ms(&self) -> u64
Return this clock’s configured maximum forward drift in milliseconds.
Sourcepub fn now(&mut self) -> Result<Timestamp>
pub fn now(&mut self) -> Result<Timestamp>
Generate the next timestamp.
Guarantees: the returned timestamp is strictly greater than any previously returned by this clock.
Sourcepub fn update(&mut self, remote: &Timestamp) -> Result<Timestamp>
pub fn update(&mut self, remote: &Timestamp) -> Result<Timestamp>
Merge a remote timestamp and advance the local clock.
The returned timestamp is guaranteed to be greater than both the local state and the remote timestamp.
§Errors
Returns ExoError::ClockDrift if the remote timestamp is
unreasonably far ahead of the local physical source.