Skip to content

Commit aba2ddd

Browse files
authored
feat: add metrics finalized block (#1172)
1 parent 2500647 commit aba2ddd

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

rollup/rollup_sync_service/rollup_sync_service.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/scroll-tech/go-ethereum/core/rawdb"
1818
"github.com/scroll-tech/go-ethereum/ethdb"
1919
"github.com/scroll-tech/go-ethereum/log"
20+
"github.com/scroll-tech/go-ethereum/metrics"
2021
"github.com/scroll-tech/go-ethereum/node"
2122
"github.com/scroll-tech/go-ethereum/params"
2223
"github.com/scroll-tech/go-ethereum/rollup/da_syncer"
@@ -43,7 +44,10 @@ const (
4344
defaultLogInterval = 5 * time.Minute
4445
)
4546

46-
var ErrShouldResetSyncHeight = errors.New("ErrShouldResetSyncHeight")
47+
var (
48+
finalizedBlockGauge = metrics.NewRegisteredGauge("chain/head/finalized", nil)
49+
ErrShouldResetSyncHeight = errors.New("ErrShouldResetSyncHeight")
50+
)
4751

4852
// RollupSyncService collects ScrollChain batch commit/revert/finalize events and stores metadata into db.
4953
type RollupSyncService struct {
@@ -135,6 +139,11 @@ func (s *RollupSyncService) Start() {
135139

136140
log.Info("Starting rollup event sync background service", "latest processed block", s.callDataBlobSource.L1Height())
137141

142+
finalizedBlockHeightPtr := rawdb.ReadFinalizedL2BlockNumber(s.db)
143+
if finalizedBlockHeightPtr != nil {
144+
finalizedBlockGauge.Update(int64(*finalizedBlockHeightPtr))
145+
}
146+
138147
go func() {
139148
syncTicker := time.NewTicker(defaultSyncInterval)
140149
defer syncTicker.Stop()
@@ -321,6 +330,7 @@ func (s *RollupSyncService) updateRollupEvents(daEntries da.Entries) error {
321330
return fmt.Errorf("failed to batch write finalized batch meta to database: %w", err)
322331
}
323332
rawdb.WriteFinalizedL2BlockNumber(s.db, highestFinalizedBlockNumber)
333+
finalizedBlockGauge.Update(int64(highestFinalizedBlockNumber))
324334
rawdb.WriteLastFinalizedBatchIndex(s.db, batchIndex)
325335
log.Debug("write finalized l2 block number", "batch index", batchIndex, "finalized l2 block height", highestFinalizedBlockNumber)
326336

0 commit comments

Comments
 (0)