Highlight execution client for optimistically synced node (#4266)

...such that the user knows where to look
This commit is contained in:
Jacek Sieka 2022-10-27 19:22:32 +02:00 committed by GitHub
parent 63a3f2b1ad
commit 1572814a0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 11 deletions

View File

@ -1200,7 +1200,7 @@ proc onSlotEnd(node: BeaconNode, slot: Slot) {.async.} =
# Update upcoming actions - we do this every slot in case a reorg happens
let head = node.dag.head
if node.isSynced(head):
if node.isSynced(head) == SyncStatus.synced:
withState(node.dag.headState):
if node.consensusManager[].actionTracker.needsUpdate(
forkyState, slot.epoch + 1):

View File

@ -36,7 +36,7 @@ func match(data: openArray[char], charset: set[char]): int =
proc getSyncedHead*(node: BeaconNode, slot: Slot): Result[BlockRef, cstring] =
let head = node.dag.head
if slot > head.slot and not node.isSynced(head):
if slot > head.slot and node.isSynced(head) != SyncStatus.synced:
return err("Requesting way ahead of the current head")
ok(head)

View File

@ -265,7 +265,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.jsonResponseWOpt(res, optimistic)
elif qSyncPeriod > headSyncPeriod:
# The requested epoch may still be too far in the future.
if not(node.isSynced(node.dag.head)):
if node.isSynced(node.dag.head) != SyncStatus.synced:
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
else:
return RestApiResponse.jsonError(Http400, EpochFromFutureError)
@ -566,7 +566,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
InvalidSubscriptionRequestValueError,
$dres.error())
dres.get()
if not(node.isSynced(node.dag.head)):
if node.isSynced(node.dag.head) != SyncStatus.synced:
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
let

View File

@ -207,7 +207,7 @@ proc checkSync(vc: ValidatorClientRef,
head_slot = syncInfo.head_slot, is_opimistic = optimistic
RestBeaconNodeStatus.Online
else:
warn "Beacon node is optimistically synced only",
warn "Execution client not in sync (beacon node optimistically synced)",
sync_distance = syncInfo.sync_distance,
head_slot = syncInfo.head_slot, is_opimistic = optimistic
RestBeaconNodeStatus.NotSynced

View File

@ -91,6 +91,11 @@ logScope: topics = "beacval"
type
ForkedBlockResult* = Result[ForkedBeaconBlock, string]
SyncStatus* {.pure.} = enum
synced
unsynced
optimistic
proc findValidator*(validators: auto, pubkey: ValidatorPubKey): Opt[ValidatorIndex] =
let idx = validators.findIt(it.pubkey == pubkey)
if idx == -1:
@ -153,7 +158,7 @@ proc getAttachedValidator(node: BeaconNode,
idx, head = shortLog(node.dag.head)
nil
proc isSynced*(node: BeaconNode, head: BlockRef): bool =
proc isSynced*(node: BeaconNode, head: BlockRef): SyncStatus =
## TODO This function is here as a placeholder for some better heurestics to
## determine if we're in sync and should be producing blocks and
## attestations. Generally, the problem is that slot time keeps advancing
@ -176,9 +181,12 @@ proc isSynced*(node: BeaconNode, head: BlockRef): bool =
# else to do it
if wallSlot.afterGenesis and
head.slot + node.config.syncHorizon < wallSlot.slot:
false
SyncStatus.unsynced
else:
not node.dag.is_optimistic(head.root)
if node.dag.is_optimistic(head.root):
SyncStatus.optimistic
else:
SyncStatus.synced
proc handleLightClientUpdates*(node: BeaconNode, slot: Slot) {.async.} =
static: doAssert lightClientFinalityUpdateSlotOffset ==
@ -1353,8 +1361,9 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
# The dag head might be updated by sync while we're working due to the
# await calls, thus we use a local variable to keep the logic straight here
var head = node.dag.head
if not node.isSynced(head):
info "Syncing in progress; skipping validator duties for now",
case node.isSynced(head)
of SyncStatus.unsynced:
info "Beacon node not in sync; skipping validator duties for now",
slot, headSlot = head.slot
# Rewards will be growing though, as we sync..
@ -1362,6 +1371,17 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
return
of SyncStatus.optimistic:
info "Execution client not in sync; skipping validator duties for now",
slot, headSlot = head.slot
# Rewards will be growing though, as we sync..
updateValidatorMetrics(node)
return
of SyncStatus.synced:
discard # keep going
var curSlot = lastSlot + 1
# If broadcastStartEpoch is 0, it hasn't had time to initialize yet, which
@ -1495,7 +1515,7 @@ proc registerDuties*(node: BeaconNode, wallSlot: Slot) {.async.} =
## Register upcoming duties of attached validators with the duty tracker
if node.attachedValidators[].count() == 0 or
not node.isSynced(node.dag.head):
node.isSynced(node.dag.head) != SyncStatus.synced:
# Nothing to do because we have no validator attached
return