@@ -18,6 +18,7 @@ use ethrex_common::{
1818 } ,
1919} ;
2020use ethrex_levm:: EVMConfig ;
21+ use ethrex_levm:: call_frame:: Stack ;
2122use ethrex_levm:: constants:: { SYS_CALL_GAS_LIMIT , TX_BASE_COST } ;
2223use ethrex_levm:: db:: gen_db:: GeneralizedDatabase ;
2324use ethrex_levm:: errors:: { InternalError , TxValidationError } ;
@@ -91,13 +92,22 @@ impl LEVM {
9192 ) -> Result < BlockExecutionResult , EvmError > {
9293 Self :: prepare_block ( block, db, vm_type) ?;
9394
95+ let mut shared_stack_pool = Vec :: with_capacity ( 1024 ) ;
96+
9497 let mut receipts = Vec :: new ( ) ;
9598 let mut cumulative_gas_used = 0 ;
9699
97100 for ( tx, tx_sender) in block. body . get_transactions_with_sender ( ) . map_err ( |error| {
98101 EvmError :: Transaction ( format ! ( "Couldn't recover addresses with error: {error}" ) )
99102 } ) ? {
100- let report = Self :: execute_tx ( tx, tx_sender, & block. header , db, vm_type) ?;
103+ let report = Self :: execute_tx_in_block (
104+ tx,
105+ tx_sender,
106+ & block. header ,
107+ db,
108+ vm_type,
109+ & mut shared_stack_pool,
110+ ) ?;
101111 LEVM :: send_state_transitions_tx ( & merkleizer, db, queue_length) ?;
102112
103113 cumulative_gas_used += report. gas_used ;
@@ -215,6 +225,26 @@ impl LEVM {
215225 vm. execute ( ) . map_err ( VMError :: into)
216226 }
217227
228+ pub fn execute_tx_in_block (
229+ // The transaction to execute.
230+ tx : & Transaction ,
231+ // The transactions recovered address
232+ tx_sender : Address ,
233+ // The block header for the current block.
234+ block_header : & BlockHeader ,
235+ db : & mut GeneralizedDatabase ,
236+ vm_type : VMType ,
237+ stack_pool : & mut Vec < Stack > ,
238+ ) -> Result < ExecutionReport , EvmError > {
239+ let env = Self :: setup_env ( tx, tx_sender, block_header, db, vm_type) ?;
240+ let mut vm = VM :: new ( env, db, tx, LevmCallTracer :: disabled ( ) , vm_type) ?;
241+
242+ std:: mem:: swap ( & mut vm. stack_pool , stack_pool) ;
243+ let result = vm. execute ( ) . map_err ( VMError :: into) ;
244+ std:: mem:: swap ( & mut vm. stack_pool , stack_pool) ;
245+ result
246+ }
247+
218248 pub fn undo_last_tx ( db : & mut GeneralizedDatabase ) -> Result < ( ) , EvmError > {
219249 db. undo_last_transaction ( ) ?;
220250 Ok ( ( ) )
0 commit comments