Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engine API: Don't build payload if requested timestamp is invalid #1865

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions nimbus/beacon/api_handler/api_forkchoice.nim
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
# that should be fixed, not papered over.
if not ben.get(blockHash, header):
warn "Forkchoice requested unknown head",
hash = blockHash
hash = blockHash.short
return simpleFCU(PayloadExecutionStatus.syncing)

# Header advertised via a past newPayload request. Start syncing to it.
Expand Down Expand Up @@ -107,16 +107,16 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
if not db.getTd(blockHash, td) or (blockNumber > 0'u64 and not db.getTd(header.parentHash, ptd)):
error "TDs unavailable for TTD check",
number = blockNumber,
hash = blockHash,
hash = blockHash.short,
td = td,
parent = header.parentHash,
parent = header.parentHash.short,
ptd = ptd
return simpleFCU(PayloadExecutionStatus.invalid, "TDs unavailable for TDD check")

if td < ttd or (blockNumber > 0'u64 and ptd > ttd):
error "Refusing beacon update to pre-merge",
number = blockNumber,
hash = blockHash,
hash = blockHash.short,
diff = header.difficulty,
ptd = ptd,
ttd = ttd
Expand Down Expand Up @@ -146,39 +146,39 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
var finalBlock: common.BlockHeader
if not db.getBlockHeader(finalizedBlockHash, finalBlock):
warn "Final block not available in database",
hash=finalizedBlockHash
hash=finalizedBlockHash.short
raise invalidParams("finalized block header not available")
var finalHash: common.Hash256
if not db.getBlockHash(finalBlock.blockNumber, finalHash):
warn "Final block not in canonical chain",
number=finalBlock.blockNumber,
hash=finalizedBlockHash
hash=finalizedBlockHash.short
raise invalidParams("finalized block hash not available")
if finalHash != finalizedBlockHash:
warn "Final block not in canonical chain",
number=finalBlock.blockNumber,
expect=finalizedBlockHash,
get=finalHash
raise invalidParams("finalilized block not canonical")
expect=finalizedBlockHash.short,
get=finalHash.short
raise invalidParams("finalized block not canonical")
db.finalizedHeaderHash(finalizedBlockHash)

let safeBlockHash = ethHash update.safeBlockHash
if safeBlockHash != common.Hash256():
var safeBlock: common.BlockHeader
if not db.getBlockHeader(safeBlockHash, safeBlock):
warn "Safe block not available in database",
hash = safeBlockHash
hash = safeBlockHash.short
raise invalidParams("safe head not available")
var safeHash: common.Hash256
if not db.getBlockHash(safeBlock.blockNumber, safeHash):
warn "Safe block hash not available in database",
hash = safeHash
hash = safeHash.short
raise invalidParams("safe block hash not available")
if safeHash != safeBlockHash:
warn "Safe block not in canonical chain",
blockNumber=safeBlock.blockNumber,
expect=safeBlockHash,
get=safeHash
expect=safeBlockHash.short,
get=safeHash.short
raise invalidParams("safe head not canonical")
db.safeHeaderHash(safeBlockHash)

Expand Down
3 changes: 3 additions & 0 deletions nimbus/beacon/beacon_engine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ proc generatePayload*(ben: BeaconEngineRef,
# reorg
discard xp.smartHead(headBlock)

if pos.timestamp <= headBlock.timestamp:
return err "timestamp must be strictly later than parent"

# someBaseFee = true: make sure blk.header
# have the same blockHash with generated payload
let blk = xp.ethBlock(someBaseFee = true)
Expand Down
Loading