Skip to content

Commit

Permalink
op-node: Update transactions_sequenced_total metric
Browse files Browse the repository at this point in the history
  • Loading branch information
trianglesphere committed Oct 10, 2024
1 parent 46a21ba commit 4b1f84f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
17 changes: 9 additions & 8 deletions op-node/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,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()
Expand Down Expand Up @@ -135,7 +135,7 @@ type Metrics struct {

L1ReorgDepth prometheus.Histogram

TransactionsSequencedTotal prometheus.Counter
TransactionsSequencedTotal *prometheus.CounterVec

AltDAMetrics altda.Metricer

Expand Down Expand Up @@ -268,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",
Expand Down Expand Up @@ -531,8 +530,10 @@ 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("l1_info_deposit").Add(1)
m.TransactionsSequencedTotal.WithLabelValues("deposits").Add(float64(deposits - 1))
m.TransactionsSequencedTotal.WithLabelValues("txns").Add(float64(txns - deposits))
}

func (m *Metrics) RecordL1ReorgDepth(d uint64) {
Expand Down Expand Up @@ -743,7 +744,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) {
Expand Down
12 changes: 10 additions & 2 deletions op-node/rollup/engine/build_seal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/core/types"
)

// PayloadSealInvalidEvent identifies a permanent in-consensus problem with the payload sealing.
Expand Down Expand Up @@ -106,10 +107,17 @@ 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 := 1
for i, txn := range envelope.ExecutionPayload.Transactions {
if txn[0] != types.DepositTxType {
depositCount = i
break
}
}
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{
IsLastInSpan: ev.IsLastInSpan,
Expand Down
2 changes: 1 addition & 1 deletion op-node/rollup/engine/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

type Metrics interface {
CountSequencedTxs(count int)
CountSequencedTxsInBlock(txns int, deposits int)

RecordSequencerBuildingDiffTime(duration time.Duration)
RecordSequencerSealingTime(duration time.Duration)
Expand Down
2 changes: 1 addition & 1 deletion op-service/testutils/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4b1f84f

Please sign in to comment.