attest to known valid block when possible (#5313)

* attest to known valid block when possible

* cleaner approach; slot is always == attestation slot itself

* copyright year linting
This commit is contained in:
tersec 2024-01-11 22:34:10 +00:00 committed by GitHub
parent b44e3ede1a
commit 251143fd51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 3 deletions

View File

@ -100,6 +100,7 @@ type
dutyValidatorCount*: int
## Number of validators that we've checked for activation
processingDelay*: Opt[Duration]
lastValidAttestedBlock*: Opt[BlockSlot]
const
MaxEmptySlotCount* = uint64(10*60) div SECONDS_PER_SLOT

View File

@ -736,9 +736,17 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError,
$res.error())
let tres = res.get()
if not tres.executionValid:
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
tres
if tres.executionValid:
tres
else:
let qbs = node.lastValidAttestedBlock.valueOr:
return RestApiResponse.jsonError(
Http503, BeaconNodeInSyncError)
if qbs.blck.slot > qslot:
return RestApiResponse.jsonError(
Http503, BeaconNodeInSyncError)
qbs.blck
let epochRef = node.dag.getEpochRef(qhead, qslot.epoch, true).valueOr:
return RestApiResponse.jsonError(Http400, PrunedStateError, $error)
makeAttestationData(epochRef, qhead.atSlot(qslot), qindex)

View File

@ -1785,6 +1785,23 @@ proc updateValidators(
index: index, validator: validators[int index]
)))
proc handleFallbackAttestations(node: BeaconNode, lastSlot, slot: Slot) =
# Neither block proposal nor sync committee duties can be done in this
# situation.
let attestationHead = node.lastValidAttestedBlock.valueOr:
return
if attestationHead.slot + SLOTS_PER_EPOCH < slot:
return
# Using `slot` and `curSlot` here ensure that the attestation data created
# is for the wall slot, regardless of attestationHead's block and slot.
for curSlot in (lastSlot + 1) ..< slot:
notice "Catching up on fallback attestation duties", curSlot, slot
handleAttestations(node, attestationHead.blck, curSlot)
handleAttestations(node, attestationHead.blck, slot)
proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
## Perform validator duties - create blocks, vote and aggregate existing votes
if node.attachedValidators[].count == 0:
@ -1807,6 +1824,8 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
info "Execution client not in sync; skipping validator duties for now",
slot, headSlot = head.slot
handleFallbackAttestations(node, lastSlot, slot)
# Rewards will be growing though, as we sync..
updateValidatorMetrics(node)
@ -1814,6 +1833,8 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
else:
discard # keep going
node.lastValidAttestedBlock = Opt.some head.atSlot()
withState(node.dag.headState):
node.updateValidators(forkyState.data.validators.asSeq())