Skip to content

Commit 72aa00e

Browse files
author
colinlyguo
committed
address comments
1 parent 90282fc commit 72aa00e

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

rollup/cmd/rollup_relayer/app/app.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@ func action(ctx *cli.Context) error {
9696
log.Crit("cfg.L2Config.ChunkProposerConfig.MaxL2GasPerChunk must be greater than 0")
9797
}
9898

99-
if cfg.L2Config.RelayerConfig.ValidiumMode {
100-
// Force single batch submission for validium mode, this looks a bit hacky but it avoids more changes in the relayer code.
101-
cfg.L2Config.RelayerConfig.BatchSubmission.MinBatches = 1
102-
cfg.L2Config.RelayerConfig.BatchSubmission.MaxBatches = 1
103-
log.Info("Validium mode detected, forcing single batch submission", "minBatches", 1, "maxBatches", 1)
104-
}
105-
10699
l2relayer, err := relayer.NewLayer2Relayer(ctx.Context, l2client, db, cfg.L2Config.RelayerConfig, genesis.Config, relayer.ServiceTypeL2RollupRelayer, registry)
107100
if err != nil {
108101
log.Crit("failed to create l2 relayer", "config file", cfgFile, "error", err)

rollup/internal/controller/relayer/l2_relayer.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
340340
func (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+
553564
func (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

Comments
 (0)