-
Notifications
You must be signed in to change notification settings - Fork 176
fix context create for onchain blocks #828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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, | ||||||||
|
|
@@ -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; | ||||||||
|
|
@@ -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"); | ||||||||
| evm_env.block_env.beneficiary = beneficiary; | ||||||||
|
||||||||
| evm_env.block_env.beneficiary = beneficiary; | |
| evm_env.block_env.beneficiary = beneficiary; | |
| evm_env.cfg_env.tx_chain_id_check = true; |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
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.
| assert_eq!(evm_env.block_env.number, U256::from(block_number)); | |
| debug_assert_eq!(evm_env.block_env.number, U256::from(block_number)); |
There was a problem hiding this comment.
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. Infrom_attributes(line 176), a similar call tonext_evm_envuses.ok()?to gracefully returnNoneon error, but here.expect()will panic. Consider changing the return type toOption<BlockBuildingContext>and using.ok()?instead, or provide a more descriptive error message explaining what conditions could cause this to fail.