Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 34 additions & 0 deletions beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,20 @@ proc loadExecutionAndParentBlockHash*(dag: ChainDAGRef, bid: BlockId):
else:
(Opt.some ZERO_HASH, Opt.some ZERO_HASH)

proc loadExecutionGasLimit*(dag: ChainDAGRef, bid: BlockId): Opt[uint64] =
## The `gas_limit` of the execution payload committed to by the block, i.e.
## the bid's `gas_limit` post-Gloas (the envelope must match the bid).
let blockData = dag.getForkedBlock(bid).valueOr:
return Opt.none(uint64)

withBlck(blockData):
when consensusFork >= ConsensusFork.Gloas:
Opt.some forkyBlck.message.body.signed_execution_payload_bid.message.gas_limit
elif consensusFork in ConsensusFork.Bellatrix .. ConsensusFork.Fulu:
Opt.some forkyBlck.message.body.execution_payload.gas_limit
else:
Opt.none(uint64)

proc loadExecutionAndParentBlockHash*(dag: ChainDAGRef, blck: BlockRef):
tuple[blockHash: Opt[Eth2Digest], parentHash: Opt[Eth2Digest]] =
if blck.executionBlockHash.isNone() or blck.executionParentHash.isNone():
Expand All @@ -1147,6 +1161,26 @@ proc loadExecutionAndParentBlockHash*(dag: ChainDAGRef, blck: BlockRef):

(blck.executionBlockHash, blck.executionParentHash)

proc loadExecutionParent*(dag: ChainDAGRef, blck: BlockRef): Opt[BlockRef] =
## The ancestor whose execution payload `blck` builds on, i.e. the block
## whose payload `block_hash` equals `blck`'s payload `parent_block_hash`.
## Unlike `executionParent`, this loads the hashes of ancestors on demand.
let (_, parentHash) = dag.loadExecutionAndParentBlockHash(blck)
if parentHash.isNone() or isNil(blck.parent):
return Opt.none(BlockRef)
if parentHash.get().isZero():
return Opt.some(blck.parent)

var cur = blck.parent
for _ in 0 ..< EXECUTION_PARENT_MAX_DEPTH:
if isNil(cur):
break
let (blockHash, _) = dag.loadExecutionAndParentBlockHash(cur)
if blockHash.isSome() and blockHash.get() == parentHash.get():
return Opt.some(cur)
cur = cur.parent
Opt.none(BlockRef)

proc applyBlock(
dag: ChainDAGRef, state: var ForkedHashedBeaconState, bid: BlockId,
cache: var StateCache, info: var ForkedEpochInfo,
Expand Down
20 changes: 18 additions & 2 deletions beacon_chain/gossip_processing/gossip_validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2028,9 +2028,25 @@ proc validateExecutionPayloadBid*(
# ... `is_gas_limit_target_compatible(parent_gas_limit, bid.gas_limit,
# proposer_preferences.target_gas_limit)` is True, where
# `parent_gas_limit` is the `gas_limit` of that execution payload.
#
# The execution payload identified by `bid.parent_block_hash` is either
# the parent block's own payload (`Timely`) or the payload the parent
# block builds on (`Withheld`), which can differ from the parent block's
# bid `gas_limit`.
let parentPayloadBlck =
case payloadAvailability
of PayloadAvailability.Timely:
parentBlck
of PayloadAvailability.Withheld:
dag.loadExecutionParent(parentBlck).valueOr:
Comment thread
ahshum marked this conversation as resolved.
Outdated
return errIgnore(
"ExecutionPayloadBid: parent execution payload block unknown")
let parentGasLimit =
dag.loadExecutionGasLimit(parentPayloadBlck.bid).valueOr:
return errIgnore(
"ExecutionPayloadBid: parent execution payload gas limit unknown")
if not is_gas_limit_target_compatible(
forkyState.data.latest_execution_payload_bid.gas_limit,
bid.gas_limit, seenPref.target_gas_limit):
parentGasLimit, bid.gas_limit, seenPref.target_gas_limit):
return errIgnore("ExecutionPayloadBid: gas limit not target-compatible")

# [IGNORE] bid.slot is the current slot or the next slot
Expand Down
Loading