@@ -10,10 +10,6 @@ import (
1010 "strings"
1111 "time"
1212
13- "scroll-tech/common/types"
14- "scroll-tech/common/types/message"
15- "scroll-tech/common/utils"
16-
1713 "github.com/go-resty/resty/v2"
1814 "github.com/prometheus/client_golang/prometheus"
1915 "github.com/scroll-tech/da-codec/encoding"
@@ -27,6 +23,10 @@ import (
2723 "github.com/scroll-tech/go-ethereum/params"
2824 "gorm.io/gorm"
2925
26+ "scroll-tech/common/types"
27+ "scroll-tech/common/types/message"
28+ "scroll-tech/common/utils"
29+
3030 bridgeAbi "scroll-tech/rollup/abi"
3131 "scroll-tech/rollup/internal/config"
3232 "scroll-tech/rollup/internal/controller/sender"
@@ -378,7 +378,7 @@ func (r *Layer2Relayer) ProcessGasPriceOracle() {
378378// ProcessPendingBatches processes the pending batches by sending commitBatch transactions to layer 1.
379379func (r * Layer2Relayer ) ProcessPendingBatches () {
380380 // get pending batches from database in ascending order by their index.
381- dbBatches , err := r .batchOrm .GetFailedAndPendingBatches (r .ctx , max ( 5 , r .cfg .SenderConfig .BatchSubmission .MaxBatches ) )
381+ dbBatches , err := r .batchOrm .GetFailedAndPendingBatches (r .ctx , r .cfg .SenderConfig .BatchSubmission .MaxBatches )
382382 if err != nil {
383383 log .Error ("Failed to fetch pending L2 batches" , "err" , err )
384384 return
@@ -393,63 +393,61 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
393393 return
394394 }
395395
396- batchesToSubmitLen := len (batchesToSubmit )
397396 var dbChunks []* orm.Chunk
398397 var dbParentBatch * orm.Batch
399398
400399 // Verify batches compatibility
401- {
402- dbChunks , err = r .chunkOrm .GetChunksInRange (r .ctx , dbBatch .StartChunkIndex , dbBatch .EndChunkIndex )
403- if err != nil {
404- log .Error ("failed to get chunks in range" , "err" , err )
405- return
406- }
407-
408- // check codec version
409- for _ , dbChunk := range dbChunks {
410- if dbBatch .CodecVersion != dbChunk .CodecVersion {
411- log .Error ("batch codec version is different from chunk codec version" , "batch index" , dbBatch .Index , "chunk index" , dbChunk .Index , "batch codec version" , dbBatch .CodecVersion , "chunk codec version" , dbChunk .CodecVersion )
412- return
413- }
414- }
400+ dbChunks , err = r .chunkOrm .GetChunksInRange (r .ctx , dbBatch .StartChunkIndex , dbBatch .EndChunkIndex )
401+ if err != nil {
402+ log .Error ("failed to get chunks in range" , "err" , err )
403+ return
404+ }
415405
416- if dbBatch .Index == 0 {
417- log .Error ("invalid args: batch index is 0, should only happen in committing genesis batch" )
406+ // check codec version
407+ for _ , dbChunk := range dbChunks {
408+ if dbBatch .CodecVersion != dbChunk .CodecVersion {
409+ log .Error ("batch codec version is different from chunk codec version" , "batch index" , dbBatch .Index , "chunk index" , dbChunk .Index , "batch codec version" , dbBatch .CodecVersion , "chunk codec version" , dbChunk .CodecVersion )
418410 return
419411 }
412+ }
420413
421- // get parent batch
422- if i == 0 {
423- dbParentBatch , err = r .batchOrm .GetBatchByIndex (r .ctx , dbBatch .Index - 1 )
424- if err != nil {
425- log .Error ("failed to get parent batch header" , "err" , err )
426- return
427- }
428- } else {
429- dbParentBatch = dbBatches [i - 1 ]
430- }
414+ if dbBatch .Index == 0 {
415+ log .Error ("invalid args: batch index is 0, should only happen in committing genesis batch" )
416+ return
417+ }
431418
432- // make sure batch index is continuous
433- if dbParentBatch .Index != dbBatch .Index - 1 {
434- log .Error ("parent batch index is not equal to current batch index - 1" , "index" , dbBatch .Index , "parent index" , dbParentBatch .Index )
419+ // get parent batch
420+ if i == 0 {
421+ dbParentBatch , err = r .batchOrm .GetBatchByIndex (r .ctx , dbBatch .Index - 1 )
422+ if err != nil {
423+ log .Error ("failed to get parent batch header" , "err" , err )
435424 return
436425 }
426+ } else {
427+ dbParentBatch = dbBatches [i - 1 ]
428+ }
437429
438- if dbParentBatch .CodecVersion > dbBatch .CodecVersion {
439- log .Error ("parent batch codec version is greater than current batch codec version" , "index" , dbBatch .Index , "hash" , dbBatch .Hash , "parent codec version" , dbParentBatch .CodecVersion , "current codec version" , dbBatch .CodecVersion )
440- return
441- }
430+ // make sure batch index is continuous
431+ if dbParentBatch .Index != dbBatch .Index - 1 {
432+ log .Error ("parent batch index is not equal to current batch index - 1" , "index" , dbBatch .Index , "parent index" , dbParentBatch .Index )
433+ return
434+ }
442435
443- // make sure we commit batches of the same codec version together.
444- // If we encounter a batch with a different codec version, we stop here and will commit the batches we have so far.
445- // The next call of ProcessPendingBatches will then start with the batch with the different codec version.
446- if batchesToSubmitLen > 0 && batchesToSubmit [batchesToSubmitLen - 1 ].Batch .CodecVersion != dbBatch .CodecVersion {
447- break
448- }
436+ if dbParentBatch .CodecVersion > dbBatch .CodecVersion {
437+ log .Error ("parent batch codec version is greater than current batch codec version" , "index" , dbBatch .Index , "hash" , dbBatch .Hash , "parent codec version" , dbParentBatch .CodecVersion , "current codec version" , dbBatch .CodecVersion )
438+ return
439+ }
440+
441+ // make sure we commit batches of the same codec version together.
442+ // If we encounter a batch with a different codec version, we stop here and will commit the batches we have so far.
443+ // The next call of ProcessPendingBatches will then start with the batch with the different codec version.
444+ batchesToSubmitLen := len (batchesToSubmit )
445+ if batchesToSubmitLen > 0 && batchesToSubmit [batchesToSubmitLen - 1 ].Batch .CodecVersion != dbBatch .CodecVersion {
446+ break
449447 }
450448
451449 // if one of the batches is too old, we force submit all batches that we have so far in the next step
452- if ! forceSubmit && time .Since (dbBatch .CreatedAt ) > time .Duration (r .cfg .SenderConfig .BatchSubmission .TimeoutSec )* time .Second {
450+ if r . cfg . SenderConfig . BatchSubmission . TimeoutSec > 0 && ! forceSubmit && time .Since (dbBatch .CreatedAt ) > time .Duration (r .cfg .SenderConfig .BatchSubmission .TimeoutSec )* time .Second {
453451 forceSubmit = true
454452 }
455453
@@ -466,8 +464,9 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
466464 }
467465 }
468466
467+ // we only submit batches if we have a timeout or if we have enough batches to submit
469468 if ! forceSubmit && len (batchesToSubmit ) < r .cfg .SenderConfig .BatchSubmission .MinBatches {
470- log .Debug ("Not enough batches to submit" , "count" , len (batchesToSubmit ), "minBatches" , r .cfg .SenderConfig .BatchSubmission .MinBatches , "maxBatches" , r .cfg .SenderConfig .BatchSubmission .MaxBatches )
469+ log .Info ("Not enough batches to submit" , "count" , len (batchesToSubmit ), "minBatches" , r .cfg .SenderConfig .BatchSubmission .MinBatches , "maxBatches" , r .cfg .SenderConfig .BatchSubmission .MaxBatches )
471470 return
472471 }
473472
0 commit comments