Skip to content

Commit 56ed575

Browse files
authored
chore(rpc): remove FillableTransaction (#8800)
1 parent 9c579e1 commit 56ed575

File tree

15 files changed

+79
-148
lines changed

15 files changed

+79
-148
lines changed

crates/ethereum/evm/src/execute.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ where
173173
.into())
174174
}
175175

176-
EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender);
176+
self.evm_config.fill_tx_env(evm.tx_mut(), transaction, *sender);
177177

178178
// Execute transaction.
179179
let ResultAndState { result, state } = evm.transact().map_err(move |err| {

crates/ethereum/evm/src/lib.rs

+6-34
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
1010

1111
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
12-
use reth_primitives::{
13-
revm::{config::revm_spec, env::fill_tx_env},
14-
revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, TxEnv},
15-
Address, ChainSpec, Head, Header, TransactionSigned, U256,
16-
};
1712
use reth_revm::{Database, EvmBuilder};
1813

1914
pub mod execute;
@@ -29,34 +24,7 @@ pub mod eip6110;
2924
#[non_exhaustive]
3025
pub struct EthEvmConfig;
3126

32-
impl ConfigureEvmEnv for EthEvmConfig {
33-
fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
34-
fill_tx_env(tx_env, transaction, sender)
35-
}
36-
37-
fn fill_cfg_env(
38-
cfg_env: &mut CfgEnvWithHandlerCfg,
39-
chain_spec: &ChainSpec,
40-
header: &Header,
41-
total_difficulty: U256,
42-
) {
43-
let spec_id = revm_spec(
44-
chain_spec,
45-
Head {
46-
number: header.number,
47-
timestamp: header.timestamp,
48-
difficulty: header.difficulty,
49-
total_difficulty,
50-
hash: Default::default(),
51-
},
52-
);
53-
54-
cfg_env.chain_id = chain_spec.chain().id();
55-
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;
56-
57-
cfg_env.handler_cfg.spec_id = spec_id;
58-
}
59-
}
27+
impl ConfigureEvmEnv for EthEvmConfig {}
6028

6129
impl ConfigureEvm for EthEvmConfig {
6230
type DefaultExternalContext<'a> = ();
@@ -72,7 +40,11 @@ impl ConfigureEvm for EthEvmConfig {
7240
#[cfg(test)]
7341
mod tests {
7442
use super::*;
75-
use reth_primitives::revm_primitives::{BlockEnv, CfgEnv, SpecId};
43+
use reth_primitives::{
44+
revm_primitives::{BlockEnv, CfgEnv, SpecId},
45+
ChainSpec, Header, U256,
46+
};
47+
use revm_primitives::CfgEnvWithHandlerCfg;
7648

7749
#[test]
7850
#[ignore]

crates/evm/src/lib.rs

+30-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
1010

1111
use reth_primitives::{
12-
revm::env::fill_block_env, Address, ChainSpec, Header, TransactionSigned, U256,
12+
revm::{
13+
config::revm_spec,
14+
env::{fill_block_env, fill_tx_env},
15+
},
16+
Address, ChainSpec, Head, Header, TransactionSigned, U256,
1317
};
1418
use revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector};
15-
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, SpecId, TxEnv};
19+
use revm_primitives::{
20+
AnalysisKind, BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, SpecId, TxEnv,
21+
};
1622

1723
pub mod either;
1824
pub mod execute;
@@ -96,18 +102,38 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
96102

97103
/// This represents the set of methods used to configure the EVM's environment before block
98104
/// execution.
105+
///
106+
/// Default trait method implementation is done w.r.t. L1.
99107
#[auto_impl::auto_impl(&, Arc)]
100108
pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
101109
/// Fill transaction environment from a [`TransactionSigned`] and the given sender address.
102-
fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address);
110+
fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
111+
fill_tx_env(tx_env, transaction, sender)
112+
}
103113

104114
/// Fill [`CfgEnvWithHandlerCfg`] fields according to the chain spec and given header
105115
fn fill_cfg_env(
106116
cfg_env: &mut CfgEnvWithHandlerCfg,
107117
chain_spec: &ChainSpec,
108118
header: &Header,
109119
total_difficulty: U256,
110-
);
120+
) {
121+
let spec_id = revm_spec(
122+
chain_spec,
123+
Head {
124+
number: header.number,
125+
timestamp: header.timestamp,
126+
difficulty: header.difficulty,
127+
total_difficulty,
128+
hash: Default::default(),
129+
},
130+
);
131+
132+
cfg_env.chain_id = chain_spec.chain().id();
133+
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;
134+
135+
cfg_env.handler_cfg.spec_id = spec_id;
136+
}
111137

