Better start-up logic when the beacon node is launched before the genesis time

This commit is contained in:
Zahary Karadjov 2019-08-16 13:20:46 +02:00
parent 78f7a4a505
commit 74f630eb28
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
2 changed files with 10 additions and 5 deletions

View File

@ -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",

View File

@ -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: