diff --git a/op-node/metrics/metrics.go b/op-node/metrics/metrics.go index 88d8c4d0caa36..6e1b664eca2b6 100644 --- a/op-node/metrics/metrics.go +++ b/op-node/metrics/metrics.go @@ -35,6 +35,7 @@ type Metricer interface { RecordRPCClientRequest(method string) func(err error) RecordRPCClientResponse(method string, err error) SetDerivationIdle(status bool) + SetSequencerState(active bool) RecordPipelineReset() RecordSequencingError() RecordPublishingError() @@ -48,7 +49,7 @@ type Metricer interface { RecordL2Ref(name string, ref eth.L2BlockRef) RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID) RecordDerivedBatches(batchType string) - CountSequencedTxs(count int) + CountSequencedTxsInBlock(txns int, deposits int) RecordL1ReorgDepth(d uint64) RecordSequencerInconsistentL1Origin(from eth.BlockID, to eth.BlockID) RecordSequencerReset() @@ -94,6 +95,7 @@ type Metrics struct { DerivationErrors *metrics.Event SequencingErrors *metrics.Event PublishingErrors *metrics.Event + SequencerActive prometheus.Gauge EmittedEvents *prometheus.CounterVec ProcessedEvents *prometheus.CounterVec @@ -133,7 +135,7 @@ type Metrics struct { L1ReorgDepth prometheus.Histogram - TransactionsSequencedTotal prometheus.Counter + TransactionsSequencedTotal *prometheus.CounterVec AltDAMetrics altda.Metricer @@ -209,6 +211,11 @@ func NewMetrics(procName string) *Metrics { DerivationErrors: metrics.NewEvent(factory, ns, "", "derivation_errors", "derivation errors"), SequencingErrors: metrics.NewEvent(factory, ns, "", "sequencing_errors", "sequencing errors"), PublishingErrors: metrics.NewEvent(factory, ns, "", "publishing_errors", "p2p publishing errors"), + SequencerActive: factory.NewGauge(prometheus.GaugeOpts{ + Namespace: ns, + Name: "sequencer_active", + Help: "1 if sequencer active, 0 otherwise", + }), EmittedEvents: factory.NewCounterVec( prometheus.CounterOpts{ @@ -261,12 +268,11 @@ func NewMetrics(procName string) *Metrics { Help: "Histogram of L1 Reorg Depths", }), - TransactionsSequencedTotal: factory.NewGauge(prometheus.GaugeOpts{ + TransactionsSequencedTotal: factory.NewCounterVec(prometheus.CounterOpts{ Namespace: ns, Name: "transactions_sequenced_total", Help: "Count of total transactions sequenced", - }), - + }, []string{"type"}), PeerCount: factory.NewGauge(prometheus.GaugeOpts{ Namespace: ns, Subsystem: "p2p", @@ -470,6 +476,14 @@ func (m *Metrics) SetDerivationIdle(status bool) { m.DerivationIdle.Set(val) } +func (m *Metrics) SetSequencerState(active bool) { + var val float64 + if active { + val = 1 + } + m.SequencerActive.Set(val) +} + func (m *Metrics) RecordPipelineReset() { m.PipelineResets.Record() } @@ -516,8 +530,9 @@ func (m *Metrics) RecordDerivedBatches(batchType string) { m.DerivedBatches.Record(batchType) } -func (m *Metrics) CountSequencedTxs(count int) { - m.TransactionsSequencedTotal.Add(float64(count)) +func (m *Metrics) CountSequencedTxsInBlock(txns int, deposits int) { + m.TransactionsSequencedTotal.WithLabelValues("deposits").Add(float64(deposits)) + m.TransactionsSequencedTotal.WithLabelValues("txns").Add(float64(txns - deposits)) } func (m *Metrics) RecordL1ReorgDepth(d uint64) { @@ -686,6 +701,9 @@ func (n *noopMetricer) RecordUp() { func (n *noopMetricer) SetDerivationIdle(status bool) { } +func (m *noopMetricer) SetSequencerState(active bool) { +} + func (n *noopMetricer) RecordPipelineReset() { } @@ -725,7 +743,7 @@ func (n *noopMetricer) RecordUnsafePayloadsBuffer(length uint64, memSize uint64, func (n *noopMetricer) RecordDerivedBatches(batchType string) { } -func (n *noopMetricer) CountSequencedTxs(count int) { +func (n *noopMetricer) CountSequencedTxsInBlock(txns int, deposits int) { } func (n *noopMetricer) RecordL1ReorgDepth(d uint64) { diff --git a/op-node/node/config_persistence.go b/op-node/node/config_persistence.go index 7a30c11b9c9ce..3f2b8b47537e9 100644 --- a/op-node/node/config_persistence.go +++ b/op-node/node/config_persistence.go @@ -55,6 +55,7 @@ func (p *ActiveConfigPersistence) SequencerStopped() error { func (p *ActiveConfigPersistence) persist(sequencerStarted bool) error { p.lock.Lock() defer p.lock.Unlock() + data, err := json.Marshal(persistedState{SequencerStarted: &sequencerStarted}) if err != nil { return fmt.Errorf("marshall new config: %w", err) diff --git a/op-node/rollup/driver/driver.go b/op-node/rollup/driver/driver.go index 1fd751846cf3e..01a05fe2b5380 100644 --- a/op-node/rollup/driver/driver.go +++ b/op-node/rollup/driver/driver.go @@ -49,6 +49,7 @@ type Metrics interface { RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID) SetDerivationIdle(idle bool) + SetSequencerState(active bool) RecordL1ReorgDepth(d uint64) diff --git a/op-node/rollup/engine/build_seal.go b/op-node/rollup/engine/build_seal.go index b292681e13f12..25c1d95b8e7d3 100644 --- a/op-node/rollup/engine/build_seal.go +++ b/op-node/rollup/engine/build_seal.go @@ -110,10 +110,11 @@ func (eq *EngDeriver) onBuildSeal(ev BuildSealEvent) { eq.metrics.RecordSequencerBuildingDiffTime(buildTime - time.Duration(eq.cfg.BlockTime)*time.Second) txnCount := len(envelope.ExecutionPayload.Transactions) - eq.metrics.CountSequencedTxs(txnCount) + depositCount, _ := lastDeposit(envelope.ExecutionPayload.Transactions) + eq.metrics.CountSequencedTxsInBlock(txnCount, depositCount) eq.log.Debug("Processed new L2 block", "l2_unsafe", ref, "l1_origin", ref.L1Origin, - "txs", txnCount, "time", ref.Time, "seal_time", sealTime, "build_time", buildTime) + "txs", txnCount, "deposits", depositCount, "time", ref.Time, "seal_time", sealTime, "build_time", buildTime) eq.emitter.Emit(BuildSealedEvent{ Concluding: ev.Concluding, diff --git a/op-node/rollup/engine/events.go b/op-node/rollup/engine/events.go index bb44995648752..b6ba85cbcbe78 100644 --- a/op-node/rollup/engine/events.go +++ b/op-node/rollup/engine/events.go @@ -15,7 +15,7 @@ import ( ) type Metrics interface { - CountSequencedTxs(count int) + CountSequencedTxsInBlock(txns int, deposits int) RecordSequencerBuildingDiffTime(duration time.Duration) RecordSequencerSealingTime(duration time.Duration) diff --git a/op-node/rollup/sequencing/sequencer.go b/op-node/rollup/sequencing/sequencer.go index b6605d601fa7a..e8b7033273edb 100644 --- a/op-node/rollup/sequencing/sequencer.go +++ b/op-node/rollup/sequencing/sequencer.go @@ -33,6 +33,7 @@ type L1OriginSelectorIface interface { } type Metrics interface { + SetSequencerState(active bool) RecordSequencerInconsistentL1Origin(from eth.BlockID, to eth.BlockID) RecordSequencerReset() RecordSequencingError() @@ -619,6 +620,7 @@ func (d *Sequencer) Init(ctx context.Context, active bool) error { if active { return d.forceStart() } else { + d.metrics.SetSequencerState(false) if err := d.listener.SequencerStopped(); err != nil { return fmt.Errorf("failed to notify sequencer-state listener of initial stopped state: %w", err) } @@ -652,6 +654,7 @@ func (d *Sequencer) forceStart() error { d.nextActionOK = true d.nextAction = d.timeNow() d.active.Store(true) + d.metrics.SetSequencerState(true) d.log.Info("Sequencer has been started", "next action", d.nextAction) return nil } @@ -697,6 +700,7 @@ func (d *Sequencer) Stop(ctx context.Context) (common.Hash, error) { d.nextActionOK = false d.active.Store(false) + d.metrics.SetSequencerState(false) d.log.Info("Sequencer has been stopped") return d.latestHead.Hash, nil } diff --git a/op-service/testutils/metrics.go b/op-service/testutils/metrics.go index 421d32f2109c5..25edee14a0684 100644 --- a/op-service/testutils/metrics.go +++ b/op-service/testutils/metrics.go @@ -17,7 +17,7 @@ type TestDerivationMetrics struct { FnRecordChannelTimedOut func() } -func (t *TestDerivationMetrics) CountSequencedTxs(count int) { +func (t *TestDerivationMetrics) CountSequencedTxsInBlock(txns int, deposits int) { } func (t *TestDerivationMetrics) RecordSequencerBuildingDiffTime(duration time.Duration) {