diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index d4bf25f6e..1504381c2 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -720,10 +720,9 @@ proc run*(node: BeaconNode) = node.onAttestation(attestation) let - wallSlot = node.beaconClock.now().toSlot() - startSlot = - if wallSlot.afterGenesis: wallSlot.slot + 1 - else: GENESIS_SLOT + 1 + t = node.beaconClock.now() + startSlot = if t > BeaconTime(0): t.toSlot + 1 + else: GENESIS_SLOT + 1 fromNow = saturate(node.beaconClock.fromNow(startSlot)) info "Scheduling first slot action", diff --git a/beacon_chain/time.nim b/beacon_chain/time.nim index 8429da344..1f5f50cc3 100644 --- a/beacon_chain/time.nim +++ b/beacon_chain/time.nim @@ -38,6 +38,12 @@ proc init*(T: type BeaconClock, state: BeaconState): T = T(genesis: unixGenesis - unixGenesisOffset) +template `<`*(a, b: BeaconTime): bool = + int64(a) < int64(b) + +template `<=`*(a, b: BeaconTime): bool = + int64(a) <= int64(b) + func toSlot*(t: BeaconTime): tuple[afterGenesis: bool, slot: Slot] = let ti = t.int64 if ti >= 0: @@ -94,4 +100,4 @@ func shortLog*(d: Duration): string = tmp &= $frac & "m" tmp -func shortLog*(v: BeaconTime): int64 = v.int64 \ No newline at end of file +func shortLog*(v: BeaconTime): int64 = v.int64