Skip to content

Commit

Permalink
Engine API: Don't build payload if requested timestamp is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Oct 28, 2023
1 parent 3fe0a49 commit ddfaf2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
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

0 comments on commit ddfaf2a

Please sign in to comment.