@@ -390,6 +390,10 @@ impl<
390390 self . network . handle ( ) . set_gossip ( enabled) . await ;
391391 let _ = tx. send ( ( ) ) ;
392392 }
393+ #[ cfg( feature = "test-utils" ) ]
394+ ChainOrchestratorCommand :: DatabaseHandle ( tx) => {
395+ let _ = tx. send ( self . database . clone ( ) ) ;
396+ }
393397 }
394398
395399 Ok ( ( ) )
@@ -708,7 +712,7 @@ impl<
708712 . await ?;
709713
710714 if self . sync_state . is_synced ( ) {
711- self . derivation_pipeline . push_batch ( batch_info, BatchStatus :: Committed ) . await ;
715+ self . derivation_pipeline . push_batch ( batch_info, BatchStatus :: Consolidated ) . await ;
712716 }
713717
714718 Ok ( event)
@@ -763,12 +767,12 @@ impl<
763767
764768 /// Handles a batch revert event by updating the database.
765769 async fn handle_batch_revert (
766- & self ,
770+ & mut self ,
767771 start_index : u64 ,
768772 end_index : u64 ,
769773 l1_block_info : BlockInfo ,
770774 ) -> Result < Option < ChainOrchestratorEvent > , ChainOrchestratorError > {
771- let event = self
775+ let ( safe_block_info , batch_info ) = self
772776 . database
773777 . tx_mut ( move |tx| async move {
774778 tx. insert_l1_block_info ( l1_block_info) . await ?;
@@ -780,15 +784,14 @@ impl<
780784 . await ?;
781785
782786 // handle the case of a batch revert.
783- let ( safe_head, batch_info) = tx. get_latest_safe_l2_info ( ) . await ?;
784-
785- let event = ChainOrchestratorEvent :: BatchReverted { batch_info, safe_head } ;
786-
787- Ok :: < _ , ChainOrchestratorError > ( Some ( event) )
787+ Ok :: < _ , ChainOrchestratorError > ( tx. get_latest_safe_l2_info ( ) . await ?)
788788 } )
789789 . await ?;
790790
791- Ok ( event)
791+ // Update the forkchoice state to the new safe block.
792+ self . engine . update_fcs ( None , Some ( safe_block_info) , None ) . await ?;
793+
794+ Ok ( Some ( ChainOrchestratorEvent :: BatchReverted { batch_info, safe_head : safe_block_info } ) )
792795 }
793796
794797 /// Handles an L1 message by inserting it into the database.
@@ -1144,7 +1147,7 @@ impl<
11441147 ///
11451148 /// This involves validating the L1 messages in the blocks against the expected L1 messages
11461149 /// synced from L1.
1147- async fn consolidate_chain ( & self ) -> Result < ( ) , ChainOrchestratorError > {
1150+ async fn consolidate_chain ( & mut self ) -> Result < ( ) , ChainOrchestratorError > {
11481151 tracing:: trace!( target: "scroll::chain_orchestrator" , fcs = ?self . engine. fcs( ) , "Consolidating chain from safe to head" ) ;
11491152
11501153 let safe_block_number = self . engine . fcs ( ) . safe_block_info ( ) . number ;
@@ -1181,6 +1184,14 @@ impl<
11811184 // transactions into the transaction pool.
11821185 self . network . handle ( ) . inner ( ) . update_sync_state ( RethSyncState :: Idle ) ;
11831186
1187+ // Fetch all unprocessed committed batches and push them to the derivation pipeline as
1188+ // consolidated.
1189+ let committed_batches =
1190+ self . database . fetch_and_update_unprocessed_committed_batches ( ) . await ?;
1191+ for batch_commit in committed_batches {
1192+ self . derivation_pipeline . push_batch ( batch_commit, BatchStatus :: Consolidated ) . await ;
1193+ }
1194+
11841195 self . notify ( ChainOrchestratorEvent :: ChainConsolidated {
11851196 from : safe_block_number,
11861197 to : head_block_number,
0 commit comments