Skip to content

Commit 404a625

Browse files
authored
feat(rollup-relayer): add sync height and throughput metrics (#1520)
1 parent 736d850 commit 404a625

File tree

7 files changed

+70
-1
lines changed

7 files changed

+70
-1
lines changed

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.4.61"
8+
var tag = "v4.4.62"
99

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

rollup/internal/controller/relayer/l2_relayer.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,18 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
450450
log.Error("UpdateCommitTxHashAndRollupStatus failed", "hash", dbBatch.Hash, "index", dbBatch.Index, "err", err)
451451
return
452452
}
453+
454+
var maxBlockHeight uint64
455+
var totalGasUsed uint64
456+
for _, dbChunk := range dbChunks {
457+
if dbChunk.EndBlockNumber > maxBlockHeight {
458+
maxBlockHeight = dbChunk.EndBlockNumber
459+
}
460+
totalGasUsed += dbChunk.TotalL2TxGas
461+
}
462+
r.metrics.rollupL2RelayerCommitBlockHeight.Set(float64(maxBlockHeight))
463+
r.metrics.rollupL2RelayerCommitThroughput.Add(float64(totalGasUsed))
464+
453465
r.metrics.rollupL2RelayerProcessPendingBatchSuccessTotal.Inc()
454466
log.Info("Sent the commitBatch tx to layer1", "batch index", dbBatch.Index, "batch hash", dbBatch.Hash, "tx hash", txHash.String())
455467
}

rollup/internal/controller/relayer/l2_relayer_metrics.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type l2RelayerMetrics struct {
2929
rollupL2RelayerProcessPendingBundlesFinalizedSuccessTotal prometheus.Counter
3030
rollupL2BundlesFinalizedConfirmedTotal prometheus.Counter
3131
rollupL2BundlesFinalizedConfirmedFailedTotal prometheus.Counter
32+
33+
rollupL2RelayerCommitBlockHeight prometheus.Gauge
34+
rollupL2RelayerCommitThroughput prometheus.Counter
3235
}
3336

3437
var (
@@ -123,6 +126,14 @@ func initL2RelayerMetrics(reg prometheus.Registerer) *l2RelayerMetrics {
123126
Name: "rollup_layer2_bundles_finalized_confirmed_failed_total",
124127
Help: "Total number of failed confirmations for finalized bundles on layer2.",
125128
}),
129+
rollupL2RelayerCommitBlockHeight: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
130+
Name: "rollup_l2_relayer_commit_block_height",
131+
Help: "The latest block height committed by the L2 relayer",
132+
}),
133+
rollupL2RelayerCommitThroughput: promauto.With(reg).NewCounter(prometheus.CounterOpts{
134+
Name: "rollup_l2_relayer_commit_throughput",
135+
Help: "The cumulative gas used in blocks committed by the L2 relayer",
136+
}),
126137
}
127138
})
128139
return l2RelayerMetric

rollup/internal/controller/watcher/batch_proposer.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ type BatchProposer struct {
5353

5454
// total number of times that batch proposer stops early due to compressed data compatibility breach
5555
compressedDataCompatibilityBreachTotal prometheus.Counter
56+
57+
batchProposeBlockHeight prometheus.Gauge
58+
batchProposeThroughput prometheus.Counter
5659
}
5760

5861
// NewBatchProposer creates a new BatchProposer instance.
@@ -134,6 +137,14 @@ func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, chai
134137
Name: "rollup_propose_batch_estimate_blob_size_time",
135138
Help: "Time taken to estimate blob size for the chunk.",
136139
}),
140+
batchProposeBlockHeight: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
141+
Name: "rollup_batch_propose_block_height",
142+
Help: "The block height of the latest proposed batch",
143+
}),
144+
batchProposeThroughput: promauto.With(reg).NewCounter(prometheus.CounterOpts{
145+
Name: "rollup_batch_propose_throughput",
146+
Help: "The total gas used in proposed batches",
147+
}),
137148
}
138149

139150
return p
@@ -195,6 +206,18 @@ func (p *BatchProposer) updateDBBatchInfo(batch *encoding.Batch, codecVersion en
195206
p.recordAllBatchMetrics(metrics)
196207
}
197208

