@@ -4,7 +4,7 @@ use crate::{ReadConnectionProvider, WriteConnectionProvider};
44use alloy_primitives:: { Signature , B256 } ;
55use rollup_node_primitives:: {
66 BatchCommitData , BatchConsolidationOutcome , BatchInfo , BatchStatus , BlockInfo ,
7- L1MessageEnvelope , L2BlockInfoWithL1Messages , Metadata ,
7+ L1BlockStartupInfo , L1MessageEnvelope , L2BlockInfoWithL1Messages , Metadata ,
88} ;
99use scroll_alloy_rpc_types_engine:: BlockDataHint ;
1010use sea_orm:: {
@@ -118,16 +118,8 @@ pub trait DatabaseWriteOperations {
118118 l1_block_number : u64 ,
119119 ) -> Result < Vec < L1MessageEnvelope > , DatabaseError > ;
120120
121- /// Prepare the database on startup and return metadata used for other components in the
122- /// rollup-node.
123- ///
124- /// This method first unwinds the database to the finalized L1 block. It then fetches the batch
125- /// info for the latest safe L2 block. It takes note of the L1 block number at which
126- /// this batch was produced (currently the finalized block for the batch until we implement
127- /// issue #273). It then retrieves the latest block for the previous batch (i.e., the batch
128- /// before the latest safe block). It returns a tuple of this latest fetched block and the
129- /// L1 block number of the batch.
130- async fn prepare_on_startup ( & self ) -> Result < ( Vec < BlockInfo > , Option < u64 > ) , DatabaseError > ;
121+ /// Returns the L1 block info required to start the L1 watcher on startup.
122+ async fn prepare_l1_watcher_start_info ( & self ) -> Result < L1BlockStartupInfo , DatabaseError > ;
131123
132124 /// Delete all L2 blocks with a block number greater than the provided block number.
133125 async fn delete_l2_blocks_gt_block_number (
@@ -598,7 +590,7 @@ impl<T: WriteConnectionProvider + ?Sized + Sync> DatabaseWriteOperations for T {
598590 Ok ( removed_messages. into_iter ( ) . map ( Into :: into) . collect ( ) )
599591 }
600592
601- async fn prepare_on_startup ( & self ) -> Result < ( Vec < BlockInfo > , Option < u64 > ) , DatabaseError > {
593+ async fn prepare_l1_watcher_start_info ( & self ) -> Result < L1BlockStartupInfo , DatabaseError > {
602594 tracing:: trace!( target: "scroll::db" , "Fetching startup safe block from database." ) ;
603595
604596 // set all batches with processing status back to committed
@@ -608,7 +600,7 @@ impl<T: WriteConnectionProvider + ?Sized + Sync> DatabaseWriteOperations for T {
608600 let l1_block_infos = self . get_l1_block_info ( ) . await ?;
609601 let latest_l1_block_info = self . get_latest_indexed_event_l1_block_number ( ) . await ?;
610602
611- Ok ( ( l1_block_infos, latest_l1_block_info) )
603+ Ok ( L1BlockStartupInfo :: new ( l1_block_infos, latest_l1_block_info) )
612604 }
613605
614606 async fn delete_l2_blocks_gt_block_number (
@@ -1041,13 +1033,7 @@ impl<T: ReadConnectionProvider + Sync + ?Sized> DatabaseReadOperations for T {
10411033 . into_tuple :: < ( Option < i64 > , Option < i64 > , Option < i64 > ) > ( )
10421034 . one ( self . get_connection ( ) )
10431035 . await ?
1044- . map ( |( block_number, finalized_block_number, reverted_block_number) | {
1045- [ block_number, finalized_block_number, reverted_block_number]
1046- . into_iter ( )
1047- . flatten ( )
1048- . max ( )
1049- } )
1050- . flatten ( ) ;
1036+ . and_then ( |tuple| <[ Option < i64 > ; 3 ] >:: from ( tuple) . into_iter ( ) . flatten ( ) . max ( ) ) ;
10511037
10521038 let latest_l1_block_number =
10531039 [ latest_l1_message, latest_batch_event] . into_iter ( ) . flatten ( ) . max ( ) ;
0 commit comments