mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-25 04:57:17 +00:00
Allow slot clock to work on genesis (#573)
* Allow slot clock to work on genesis * Loose over-strict requirements for slot clock tests
This commit is contained in:
parent
a488c4dccd
commit
2c6b40be78
@ -29,10 +29,10 @@ impl SlotClock for SystemTimeSlotClock {
|
||||
let now = SystemTime::now().duration_since(UNIX_EPOCH).ok()?;
|
||||
let genesis = self.genesis_duration;
|
||||
|
||||
if now > genesis {
|
||||
if now >= genesis {
|
||||
let since_genesis = now
|
||||
.checked_sub(genesis)
|
||||
.expect("Control flow ensures now is greater than genesis");
|
||||
.expect("Control flow ensures now is greater than or equal to genesis");
|
||||
let slot =
|
||||
Slot::from((since_genesis.as_millis() / self.slot_duration.as_millis()) as u64);
|
||||
Some(slot + self.genesis_slot)
|
||||
@ -50,7 +50,7 @@ impl SlotClock for SystemTimeSlotClock {
|
||||
genesis + slot * self.slot_duration
|
||||
};
|
||||
|
||||
if now > genesis {
|
||||
if now >= genesis {
|
||||
Some(
|
||||
slot_start(self.now()? + 1)
|
||||
.checked_sub(now)
|
||||
@ -100,12 +100,12 @@ mod tests {
|
||||
let clock =
|
||||
SystemTimeSlotClock::new(genesis_slot, prior_genesis(500), Duration::from_secs(1));
|
||||
assert_eq!(clock.now(), Some(Slot::new(0)));
|
||||
assert!(clock.duration_to_next_slot().unwrap() < Duration::from_millis(500));
|
||||
assert!(clock.duration_to_next_slot().unwrap() <= Duration::from_millis(500));
|
||||
|
||||
let clock =
|
||||
SystemTimeSlotClock::new(genesis_slot, prior_genesis(1_500), Duration::from_secs(1));
|
||||
assert_eq!(clock.now(), Some(Slot::new(1)));
|
||||
assert!(clock.duration_to_next_slot().unwrap() < Duration::from_millis(500));
|
||||
assert!(clock.duration_to_next_slot().unwrap() <= Duration::from_millis(500));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user