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)
|
node.beaconState = await obtainTrustedStateSnapshot(node.db)
|
||||||
else:
|
else:
|
||||||
node.beaconState = persistedState
|
node.beaconState = persistedState
|
||||||
var targetSlot = toSlot timeSinceGenesis(node.beaconState)
|
var targetSlot = node.beaconState.getSlotFromTime()
|
||||||
|
|
||||||
let t = now()
|
let t = now()
|
||||||
if t < node.beaconState.genesisTime * 1000:
|
if t < node.beaconState.genesisTime * 1000:
|
||||||
|
@ -388,7 +388,7 @@ proc processBlocks*(node: BeaconNode) =
|
||||||
|
|
||||||
node.attestationPool.add(a, node.beaconState)
|
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)
|
node.scheduleEpochActions(epoch)
|
||||||
|
|
||||||
runForever()
|
runForever()
|
||||||
|
|
|
@ -16,8 +16,9 @@ proc timeSinceGenesis*(s: BeaconState): Timestamp =
|
||||||
Timestamp(int64(fastEpochTime() - s.genesis_time * 1000) -
|
Timestamp(int64(fastEpochTime() - s.genesis_time * 1000) -
|
||||||
detectedClockDrift)
|
detectedClockDrift)
|
||||||
|
|
||||||
template toSlot*(t: Timestamp): uint64 =
|
proc getSlotFromTime*(s: BeaconState, t = now()): SlotNumber =
|
||||||
t div (SLOT_DURATION * 1000)
|
GENESIS_SLOT + uint64((int64(t - s.genesis_time * 1000) - detectedClockDrift) div
|
||||||
|
int64(SLOT_DURATION * 1000))
|
||||||
|
|
||||||
template slotStart*(s: BeaconState, slot: uint64): Timestamp =
|
template slotStart*(s: BeaconState, slot: uint64): Timestamp =
|
||||||
(s.genesis_time + (slot * SLOT_DURATION)) * 1000
|
(s.genesis_time + (slot * SLOT_DURATION)) * 1000
|
||||||
|
|
Loading…
Reference in New Issue