@@ -11,7 +11,7 @@ use crate::blockifier::config::TransactionExecutorConfig;
1111use crate :: bouncer:: { Bouncer , BouncerWeights } ;
1212use crate :: concurrency:: worker_logic:: WorkerExecutor ;
1313use crate :: context:: BlockContext ;
14- use crate :: state:: cached_state:: { CachedState , CommitmentStateDiff , TransactionalState } ;
14+ use crate :: state:: cached_state:: { CachedState , CommitmentStateDiff , StateMaps , TransactionalState } ;
1515use crate :: state:: errors:: StateError ;
1616use crate :: state:: state_api:: { StateReader , StateResult } ;
1717use crate :: state:: stateful_compression:: { allocate_aliases_in_storage, compress, CompressionError } ;
@@ -27,6 +27,8 @@ pub mod transaction_executor_test;
2727pub const BLOCK_STATE_ACCESS_ERR : & str = "Error: The block state should be `Some`." ;
2828pub const DEFAULT_STACK_SIZE : usize = 60 * 1024 * 1024 ;
2929
30+ pub type TransactionExecutionOutput = ( TransactionExecutionInfo , StateMaps ) ;
31+
3032#[ derive( Debug , Error ) ]
3133pub enum TransactionExecutorError {
3234 #[ error( "Transaction cannot be added to the current block, block capacity reached." ) ]
@@ -103,7 +105,7 @@ impl<S: StateReader> TransactionExecutor<S> {
103105 pub fn execute (
104106 & mut self ,
105107 tx : & Transaction ,
106- ) -> TransactionExecutorResult < TransactionExecutionInfo > {
108+ ) -> TransactionExecutorResult < TransactionExecutionOutput > {
107109 let mut transactional_state = TransactionalState :: create_transactional (
108110 self . block_state . as_mut ( ) . expect ( BLOCK_STATE_ACCESS_ERR ) ,
109111 ) ;
@@ -116,14 +118,16 @@ impl<S: StateReader> TransactionExecutor<S> {
116118 Ok ( tx_execution_info) => {
117119 let tx_state_changes_keys =
118120 transactional_state. get_actual_state_changes ( ) ?. state_maps . into_keys ( ) ;
121+ let state_diff = transactional_state. to_state_diff ( ) ?. state_maps ;
119122 self . bouncer . try_update (
120123 & transactional_state,
121124 & tx_state_changes_keys,
122125 & tx_execution_info. summarize ( & self . block_context . versioned_constants ) ,
123126 & tx_execution_info. receipt . resources ,
124127 ) ?;
125128 transactional_state. commit ( ) ;
126- Ok ( tx_execution_info)
129+
130+ Ok ( ( tx_execution_info, state_diff) )
127131 }
128132 Err ( error) => {
129133 transactional_state. abort ( ) ;
@@ -132,14 +136,16 @@ impl<S: StateReader> TransactionExecutor<S> {
132136 }
133137 }
134138
135- pub fn execute_txs_sequentially_inner (
139+ fn execute_txs_sequentially_inner (
136140 & mut self ,
137141 txs : & [ Transaction ] ,
138- ) -> Vec < TransactionExecutorResult < TransactionExecutionInfo > > {
142+ ) -> Vec < TransactionExecutorResult < TransactionExecutionOutput > > {
139143 let mut results = Vec :: new ( ) ;
140144 for tx in txs {
141145 match self . execute ( tx) {
142- Ok ( tx_execution_info) => results. push ( Ok ( tx_execution_info) ) ,
146+ Ok ( ( tx_execution_info, state_diff) ) => {
147+ results. push ( Ok ( ( tx_execution_info, state_diff) ) )
148+ }
143149 Err ( TransactionExecutorError :: BlockFull ) => break ,
144150 Err ( error) => results. push ( Err ( error) ) ,
145151 }
@@ -196,6 +202,9 @@ impl<S: StateReader + Send + Sync> TransactionExecutor<S> {
196202 if !self . config . concurrency_config . enabled {
197203 log:: debug!( "Executing transactions sequentially." ) ;
198204 self . execute_txs_sequentially ( txs)
205+ . into_iter ( )
206+ . map ( |result| result. map ( |( info, _) | info) )
207+ . collect ( )
199208 } else {
200209 log:: debug!( "Executing transactions concurrently." ) ;
201210 let chunk_size = self . config . concurrency_config . chunk_size ;
@@ -228,40 +237,41 @@ impl<S: StateReader + Send + Sync> TransactionExecutor<S> {
228237 }
229238 }
230239
231- pub fn execute_txs_sequentially (
240+ fn execute_txs_sequentially (
232241 & mut self ,
233242 txs : & [ Transaction ] ,
234- ) -> Vec < TransactionExecutorResult < TransactionExecutionInfo > > {
243+ ) -> Vec < TransactionExecutorResult < TransactionExecutionOutput > > {
235244 #[ cfg( not( feature = "cairo_native" ) ) ]
236245 return self . execute_txs_sequentially_inner ( txs) ;
246+
237247 #[ cfg( feature = "cairo_native" ) ]
238248 {
239249 // TODO meshi: find a way to access the contract class manager config from transaction
240250 // executor.
241251 let txs = txs. to_vec ( ) ;
242252 std:: thread:: scope ( |s| {
243253 std:: thread:: Builder :: new ( )
244- // when running Cairo natively, the real stack is used and could get overflowed
245- // (unlike the VM where the stack is simulated in the heap as a memory segment).
246- //
247- // We pre-allocate the stack here, and not during Native execution (not trivial), so it
248- // needs to be big enough ahead.
249- // However, making it very big is wasteful (especially with multi-threading).
250- // So, the stack size should support calls with a reasonable gas limit, for extremely deep
251- // recursions to reach out-of-gas before hitting the bottom of the recursion.
252- //
253- // The gas upper bound is MAX_POSSIBLE_SIERRA_GAS, and sequencers must not raise it without
254- // adjusting the stack size.
255- . stack_size ( self . config . stack_size )
256- . spawn_scoped ( s, || self . execute_txs_sequentially_inner ( & txs) )
257- . expect ( "Failed to spawn thread" )
258- . join ( )
259- . expect ( "Failed to join thread." )
254+ // when running Cairo natively, the real stack is used and could get overflowed
255+ // (unlike the VM where the stack is simulated in the heap as a memory segment).
256+ //
257+ // We pre-allocate the stack here, and not during Native execution (not trivial), so it
258+ // needs to be big enough ahead.
259+ // However, making it very big is wasteful (especially with multi-threading).
260+ // So, the stack size should support calls with a reasonable gas limit, for extremely deep
261+ // recursions to reach out-of-gas before hitting the bottom of the recursion.
262+ //
263+ // The gas upper bound is MAX_POSSIBLE_SIERRA_GAS, and sequencers must not raise it without
264+ // adjusting the stack size.
265+ . stack_size ( self . config . stack_size )
266+ . spawn_scoped ( s, || self . execute_txs_sequentially_inner ( & txs) )
267+ . expect ( "Failed to spawn thread" )
268+ . join ( )
269+ . expect ( "Failed to join thread." )
260270 } )
261271 }
262272 }
263273
264- pub fn execute_chunk (
274+ fn execute_chunk (
265275 & mut self ,
266276 chunk : & [ Transaction ] ,
267277 ) -> Vec < TransactionExecutorResult < TransactionExecutionInfo > > {
0 commit comments