FCU should consider ForkedChainRef when calculating valid ancestor (#2651)
This commit is contained in:
parent
0fb9581b96
commit
38d651c9c8
|
@ -155,8 +155,7 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
|
||||||
# probably resyncing. Ignore the update.
|
# probably resyncing. Ignore the update.
|
||||||
# See point 2 of fCUV1 specification
|
# See point 2 of fCUV1 specification
|
||||||
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#specification-1
|
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#specification-1
|
||||||
var canonHash: common.Hash256
|
if ben.chain.isCanonicalAncestor(header.number, blockHash):
|
||||||
if db.getBlockHash(header.number, canonHash) and canonHash == blockHash:
|
|
||||||
notice "Ignoring beacon update to old head",
|
notice "Ignoring beacon update to old head",
|
||||||
blockHash=blockHash.short,
|
blockHash=blockHash.short,
|
||||||
blockNumber=header.number
|
blockNumber=header.number
|
||||||
|
|
|
@ -632,3 +632,28 @@ func isCanonical*(c: ForkedChainRef, blockHash: Hash256): bool =
|
||||||
if blockHash == prevHash:
|
if blockHash == prevHash:
|
||||||
return true
|
return true
|
||||||
prevHash = item.blk.header.parentHash
|
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
|
||||||
|
|
Loading…
Reference in New Issue