chore: remove tx_env_with_recovered from rpc crates (#9158)

This commit is contained in:
joshieDo
2024-06-28 17:43:55 +02:00
committed by GitHub
parent 5416adf97b
commit b24ca7637f
6 changed files with 64 additions and 28 deletions

View File

@ -12,10 +12,12 @@
#[cfg(not(feature = "std"))]
extern crate alloc;
use core::ops::Deref;
use reth_chainspec::ChainSpec;
use reth_primitives::{
revm::env::{fill_block_env, fill_tx_env},
Address, Header, TransactionSigned, U256,
Address, Header, TransactionSigned, TransactionSignedEcRecovered, U256,
};
use revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector};
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, SpecId, TxEnv};
@ -106,6 +108,13 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
/// Default trait method implementation is done w.r.t. L1.
#[auto_impl::auto_impl(&, Arc)]
pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
/// Returns a [`TxEnv`] from a [`TransactionSignedEcRecovered`].
fn tx_env(&self, transaction: &TransactionSignedEcRecovered) -> TxEnv {
let mut tx_env = TxEnv::default();
self.fill_tx_env(&mut tx_env, transaction.deref(), transaction.signer());
tx_env
}
/// Fill transaction environment from a [`TransactionSigned`] and the given sender address.
fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
fill_tx_env(tx_env, transaction, sender)

View File

@ -4,7 +4,6 @@
use futures::Future;
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::{
revm::env::tx_env_with_recovered,
revm_primitives::{
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ExecutionResult, HaltReason,
ResultAndState, TransactTo,
@ -119,9 +118,11 @@ pub trait EthCall: Call + LoadPendingBlock {
// to be replayed
let transactions = block.into_transactions_ecrecovered().take(num_txs);
for tx in transactions {
let tx = tx_env_with_recovered(&tx);
let env =
EnvWithHandlerCfg::new_with_cfg_env(cfg.clone(), block_env.clone(), tx);
let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg.clone(),
block_env.clone(),
Call::evm_config(&this).tx_env(&tx),
);
let (res, _) = this.transact(&mut db, env)?;
db.commit(res.state);
}
@ -422,8 +423,11 @@ pub trait Call: LoadState + SpawnBlocking {
tx.hash,
)?;
let env =
EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, tx_env_with_recovered(&tx));
let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg,
block_env,
Call::evm_config(&this).tx_env(&tx),
);
let (res, _) = this.transact(&mut db, env)?;
f(tx_info, res, db)

View File

@ -5,12 +5,11 @@ use std::time::{Duration, Instant};
use futures::Future;
use reth_chainspec::EthereumHardforks;
use reth_evm::ConfigureEvm;
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_execution_types::ExecutionOutcome;
use reth_primitives::{
constants::{eip4844::MAX_DATA_GAS_PER_BLOCK, BEACON_NONCE, EMPTY_ROOT_HASH},
proofs::calculate_transaction_root,
revm::env::tx_env_with_recovered,
revm_primitives::{
BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, EVMError, Env, ExecutionResult, InvalidTransaction,
ResultAndState, SpecId,
@ -292,8 +291,11 @@ pub trait LoadPendingBlock {
}
// Configure the environment for the block.
let env =
Env::boxed(cfg.cfg_env.clone(), block_env.clone(), tx_env_with_recovered(&tx));
let env = Env::boxed(
cfg.cfg_env.clone(),
block_env.clone(),
Self::evm_config(self).tx_env(&tx),
);
let mut evm = revm::Evm::builder().with_env(env).with_db(&mut db).build();

View File

@ -1,8 +1,8 @@
//! Loads a pending block from database. Helper trait for `eth_` call and trace RPC methods.
use futures::Future;
use reth_evm::ConfigureEvm;
use reth_primitives::{revm::env::tx_env_with_recovered, B256};
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::B256;
use reth_revm::database::StateProviderDatabase;
use reth_rpc_eth_types::{
cache::db::{StateCacheDb, StateCacheDbRefMutWrapper, StateProviderTraitObjWrapper},
@ -196,8 +196,11 @@ pub trait Trace: LoadState {
tx.hash,
)?;
let env =
EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, tx_env_with_recovered(&tx));
let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg,
block_env,
Call::evm_config(&this).tx_env(&tx),
);
let (res, _) =
this.inspect(StateCacheDbRefMutWrapper(&mut db), env, &mut inspector)?;
f(tx_info, inspector, res, db)
@ -308,7 +311,7 @@ pub trait Trace: LoadState {
block_number: Some(block_number),
base_fee: Some(base_fee),
};
let tx_env = tx_env_with_recovered(&tx);
let tx_env = Trace::evm_config(&this).tx_env(&tx);
(tx_info, tx_env)
})
.peekable();

