diff --git a/beacon_chain/consensus_object_pools/blockchain_dag.nim b/beacon_chain/consensus_object_pools/blockchain_dag.nim index cebe8bf121..ead0e8d56c 100644 --- a/beacon_chain/consensus_object_pools/blockchain_dag.nim +++ b/beacon_chain/consensus_object_pools/blockchain_dag.nim @@ -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(): diff --git a/beacon_chain/gossip_processing/gossip_validation.nim b/beacon_chain/gossip_processing/gossip_validation.nim index 916e340ade..14435b4a4c 100644 --- a/beacon_chain/gossip_processing/gossip_validation.nim +++ b/beacon_chain/gossip_processing/gossip_validation.nim @@ -2028,9 +2028,20 @@ 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 or one the parent block builds on + # (withheld), whose `gas_limit` can differ from the parent block's bid. + let parentPayloadBlck = + dag.executionParent(parentBlck, bid.parent_block_hash).valueOr: + 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