@@ -11,7 +11,7 @@ use reth_network_p2p::{BlockClient, BodiesClient};
1111use reth_scroll_primitives:: ScrollBlock ;
1212use rollup_node_primitives:: {
1313 BatchCommitData , BatchInfo , BlockInfo , BoundedVec , ChainImport , L1MessageEnvelope ,
14- L2BlockInfoWithL1Messages , WithBlockNumber ,
14+ L2BlockInfoWithL1Messages ,
1515} ;
1616use rollup_node_watcher:: L1Notification ;
1717use scroll_alloy_consensus:: TxL1Message ;
@@ -21,7 +21,6 @@ use scroll_db::{Database, DatabaseError, DatabaseOperations, L1MessageStart, Unw
2121use scroll_network:: NewBlockWithPeer ;
2222use std:: {
2323 collections:: { HashMap , VecDeque } ,
24- ops:: Add ,
2524 pin:: Pin ,
2625 sync:: {
2726 atomic:: { AtomicU64 , Ordering } ,
@@ -67,8 +66,6 @@ pub struct ChainOrchestrator<ChainSpec, BC, P> {
6766 pending_futures : VecDeque < ChainOrchestratorFuture > ,
6867 /// The block number of the L1 finalized block.
6968 l1_finalized_block_number : Arc < AtomicU64 > ,
70- /// The block number of the L2 finalized block.
71- l2_finalized_block_number : Arc < AtomicU64 > ,
7269 /// The chain specification for the chain orchestrator.
7370 chain_spec : Arc < ChainSpec > ,
7471 /// The metrics for the chain orchestrator.
@@ -109,7 +106,6 @@ impl<
109106 database,
110107 pending_futures : Default :: default ( ) ,
111108 l1_finalized_block_number : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
112- l2_finalized_block_number : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
113109 chain_spec,
114110 metrics : ChainOrchestratorItem :: iter ( )
115111 . map ( |i| {
@@ -529,7 +525,6 @@ impl<
529525 self . database . clone ( ) ,
530526 block_number,
531527 self . l1_finalized_block_number . clone ( ) ,
532- self . l2_finalized_block_number . clone ( ) ,
533528 ) ) ,
534529 ) )
535530 }
@@ -551,16 +546,13 @@ impl<
551546 ) ) ,
552547 ) )
553548 }
554- L1Notification :: BatchFinalization { hash, index, block_number } => {
549+ L1Notification :: BatchFinalization { hash : _hash , index, block_number } => {
555550 ChainOrchestratorFuture :: HandleBatchFinalization ( self . handle_metered (
556551 ChainOrchestratorItem :: BatchFinalization ,
557552 Box :: pin ( Self :: handle_batch_finalization (
558553 self . database . clone ( ) ,
559- hash,
560554 index,
561555 block_number,
562- self . l1_finalized_block_number . clone ( ) ,
563- self . l2_finalized_block_number . clone ( ) ,
564556 ) ) ,
565557 ) )
566558 }
@@ -615,35 +607,18 @@ impl<
615607 database : Arc < Database > ,
616608 block_number : u64 ,
617609 l1_block_number : Arc < AtomicU64 > ,
618- l2_block_number : Arc < AtomicU64 > ,
619610 ) -> Result < Option < ChainOrchestratorEvent > , ChainOrchestratorError > {
620611 // Set the latest finalized L1 block in the database.
621612 database. set_latest_finalized_l1_block_number ( block_number) . await ?;
622613
623- // get the finalized batch infos.
624- // we add 1 to the low finalized l1 block number to avoid fetching the last finalized batch
625- // a second time.
626- let low_finalized_l1_block_number =
627- l1_block_number. load ( Ordering :: Relaxed ) . add ( 1 ) . max ( block_number) ;
628- let finalized_batches = database
629- . get_batches_by_finalized_block_range ( low_finalized_l1_block_number, block_number)
630- . await ?;
631-
632- // get the finalized block for the batch.
633- let finalized_block = if let Some ( info) = finalized_batches. last ( ) {
634- Self :: fetch_highest_finalized_block ( database, info. hash , l2_block_number) . await ?
635- } else {
636- None
637- } ;
614+ // Get all unprocessed batches that have been finalized by this L1 block finalization.
615+ let finalized_batches =
616+ database. fetch_and_update_unprocessed_finalized_batches ( block_number) . await ?;
638617
639- // update the chain orchestrator l1 block number.
618+ // Update the chain orchestrator L1 block number.
640619 l1_block_number. store ( block_number, Ordering :: Relaxed ) ;
641620
642- Ok ( Some ( ChainOrchestratorEvent :: L1BlockFinalized (
643- block_number,
644- finalized_batches,
645- finalized_block,
646- ) ) )
621+ Ok ( Some ( ChainOrchestratorEvent :: L1BlockFinalized ( block_number, finalized_batches) ) )
647622 }
648623
649624 /// Handles an L1 message by inserting it into the database.
@@ -715,54 +690,13 @@ impl<
715690 /// Handles a batch finalization event by updating the batch input in the database.
716691 async fn handle_batch_finalization (
717692 database : Arc < Database > ,
718- batch_hash : B256 ,
719693 batch_index : u64 ,
720694 block_number : u64 ,
721- l1_block_number : Arc < AtomicU64 > ,
722- l2_block_number : Arc < AtomicU64 > ,
723695 ) -> Result < Option < ChainOrchestratorEvent > , ChainOrchestratorError > {
724696 // finalize all batches up to `batch_index`.
725697 database. finalize_batches_up_to_index ( batch_index, block_number) . await ?;
726698
727- let mut finalized_block = None ;
728- let mut finalized_batch = None ;
729-
730- // check if the block where the batch was finalized is finalized on L1.
731- let l1_block_number_value = l1_block_number. load ( Ordering :: Relaxed ) ;
732- if l1_block_number_value >= block_number {
733- // fetch the finalized block.
734- finalized_block =
735- Self :: fetch_highest_finalized_block ( database, batch_hash, l2_block_number) . await ?;
736-
737- // set the finalized batch info.
738- finalized_batch =
739- Some ( WithBlockNumber :: new ( block_number, BatchInfo :: new ( batch_index, batch_hash) ) ) ;
740- }
741-
742- let event = ChainOrchestratorEvent :: BatchFinalized ( finalized_batch, finalized_block) ;
743- Ok ( Some ( event) )
744- }
745-
746- /// Returns the highest finalized block for the provided batch hash. Will return [`None`] if the
747- /// block number has already been seen by the chain orchestrator.
748- async fn fetch_highest_finalized_block (
749- database : Arc < Database > ,
750- batch_hash : B256 ,
751- l2_block_number : Arc < AtomicU64 > ,
752- ) -> Result < Option < BlockInfo > , ChainOrchestratorError > {
753- let finalized_block = database. get_highest_block_for_batch_hash ( batch_hash) . await ?;
754-
755- // only return the block if the chain orchestrator hasn't seen it.
756- // in which case also update the `l2_finalized_block_number` value.
757- Ok ( finalized_block. filter ( |info| {
758- let current_l2_block_number = l2_block_number. load ( Ordering :: Relaxed ) ;
759- if info. number > current_l2_block_number {
760- l2_block_number. store ( info. number , Ordering :: Relaxed ) ;
761- true
762- } else {
763- false
764- }
765- } ) )
699+ Ok ( None )
766700 }
767701}
768702
0 commit comments