Skip to content

Commit

Permalink
Remove trait method Call::evm_config (#12095)
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane authored Oct 26, 2024
1 parent b257408 commit 1bdf429
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 40 deletions.
11 changes: 3 additions & 8 deletions crates/optimism/rpc/src/eth/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use reth_primitives::{
};
use reth_rpc_eth_api::{
helpers::{Call, EthCall, LoadState, SpawnBlocking},
FromEthApiError, IntoEthApiError,
FromEthApiError, IntoEthApiError, RpcNodeCore,
};
use reth_rpc_eth_types::{revm_utils::CallFees, RpcInvalidTransactionError};

Expand All @@ -24,9 +24,9 @@ where

impl<N> Call for OpEthApi<N>
where
Self: LoadState + SpawnBlocking,
N: RpcNodeCore,
Self: LoadState<Evm: ConfigureEvm<Header = Header>> + SpawnBlocking,
Self::Error: From<OpEthApiError>,
N: FullNodeComponents,
{
#[inline]
fn call_gas_limit(&self) -> u64 {
Expand All @@ -38,11 +38,6 @@ where
self.inner.max_simulate_blocks()
}

#[inline]
fn evm_config(&self) -> &impl ConfigureEvm<Header = Header> {
self.inner.evm_config()
}

fn create_txn_env(
&self,
block_env: &BlockEnv,
Expand Down
20 changes: 8 additions & 12 deletions crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use crate::{
AsEthApiError, FromEthApiError, FromEvmError, FullEthApiTypes, IntoEthApiError, RpcBlock,
RpcNodeCore,
};
use alloy_eips::{eip1559::calc_next_block_base_fee, eip2930::AccessListResult};
use alloy_primitives::{Address, Bytes, TxKind, B256, U256};
Expand Down Expand Up @@ -300,7 +301,7 @@ pub trait EthCall: Call + LoadPendingBlock {
let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg.clone(),
block_env.clone(),
Call::evm_config(&this).tx_env(tx, *signer),
RpcNodeCore::evm_config(&this).tx_env(tx, *signer),
);
let (res, _) = this.transact(&mut db, env)?;
db.commit(res.state);
Expand Down Expand Up @@ -452,7 +453,7 @@ pub trait EthCall: Call + LoadPendingBlock {
}

/// Executes code on state.
pub trait Call: LoadState + SpawnBlocking {
pub trait Call: LoadState<Evm: ConfigureEvm<Header = Header>> + SpawnBlocking {
/// Returns default gas limit to use for `eth_call` and tracing RPC methods.
///
/// Data access in default trait method implementations.
Expand All @@ -461,11 +462,6 @@ pub trait Call: LoadState + SpawnBlocking {
/// Returns the maximum number of blocks accepted for `eth_simulateV1`.
fn max_simulate_blocks(&self) -> u64;

/// Returns a handle for reading evm config.
///
/// Data access in default (L1) trait method implementations.
fn evm_config(&self) -> &impl ConfigureEvm<Header = Header>;

/// Executes the closure with the state that corresponds to the given [`BlockId`].
fn with_state_at_block<F, R>(&self, at: BlockId, f: F) -> Result<R, Self::Error>
where
Expand All @@ -486,7 +482,7 @@ pub trait Call: LoadState + SpawnBlocking {
DB: Database,
EthApiError: From<DB::Error>,
{
let mut evm = Call::evm_config(self).evm_with_env(db, env);
let mut evm = self.evm_config().evm_with_env(db, env);
let res = evm.transact().map_err(Self::Error::from_evm_err)?;
let (_, env) = evm.into_db_and_env_with_handler_cfg();
Ok((res, env))
Expand All @@ -504,7 +500,7 @@ pub trait Call: LoadState + SpawnBlocking {
DB: Database,
EthApiError: From<DB::Error>,
{
let mut evm = Call::evm_config(self).evm_with_env_and_inspector(db, env, inspector);
let mut evm = self.evm_config().evm_with_env_and_inspector(db, env, inspector);
let res = evm.transact().map_err(Self::Error::from_evm_err)?;
let (_, env) = evm.into_db_and_env_with_handler_cfg();
Ok((res, env))
Expand Down Expand Up @@ -636,7 +632,7 @@ pub trait Call: LoadState + SpawnBlocking {
let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg,
block_env,
Call::evm_config(&this).tx_env(tx.as_signed(), tx.signer()),
RpcNodeCore::evm_config(&this).tx_env(tx.as_signed(), tx.signer()),
);

let (res, _) = this.transact(&mut db, env)?;
Expand Down Expand Up @@ -669,15 +665,15 @@ pub trait Call: LoadState + SpawnBlocking {
{
let env = EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, Default::default());

let mut evm = Call::evm_config(self).evm_with_env(db, env);
let mut evm = self.evm_config().evm_with_env(db, env);
let mut index = 0;
for (sender, tx) in transactions {
if tx.hash() == target_tx_hash {
// reached the target transaction
break
}

Call::evm_config(self).fill_tx_env(evm.tx_mut(), tx, *sender);
self.evm_config().fill_tx_env(evm.tx_mut(), tx, *sender);
evm.transact_commit().map_err(Self::Error::from_evm_err)?;
index += 1;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-api/src/helpers/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub trait Trace: LoadState {
let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg,
block_env,
Call::evm_config(&this).tx_env(tx.as_signed(), tx.signer()),
RpcNodeCore::evm_config(&this).tx_env(tx.as_signed(), tx.signer()),
);
let (res, _) =
this.inspect(StateCacheDbRefMutWrapper(&mut db), env, &mut inspector)?;
Expand Down
11 changes: 6 additions & 5 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use reth_provider::{
use reth_revm::database::StateProviderDatabase;
use reth_rpc_api::DebugApiServer;
use reth_rpc_eth_api::{
helpers::{Call, EthApiSpec, EthTransactions, TraceExt},
helpers::{EthApiSpec, EthTransactions, TraceExt},
EthApiTypes, FromEthApiError, RpcNodeCore,
};
use reth_rpc_eth_types::{EthApiError, StateCacheDb};
Expand Down Expand Up @@ -120,7 +120,8 @@ where
env: Env::boxed(
cfg.cfg_env.clone(),
block_env.clone(),
Call::evm_config(this.eth_api()).tx_env(tx.as_signed(), tx.signer()),
RpcNodeCore::evm_config(this.eth_api())
.tx_env(tx.as_signed(), tx.signer()),
),
handler_cfg: cfg.handler_cfg,
};
Expand Down Expand Up @@ -263,7 +264,7 @@ where

// apply relevant system calls
let mut system_caller = SystemCaller::new(
Call::evm_config(this.eth_api()).clone(),
RpcNodeCore::evm_config(this.eth_api()).clone(),
RpcNodeCore::provider(this.eth_api()).chain_spec(),
);

Expand Down Expand Up @@ -293,7 +294,7 @@ where
env: Env::boxed(
cfg.cfg_env.clone(),
block_env,
Call::evm_config(this.eth_api()).tx_env(tx.as_signed(), tx.signer()),
RpcNodeCore::evm_config(this.eth_api()).tx_env(tx.as_signed(), tx.signer()),
),
handler_cfg: cfg.handler_cfg,
};
Expand Down Expand Up @@ -562,7 +563,7 @@ where
env: Env::boxed(
cfg.cfg_env.clone(),
block_env.clone(),
Call::evm_config(this.eth_api()).tx_env(tx, *signer),
RpcNodeCore::evm_config(this.eth_api()).tx_env(tx, *signer),
),
handler_cfg: cfg.handler_cfg,
};
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/rpc/src/eth/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use reth_primitives::{
PooledTransactionsElement,
};
use reth_revm::database::StateProviderDatabase;
use reth_rpc_eth_api::{FromEthApiError, FromEvmError};
use reth_rpc_eth_api::{FromEthApiError, FromEvmError, RpcNodeCore};
use reth_tasks::pool::BlockingTaskGuard;
use revm::{
db::CacheDB,
Expand Down Expand Up @@ -166,7 +166,7 @@ where
let mut total_gas_fess = U256::ZERO;
let mut hasher = Keccak256::new();

let mut evm = Call::evm_config(&eth_api).evm_with_env(db, env);
let mut evm = RpcNodeCore::evm_config(&eth_api).evm_with_env(db, env);

let mut results = Vec::with_capacity(transactions.len());
let mut transactions = transactions.into_iter().peekable();
Expand All @@ -187,7 +187,7 @@ where
.effective_tip_per_gas(basefee)
.ok_or_else(|| RpcInvalidTransactionError::FeeCapTooLow)
.map_err(Eth::Error::from_eth_err)?;
Call::evm_config(&eth_api).fill_tx_env(evm.tx_mut(), &tx, signer);
RpcNodeCore::evm_config(&eth_api).fill_tx_env(evm.tx_mut(), &tx, signer);
let ResultAndState { result, state } =
evm.transact().map_err(Eth::Error::from_evm_err)?;

Expand Down
7 changes: 1 addition & 6 deletions crates/rpc/rpc/src/eth/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl<Provider, Pool, Network, EvmConfig> EthCall for EthApi<Provider, Pool, Netw

impl<Provider, Pool, Network, EvmConfig> Call for EthApi<Provider, Pool, Network, EvmConfig>
where
Self: LoadState + SpawnBlocking,
Self: LoadState<Evm: ConfigureEvm<Header = Header>> + SpawnBlocking,
EvmConfig: ConfigureEvm<Header = Header>,
{
#[inline]
Expand All @@ -25,9 +25,4 @@ where
fn max_simulate_blocks(&self) -> u64 {
self.inner.max_simulate_blocks()
}

#[inline]
fn evm_config(&self) -> &impl ConfigureEvm<Header = Header> {
self.inner.evm_config()
}
}
7 changes: 2 additions & 5 deletions crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ use reth_primitives::{BlockId, Header};
use reth_provider::{BlockReader, ChainSpecProvider, EvmEnvProvider, StateProviderFactory};
use reth_revm::database::StateProviderDatabase;
use reth_rpc_api::TraceApiServer;
use reth_rpc_eth_api::{
helpers::{Call, TraceExt},
FromEthApiError,
};
use reth_rpc_eth_api::{helpers::TraceExt, FromEthApiError, RpcNodeCore};
use reth_rpc_eth_types::{error::EthApiError, utils::recover_raw_transaction};
use reth_tasks::pool::BlockingTaskGuard;
use revm::{
Expand Down Expand Up @@ -124,7 +121,7 @@ where
let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg,
block,
Call::evm_config(self.eth_api()).tx_env(tx.as_signed(), tx.signer()),
RpcNodeCore::evm_config(self.eth_api()).tx_env(tx.as_signed(), tx.signer()),
);

let config = TracingInspectorConfig::from_parity_config(&trace_types);
Expand Down

0 comments on commit 1bdf429

Please sign in to comment.