112138
/// Convenience function to call both [`fill_cfg_env`](ConfigureEvmEnv::fill_cfg_env) and
113139
/// [`fill_block_env`].

crates/optimism/evm/src/execute.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ where
175175
.transpose()
176176
.map_err(|_| OptimismBlockExecutionError::AccountLoadFailed(*sender))?;
177177

178-
EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender);
178+
self.evm_config.fill_tx_env(evm.tx_mut(), transaction, *sender);
179179

180180
// Execute transaction.
181181
let ResultAndState { result, state } = evm.transact().map_err(move |err| {

crates/optimism/evm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub use error::OptimismBlockExecutionError;
3131
pub struct OptimismEvmConfig;
3232

3333
impl ConfigureEvmEnv for OptimismEvmConfig {
34-
fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
34+
fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
3535
let mut buf = Vec::with_capacity(transaction.length_without_header());
3636
transaction.encode_enveloped(&mut buf);
3737
fill_op_tx_env(tx_env, transaction, sender, buf.into());

crates/optimism/rpc/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ workspace = true
1515
# reth
1616
reth-evm.workspace = true
1717
reth-evm-optimism = { workspace = true, features = ["optimism"] }
18-
revm.workspace = true
18+
revm = { workspace = true, features = ["optimism"] }
1919
reth-network-api.workspace = true
2020
reth-rpc = { workspace = true, features = ["optimism"] }
2121
reth-rpc-api.workspace = true
2222
reth-rpc-types.workspace = true
2323
reth-primitives = { workspace = true, features = ["optimism"] }
24-
reth-provider.workspace = true
24+
reth-provider = { workspace = true, features = ["optimism"] }
2525
reth-transaction-pool.workspace = true
2626
reth-tasks.workspace = true
2727

crates/rpc/rpc-builder/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
//! Pool: TransactionPool + Clone + 'static,
4848
//! Network: NetworkInfo + Peers + Clone + 'static,
4949
//! Events: CanonStateSubscriptions + Clone + 'static,
50-
//! EvmConfig: ConfigureEvm + 'static,
50+
//! EvmConfig: ConfigureEvm,
5151
//! {
5252
//! // configure the rpc module per transport
5353
//! let transports = TransportRpcModuleConfig::default().with_http(vec![
@@ -115,7 +115,7 @@
115115
//! Events: CanonStateSubscriptions + Clone + 'static,
116116
//! EngineApi: EngineApiServer<EngineT>,
117117
//! EngineT: EngineTypes + 'static,
118-
//! EvmConfig: ConfigureEvm + 'static,
118+
//! EvmConfig: ConfigureEvm,
119119
//! {
120120
//! // configure the rpc module per transport
121121
//! let transports = TransportRpcModuleConfig::default().with_http(vec![
@@ -256,7 +256,7 @@ where
256256
Network: NetworkInfo + Peers + Clone + 'static,
257257
Tasks: TaskSpawner + Clone + 'static,
258258
Events: CanonStateSubscriptions + Clone + 'static,
259-
EvmConfig: ConfigureEvm + 'static,
259+
EvmConfig: ConfigureEvm,
260260
{
261261
let module_config = module_config.into();
262262
let server_config = server_config.into();
@@ -447,7 +447,7 @@ where
447447
Network: NetworkInfo + Peers + Clone + 'static,
448448
Tasks: TaskSpawner + Clone + 'static,
449449
Events: CanonStateSubscriptions + Clone + 'static,
450-
EvmConfig: ConfigureEvm + 'static,
450+
EvmConfig: ConfigureEvm,
451451
{
452452
/// Configures all [`RpcModule`]s specific to the given [`TransportRpcModuleConfig`] which can
453453
/// be used to start the transport server(s).
@@ -772,7 +772,7 @@ where
772772
Network: NetworkInfo + Peers + Clone + 'static,
773773
Tasks: TaskSpawner + Clone + 'static,
774774
Events: CanonStateSubscriptions + Clone + 'static,
775-
EvmConfig: ConfigureEvm + 'static,
775+
EvmConfig: ConfigureEvm,
776776
{
777777
/// Register Eth Namespace
778778
///

crates/rpc/rpc/src/eth/api/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ where
221221
Provider:
222222
BlockReaderIdExt + ChainSpecProvider + StateProviderFactory + EvmEnvProvider + 'static,
223223
Network: NetworkInfo + 'static,
224-
EvmConfig: ConfigureEvm + 'static,
224+
EvmConfig: ConfigureEvm,
225225
{
226226
/// Returns the current ethereum protocol version.
227227
///

crates/rpc/rpc/src/eth/api/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ where
4040
+ EvmEnvProvider
4141
+ 'static,
4242
Network: NetworkInfo + Send + Sync + 'static,
43-
EvmConfig: ConfigureEvm + 'static,
43+
EvmConfig: ConfigureEvm,
4444
{
4545
/// Handler for: `eth_protocolVersion`
4646
async fn protocol_version(&self) -> Result<U64> {

crates/rpc/rpc/src/eth/api/traits/call.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
//! methods.
33
44
use futures::Future;
5-
use reth_evm::ConfigureEvm;
6-
use reth_primitives::{revm::env::tx_env_with_recovered, Bytes, TxKind, B256, U256};
5+
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
6+
use reth_primitives::{
7+
revm::env::tx_env_with_recovered,
8+
revm_primitives::{
9+
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ExecutionResult, HaltReason,
10+
ResultAndState, TransactTo,
11+
},
12+
Bytes, TransactionSignedEcRecovered, TxKind, B256, U256,
13+
};
714
use reth_provider::StateProvider;
815
use reth_revm::{database::StateProviderDatabase, db::CacheDB, DatabaseRef};
916
use reth_rpc_types::{
@@ -12,10 +19,6 @@ use reth_rpc_types::{
1219
};
1320
use revm::{Database, DatabaseCommit};
1421
use revm_inspectors::access_list::AccessListInspector;
15-
use revm_primitives::{
16-
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ExecutionResult, HaltReason, ResultAndState,
17-
TransactTo,
18-
};
1922
use tracing::trace;
2023

2124
use crate::eth::{
@@ -24,7 +27,6 @@ use crate::eth::{
2427
revm_utils::{
2528
apply_state_overrides, build_call_evm_env, caller_gas_allowance,
2629
cap_tx_gas_limit_with_caller_allowance, get_precompiles, prepare_call_env, EvmOverrides,
27-
FillableTransaction,
2830
},
2931
};
3032

@@ -444,19 +446,17 @@ pub trait Call: LoadState + SpawnBlocking {
444446
///
445447
/// Note: This assumes the target transaction is in the given iterator.
446448
/// Returns the index of the target transaction in the given iterator.
447-
fn replay_transactions_until<DB, I, Tx>(
449+
fn replay_transactions_until<DB>(
448450
&self,
449451
db: &mut CacheDB<DB>,
450452
cfg: CfgEnvWithHandlerCfg,
451453
block_env: BlockEnv,
452-
transactions: I,
454+
transactions: impl IntoIterator<Item = TransactionSignedEcRecovered>,
453455
target_tx_hash: B256,
454456
) -> Result<usize, EthApiError>
455457
where
456458
DB: DatabaseRef,
457459
EthApiError: From<<DB as DatabaseRef>::Error>,
458-
I: IntoIterator<Item = Tx>,
459-
Tx: FillableTransaction,
460460
{
461461
let env = EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, Default::default());
462462

@@ -468,7 +468,8 @@ pub trait Call: LoadState + SpawnBlocking {
468468
break
469469
}
470470

471-
tx.try_fill_tx_env(evm.tx_mut())?;
471+
let sender = tx.signer();
472+
self.evm_config().fill_tx_env(evm.tx_mut(), &tx.into_signed(), sender);
472473
evm.transact_commit()?;
473474
index += 1;
474475
}

crates/rpc/rpc/src/eth/api/transactions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use reth_primitives::{TransactionSignedEcRecovered, B256};
44
use reth_rpc_types::{Transaction, TransactionInfo};
55
use reth_rpc_types_compat::transaction::from_recovered_with_block_context;
66

7-
use crate::{eth::revm_utils::FillableTransaction, EthApi};
7+
use crate::EthApi;
88

99
/// Implements [`EthTransactions`](crate::eth::api::EthTransactions) for a type, that has similar
1010
/// data layout to [`EthApi`].

crates/rpc/rpc/src/eth/bundle.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::sync::Arc;
44

55
use jsonrpsee::core::RpcResult;
6+
use reth_evm::ConfigureEvmEnv;
67
use reth_primitives::{
78
constants::eip4844::MAINNET_KZG_TRUSTED_SETUP,
89
keccak256,
@@ -22,7 +23,6 @@ use revm_primitives::{EnvWithHandlerCfg, MAX_BLOB_GAS_PER_BLOCK};
2223
use crate::eth::{
2324
api::{Call, EthTransactions, LoadPendingBlock},
2425
error::{EthApiError, EthResult, RpcInvalidTransactionError},
25-
revm_utils::FillableTransaction,
2626
utils::recover_raw_transaction,
2727
};
2828

@@ -101,6 +101,8 @@ where
101101
// use the block number of the request
102102
block_env.number = U256::from(block_number);
103103

104+
let eth_api = self.inner.eth_api.clone();
105+
104106
self.inner
105107
.eth_api
106108
.spawn_with_state_at_block(at, move |state| {
@@ -132,13 +134,13 @@ where
132134
.map_err(|e| EthApiError::InvalidParams(e.to_string()))?;
133135
}
134136

135-
let tx = tx.into_ecrecovered_transaction(signer);
137+
let tx = tx.into_transaction();
136138

137139
hash_bytes.extend_from_slice(tx.hash().as_slice());
138140
let gas_price = tx
139141
.effective_tip_per_gas(basefee)
140142
.ok_or_else(|| RpcInvalidTransactionError::FeeCapTooLow)?;
141-
tx.try_fill_tx_env(evm.tx_mut())?;
143+
Call::evm_config(&eth_api).fill_tx_env(evm.tx_mut(), &tx.clone(), signer);
142144
let ResultAndState { result, state } = evm.transact()?;
143145

144146
let gas_used = result.gas_used();
@@ -169,7 +171,7 @@ where
169171
let tx_res = EthCallBundleTransactionResult {
170172
coinbase_diff,
171173
eth_sent_to_coinbase,
172-
from_address: tx.signer(),
174+
from_address: signer,
173175
gas_fees,
174176
gas_price: U256::from(gas_price),
175177
gas_used,
@@ -215,7 +217,7 @@ where
215217
#[async_trait::async_trait]
216218
impl<Eth> EthCallBundleApiServer for EthBundle<Eth>
217219
where
218-
Eth: EthTransactions + 'static,
220+
Eth: EthTransactions + LoadPendingBlock + Call + 'static,
219221
{
220222
async fn call_bundle(&self, request: EthCallBundle) -> RpcResult<EthCallBundleResponse> {
221223
Ok(Self::call_bundle(self, request).await?)

crates/rpc/rpc/src/eth/cache/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl EthStateCache {
107107
) -> Self
108108
where
109109
Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static,
110-
EvmConfig: ConfigureEvm + 'static,
110+
EvmConfig: ConfigureEvm,
111111
{
112112
Self::spawn_with(provider, config, TokioTaskExecutor::default(), evm_config)
113113
}
@@ -125,7 +125,7 @@ impl EthStateCache {
125125
where
126126
Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static,
127127
Tasks: TaskSpawner + Clone + 'static,
128-
EvmConfig: ConfigureEvm + 'static,
128+
EvmConfig: ConfigureEvm,
129129
{
130130
let EthStateCacheConfig { max_blocks, max_receipts, max_envs, max_concurrent_db_requests } =
131131
config;
@@ -316,7 +316,7 @@ impl<Provider, Tasks, EvmConfig> EthStateCacheService<Provider, Tasks, EvmConfig
316316
where
317317
Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static,
318318
Tasks: TaskSpawner + Clone + 'static,
319-
EvmConfig: ConfigureEvm + 'static,
319+
EvmConfig: ConfigureEvm,
320320
{
321321
fn on_new_block(&mut self, block_hash: B256, res: ProviderResult<Option<BlockWithSenders>>) {
322322
if let Some(queued) = self.full_block_cache.remove(&block_hash) {
@@ -403,7 +403,7 @@ impl<Provider, Tasks, EvmConfig> Future for EthStateCacheService<Provider, Tasks
403403
where
404404
Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static,
405405
Tasks: TaskSpawner + Clone + 'static,
406-
EvmConfig: ConfigureEvm + 'static,
406+
EvmConfig: ConfigureEvm,
407407
{
408408
type Output = ();
409409

0 commit comments

Comments
 (0)