Skip to content

Commit ae34020

Browse files
ranchalpjonastheis
andauthored
perf(relayer): submission strategy fix logs, use blocktime for submission strategy and log metrics. (#1663)
Co-authored-by: ranchalp <[email protected]> Co-authored-by: Jonas Theis <[email protected]>
1 parent fa9fab6 commit ae34020

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

common/database/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (g *gormLogger) Error(_ context.Context, msg string, data ...interface{}) {
4141
func (g *gormLogger) Trace(_ context.Context, begin time.Time, fc func() (string, int64), err error) {
4242
elapsed := time.Since(begin)
4343
sql, rowsAffected := fc()
44-
g.gethLogger.Debug("gorm", "line", utils.FileWithLineNum(), "cost", elapsed, "sql", sql, "rowsAffected", rowsAffected, "err", err)
44+
g.gethLogger.Trace("gorm", "line", utils.FileWithLineNum(), "cost", elapsed, "sql", sql, "rowsAffected", rowsAffected, "err", err)
4545
}
4646

4747
// InitDB init the db handler

common/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"runtime/debug"
66
)
77

8-
var tag = "v4.5.15"
8+
var tag = "v4.5.16"
99

1010
var commit = func() string {
1111
if info, ok := debug.ReadBuildInfo(); ok {

rollup/internal/controller/relayer/l2_relayer.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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(

rollup/internal/controller/relayer/l2_relayer_metrics.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ type l2RelayerMetrics struct {
2626

2727
rollupL2RelayerCommitBlockHeight prometheus.Gauge
2828
rollupL2RelayerCommitThroughput prometheus.Counter
29+
30+
rollupL2RelayerCurrentBlobPrice prometheus.Gauge
31+
rollupL2RelayerTargetBlobPrice prometheus.Gauge
32+
rollupL2RelayerCommitLatency prometheus.Gauge
33+
rollupL2RelayerBacklogCounts prometheus.Gauge
2934
}
3035

3136
var (
@@ -104,6 +109,22 @@ func initL2RelayerMetrics(reg prometheus.Registerer) *l2RelayerMetrics {
104109
Name: "rollup_l2_relayer_commit_throughput",
105110
Help: "The cumulative gas used in blocks committed by the L2 relayer",
106111
}),
112+
rollupL2RelayerTargetBlobPrice: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
113+
Name: "rollup_l2_relayer_target_blob_price",
114+
Help: "The target blob price for the L2 relayer's submission strategy",
115+
}),
116+
rollupL2RelayerCurrentBlobPrice: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
117+
Name: "rollup_l2_relayer_current_blob_price",
118+
Help: "The current blob price",
119+
}),
120+
rollupL2RelayerCommitLatency: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
121+
Name: "rollup_l2_relayer_commit_latency",
122+
Help: "The latency of the commit measured from oldest blocktime",
123+
}),
124+
rollupL2RelayerBacklogCounts: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
125+
Name: "rollup_l2_relayer_backlog_counts",
126+
Help: "The number of pending batches in the backlog",
127+
}),
107128
}
108129
})
109130
return l2RelayerMetric

0 commit comments

Comments
 (0)