Fix for getting the current epoch number
This commit is contained in:
parent
bc44744acd
commit
dfcd22519b
|
@ -93,7 +93,7 @@ proc sync*(node: BeaconNode): Future[bool] {.async.} =
|
|||
node.beaconState = await obtainTrustedStateSnapshot(node.db)
|
||||
else:
|
||||
node.beaconState = persistedState
|
||||
var targetSlot = toSlot timeSinceGenesis(node.beaconState)
|
||||
var targetSlot = node.beaconState.getSlotFromTime()
|
||||
|
||||
let t = now()
|
||||
if t < node.beaconState.genesisTime * 1000:
|
||||
|
@ -388,7 +388,7 @@ proc processBlocks*(node: BeaconNode) =
|
|||
|
||||
node.attestationPool.add(a, node.beaconState)
|
||||
|
||||
let epoch = node.beaconState.timeSinceGenesis().toSlot div EPOCH_LENGTH
|
||||
let epoch = node.beaconState.getSlotFromTime div EPOCH_LENGTH
|
||||
node.scheduleEpochActions(epoch)
|
||||
|
||||
runForever()
|
||||
|
|
|
@ -16,8 +16,9 @@ proc timeSinceGenesis*(s: BeaconState): Timestamp =
|
|||
Timestamp(int64(fastEpochTime() - s.genesis_time * 1000) -
|
||||
detectedClockDrift)
|
||||
|
||||
template toSlot*(t: Timestamp): uint64 =
|
||||
t div (SLOT_DURATION * 1000)
|
||||
proc getSlotFromTime*(s: BeaconState, t = now()): SlotNumber =
|
||||
GENESIS_SLOT + uint64((int64(t - s.genesis_time * 1000) - detectedClockDrift) div
|
||||
int64(SLOT_DURATION * 1000))
|
||||
|
||||
template slotStart*(s: BeaconState, slot: uint64): Timestamp =
|
||||
(s.genesis_time + (slot * SLOT_DURATION)) * 1000
|
||||
|
|
Loading…
Reference in New Issue