Skip to content

Commit

Permalink
fix: add excess_blob_gas for first cancun block (#4700)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored Sep 21, 2023
1 parent a29f102 commit f00df57
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/payload/builder/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 cfg.spec_id == SpecId::CANCUN {
// 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,
Expand All @@ -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)
Expand Down

0 comments on commit f00df57

Please sign in to comment.