* Start fixing enr-fork-id

* Fix time-until-next-fork logic

* Remove fork crate
This commit is contained in:
Paul Hauner
2020-03-26 17:35:12 +11:00
committed by Age Manning
parent bb065e3d00
commit f26bafe436
14 changed files with 129 additions and 152 deletions

View File

@@ -35,6 +35,9 @@ pub trait SlotClock: Send + Sync + Sized {
/// Returns the duration between slots
fn slot_duration(&self) -> Duration;
/// Returns the duration from now until `slot`.
fn duration_to_slot(&self, slot: Slot) -> Option<Duration>;
/// Returns the duration until the next slot.
fn duration_to_next_slot(&self) -> Option<Duration>;

View File

@@ -135,6 +135,10 @@ impl SlotClock for ManualSlotClock {
self.slot_duration
}
fn duration_to_slot(&self, slot: Slot) -> Option<Duration> {
self.duration_to_slot(slot, *self.current_time.read())
}
fn genesis_slot(&self) -> Slot {
self.genesis_slot
}

View File

@@ -44,6 +44,11 @@ impl SlotClock for SystemTimeSlotClock {
self.clock.slot_duration()
}
fn duration_to_slot(&self, slot: Slot) -> Option<Duration> {
let now = SystemTime::now().duration_since(UNIX_EPOCH).ok()?;
self.clock.duration_to_slot(slot, now)
}
fn genesis_slot(&self) -> Slot {
self.clock.genesis_slot()
}