Struct nakamoto_common::block::time::AdjustedTime
source · pub struct AdjustedTime<K> { /* private fields */ }
Expand description
Network-adjusted time tracker.
Network-adjusted time is the median timestamp of all connected peers. Since we store only time offsets for each peer, the network-adjusted time is the local time plus the median offset of all connected peers.
Nb. Network time is never adjusted more than 70 minutes from local system time.
Implementations
sourceimpl<K: Hash + Eq> AdjustedTime<K>
impl<K: Hash + Eq> AdjustedTime<K>
sourcepub fn new(local_time: LocalTime) -> Self
pub fn new(local_time: LocalTime) -> Self
Create a new network-adjusted time tracker. Starts with a single sample of zero.
sourcepub fn record_offset(&mut self, source: K, sample: TimeOffset)
pub fn record_offset(&mut self, source: K, sample: TimeOffset)
Add a time sample to influence the network-adjusted time.
sourcepub fn offset(&self) -> TimeOffset
pub fn offset(&self) -> TimeOffset
Get the median network time offset.
sourcepub fn from(&self, time: BlockTime) -> BlockTime
pub fn from(&self, time: BlockTime) -> BlockTime
Get the network-adjusted time given a local time.
sourcepub fn set_local_time(&mut self, time: LocalTime)
pub fn set_local_time(&mut self, time: LocalTime)
Set the local time to the given value.
sourcepub fn local_time(&self) -> LocalTime
pub fn local_time(&self) -> LocalTime
Get the last known local time.
Trait Implementations
sourceimpl<K: Eq + Clone + Hash> AdjustedClock<K> for AdjustedTime<K>
impl<K: Eq + Clone + Hash> AdjustedClock<K> for AdjustedTime<K>
sourcefn record_offset(&mut self, source: K, sample: TimeOffset)
fn record_offset(&mut self, source: K, sample: TimeOffset)
Record a peer offset.
sourceimpl<K: Eq + Clone + Hash> Clock for AdjustedTime<K>
impl<K: Eq + Clone + Hash> Clock for AdjustedTime<K>
sourcefn block_time(&self) -> BlockTime
fn block_time(&self) -> BlockTime
Return the local time as seconds since Epoch.
This is the same representation as used in block header timestamps. Read more
sourcefn local_time(&self) -> LocalTime
fn local_time(&self) -> LocalTime
Tell the time in local time.
sourcefn from_block_time(t: BlockTime) -> Self
fn from_block_time(t: BlockTime) -> Self
Create a clock from a block time.
sourceimpl<K: Clone> Clone for AdjustedTime<K>
impl<K: Clone> Clone for AdjustedTime<K>
sourcefn clone(&self) -> AdjustedTime<K>
fn clone(&self) -> AdjustedTime<K>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<K: Debug> Debug for AdjustedTime<K>
impl<K: Debug> Debug for AdjustedTime<K>
Auto Trait Implementations
impl<K> RefUnwindSafe for AdjustedTime<K>where
K: RefUnwindSafe,
impl<K> Send for AdjustedTime<K>where
K: Send,
impl<K> Sync for AdjustedTime<K>where
K: Sync,
impl<K> Unpin for AdjustedTime<K>where
K: Unpin,
impl<K> UnwindSafe for AdjustedTime<K>where
K: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more