FCU should consider ForkedChainRef when calculating valid ancestor (#2651)

This commit is contained in:
andri lim 2024-09-24 17:53:18 +07:00 committed by GitHub
parent 0fb9581b96
commit 38d651c9c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View File

@ -155,8 +155,7 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
# probably resyncing. Ignore the update.
# See point 2 of fCUV1 specification
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#specification-1
var canonHash: common.Hash256
if db.getBlockHash(header.number, canonHash) and canonHash == blockHash:
if ben.chain.isCanonicalAncestor(header.number, blockHash):
notice "Ignoring beacon update to old head",
blockHash=blockHash.short,
blockNumber=header.number

View File

@ -632,3 +632,28 @@ func isCanonical*(c: ForkedChainRef, blockHash: Hash256): bool =
if blockHash == prevHash:
return true
prevHash = item.blk.header.parentHash
proc isCanonicalAncestor*(c: ForkedChainRef,
blockNumber: BlockNumber,
blockHash: Hash256): bool =
if blockNumber >= c.cursorHeader.number:
return false
if blockHash == c.cursorHash:
return false
if c.baseHeader.number < c.cursorHeader.number:
# The current canonical chain in memory is headed by
# cursorHeader
shouldNotKeyError:
var prevHash = c.cursorHeader.parentHash
while prevHash != c.baseHash:
var header = c.blocks[prevHash].blk.header
if prevHash == blockHash and blockNumber == header.number:
return true
prevHash = header.parentHash
# canonical chain in database should have a marker
# and the marker is block number
var canonHash: common.Hash256
c.db.getBlockHash(blockNumber, canonHash) and canonHash == blockHash