Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
43 changes: 8 additions & 35 deletions crates/rbuilder/src/building/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
utils::{
a2r_withdrawal,
constants::BASE_TX_GAS,
default_cfg_env, elapsed_ms,
elapsed_ms,
receipts::{
calculate_receipts_data, calculate_tx_root_and_placeholder_proof, ReceiptsData,
ReceiptsDataCache, TransactionRootCache,
Expand Down Expand Up @@ -55,9 +55,7 @@ use reth_payload_builder::EthPayloadBuilderAttributes;
use reth_primitives::BlockBody;
use reth_primitives_traits::{proofs, Block as _};
use revm::{
context::BlockEnv,
context_interface::{block::BlobExcessGasAndPrice, result::InvalidTransaction},
database::states::bundle_state::BundleRetention,
context_interface::result::InvalidTransaction, database::states::bundle_state::BundleRetention,
primitives::hardfork::SpecId,
};
use serde::Deserialize;
Expand Down Expand Up @@ -252,37 +250,12 @@ impl BlockBuildingContext {
mev_blocker_price: U256,
) -> BlockBuildingContext {
let block_number = onchain_block.header.number;

let blob_excess_gas_and_price =
if chain_spec.is_cancun_active_at_timestamp(onchain_block.header.timestamp) {
Some(BlobExcessGasAndPrice::new(
onchain_block.header.excess_blob_gas.unwrap_or_default(),
chain_spec
.blob_params_at_timestamp(onchain_block.header.timestamp)
.unwrap_or(BlobParams::cancun())
.update_fraction
.try_into()
.expect("update_fraction too large for u64"),
))
} else {
None
};
let block_env = BlockEnv {
number: U256::from(block_number),
beneficiary,
timestamp: U256::from(onchain_block.header.timestamp),
difficulty: onchain_block.header.difficulty,
prevrandao: Some(onchain_block.header.mix_hash),
basefee: onchain_block
.header
.base_fee_per_gas
.expect("Failed to get basefee"), // TODO: improve
gas_limit: onchain_block.header.gas_limit,
blob_excess_gas_and_price,
};
let cfg = default_cfg_env(&chain_spec, timestamp_as_u64(&onchain_block), block_number);
// @TODO: revise
let evm_env = EvmEnv::from((cfg, block_env));
let eth_evm_config = EthEvmConfig::new(chain_spec.clone());
let mut evm_env = eth_evm_config
.evm_env(&onchain_block.header)
.expect("evm env config");
Comment on lines +254 to +256
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling here is inconsistent with from_attributes. In from_attributes (line 176), a similar call to next_evm_env uses .ok()? to gracefully return None on error, but here .expect() will panic. Consider changing the return type to Option<BlockBuildingContext> and using .ok()? instead, or provide a more descriptive error message explaining what conditions could cause this to fail.

Copilot uses AI. Check for mistakes.
evm_env.block_env.beneficiary = beneficiary;
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing evm_env.cfg_env.tx_chain_id_check = true; configuration that exists in the from_attributes method (line 177). This inconsistency could lead to different EVM behavior for chain ID validation between blocks created from attributes vs onchain blocks. Consider adding this configuration after modifying the beneficiary to ensure consistent behavior.

Suggested change
evm_env.block_env.beneficiary = beneficiary;
evm_env.block_env.beneficiary = beneficiary;
evm_env.cfg_env.tx_chain_id_check = true;

Copilot uses AI. Check for mistakes.
assert_eq!(evm_env.block_env.number, U256::from(block_number));
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion verifies that evm_env.block_env.number matches the expected block number, which is good for catching configuration issues early. However, consider whether a runtime assertion is appropriate here or if this should be a debug assertion (debug_assert_eq!) for production builds, given that from_attributes doesn't perform similar verification.

Suggested change
assert_eq!(evm_env.block_env.number, U256::from(block_number));
debug_assert_eq!(evm_env.block_env.number, U256::from(block_number));

Copilot uses AI. Check for mistakes.

let withdrawals = Withdrawals::new(
onchain_block
Expand Down
3 changes: 3 additions & 0 deletions crates/rbuilder/src/building/payout_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ mod tests {
block.header.base_fee_per_gas = Some(INITIAL_BASE_FEE);
block.header.timestamp = cancun_timestamp + 1;
block.header.gas_limit = 30_000_000;
block.header.mix_hash = B256::random();
block.header.number = EthereumHardfork::Prague.mainnet_activation_block().unwrap();
block.header.excess_blob_gas = Some(1000);
let ctx = BlockBuildingContext::from_onchain_block(
block,
chain_spec,
Expand Down
Loading