@@ -326,16 +326,24 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
326326
327327 // if backlog outgrow max size, force‐submit enough oldest batches
328328 backlogCount , err := r .batchOrm .GetFailedAndPendingBatchesCount (r .ctx )
329+ r .metrics .rollupL2RelayerBacklogCounts .Set (float64 (backlogCount ))
330+
329331 if err != nil {
330332 log .Error ("Failed to fetch pending L2 batches" , "err" , err )
331333 return
332334 }
333335
334336 var forceSubmit bool
335337
336- oldestBatchTimestamp := dbBatches [0 ].CreatedAt
338+ startChunk , err := r .chunkOrm .GetChunkByIndex (r .ctx , dbBatches [0 ].StartChunkIndex )
339+ oldestBlockTimestamp := time .Unix (int64 (startChunk .StartBlockTime ), 0 )
340+ if err != nil {
341+ log .Error ("failed to get first chunk" , "err" , err , "batch index" , dbBatches [0 ].Index , "chunk index" , dbBatches [0 ].StartChunkIndex )
342+ return
343+ }
344+
337345 // if the batch with the oldest index is too old, we force submit all batches that we have so far in the next step
338- if r .cfg .BatchSubmission .TimeoutSec > 0 && time .Since (oldestBatchTimestamp ) > time .Duration (r .cfg .BatchSubmission .TimeoutSec )* time .Second {
346+ if r .cfg .BatchSubmission .TimeoutSec > 0 && time .Since (oldestBlockTimestamp ) > time .Duration (r .cfg .BatchSubmission .TimeoutSec )* time .Second {
339347 forceSubmit = true
340348 }
341349
@@ -346,10 +354,12 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
346354
347355 if ! forceSubmit {
348356 // check if we should skip submitting the batch based on the fee target
349- skip , err := r .skipSubmitByFee (oldestBatchTimestamp )
357+ skip , err := r .skipSubmitByFee (oldestBlockTimestamp , r . metrics )
350358 // return if not hitting target price
351359 if skip {
352- log .Debug ("Skipping batch submission" , "reason" , err )
360+ log .Debug ("Skipping batch submission" , "first batch index" , dbBatches [0 ].Index , "backlog count" , backlogCount , "reason" , err )
361+ log .Debug ("first batch index" , dbBatches [0 ].Index )
362+ log .Debug ("backlog count" , backlogCount )
353363 return
354364 }
355365 if err != nil {
@@ -432,7 +442,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
432442 }
433443
434444 if forceSubmit {
435- log .Info ("Forcing submission of batches due to timeout" , "batch index" , batchesToSubmit [0 ].Batch .Index , "created at" , batchesToSubmit [ 0 ]. Batch . CreatedAt )
445+ log .Info ("Forcing submission of batches due to timeout" , "batch index" , batchesToSubmit [0 ].Batch .Index , "first block created at" , oldestBlockTimestamp )
436446 }
437447
438448 // We have at least 1 batch to commit
@@ -497,6 +507,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
497507 r .metrics .rollupL2RelayerCommitThroughput .Add (float64 (totalGasUsed ))
498508 r .metrics .rollupL2RelayerProcessPendingBatchSuccessTotal .Add (float64 (len (batchesToSubmit )))
499509 r .metrics .rollupL2RelayerProcessBatchesPerTxCount .Set (float64 (len (batchesToSubmit )))
510+ r .metrics .rollupL2RelayerCommitLatency .Set (time .Since (oldestBlockTimestamp ).Seconds ())
500511
501512 log .Info ("Sent the commitBatches tx to layer1" , "batches count" , len (batchesToSubmit ), "start index" , firstBatch .Index , "start hash" , firstBatch .Hash , "end index" , lastBatch .Index , "end hash" , lastBatch .Hash , "tx hash" , txHash .String ())
502513}
@@ -1079,7 +1090,7 @@ func calculateTargetPrice(windowSec uint64, strategy StrategyParams, firstTime t
10791090// skipSubmitByFee returns (true, nil) when submission should be skipped right now
10801091// because the blob‐fee is above target and the timeout window hasn’t yet elapsed.
10811092// Otherwise returns (false, err)
1082- func (r * Layer2Relayer ) skipSubmitByFee (oldest time.Time ) (bool , error ) {
1093+ func (r * Layer2Relayer ) skipSubmitByFee (oldest time.Time , metrics * l2RelayerMetrics ) (bool , error ) {
10831094 windowSec := uint64 (r .cfg .BatchSubmission .TimeoutSec )
10841095
10851096 hist , err := r .fetchBlobFeeHistory (windowSec )
@@ -1094,6 +1105,11 @@ func (r *Layer2Relayer) skipSubmitByFee(oldest time.Time) (bool, error) {
10941105 target := calculateTargetPrice (windowSec , r .batchStrategy , oldest , hist )
10951106 current := hist [len (hist )- 1 ]
10961107
1108+ currentFloat , _ := current .Float64 ()
1109+ targetFloat , _ := target .Float64 ()
1110+ metrics .rollupL2RelayerCurrentBlobPrice .Set (currentFloat )
1111+ metrics .rollupL2RelayerTargetBlobPrice .Set (targetFloat )
1112+
10971113 // if current fee > target and still inside the timeout window, skip
10981114 if current .Cmp (target ) > 0 && time .Since (oldest ) < time .Duration (windowSec )* time .Second {
10991115 return true , fmt .Errorf (
0 commit comments