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:
parent
b44e3ede1a
commit
251143fd51
|
@ -100,6 +100,7 @@ type
|
||||||
dutyValidatorCount*: int
|
dutyValidatorCount*: int
|
||||||
## Number of validators that we've checked for activation
|
## Number of validators that we've checked for activation
|
||||||
processingDelay*: Opt[Duration]
|
processingDelay*: Opt[Duration]
|
||||||
|
lastValidAttestedBlock*: Opt[BlockSlot]
|
||||||
|
|
||||||
const
|
const
|
||||||
MaxEmptySlotCount* = uint64(10*60) div SECONDS_PER_SLOT
|
MaxEmptySlotCount* = uint64(10*60) div SECONDS_PER_SLOT
|
||||||
|
|
|
@ -736,9 +736,17 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError,
|
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError,
|
||||||
$res.error())
|
$res.error())
|
||||||
let tres = res.get()
|
let tres = res.get()
|
||||||
if not tres.executionValid:
|
if tres.executionValid:
|
||||||
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
tres
|
||||||
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:
|
let epochRef = node.dag.getEpochRef(qhead, qslot.epoch, true).valueOr:
|
||||||
return RestApiResponse.jsonError(Http400, PrunedStateError, $error)
|
return RestApiResponse.jsonError(Http400, PrunedStateError, $error)
|
||||||
makeAttestationData(epochRef, qhead.atSlot(qslot), qindex)
|
makeAttestationData(epochRef, qhead.atSlot(qslot), qindex)
|
||||||
|
|
|
@ -1785,6 +1785,23 @@ proc updateValidators(
|
||||||
index: index, validator: validators[int index]
|
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.} =
|
proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
|
||||||
## Perform validator duties - create blocks, vote and aggregate existing votes
|
## Perform validator duties - create blocks, vote and aggregate existing votes
|
||||||
if node.attachedValidators[].count == 0:
|
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",
|
info "Execution client not in sync; skipping validator duties for now",
|
||||||
slot, headSlot = head.slot
|
slot, headSlot = head.slot
|
||||||
|
|
||||||
|
handleFallbackAttestations(node, lastSlot, slot)
|
||||||
|
|
||||||
# Rewards will be growing though, as we sync..
|
# Rewards will be growing though, as we sync..
|
||||||
updateValidatorMetrics(node)
|
updateValidatorMetrics(node)
|
||||||
|
|
||||||
|
@ -1814,6 +1833,8 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
|
||||||
else:
|
else:
|
||||||
discard # keep going
|
discard # keep going
|
||||||
|
|
||||||
|
node.lastValidAttestedBlock = Opt.some head.atSlot()
|
||||||
|
|
||||||
withState(node.dag.headState):
|
withState(node.dag.headState):
|
||||||
node.updateValidators(forkyState.data.validators.asSeq())
|
node.updateValidators(forkyState.data.validators.asSeq())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue