Fix /eth/v1/node/syncing (#3720)
* Fix REST `/eth/v1/node/syncing` call to return values even if SyncManager is not running. * Use syncManager.inProgress as is_syncing indicator.
This commit is contained in:
parent
81ff20b3f0
commit
1b6651dfc3
|
@ -253,7 +253,19 @@ proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
|
||||
# https://ethereum.github.io/beacon-APIs/#/Node/getSyncingStatus
|
||||
router.api(MethodGet, "/eth/v1/node/syncing") do () -> RestApiResponse:
|
||||
return RestApiResponse.jsonResponse(node.syncManager.getInfo())
|
||||
let
|
||||
wallSlot = node.beaconClock.now().slotOrZero()
|
||||
headSlot = node.dag.head.slot
|
||||
distance = wallSlot - headSlot
|
||||
info = RestSyncInfo(
|
||||
head_slot: headSlot, sync_distance: distance,
|
||||
is_syncing:
|
||||
if isNil(node.syncManager):
|
||||
false
|
||||
else:
|
||||
node.syncManager.inProgress
|
||||
)
|
||||
return RestApiResponse.jsonResponse(info)
|
||||
|
||||
# https://ethereum.github.io/beacon-APIs/#/Node/getHealth
|
||||
router.api(MethodGet, "/eth/v1/node/health") do () -> RestApiResponse:
|
||||
|
|
|
@ -669,14 +669,3 @@ proc syncLoop[A, B](man: SyncManager[A, B]) {.async.} =
|
|||
proc start*[A, B](man: SyncManager[A, B]) =
|
||||
## Starts SyncManager's main loop.
|
||||
man.syncFut = man.syncLoop()
|
||||
|
||||
proc getInfo*[A, B](man: SyncManager[A, B]): RestSyncInfo =
|
||||
## Returns current synchronization information for RPC call.
|
||||
let wallSlot = man.getLocalWallSlot()
|
||||
let headSlot = man.getLocalHeadSlot()
|
||||
let sync_distance = wallSlot - headSlot
|
||||
RestSyncInfo(
|
||||
head_slot: headSlot,
|
||||
sync_distance: sync_distance,
|
||||
is_syncing: man.inProgress
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue