From da4bd50e2c94e6f2ddb9d5c4f88bf6173b161d74 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 20 Sep 2023 19:25:39 -0400 Subject: [PATCH 1/2] fix: add excess_blob_gas for first cancun block --- crates/payload/builder/src/payload.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/payload/builder/src/payload.rs b/crates/payload/builder/src/payload.rs index d63d694e54ff..4ce460d5e1a1 100644 --- a/crates/payload/builder/src/payload.rs +++ b/crates/payload/builder/src/payload.rs @@ -177,9 +177,24 @@ impl PayloadBuilderAttributes { // configure evm env based on parent block let mut cfg = CfgEnv::default(); cfg.chain_id = chain_spec.chain().id(); + // ensure we're not missing any timestamp based hardforks cfg.spec_id = revm_spec_by_timestamp_after_merge(chain_spec, self.timestamp); + // if the parent block did not have excess blob gas (i.e. it was pre-cancun), but it is + // cancun now, we need to set the excess blob gas to the default value + let excess_blob_gas = parent.next_block_blob_fee().map_or_else( + || { + if chain_spec.is_cancun_activated_at_timestamp(self.timestamp) { + // default excess blob gas is zero + Some(0) + } else { + None + } + }, + Some, + ); + let block_env = BlockEnv { number: U256::from(parent.number + 1), coinbase: self.suggested_fee_recipient, @@ -192,7 +207,7 @@ impl PayloadBuilderAttributes { parent.next_block_base_fee(chain_spec.base_fee_params).unwrap_or_default(), ), // calculate excess gas based on parent block's blob gas usage - excess_blob_gas: parent.next_block_blob_fee(), + excess_blob_gas, }; (cfg, block_env) From c0944c8b9113a506b30ab14c803e9196ca0c3f73 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 20 Sep 2023 20:29:32 -0400 Subject: [PATCH 2/2] use SpecId to select excess_blob_gas --- crates/payload/builder/src/payload.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/payload/builder/src/payload.rs b/crates/payload/builder/src/payload.rs index 4ce460d5e1a1..222af177b97a 100644 --- a/crates/payload/builder/src/payload.rs +++ b/crates/payload/builder/src/payload.rs @@ -13,7 +13,7 @@ use reth_rpc_types_compat::engine::payload::{ convert_block_to_payload_field_v2, convert_standalonewithdraw_to_withdrawal, try_block_to_payload_v1, try_block_to_payload_v3, }; -use revm_primitives::{BlockEnv, CfgEnv}; +use revm_primitives::{BlockEnv, CfgEnv, SpecId}; /// Contains the built payload. /// /// According to the [engine API specification](https://github.com/ethereum/execution-apis/blob/main/src/engine/README.md) the execution layer should build the initial version of the payload with an empty transaction set and then keep update it in order to maximize the revenue. @@ -185,7 +185,7 @@ impl PayloadBuilderAttributes { // cancun now, we need to set the excess blob gas to the default value let excess_blob_gas = parent.next_block_blob_fee().map_or_else( || { - if chain_spec.is_cancun_activated_at_timestamp(self.timestamp) { + if cfg.spec_id == SpecId::CANCUN { // default excess blob gas is zero Some(0) } else {