Skip to content

Commit ec71458

Browse files
committed
feat: add metrics chain/head/finalized
1 parent d178b00 commit ec71458

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

rollup/rollup_sync_service/rollup_sync_service.go

Lines changed: 13 additions & 1 deletion
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,13 @@ func (s *RollupSyncService) Start() {
135139

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

142+
143+
144+
finalizedBlockHeightPtr := rawdb.ReadFinalizedL2BlockNumber(s.db)
145+
if finalizedBlockHeightPtr != nil {
146+
finalizedBlockGauge.Update(int64(*finalizedBlockHeightPtr))
147+
}
148+
138149
go func() {
139150
syncTicker := time.NewTicker(defaultSyncInterval)
140151
defer syncTicker.Stop()
@@ -321,6 +332,7 @@ func (s *RollupSyncService) updateRollupEvents(daEntries da.Entries) error {
321332
return fmt.Errorf("failed to batch write finalized batch meta to database: %w", err)
322333
}
323334
rawdb.WriteFinalizedL2BlockNumber(s.db, highestFinalizedBlockNumber)
335+
finalizedBlockGauge.Update(int64(highestFinalizedBlockNumber))
324336
rawdb.WriteLastFinalizedBatchIndex(s.db, batchIndex)
325337
log.Debug("write finalized l2 block number", "batch index", batchIndex, "finalized l2 block height", highestFinalizedBlockNumber)
326338

0 commit comments

Comments
 (0)