From aba2ddda86ea3d28f8ff622c46434a7cff768f4d Mon Sep 17 00:00:00 2001 From: Morty <70688412+yiweichi@users.noreply.github.com> Date: Thu, 15 May 2025 16:29:34 +0800 Subject: [PATCH] feat: add metrics finalized block (#1172) --- rollup/rollup_sync_service/rollup_sync_service.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rollup/rollup_sync_service/rollup_sync_service.go b/rollup/rollup_sync_service/rollup_sync_service.go index 190fd0810e..844147e28c 100644 --- a/rollup/rollup_sync_service/rollup_sync_service.go +++ b/rollup/rollup_sync_service/rollup_sync_service.go @@ -17,6 +17,7 @@ import ( "github.com/scroll-tech/go-ethereum/core/rawdb" "github.com/scroll-tech/go-ethereum/ethdb" "github.com/scroll-tech/go-ethereum/log" + "github.com/scroll-tech/go-ethereum/metrics" "github.com/scroll-tech/go-ethereum/node" "github.com/scroll-tech/go-ethereum/params" "github.com/scroll-tech/go-ethereum/rollup/da_syncer" @@ -43,7 +44,10 @@ const ( defaultLogInterval = 5 * time.Minute ) -var ErrShouldResetSyncHeight = errors.New("ErrShouldResetSyncHeight") +var ( + finalizedBlockGauge = metrics.NewRegisteredGauge("chain/head/finalized", nil) + ErrShouldResetSyncHeight = errors.New("ErrShouldResetSyncHeight") +) // RollupSyncService collects ScrollChain batch commit/revert/finalize events and stores metadata into db. type RollupSyncService struct { @@ -135,6 +139,11 @@ func (s *RollupSyncService) Start() { log.Info("Starting rollup event sync background service", "latest processed block", s.callDataBlobSource.L1Height()) + finalizedBlockHeightPtr := rawdb.ReadFinalizedL2BlockNumber(s.db) + if finalizedBlockHeightPtr != nil { + finalizedBlockGauge.Update(int64(*finalizedBlockHeightPtr)) + } + go func() { syncTicker := time.NewTicker(defaultSyncInterval) defer syncTicker.Stop() @@ -321,6 +330,7 @@ func (s *RollupSyncService) updateRollupEvents(daEntries da.Entries) error { return fmt.Errorf("failed to batch write finalized batch meta to database: %w", err) } rawdb.WriteFinalizedL2BlockNumber(s.db, highestFinalizedBlockNumber) + finalizedBlockGauge.Update(int64(highestFinalizedBlockNumber)) rawdb.WriteLastFinalizedBatchIndex(s.db, batchIndex) log.Debug("write finalized l2 block number", "batch index", batchIndex, "finalized l2 block height", highestFinalizedBlockNumber)