dag: protect against finalized epoch moving before BlockRef cutoff (#3847)

This commit is contained in:
Jacek Sieka 2022-07-07 16:24:31 +02:00 committed by GitHub
parent 9de2c6171f
commit b00eac7a50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -152,11 +152,9 @@ proc init*(T: type AttestationPool, dag: ChainDAGRef,
doAssert status.isOk(), "Error in preloading the fork choice: " & $status.error
info "Fork choice initialized",
justified_epoch = getStateField(
dag.headState, current_justified_checkpoint).epoch,
finalized_epoch = getStateField(dag.headState, finalized_checkpoint).epoch,
finalized_root = shortLog(dag.finalizedHead.blck.root)
justified = shortLog(getStateField(
dag.headState, current_justified_checkpoint)),
finalized = shortLog(getStateField(dag.headState, finalized_checkpoint))
T(
dag: dag,
quarantine: quarantine,

View File

@ -1696,7 +1696,11 @@ proc updateHead*(
let
finalized_checkpoint =
getStateField(dag.headState, finalized_checkpoint)
finalizedSlot = max(finalized_checkpoint.epoch.start_slot(), dag.tail.slot)
finalizedSlot =
# finalized checkpoint may move back in the head state compared to what
# we've seen in other forks - it does not move back in fork choice
# however, so we'll use the last-known-finalized in that case
max(finalized_checkpoint.epoch.start_slot(), dag.finalizedHead.slot)
finalizedHead = newHead.atSlot(finalizedSlot)
doAssert (not finalizedHead.blck.isNil),