@@ -13,7 +13,8 @@ use zksync_dal::{Connection, ConnectionPool, Core, CoreDal};
1313use zksync_health_check:: { Health , HealthStatus , HealthUpdater , ReactiveHealthCheck } ;
1414use zksync_shared_metrics:: EN_METRICS ;
1515use zksync_types:: {
16- aggregated_operations:: L1BatchAggregatedActionType , api, L1BatchNumber , SLChainId , H256 ,
16+ aggregated_operations:: L1BatchAggregatedActionType , api, L1BatchNumber , L1ChainId , SLChainId ,
17+ H256 ,
1718} ;
1819use zksync_web3_decl:: {
1920 client:: { DynClient , L2 } ,
@@ -41,7 +42,7 @@ struct BatchStatusChange {
4142 number : L1BatchNumber ,
4243 l1_tx_hash : H256 ,
4344 happened_at : DateTime < Utc > ,
44- sl_chain_id : Option < SLChainId > ,
45+ sl_chain_id : SLChainId ,
4546}
4647
4748#[ derive( Debug , Default ) ]
@@ -103,10 +104,14 @@ struct UpdaterCursor {
103104 last_executed_l1_batch : L1BatchNumber ,
104105 last_proven_l1_batch : L1BatchNumber ,
105106 last_committed_l1_batch : L1BatchNumber ,
107+ default_sl_chain_id : SLChainId ,
106108}
107109
108110impl UpdaterCursor {
109- async fn new ( storage : & mut Connection < ' _ , Core > ) -> anyhow:: Result < Self > {
111+ async fn new (
112+ storage : & mut Connection < ' _ , Core > ,
113+ default_sl_chain_id : SLChainId ,
114+ ) -> anyhow:: Result < Self > {
110115 let first_l1_batch_number = projected_first_l1_batch ( storage) . await ?;
111116 // Use the snapshot L1 batch, or the genesis batch if we are not using a snapshot. Technically, the snapshot L1 batch
112117 // is not necessarily proven / executed yet, but since it and earlier batches are not stored, it serves
@@ -132,6 +137,7 @@ impl UpdaterCursor {
132137 last_executed_l1_batch,
133138 last_proven_l1_batch,
134139 last_committed_l1_batch,
140+ default_sl_chain_id,
135141 } )
136142 }
137143
@@ -211,7 +217,7 @@ impl UpdaterCursor {
211217 number : batch_info. number ,
212218 l1_tx_hash,
213219 happened_at,
214- sl_chain_id,
220+ sl_chain_id : sl_chain_id . unwrap_or ( self . default_sl_chain_id ) ,
215221 } ) ;
216222 tracing:: info!( "Batch {}: {action_str}" , batch_info. number) ;
217223 FETCHER_METRICS . l1_batch [ & stage. into ( ) ] . set ( batch_info. number . 0 . into ( ) ) ;
@@ -230,6 +236,7 @@ impl UpdaterCursor {
230236/// L1 transaction information in `zks_getBlockDetails` and `zks_getL1BatchDetails` RPC methods.
231237#[ derive( Debug ) ]
232238pub struct BatchStatusUpdater {
239+ l1_chain_id : SLChainId ,
233240 client : Box < dyn MainNodeClient > ,
234241 pool : ConnectionPool < Core > ,
235242 health_updater : HealthUpdater ,
@@ -242,20 +249,27 @@ pub struct BatchStatusUpdater {
242249impl BatchStatusUpdater {
243250 const DEFAULT_SLEEP_INTERVAL : Duration = Duration :: from_secs ( 5 ) ;
244251
245- pub fn new ( client : Box < DynClient < L2 > > , pool : ConnectionPool < Core > ) -> Self {
252+ pub fn new (
253+ l1_chain_id : L1ChainId ,
254+ client : Box < DynClient < L2 > > ,
255+ pool : ConnectionPool < Core > ,
256+ ) -> Self {
246257 Self :: from_parts (
258+ l1_chain_id. into ( ) , // needed because this is used when l1 is sl
247259 Box :: new ( client. for_component ( "batch_transaction_fetcher" ) ) ,
248260 pool,
249261 Self :: DEFAULT_SLEEP_INTERVAL ,
250262 )
251263 }
252264
253265 fn from_parts (
266+ l1_chain_id : SLChainId ,
254267 client : Box < dyn MainNodeClient > ,
255268 pool : ConnectionPool < Core > ,
256269 sleep_interval : Duration ,
257270 ) -> Self {
258271 Self {
272+ l1_chain_id,
259273 client,
260274 pool,
261275 health_updater : ReactiveHealthCheck :: new ( "batch_transaction_fetcher" ) . 1 ,
@@ -271,7 +285,7 @@ impl BatchStatusUpdater {
271285
272286 pub async fn run ( self , mut stop_receiver : watch:: Receiver < bool > ) -> anyhow:: Result < ( ) > {
273287 let mut storage = self . pool . connection_tagged ( "sync_layer" ) . await ?;
274- let mut cursor = UpdaterCursor :: new ( & mut storage) . await ?;
288+ let mut cursor = UpdaterCursor :: new ( & mut storage, self . l1_chain_id ) . await ?;
275289 drop ( storage) ;
276290 tracing:: info!( "Initialized batch status updater cursor: {cursor:?}" ) ;
277291 self . health_updater
@@ -400,7 +414,7 @@ impl BatchStatusUpdater {
400414 change. number ,
401415 L1BatchAggregatedActionType :: Commit ,
402416 change. l1_tx_hash ,
403- change. sl_chain_id ,
417+ Some ( change. sl_chain_id ) ,
404418 )
405419 . await ?;
406420 cursor. last_committed_l1_batch = change. number ;
@@ -424,7 +438,7 @@ impl BatchStatusUpdater {
424438 change. number ,
425439 L1BatchAggregatedActionType :: PublishProofOnchain ,
426440 change. l1_tx_hash ,
427- change. sl_chain_id ,
441+ Some ( change. sl_chain_id ) ,
428442 )
429443 . await ?;
430444 cursor. last_proven_l1_batch = change. number ;
@@ -448,7 +462,7 @@ impl BatchStatusUpdater {
448462 change. number ,
449463 L1BatchAggregatedActionType :: Execute ,
450464 change. l1_tx_hash ,
451- change. sl_chain_id ,
465+ Some ( change. sl_chain_id ) ,
452466 )
453467 . await ?;
454468 cursor. last_executed_l1_batch = change. number ;
0 commit comments