Add slot timer to beacon node

This commit is contained in:
Paul Hauner
2019-03-27 10:36:20 +11:00
parent b887509607
commit b006586d19
9 changed files with 132 additions and 3 deletions

View File

@@ -409,6 +409,20 @@ where
}
}
/// Reads the slot clock (see `self.read_slot_clock()` and returns the number of slots since
/// genesis.
pub fn slots_since_genesis(&self) -> Option<SlotHeight> {
let now = self.read_slot_clock()?;
if now < self.spec.genesis_slot {
None
} else {
Some(SlotHeight::from(
now.as_u64() - self.spec.genesis_slot.as_u64(),
))
}
}
/// Returns slot of the present state.
///
/// This is distinct to `read_slot_clock`, which reads from the actual system clock. If