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:
Eugene Kabanov 2022-06-14 23:26:23 +03:00 committed by GitHub
parent 81ff20b3f0
commit 1b6651dfc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 12 deletions

View File

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

View File

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