From 1b6651dfc3ef1ec16a553c4f046bcf347c6ec565 Mon Sep 17 00:00:00 2001 From: Eugene Kabanov Date: Tue, 14 Jun 2022 23:26:23 +0300 Subject: [PATCH] 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. --- beacon_chain/rpc/rest_node_api.nim | 14 +++++++++++++- beacon_chain/sync/sync_manager.nim | 11 ----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/beacon_chain/rpc/rest_node_api.nim b/beacon_chain/rpc/rest_node_api.nim index d55237af1..04e2d5480 100644 --- a/beacon_chain/rpc/rest_node_api.nim +++ b/beacon_chain/rpc/rest_node_api.nim @@ -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: diff --git a/beacon_chain/sync/sync_manager.nim b/beacon_chain/sync/sync_manager.nim index 451ea0bbb..2131d59b1 100644 --- a/beacon_chain/sync/sync_manager.nim +++ b/beacon_chain/sync/sync_manager.nim @@ -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 - )