diff --git a/node/derivation/derivation.go b/node/derivation/derivation.go index 19831f253..cd31e6353 100644 --- a/node/derivation/derivation.go +++ b/node/derivation/derivation.go @@ -174,11 +174,14 @@ func (d *Derivation) derivationBlock(ctx context.Context) { d.logger.Error("eth_getLogs failed", "err", err) return } - latestBatchIndex, err := d.rollup.LastCommittedBatchIndex(nil) + latestBatchIndex, err := d.rollup.LastCommittedBatchIndex(&bind.CallOpts{ + BlockNumber: big.NewInt(int64(latest)), + }) if err != nil { d.logger.Error("query rollup latestCommitted batch Index failed", "err", err) return } + d.metrics.SetLatestBatchIndex(latestBatchIndex.Uint64()) d.logger.Info("fetched rollup tx", "txNum", len(logs), "latestBatchIndex", latestBatchIndex) for _, lg := range logs { @@ -208,6 +211,7 @@ func (d *Derivation) derivationBlock(ctx context.Context) { // only last block of batch d.logger.Info("batch derivation complete", "batch_index", batchInfo.batchIndex, "currentBatchEndBlock", lastHeader.Number.Uint64()) d.metrics.SetL2DeriveHeight(lastHeader.Number.Uint64()) + d.metrics.SetSyncedBatchIndex(batchInfo.batchIndex) withdrawalRoot, err := d.L2ToL1MessagePasser.MessageRoot(&bind.CallOpts{ BlockNumber: lastHeader.Number, }) diff --git a/node/derivation/metrics.go b/node/derivation/metrics.go index 9003db632..da5e8937d 100644 --- a/node/derivation/metrics.go +++ b/node/derivation/metrics.go @@ -18,10 +18,12 @@ const ( ) type Metrics struct { - L1SyncHeight metrics.Gauge - RollupL2Height metrics.Gauge - DeriveL2Height metrics.Gauge - BatchStatus metrics.Gauge + L1SyncHeight metrics.Gauge + RollupL2Height metrics.Gauge + DeriveL2Height metrics.Gauge + BatchStatus metrics.Gauge + LatestBatchIndex metrics.Gauge + SyncedBatchIndex metrics.Gauge } func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { @@ -54,6 +56,18 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { Name: "batch_root_exception", Help: "", }, labels).With(labelsAndValues...), + LatestBatchIndex: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: metricsSubsystem, + Name: "latest_batch_index", + Help: "", + }, labels).With(labelsAndValues...), + SyncedBatchIndex: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: metricsSubsystem, + Name: "synced_batch_index", + Help: "", + }, labels).With(labelsAndValues...), } } @@ -73,6 +87,14 @@ func (m *Metrics) SetBatchStatus(status uint64) { m.BatchStatus.Set(float64(status)) } +func (m *Metrics) SetLatestBatchIndex(batchIndex uint64) { + m.LatestBatchIndex.Set(float64(batchIndex)) +} + +func (m *Metrics) SetSyncedBatchIndex(batchIndex uint64) { + m.SyncedBatchIndex.Set(float64(batchIndex)) +} + func (m *Metrics) Serve(hostname string, port uint64) (*http.Server, error) { mux := http.NewServeMux() mux.Handle("/metrics", promhttp.Handler())