document two uint64 -> int64 conversions (#2375)
* document two uint64 -> int64 conversions * fix minimal preset slot time & calculation
This commit is contained in:
parent
c4edff504b
commit
4278e80657
|
@ -13,7 +13,7 @@ import
|
|||
stew/shims/[tables, macros],
|
||||
chronos, confutils, metrics, json_rpc/[rpcclient, jsonmarshal],
|
||||
chronicles,
|
||||
json_serialization/std/[options, sets, net],
|
||||
json_serialization/std/[options, net],
|
||||
|
||||
# Local modules
|
||||
spec/[datatypes, digest, crypto, helpers, network, signatures],
|
||||
|
|
|
@ -1135,4 +1135,10 @@ proc getInfo*[A, B](man: SyncManager[A, B]): SyncInfo =
|
|||
## Returns current synchronization information for RPC call.
|
||||
let wallSlot = man.getLocalWallSlot()
|
||||
let headSlot = man.getLocalHeadSlot()
|
||||
SyncInfo(head_slot: headSlot, sync_distance: int64(wallSlot - headSlot))
|
||||
|
||||
# Even with 6 second slots (minimal presets), this overflows about 1.75
|
||||
# trillion years into the chain's existence, if headSlot is 0.
|
||||
let sync_distance = wallSlot - headSlot
|
||||
doAssert sync_distance <= high(int64).uint64
|
||||
|
||||
SyncInfo(head_slot: headSlot, sync_distance: int64(sync_distance))
|
||||
|
|
|
@ -25,6 +25,9 @@ type
|
|||
BeaconTime* = distinct Duration ## Nanoseconds from beacon genesis time
|
||||
|
||||
proc init*(T: type BeaconClock, genesis_time: uint64): T =
|
||||
# ~290 billion years into the future
|
||||
doAssert genesis_time <= high(int64).uint64
|
||||
|
||||
let
|
||||
unixGenesis = fromUnix(genesis_time.int64)
|
||||
# GENESIS_SLOT offsets slot time, but to simplify calculations, we apply that
|
||||
|
|
|
@ -12,7 +12,7 @@ import
|
|||
# Status libraries
|
||||
stew/[byteutils, endians2],
|
||||
# Internals
|
||||
../../beacon_chain/spec/[datatypes, digest, presets],
|
||||
../../beacon_chain/spec/[datatypes, presets],
|
||||
# Test utilities
|
||||
../testutil, ./fixtures_utils
|
||||
|
||||
|
|
Loading…
Reference in New Issue