Skip to content

Commit

Permalink
Fix /eth/v1/node/syncing (#3720)
Browse files Browse the repository at this point in the history
* Fix REST `/eth/v1/node/syncing` call to return values even if SyncManager is not running.

* Use syncManager.inProgress as is_syncing indicator.
  • Loading branch information
cheatfate authored Jun 14, 2022
1 parent 81ff20b commit 1b6651d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
14 changes: 13 additions & 1 deletion beacon_chain/rpc/rest_node_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 0 additions & 11 deletions beacon_chain/sync/sync_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 1b6651d

Please sign in to comment.