From b3964960e94b2a2b535af0f780cb7b16f917a92d Mon Sep 17 00:00:00 2001 From: Alejandro Ranchal-Pedrosa Date: Thu, 22 May 2025 09:15:56 +0200 Subject: [PATCH 1/6] Fix logs and use blocktime instead of batchtime --- common/database/db.go | 2 +- rollup/internal/controller/relayer/l2_relayer.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/common/database/db.go b/common/database/db.go index 322ba27115..cd77829ba5 100644 --- a/common/database/db.go +++ b/common/database/db.go @@ -41,7 +41,7 @@ func (g *gormLogger) Error(_ context.Context, msg string, data ...interface{}) { func (g *gormLogger) Trace(_ context.Context, begin time.Time, fc func() (string, int64), err error) { elapsed := time.Since(begin) sql, rowsAffected := fc() - g.gethLogger.Debug("gorm", "line", utils.FileWithLineNum(), "cost", elapsed, "sql", sql, "rowsAffected", rowsAffected, "err", err) + g.gethLogger.Trace("gorm", "line", utils.FileWithLineNum(), "cost", elapsed, "sql", sql, "rowsAffected", rowsAffected, "err", err) } // InitDB init the db handler diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index 856450a8ac..9208cc994c 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -333,9 +333,15 @@ func (r *Layer2Relayer) ProcessPendingBatches() { var forceSubmit bool - oldestBatchTimestamp := dbBatches[0].CreatedAt + startChunk, err := r.chunkOrm.GetChunkByIndex(r.ctx, dbBatches[0].StartChunkIndex) + oldestBlockTimestamp := time.Unix(int64(startChunk.StartBlockTime), 0) + if err != nil { + log.Error("failed to get first chunk", "err", err, "batch index", dbBatches[0].Index, "chunk index", dbBatches[0].StartChunkIndex) + return + } + // if the batch with the oldest index is too old, we force submit all batches that we have so far in the next step - if r.cfg.BatchSubmission.TimeoutSec > 0 && time.Since(oldestBatchTimestamp) > time.Duration(r.cfg.BatchSubmission.TimeoutSec)*time.Second { + if r.cfg.BatchSubmission.TimeoutSec > 0 && time.Since(oldestBlockTimestamp) > time.Duration(r.cfg.BatchSubmission.TimeoutSec)*time.Second { forceSubmit = true } @@ -346,7 +352,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() { if !forceSubmit { // check if we should skip submitting the batch based on the fee target - skip, err := r.skipSubmitByFee(oldestBatchTimestamp) + skip, err := r.skipSubmitByFee(oldestBlockTimestamp) // return if not hitting target price if skip { log.Debug("Skipping batch submission", "reason", err) @@ -432,7 +438,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() { } if forceSubmit { - log.Info("Forcing submission of batches due to timeout", "batch index", batchesToSubmit[0].Batch.Index, "created at", batchesToSubmit[0].Batch.CreatedAt) + log.Info("Forcing submission of batches due to timeout", "batch index", batchesToSubmit[0].Batch.Index, "first block created at", oldestBlockTimestamp) } // We have at least 1 batch to commit From 299759b306c6c22c120d1cdc32c2e6b9a72b7f19 Mon Sep 17 00:00:00 2001 From: Alejandro Ranchal-Pedrosa Date: Thu, 22 May 2025 09:37:41 +0200 Subject: [PATCH 2/6] Add metrics for rollupL2Relayer --- rollup/internal/controller/relayer/l2_relayer.go | 12 ++++++++++-- .../controller/relayer/l2_relayer_metrics.go | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index 9208cc994c..8029add460 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -326,6 +326,8 @@ func (r *Layer2Relayer) ProcessPendingBatches() { // if backlog outgrow max size, force‐submit enough oldest batches backlogCount, err := r.batchOrm.GetFailedAndPendingBatchesCount(r.ctx) + r.metrics.rollupL2RelayerBacklogCounts.Set(float64(backlogCount)) + if err != nil { log.Error("Failed to fetch pending L2 batches", "err", err) return @@ -352,7 +354,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() { if !forceSubmit { // check if we should skip submitting the batch based on the fee target - skip, err := r.skipSubmitByFee(oldestBlockTimestamp) + skip, err := r.skipSubmitByFee(oldestBlockTimestamp, r.metrics) // return if not hitting target price if skip { log.Debug("Skipping batch submission", "reason", err) @@ -503,6 +505,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() { r.metrics.rollupL2RelayerCommitThroughput.Add(float64(totalGasUsed)) r.metrics.rollupL2RelayerProcessPendingBatchSuccessTotal.Add(float64(len(batchesToSubmit))) r.metrics.rollupL2RelayerProcessBatchesPerTxCount.Set(float64(len(batchesToSubmit))) + r.metrics.rollupL2RelayerCommitLatency.Set(time.Since(oldestBlockTimestamp).Seconds()) 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()) } @@ -1085,7 +1088,7 @@ func calculateTargetPrice(windowSec uint64, strategy StrategyParams, firstTime t // skipSubmitByFee returns (true, nil) when submission should be skipped right now // because the blob‐fee is above target and the timeout window hasn’t yet elapsed. // Otherwise returns (false, err) -func (r *Layer2Relayer) skipSubmitByFee(oldest time.Time) (bool, error) { +func (r *Layer2Relayer) skipSubmitByFee(oldest time.Time, metrics *l2RelayerMetrics) (bool, error) { windowSec := uint64(r.cfg.BatchSubmission.TimeoutSec) hist, err := r.fetchBlobFeeHistory(windowSec) @@ -1100,6 +1103,11 @@ func (r *Layer2Relayer) skipSubmitByFee(oldest time.Time) (bool, error) { target := calculateTargetPrice(windowSec, r.batchStrategy, oldest, hist) current := hist[len(hist)-1] + currentFloat, _ := current.Float64() + targetFloat, _ := target.Float64() + metrics.rollupL2RelayerCurrentBlobPrice.Set(currentFloat) + metrics.rollupL2RelayerTargetBlobPrice.Set(targetFloat) + // if current fee > target and still inside the timeout window, skip if current.Cmp(target) > 0 && time.Since(oldest) < time.Duration(windowSec)*time.Second { return true, fmt.Errorf( diff --git a/rollup/internal/controller/relayer/l2_relayer_metrics.go b/rollup/internal/controller/relayer/l2_relayer_metrics.go index 12c70354f5..1abe26ee6d 100644 --- a/rollup/internal/controller/relayer/l2_relayer_metrics.go +++ b/rollup/internal/controller/relayer/l2_relayer_metrics.go @@ -26,6 +26,11 @@ type l2RelayerMetrics struct { rollupL2RelayerCommitBlockHeight prometheus.Gauge rollupL2RelayerCommitThroughput prometheus.Counter + + rollupL2RelayerCurrentBlobPrice prometheus.Gauge + rollupL2RelayerTargetBlobPrice prometheus.Gauge + rollupL2RelayerCommitLatency prometheus.Gauge + rollupL2RelayerBacklogCounts prometheus.Gauge } var ( From ba5e26d0f870efba8f9ce6064670597785ad4275 Mon Sep 17 00:00:00 2001 From: ranchalp Date: Thu, 22 May 2025 07:40:39 +0000 Subject: [PATCH 3/6] =?UTF-8?q?chore:=20auto=20version=20bump=E2=80=89[bot?= =?UTF-8?q?]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/version/version.go b/common/version/version.go index 847d24c076..cb1ff7acc6 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.5.15" +var tag = "v4.5.16" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { From 8c8349b200d695da6ac174cb14b1b7dabfc57f09 Mon Sep 17 00:00:00 2001 From: Alejandro Ranchal-Pedrosa Date: Thu, 22 May 2025 09:58:30 +0200 Subject: [PATCH 4/6] Log batch index and backlog count --- rollup/internal/controller/relayer/l2_relayer.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index 8029add460..6a5277a9c6 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -358,6 +358,8 @@ func (r *Layer2Relayer) ProcessPendingBatches() { // return if not hitting target price if skip { log.Debug("Skipping batch submission", "reason", err) + log.Debug("first batch index", dbBatches[0].Index) + log.Debug("backlog count", backlogCount) return } if err != nil { From fe588650cd1c07c7de346030ceb8e169408dd27f Mon Sep 17 00:00:00 2001 From: Alejandro Ranchal-Pedrosa Date: Thu, 22 May 2025 11:08:04 +0100 Subject: [PATCH 5/6] Update rollup/internal/controller/relayer/l2_relayer.go Co-authored-by: Jonas Theis <4181434+jonastheis@users.noreply.github.com> --- rollup/internal/controller/relayer/l2_relayer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index 6a5277a9c6..418762a470 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -357,7 +357,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() { skip, err := r.skipSubmitByFee(oldestBlockTimestamp, r.metrics) // return if not hitting target price if skip { - log.Debug("Skipping batch submission", "reason", err) + log.Debug("Skipping batch submission", "first batch index", dbBatches[0].Index, "backlog count", backlogCount, "reason", err) log.Debug("first batch index", dbBatches[0].Index) log.Debug("backlog count", backlogCount) return From d9453183ba0804201581c0a51f9f73d2924a32c7 Mon Sep 17 00:00:00 2001 From: Alejandro Ranchal-Pedrosa Date: Thu, 22 May 2025 12:13:32 +0200 Subject: [PATCH 6/6] Init new metrics --- .../controller/relayer/l2_relayer_metrics.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rollup/internal/controller/relayer/l2_relayer_metrics.go b/rollup/internal/controller/relayer/l2_relayer_metrics.go index 1abe26ee6d..00e550588f 100644 --- a/rollup/internal/controller/relayer/l2_relayer_metrics.go +++ b/rollup/internal/controller/relayer/l2_relayer_metrics.go @@ -109,6 +109,22 @@ func initL2RelayerMetrics(reg prometheus.Registerer) *l2RelayerMetrics { Name: "rollup_l2_relayer_commit_throughput", Help: "The cumulative gas used in blocks committed by the L2 relayer", }), + rollupL2RelayerTargetBlobPrice: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ + Name: "rollup_l2_relayer_target_blob_price", + Help: "The target blob price for the L2 relayer's submission strategy", + }), + rollupL2RelayerCurrentBlobPrice: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ + Name: "rollup_l2_relayer_current_blob_price", + Help: "The current blob price", + }), + rollupL2RelayerCommitLatency: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ + Name: "rollup_l2_relayer_commit_latency", + Help: "The latency of the commit measured from oldest blocktime", + }), + rollupL2RelayerBacklogCounts: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ + Name: "rollup_l2_relayer_backlog_counts", + Help: "The number of pending batches in the backlog", + }), } }) return l2RelayerMetric