Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDhejavu committed Dec 13, 2024
1 parent f586549 commit eca90aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
6 changes: 4 additions & 2 deletions crates/optimism/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use op_alloy_consensus::DepositTransaction;
use reth_chainspec::EthereumHardforks;
use reth_consensus::ConsensusError;
use reth_evm::{
env::EvmEnv,
execute::{
balance_increment_state, BasicBlockExecutorProvider, BlockExecutionError,
BlockExecutionStrategy, BlockExecutionStrategyFactory, BlockValidationError, ExecuteOutput,
Expand Down Expand Up @@ -111,8 +112,9 @@ where
///
/// Caution: this does not initialize the tx environment.
fn evm_env_for_block(&self, header: &Header, total_difficulty: U256) -> EnvWithHandlerCfg {
let (cfg, block_env) = self.evm_config.cfg_and_block_env(header, total_difficulty);
EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, Default::default())
let evm_env = self.evm_config.cfg_and_block_env(header, total_difficulty);
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
EnvWithHandlerCfg::new_with_cfg_env(cfg_env_with_handler_cfg, block_env, Default::default())
}
}

Expand Down
13 changes: 7 additions & 6 deletions crates/optimism/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use alloc::{sync::Arc, vec::Vec};
use alloy_consensus::Header;
use alloy_primitives::{Address, U256};
use op_alloy_consensus::EIP1559ParamError;
use reth_evm::{ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes};
use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes};
use reth_optimism_chainspec::OpChainSpec;
use reth_primitives::{transaction::FillTxEnv, Head, TransactionSigned};
use reth_revm::{
Expand Down Expand Up @@ -138,7 +138,7 @@ impl ConfigureEvmEnv for OpEvmConfig {
&self,
parent: &Self::Header,
attributes: NextBlockEnvAttributes,
) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), Self::Error> {
) -> Result<EvmEnv, Self::Error> {
// configure evm env based on parent block
let cfg = CfgEnv::default().with_chain_id(self.chain_spec.chain().id());

Expand Down Expand Up @@ -173,7 +173,7 @@ impl ConfigureEvmEnv for OpEvmConfig {
};
}

Ok((cfg_env_with_handler_cfg, block_env))
Ok((cfg_env_with_handler_cfg, block_env).into())
}
}

Expand Down Expand Up @@ -251,12 +251,13 @@ mod tests {

// Use the `OpEvmConfig` to create the `cfg_env` and `block_env` based on the ChainSpec,
// Header, and total difficulty
let (cfg_env, _) = OpEvmConfig::new(Arc::new(OpChainSpec { inner: chain_spec.clone() }))
.cfg_and_block_env(&header, total_difficulty);
let EvmEnv { cfg_env_with_handler_cfg, .. } =
OpEvmConfig::new(Arc::new(OpChainSpec { inner: chain_spec.clone() }))
.cfg_and_block_env(&header, total_difficulty);

// Assert that the chain ID in the `cfg_env` is correctly set to the chain ID of the
// ChainSpec
assert_eq!(cfg_env.chain_id, chain_spec.chain().id());
assert_eq!(cfg_env_with_handler_cfg.chain_id, chain_spec.chain().id());
}

#[test]
Expand Down
20 changes: 11 additions & 9 deletions crates/optimism/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use op_alloy_rpc_types_engine::OpPayloadAttributes;
use reth_basic_payload_builder::*;
use reth_chain_state::ExecutedBlock;
use reth_chainspec::{ChainSpecProvider, EthereumHardforks};
use reth_evm::{system_calls::SystemCaller, ConfigureEvm, NextBlockEnvAttributes};
use reth_evm::{env::EvmEnv, system_calls::SystemCaller, ConfigureEvm, NextBlockEnvAttributes};
use reth_execution_types::ExecutionOutcome;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism;
Expand Down Expand Up @@ -124,18 +124,19 @@ where
Client: StateProviderFactory + ChainSpecProvider<ChainSpec = OpChainSpec>,
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TransactionSigned>>,
{
let (initialized_cfg, initialized_block_env) = self
let evm_env = self
.cfg_and_block_env(&args.config.attributes, &args.config.parent_header)
.map_err(PayloadBuilderError::other)?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;

let BuildArguments { client, pool, mut cached_reads, config, cancel, best_payload } = args;

let ctx = OpPayloadBuilderCtx {
evm_config: self.evm_config.clone(),
chain_spec: client.chain_spec(),
config,
initialized_cfg,
initialized_block_env,
initialized_cfg: cfg_env_with_handler_cfg,
initialized_block_env: block_env,
cancel,
best_payload,
};
Expand Down Expand Up @@ -164,13 +165,13 @@ impl<EvmConfig, Txs> OpPayloadBuilder<EvmConfig, Txs>
where
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
{
/// Returns the configured [`CfgEnvWithHandlerCfg`] and [`BlockEnv`] for the targeted payload
/// Returns the configured [`EvmEnv`] for the targeted payload
/// (that has the `parent` as its parent).
pub fn cfg_and_block_env(
&self,
attributes: &OpPayloadBuilderAttributes,
parent: &Header,
) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), EvmConfig::Error> {
) -> Result<EvmEnv, EvmConfig::Error> {
let next_attributes = NextBlockEnvAttributes {
timestamp: attributes.timestamp(),
suggested_fee_recipient: attributes.suggested_fee_recipient(),
Expand All @@ -193,16 +194,17 @@ where
let attributes = OpPayloadBuilderAttributes::try_new(parent.hash(), attributes, 3)
.map_err(PayloadBuilderError::other)?;

let (initialized_cfg, initialized_block_env) =
let evm_env =
self.cfg_and_block_env(&attributes, &parent).map_err(PayloadBuilderError::other)?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;

let config = PayloadConfig { parent_header: Arc::new(parent), attributes };
let ctx = OpPayloadBuilderCtx {
evm_config: self.evm_config.clone(),
chain_spec: client.chain_spec(),
config,
initialized_cfg,
initialized_block_env,
initialized_cfg: cfg_env_with_handler_cfg,
initialized_block_env: block_env,
cancel: Default::default(),
best_payload: Default::default(),
};
Expand Down

0 comments on commit eca90aa

Please sign in to comment.