@@ -71,7 +71,27 @@ pub trait DatabaseWriteOperations: WriteConnectionProvider + DatabaseReadOperati
71
71
) -> Result < ( ) , DatabaseError > {
72
72
tracing:: trace!( target: "scroll::db" , block_number, "Updating the latest finalized L1 block number in the database." ) ;
73
73
let metadata: models:: metadata:: ActiveModel =
74
- Metadata { l1_finalized_block : block_number } . into ( ) ;
74
+ Metadata { key : "l1_finalized_block" . to_string ( ) , value : block_number. to_string ( ) }
75
+ . into ( ) ;
76
+ Ok ( models:: metadata:: Entity :: insert ( metadata)
77
+ . on_conflict (
78
+ OnConflict :: column ( models:: metadata:: Column :: Key )
79
+ . update_column ( models:: metadata:: Column :: Value )
80
+ . to_owned ( ) ,
81
+ )
82
+ . exec ( self . get_connection ( ) )
83
+ . await
84
+ . map ( |_| ( ) ) ?)
85
+ }
86
+
87
+ /// Set the L2 head block info.
88
+ async fn set_l2_head_block_info ( & self , block_info : BlockInfo ) -> Result < ( ) , DatabaseError > {
89
+ tracing:: trace!( target: "scroll::db" , ?block_info, "Updating the L2 head block info in the database." ) ;
90
+ let metadata: models:: metadata:: ActiveModel = Metadata {
91
+ key : "l2_head_block" . to_string ( ) ,
92
+ value : serde_json:: to_string ( & block_info) ?,
93
+ }
94
+ . into ( ) ;
75
95
Ok ( models:: metadata:: Entity :: insert ( metadata)
76
96
. on_conflict (
77
97
OnConflict :: column ( models:: metadata:: Column :: Key )
@@ -444,6 +464,18 @@ pub trait DatabaseReadOperations: ReadConnectionProvider + Sync {
444
464
. map ( |x| x. and_then ( |x| x. parse :: < u64 > ( ) . ok ( ) ) ) ?)
445
465
}
446
466
467
+ /// Get the latest L2 head block info.
468
+ async fn get_l2_head_block_info ( & self ) -> Result < Option < BlockInfo > , DatabaseError > {
469
+ Ok ( models:: metadata:: Entity :: find ( )
470
+ . filter ( models:: metadata:: Column :: Key . eq ( "l2_head_block" ) )
471
+ . select_only ( )
472
+ . column ( models:: metadata:: Column :: Value )
473
+ . into_tuple :: < String > ( )
474
+ . one ( self . get_connection ( ) )
475
+ . await
476
+ . map ( |x| x. and_then ( |x| serde_json:: from_str ( & x) . ok ( ) ) ) ?)
477
+ }
478
+
447
479
/// Get an iterator over all [`BatchCommitData`]s in the database.
448
480
async fn get_batches < ' a > (
449
481
& ' a self ,
@@ -571,7 +603,9 @@ pub trait DatabaseReadOperations: ReadConnectionProvider + Sync {
571
603
} ) ?)
572
604
}
573
605
574
- /// Get the latest safe L2 ([`BlockInfo`], [`BatchInfo`]) from the database.
606
+ /// Get the latest safe/finalized L2 ([`BlockInfo`], [`BatchInfo`]) from the database. Until we
607
+ /// update the batch handling logic with issue #273, we don't differentiate between safe and
608
+ /// finalized l2 blocks.
575
609
async fn get_latest_safe_l2_info (
576
610
& self ,
577
611
) -> Result < Option < ( BlockInfo , BatchInfo ) > , DatabaseError > {
0 commit comments