@@ -333,13 +333,16 @@ func (r *Layer2Relayer) commitGenesisBatch(batchHash string, batchHeader []byte,
333333}
334334
335335// ProcessPendingBatches processes the pending batches by sending commitBatch transactions to layer 1.
336- // Pending batchess are submitted if one of the following conditions is met:
336+ // Pending batches are submitted if one of the following conditions is met:
337337// - the first batch is too old -> forceSubmit
338338// - backlogCount > r.cfg.BatchSubmission.BacklogMax -> forceSubmit
339339// - we have at least minBatches AND price hits a desired target price
340340func (r * Layer2Relayer ) ProcessPendingBatches () {
341+ // Get effective batch limits based on validium mode
342+ minBatches , maxBatches := r .getEffectiveBatchLimits ()
343+
341344 // get pending batches from database in ascending order by their index.
342- dbBatches , err := r .batchOrm .GetFailedAndPendingBatches (r .ctx , r . cfg . BatchSubmission . MaxBatches )
345+ dbBatches , err := r .batchOrm .GetFailedAndPendingBatches (r .ctx , maxBatches )
343346 if err != nil {
344347 log .Error ("Failed to fetch pending L2 batches" , "err" , err )
345348 return
@@ -448,21 +451,21 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
448451 break
449452 }
450453
451- if batchesToSubmitLen < r . cfg . BatchSubmission . MaxBatches {
454+ if batchesToSubmitLen < maxBatches {
452455 batchesToSubmit = append (batchesToSubmit , & dbBatchWithChunks {
453456 Batch : dbBatch ,
454457 Chunks : dbChunks ,
455458 })
456459 }
457460
458- if len (batchesToSubmit ) >= r . cfg . BatchSubmission . MaxBatches {
461+ if len (batchesToSubmit ) >= maxBatches {
459462 break
460463 }
461464 }
462465
463466 // we only submit batches if we have a timeout or if we have enough batches to submit
464- if ! forceSubmit && len (batchesToSubmit ) < r . cfg . BatchSubmission . MinBatches {
465- log .Debug ("Not enough batches to submit" , "count" , len (batchesToSubmit ), "minBatches" , r . cfg . BatchSubmission . MinBatches , "maxBatches" , r . cfg . BatchSubmission . MaxBatches )
467+ if ! forceSubmit && len (batchesToSubmit ) < minBatches {
468+ log .Debug ("Not enough batches to submit" , "count" , len (batchesToSubmit ), "minBatches" , minBatches , "maxBatches" , maxBatches )
466469 return
467470 }
468471
@@ -550,6 +553,14 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
550553 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 ())
551554}
552555
556+ // getEffectiveBatchLimits returns the effective min and max batch limits based on validium mode
557+ func (r * Layer2Relayer ) getEffectiveBatchLimits () (int , int ) {
558+ if r .cfg .ValidiumMode {
559+ return 1 , 1 // minBatches=1, maxBatches=1
560+ }
561+ return r .cfg .BatchSubmission .MinBatches , r .cfg .BatchSubmission .MaxBatches
562+ }
563+
553564func (r * Layer2Relayer ) contextIDFromBatches (codecVersion encoding.CodecVersion , batches []* dbBatchWithChunks ) string {
554565 contextIDs := []string {fmt .Sprintf ("v%d" , codecVersion )}
555566 for _ , batch := range batches {
0 commit comments