209+
if len(batch.Chunks) > 0 && len(batch.Chunks[len(batch.Chunks)-1].Blocks) > 0 {
210+
lastChunk := batch.Chunks[len(batch.Chunks)-1]
211+
lastBlock := lastChunk.Blocks[len(lastChunk.Blocks)-1]
212+
p.batchProposeBlockHeight.Set(float64(lastBlock.Header.Number.Uint64()))
213+
}
214+
215+
var totalGasUsed uint64
216+
for _, chunk := range batch.Chunks {
217+
totalGasUsed += chunk.L2GasUsed()
218+
}
219+
p.batchProposeThroughput.Add(float64(totalGasUsed))
220+
198221
p.proposeBatchUpdateInfoTotal.Inc()
199222
err := p.db.Transaction(func(dbTX *gorm.DB) error {
200223
dbBatch, dbErr := p.batchOrm.InsertBatch(p.ctx, batch, codecConfig, *metrics, dbTX)

rollup/internal/controller/watcher/chunk_proposer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ type ChunkProposer struct {
5656

5757
// total number of times that chunk proposer stops early due to compressed data compatibility breach
5858
compressedDataCompatibilityBreachTotal prometheus.Counter
59+
60+
chunkProposeBlockHeight prometheus.Gauge
61+
chunkProposeThroughput prometheus.Counter
5962
}
6063

6164
// NewChunkProposer creates a new ChunkProposer instance.
@@ -150,6 +153,14 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, chai
150153
Name: "rollup_propose_chunk_estimate_blob_size_time",
151154
Help: "Time taken to estimate blob size for the chunk.",
152155
}),
156+
chunkProposeBlockHeight: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
157+
Name: "rollup_chunk_propose_block_height",
158+
Help: "The block height of the latest proposed chunk",
159+
}),
160+
chunkProposeThroughput: promauto.With(reg).NewCounter(prometheus.CounterOpts{
161+
Name: "rollup_chunk_propose_throughput",
162+
Help: "The total gas used in proposed chunks",
163+
}),
153164
}
154165

155166
return p
@@ -214,6 +225,11 @@ func (p *ChunkProposer) updateDBChunkInfo(chunk *encoding.Chunk, codecVersion en
214225
p.recordAllChunkMetrics(metrics)
215226
}
216227

228+
if len(chunk.Blocks) > 0 {
229+
p.chunkProposeBlockHeight.Set(float64(chunk.Blocks[len(chunk.Blocks)-1].Header.Number.Uint64()))
230+
}
231+
p.chunkProposeThroughput.Add(float64(chunk.L2GasUsed()))
232+
217233
p.proposeChunkUpdateInfoTotal.Inc()
218234
err := p.db.Transaction(func(dbTX *gorm.DB) error {
219235
dbChunk, err := p.chunkOrm.InsertChunk(p.ctx, chunk, codecConfig, *metrics, dbTX)

rollup/internal/controller/watcher/l2_watcher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func (w *L2WatcherClient) getAndStoreBlocks(ctx context.Context, from, to uint64
152152
return fmt.Errorf("failed to estimate block L1 commit calldata size: %v", err)
153153
}
154154
w.metrics.rollupL2BlockL1CommitCalldataSize.Set(float64(blockL1CommitCalldataSize))
155+
w.metrics.rollupL2WatcherSyncThroughput.Add(float64(block.Header.GasUsed))
155156
}
156157
if err := w.l2BlockOrm.InsertL2Blocks(w.ctx, blocks); err != nil {
157158
return fmt.Errorf("failed to batch insert BlockTraces: %v", err)

rollup/internal/controller/watcher/l2_watcher_metrics.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type l2WatcherMetrics struct {
1313
rollupL2BlocksFetchedGap prometheus.Gauge
1414
rollupL2BlockL1CommitCalldataSize prometheus.Gauge
1515
fetchNilRowConsumptionBlockTotal prometheus.Counter
16+
17+
rollupL2WatcherSyncThroughput prometheus.Counter
1618
}
1719

1820
var (
@@ -43,6 +45,10 @@ func initL2WatcherMetrics(reg prometheus.Registerer) *l2WatcherMetrics {
4345
Name: "rollup_l2_watcher_fetch_nil_row_consumption_block_total",
4446
Help: "The total number of occurrences where a fetched block has nil RowConsumption",
4547
}),
48+
rollupL2WatcherSyncThroughput: prometheus.NewCounter(prometheus.CounterOpts{
49+
Name: "rollup_l2_watcher_sync_throughput",
50+
Help: "The cumulative gas used in blocks that L2 watcher sync",
51+
}),
4652
}
4753
})
4854
return l2WatcherMetric

0 commit comments

Comments
 (0)