View File

@ -4,9 +4,10 @@ use alloy_rlp::{Decodable, Encodable};
use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use reth_chainspec::EthereumHardforks;
use reth_evm::ConfigureEvmEnv;
use reth_primitives::{
revm::env::tx_env_with_recovered, Address, Block, BlockId, BlockNumberOrTag, Bytes,
TransactionSignedEcRecovered, Withdrawals, B256, U256,
Address, Block, BlockId, BlockNumberOrTag, Bytes, TransactionSignedEcRecovered, Withdrawals,
B256, U256,
};
use reth_provider::{
BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, HeaderProvider, StateProviderFactory,
@ -14,7 +15,7 @@ use reth_provider::{
};
use reth_revm::database::StateProviderDatabase;
use reth_rpc_api::DebugApiServer;
use reth_rpc_eth_api::helpers::{EthApiSpec, EthTransactions, TraceExt};
use reth_rpc_eth_api::helpers::{Call, EthApiSpec, EthTransactions, TraceExt};
use reth_rpc_eth_types::{revm_utils::prepare_call_env, EthApiError, EthResult, StateCacheDb};
use reth_rpc_server_types::{result::internal_rpc_err, ToRpcResult};
use reth_rpc_types::{
@ -99,9 +100,13 @@ where
let mut transactions = transactions.into_iter().enumerate().peekable();
while let Some((index, tx)) = transactions.next() {
let tx_hash = tx.hash;
let tx = tx_env_with_recovered(&tx);
let env = EnvWithHandlerCfg {
env: Env::boxed(cfg.cfg_env.clone(), block_env.clone(), tx),
env: Env::boxed(
cfg.cfg_env.clone(),
block_env.clone(),
Call::evm_config(this.eth_api()).tx_env(&tx),
),
handler_cfg: cfg.handler_cfg,
};
let (result, state_changes) = this.trace_transaction(
@ -240,7 +245,11 @@ where
)?;
let env = EnvWithHandlerCfg {
env: Env::boxed(cfg.cfg_env.clone(), block_env, tx_env_with_recovered(&tx)),
env: Env::boxed(
cfg.cfg_env.clone(),
block_env,
Call::evm_config(this.eth_api()).tx_env(&tx),
),
handler_cfg: cfg.handler_cfg,
};
@ -453,6 +462,7 @@ where
}
let this = self.clone();
self.inner
.eth_api
.spawn_with_state_at_block(at.into(), move |state| {
@ -467,9 +477,12 @@ where
// Execute all transactions until index
for tx in transactions {
let tx = tx_env_with_recovered(&tx);
let env = EnvWithHandlerCfg {
env: Env::boxed(cfg.cfg_env.clone(), block_env.clone(), tx),
env: Env::boxed(
cfg.cfg_env.clone(),
block_env.clone(),
Call::evm_config(this.eth_api()).tx_env(&tx),
),
handler_cfg: cfg.handler_cfg,
};
let (res, _) = this.inner.eth_api.transact(&mut db, env)?;

View File

@ -6,11 +6,12 @@ use reth_chainspec::EthereumHardforks;
use reth_consensus_common::calc::{
base_block_reward, base_block_reward_pre_merge, block_reward, ommer_reward,
};
use reth_primitives::{revm::env::tx_env_with_recovered, BlockId, Bytes, Header, B256, U256};
use reth_evm::ConfigureEvmEnv;
use reth_primitives::{BlockId, Bytes, Header, B256, U256};
use reth_provider::{BlockReader, ChainSpecProvider, EvmEnvProvider, StateProviderFactory};
use reth_revm::database::StateProviderDatabase;
use reth_rpc_api::TraceApiServer;
use reth_rpc_eth_api::helpers::TraceExt;
use reth_rpc_eth_api::helpers::{Call, TraceExt};
use reth_rpc_eth_types::{
error::{EthApiError, EthResult},
revm_utils::prepare_call_env,
@ -113,8 +114,12 @@ where
let tx = recover_raw_transaction(tx)?;
let (cfg, block, at) = self.inner.eth_api.evm_env_at(block_id.unwrap_or_default()).await?;
let tx = tx_env_with_recovered(&tx.into_ecrecovered_transaction());
let env = EnvWithHandlerCfg::new_with_cfg_env(cfg, block, tx);
let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg,
block,
Call::evm_config(self.eth_api()).tx_env(&tx.into_ecrecovered_transaction()),
);
let config = TracingInspectorConfig::from_parity_config(&trace_types);