@@ -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,18 +92,24 @@ 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+ for _ in 0 ..1024 {
97+ shared_stack_pool. push ( Stack :: default ( ) )
98+ }
99+
94100 let mut receipts = Vec :: new ( ) ;
95101 let mut cumulative_gas_used = 0 ;
96102
97103 for ( tx, tx_sender) in block. body . get_transactions_with_sender ( ) . map_err ( |error| {
98104 EvmError :: Transaction ( format ! ( "Couldn't recover addresses with error: {error}" ) )
99105 } ) ? {
100- let report = Self :: execute_tx (
106+ let report = Self :: execute_tx_in_block (
101107 tx,
102108 tx_sender,
103109 & block. header ,
104110 db,
105- vm_type
111+ vm_type,
112+ & mut shared_stack_pool,
106113 ) ?;
107114 LEVM :: send_state_transitions_tx ( & merkleizer, db, queue_length) ?;
108115
@@ -221,6 +228,26 @@ impl LEVM {
221228 vm. execute ( ) . map_err ( VMError :: into)
222229 }
223230
231+ pub fn execute_tx_in_block (
232+ // The transaction to execute.
233+ tx : & Transaction ,
234+ // The transactions recovered address
235+ tx_sender : Address ,
236+ // The block header for the current block.
237+ block_header : & BlockHeader ,
238+ db : & mut GeneralizedDatabase ,
239+ vm_type : VMType ,
240+ stack_pool : & mut Vec < Stack > ,
241+ ) -> Result < ExecutionReport , EvmError > {
242+ let env = Self :: setup_env ( tx, tx_sender, block_header, db, vm_type) ?;
243+ let mut vm = VM :: new ( env, db, tx, LevmCallTracer :: disabled ( ) , vm_type) ?;
244+
245+ std:: mem:: swap ( & mut vm. stack , stack_pool) ;
246+ let result = vm. execute ( ) . map_err ( VMError :: into) ;
247+ std:: mem:: swap ( & mut vm. stack , stack_pool) ;
248+ result
249+ }
250+
224251 pub fn undo_last_tx ( db : & mut GeneralizedDatabase ) -> Result < ( ) , EvmError > {
225252 db. undo_last_transaction ( ) ?;
226253 Ok ( ( ) )
0 commit comments