Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion node/derivation/derivation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
})
Expand Down
30 changes: 26 additions & 4 deletions node/derivation/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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...),
}
}

Expand All @@ -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())
Expand Down