diff --git a/op-service/txmgr/metrics/noop.go b/op-service/txmgr/metrics/noop.go index b08e5f20bd438..4e9f6f1934428 100644 --- a/op-service/txmgr/metrics/noop.go +++ b/op-service/txmgr/metrics/noop.go @@ -4,4 +4,6 @@ import "github.com/ethereum/go-ethereum/core/types" type NoopTxMetrics struct{} -func (*NoopTxMetrics) RecordL1GasFee(*types.Receipt) {} +func (*NoopTxMetrics) RecordL1GasFee(*types.Receipt) {} +func (*NoopTxMetrics) RecordGasBumpCount(int) {} +func (*NoopTxMetrics) RecordTxConfirmationLatency(int64) {} diff --git a/op-service/txmgr/metrics/tx_metrics.go b/op-service/txmgr/metrics/tx_metrics.go index 6201e13a9b3c5..9f9a36811ffa3 100644 --- a/op-service/txmgr/metrics/tx_metrics.go +++ b/op-service/txmgr/metrics/tx_metrics.go @@ -10,10 +10,14 @@ import ( type TxMetricer interface { RecordL1GasFee(receipt *types.Receipt) + RecordGasBumpCount(times int) + RecordTxConfirmationLatency(latency int64) } type TxMetrics struct { - TxL1GasFee prometheus.Gauge + TxL1GasFee prometheus.Gauge + TxGasBump prometheus.Gauge + LatencyConfirmedTx prometheus.Gauge } var _ TxMetricer = (*TxMetrics)(nil) @@ -26,9 +30,29 @@ func MakeTxMetrics(ns string, factory metrics.Factory) TxMetrics { Help: "L1 gas fee for transactions in GWEI", Subsystem: "txmgr", }), + TxGasBump: factory.NewGauge(prometheus.GaugeOpts{ + Namespace: ns, + Name: "tx_gas_bump", + Help: "Number of times a transaction gas needed to be bumped before it got included", + Subsystem: "txmgr", + }), + LatencyConfirmedTx: factory.NewGauge(prometheus.GaugeOpts{ + Namespace: ns, + Name: "tx_confirmed_latency_ms", + Help: "Latency of a confirmed transaction in milliseconds", + Subsystem: "txmgr", + }), } } func (t *TxMetrics) RecordL1GasFee(receipt *types.Receipt) { t.TxL1GasFee.Set(float64(receipt.EffectiveGasPrice.Uint64() * receipt.GasUsed / params.GWei)) } + +func (t *TxMetrics) RecordGasBumpCount(times int) { + t.TxGasBump.Set(float64(times)) +} + +func (t *TxMetrics) RecordTxConfirmationLatency(latency int64) { + t.LatencyConfirmedTx.Set(float64(latency)) +} diff --git a/op-service/txmgr/txmgr.go b/op-service/txmgr/txmgr.go index 90de074e931ef..7cee0565f18de 100644 --- a/op-service/txmgr/txmgr.go +++ b/op-service/txmgr/txmgr.go @@ -216,6 +216,7 @@ func (m *SimpleTxManager) send(ctx context.Context, tx *types.Transaction) (*typ ticker := time.NewTicker(m.cfg.ResubmissionTimeout) defer ticker.Stop() + bumpCounter := 0 for { select { case <-ticker.C: @@ -231,12 +232,14 @@ func (m *SimpleTxManager) send(ctx context.Context, tx *types.Transaction) (*typ // Increase the gas price & submit the new transaction tx = m.increaseGasPrice(ctx, tx) wg.Add(1) + bumpCounter += 1 go sendTxAsync(tx) case <-ctx.Done(): return nil, ctx.Err() case receipt := <-receiptChan: + m.metr.RecordGasBumpCount(bumpCounter) return receipt, nil } } @@ -251,6 +254,7 @@ func (m *SimpleTxManager) publishAndWaitForTx(ctx context.Context, tx *types.Tra cCtx, cancel := context.WithTimeout(ctx, m.cfg.NetworkTimeout) defer cancel() + t := time.Now() err := m.backend.SendTransaction(cCtx, tx) sendState.ProcessSendError(err) @@ -282,6 +286,7 @@ func (m *SimpleTxManager) publishAndWaitForTx(ctx context.Context, tx *types.Tra } select { case receiptChan <- receipt: + m.metr.RecordTxConfirmationLatency(time.Since(t).Milliseconds()) m.metr.RecordL1GasFee(receipt) default: }