@@ -336,6 +336,45 @@ impl ExecutorThread {
336336 let _ = callback. send ( Ok ( ( ) ) ) ;
337337 Default :: default ( )
338338 }
339+ super :: ExecutorCommand :: ResetState ( callback) => {
340+ tracing:: info!( "🔄 Resetting executor state after reorg" ) ;
341+ // Reinitialize the state adapter from the current database state
342+ let new_state_adaptor = match mc_exec:: LayeredStateAdapter :: new ( self . backend . clone ( ) ) {
343+ Ok ( adaptor) => adaptor,
344+ Err ( e) => {
345+ tracing:: error!( "Failed to reinitialize state adapter after reorg: {:#}" , e) ;
346+ let _ = callback. send ( Err ( super :: ExecutorCommandError :: ChannelClosed ) ) ;
347+ return Err ( e. into ( ) ) ;
348+ }
349+ } ;
350+
351+ let latest_block_n = new_state_adaptor. previous_block_n ( ) ;
352+ tracing:: info!( "✅ State adapter reinitialized to block_n={}" , new_state_adaptor. block_n( ) ) ;
353+
354+ // Reset the executor state to NewBlock with the fresh state adapter
355+ state = ExecutorThreadState :: NewBlock ( ExecutorStateNewBlock {
356+ state_adaptor : new_state_adaptor,
357+ consumed_l1_to_l2_nonces : HashSet :: new ( ) ,
358+ } ) ;
359+
360+ // Clear any pending transactions by clearing both fields
361+ to_exec. txs . clear ( ) ;
362+ to_exec. additional_info . clear ( ) ;
363+
364+ // Reset block state flags
365+ block_empty = true ;
366+ force_close = false ;
367+ l2_gas_consumed_block = 0 ;
368+
369+ // Notify the main task that state was reset
370+ if self . replies_sender . blocking_send ( super :: ExecutorMessage :: StateReset { latest_block_n } ) . is_err ( ) {
371+ tracing:: error!( "Failed to send StateReset message to block production task" ) ;
372+ }
373+
374+ let _ = callback. send ( Ok ( ( ) ) ) ;
375+ // Continue the loop to wait for new transactions - don't return a batch
376+ continue ;
377+ }
339378 } ,
340379 // Channel closed. Exit gracefully.
341380 WaitTxBatchOutcome :: Exit => return Ok ( ( ) ) ,
0 commit comments