mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-16 12:28:24 +00:00
Merge latest from branch clock-disparity
* Account for genesis time * Use checked mul * Account for genesis slot * Change API * Refactor "duration to..." functions
This commit is contained in:
@@ -40,4 +40,18 @@ pub trait SlotClock: Send + Sync + Sized {
|
||||
|
||||
/// Returns the duration until the first slot of the next epoch.
|
||||
fn duration_to_next_epoch(&self, slots_per_epoch: u64) -> Option<Duration>;
|
||||
|
||||
/// Returns the first slot to be returned at the genesis time.
|
||||
fn genesis_slot(&self) -> Slot;
|
||||
|
||||
/// Returns the slot if the internal clock were advanced by `duration`.
|
||||
fn now_with_future_tolerance(&self, tolerance: Duration) -> Option<Slot> {
|
||||
self.slot_of(self.now_duration()?.checked_add(tolerance)?)
|
||||
}
|
||||
|
||||
/// Returns the slot if the internal clock were reversed by `duration`.
|
||||
fn now_with_past_tolerance(&self, tolerance: Duration) -> Option<Slot> {
|
||||
self.slot_of(self.now_duration()?.checked_sub(tolerance)?)
|
||||
.or_else(|| Some(self.genesis_slot()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user