@@ -3,25 +3,26 @@ use alloy_consensus::{Blob, SidecarCoder, SimpleCoder, Transaction};
3
3
use alloy_eips:: {
4
4
eip1559:: INITIAL_BASE_FEE , eip2718:: Decodable2718 , eip4844:: kzg_to_versioned_hash,
5
5
} ;
6
- use alloy_primitives:: { keccak256, Address , Bytes , B256 , U256 } ;
6
+ use alloy_primitives:: { keccak256, Bytes , B256 , U256 } ;
7
7
use alloy_rlp:: Decodable as _;
8
8
use reth:: {
9
9
api:: Block as _, core:: primitives:: SignedTransaction , transaction_pool:: TransactionPool ,
10
10
} ;
11
+ use reth_evm:: Evm ;
11
12
use reth_execution_errors:: BlockValidationError ;
12
13
use reth_node_api:: ConfigureEvm ;
13
14
use reth_node_ethereum:: { evm:: EthEvm , EthEvmConfig } ;
14
15
use reth_primitives:: {
15
- Block , BlockBody , EthereumHardfork , Header , Receipt , RecoveredBlock , TransactionSigned , TxType ,
16
+ Block , BlockBody , EthereumHardfork , Header , Receipt , Recovered , RecoveredBlock ,
17
+ TransactionSigned , TxType ,
16
18
} ;
17
19
use reth_revm:: {
18
- context:: result:: { ExecutionResult , ResultAndState } ,
20
+ context:: result:: { EVMError , ExecutionResult , ResultAndState } ,
19
21
db:: { states:: bundle_state:: BundleRetention , BundleState , StateBuilder } ,
20
22
inspector:: NoOpInspector ,
21
- DatabaseCommit , Inspector , State ,
23
+ DatabaseCommit , State ,
22
24
} ;
23
25
use reth_tracing:: tracing:: debug;
24
- use std:: ops:: DerefMut ;
25
26
26
27
/// Execute a rollup block and return (block with recovered senders)[RecoveredBlock], (bundle
27
28
/// state)[BundleState] and list of (receipts)[Receipt].
@@ -56,7 +57,7 @@ pub async fn execute_block<Pool: TransactionPool>(
56
57
Block { header, body : BlockBody { transactions : executed_txs, ..Default :: default ( ) } }
57
58
. try_into_recovered ( ) ?;
58
59
59
- let bundle = evm. deref_mut ( ) . db_mut ( ) . take_bundle ( ) ;
60
+ let bundle = evm. db_mut ( ) . take_bundle ( ) ;
60
61
61
62
Ok ( ( block, bundle, receipts, results) )
62
63
}
@@ -104,7 +105,7 @@ async fn decode_transactions<Pool: TransactionPool>(
104
105
tx : & TransactionSigned ,
105
106
block_data : Bytes ,
106
107
block_data_hash : B256 ,
107
- ) -> eyre:: Result < Vec < ( TransactionSigned , Address ) > > {
108
+ ) -> eyre:: Result < Vec < Recovered < TransactionSigned > > > {
108
109
// Get raw transactions either from the blobs, or directly from the block data
109
110
let raw_transactions = if matches ! ( tx. tx_type( ) , TxType :: Eip4844 ) {
110
111
let blobs: Vec < _ > = if let Some ( sidecar) = pool. get_blob ( * tx. hash ( ) ) ? {
@@ -161,7 +162,7 @@ async fn decode_transactions<Pool: TransactionPool>(
161
162
let tx = TransactionSigned :: decode_2718 ( & mut & raw_transaction[ ..] ) ?;
162
163
if tx. chain_id ( ) == Some ( CHAIN_ID ) {
163
164
let sender = tx. recover_signer ( ) ?;
164
- transactions. push ( ( tx , sender) ) ;
165
+ transactions. push ( tx . with_signer ( sender) ) ;
165
166
}
166
167
}
167
168
@@ -170,10 +171,10 @@ async fn decode_transactions<Pool: TransactionPool>(
170
171
171
172
/// Execute transactions and return the list of executed transactions, receipts and
172
173
/// execution results.
173
- fn execute_transactions < DB : reth_revm :: Database > (
174
+ fn execute_transactions < DB : reth_evm :: Database > (
174
175
evm : & mut EthEvm < State < DB > , NoOpInspector > ,
175
176
header : & Header ,
176
- transactions : Vec < ( TransactionSigned , Address ) > ,
177
+ transactions : Vec < Recovered < TransactionSigned > > ,
177
178
) -> eyre:: Result < ( Vec < TransactionSigned > , Vec < Receipt > , Vec < ExecutionResult > ) >
178
179
where
179
180
DB :: Error : Send ,
@@ -183,7 +184,7 @@ where
183
184
let mut results = Vec :: with_capacity ( transactions. len ( ) ) ;
184
185
if !transactions. is_empty ( ) {
185
186
let mut cumulative_gas_used = 0 ;
186
- for ( transaction, sender ) in transactions {
187
+ for transaction in transactions {
187
188
// The sum of the transaction’s gas limit, Tg, and the gas utilized in this block prior,
188
189
// must be no greater than the block’s gasLimit.
189
190
let block_available_gas = header. gas_limit - cumulative_gas_used;
@@ -195,10 +196,7 @@ where
195
196
. into ( ) ) ;
196
197
}
197
198
// Execute transaction.
198
- // Fill revm structure.
199
- * evm. tx_mut ( ) = EthEvmConfig :: new ( CHAIN_SPEC . clone ( ) ) . tx_env ( & transaction, sender) ;
200
-
201
- let ResultAndState { result, state } = match evm. transact ( ) {
199
+ let ResultAndState { result, state } = match evm. transact ( & transaction) {
202
200
Ok ( result) => result,
203
201
Err ( err) => {
204
202
match err {
@@ -233,7 +231,7 @@ where
233
231
} ) ;
234
232
235
233
// append transaction to the list of executed transactions
236
- executed_txs. push ( transaction) ;
234
+ executed_txs. push ( transaction. into_inner ( ) ) ;
237
235
results. push ( result) ;
238
236
}
239
237
@@ -246,15 +244,21 @@ where
246
244
#[ cfg( test) ]
247
245
mod tests {
248
246
use crate :: {
249
- db:: Database , execute_block, Zenith :: BlockHeader , CHAIN_ID , ROLLUP_SUBMITTER_ADDRESS ,
247
+ db:: Database , execute_block, Zenith :: BlockHeader , CHAIN_ID , CHAIN_SPEC ,
248
+ ROLLUP_SUBMITTER_ADDRESS ,
250
249
} ;
251
250
use alloy_consensus:: { constants:: ETH_TO_WEI , SidecarBuilder , SimpleCoder , TxEip2930 } ;
252
251
use alloy_eips:: eip2718:: Encodable2718 ;
253
252
use alloy_primitives:: { bytes, keccak256, BlockNumber , TxKind , U256 } ;
254
253
use alloy_sol_types:: { sol, SolCall } ;
254
+ use reth_evm:: { ConfigureEvm , Evm } ;
255
+ use reth_node_ethereum:: EthEvmConfig ;
255
256
use reth_primitives:: { public_key_to_address, Block , Receipt , RecoveredBlock , Transaction } ;
256
257
use reth_revm:: {
257
- context:: result:: { ExecutionResult , Output } ,
258
+ context:: {
259
+ result:: { ExecutionResult , Output } ,
260
+ TxEnv ,
261
+ } ,
258
262
state:: AccountInfo ,
259
263
} ;
260
264
use reth_testing_utils:: generators:: { self , sign_tx_with_key_pair} ;
@@ -298,6 +302,7 @@ mod tests {
298
302
reth_tracing:: init_test_tracing ( ) ;
299
303
300
304
let mut database = Database :: new ( Connection :: open_in_memory ( ) ?) ?;
305
+ let evm_config = EthEvmConfig :: new ( CHAIN_SPEC . clone ( ) ) ;
301
306
302
307
// Create key pair
303
308
let secp = Secp256k1 :: new ( ) ;
@@ -354,17 +359,17 @@ mod tests {
354
359
. await ?;
355
360
356
361
// Verify WETH balance
357
- let mut evm = Evm :: builder ( )
358
- . with_db ( & mut database )
359
- . with_tx_env ( TxEnv {
362
+ let mut evm = evm_config . evm_with_env ( & mut database , Default :: default ( ) ) ;
363
+ let result = evm
364
+ . transact ( TxEnv {
360
365
caller : sender_address,
361
366
gas_limit : 50_000_000 ,
362
- transact_to : TxKind :: Call ( weth_address) ,
367
+ kind : TxKind :: Call ( weth_address) ,
363
368
data : WETH :: balanceOfCall:: new ( ( sender_address, ) ) . abi_encode ( ) . into ( ) ,
364
369
..Default :: default ( )
365
370
} )
366
- . build ( ) ;
367
- let result = evm . transact ( ) . map_err ( |err| eyre :: eyre! ( err ) ) ? . result ;
371
+ . map_err ( |err| eyre :: eyre! ( err ) ) ?
372
+ . result ;
368
373
assert_eq ! (
369
374
result. output( ) ,
370
375
Some ( & U256 :: from( 0.5 * ETH_TO_WEI as f64 ) . to_be_bytes_vec( ) . into( ) )
@@ -379,17 +384,18 @@ mod tests {
379
384
database. revert_tip_block ( U256 :: from ( 1 ) ) ?;
380
385
381
386
// Verify WETH balance after revert
382
- let mut evm = Evm :: builder ( )
383
- . with_db ( & mut database )
384
- . with_tx_env ( TxEnv {
387
+ let mut evm = evm_config . evm_with_env ( & mut database , Default :: default ( ) ) ;
388
+ let result = evm
389
+ . transact ( TxEnv {
385
390
caller : sender_address,
386
391
gas_limit : 50_000_000 ,
387
- transact_to : TxKind :: Call ( weth_address) ,
392
+ kind : TxKind :: Call ( weth_address) ,
388
393
data : WETH :: balanceOfCall:: new ( ( sender_address, ) ) . abi_encode ( ) . into ( ) ,
389
394
..Default :: default ( )
390
395
} )
391
- . build ( ) ;
392
- let result = evm. transact ( ) . map_err ( |err| eyre:: eyre!( err) ) ?. result ;
396
+ . map_err ( |err| eyre:: eyre!( err) ) ?
397
+ . result ;
398
+
393
399
assert_eq ! ( result. output( ) , Some ( & U256 :: ZERO . to_be_bytes_vec( ) . into( ) ) ) ;
394
400
drop ( evm) ;
395
401
0 commit comments