Commit 78d9c5e0 authored by Madhur Shrimal's avatar Madhur Shrimal

add tx manager metrics

add L1 fee
parent f0676c10
...@@ -73,7 +73,7 @@ func NewBatchSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metri ...@@ -73,7 +73,7 @@ func NewBatchSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metri
if err != nil { if err != nil {
return nil, err return nil, err
} }
txManager := txmgr.NewSimpleTxManager("batcher", l, txManagerConfig) txManager := txmgr.NewSimpleTxManager("batcher", l, m, txManagerConfig)
batcherCfg := Config{ batcherCfg := Config{
L1Client: l1Client, L1Client: l1Client,
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/eth" "github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive" "github.com/ethereum-optimism/optimism/op-node/rollup/derive"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics" opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
txmetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
) )
const Namespace = "op_batcher" const Namespace = "op_batcher"
...@@ -22,6 +23,9 @@ type Metricer interface { ...@@ -22,6 +23,9 @@ type Metricer interface {
// Records all L1 and L2 block events // Records all L1 and L2 block events
opmetrics.RefMetricer opmetrics.RefMetricer
// Record Tx metrics
txmetrics.TxMetricer
RecordLatestL1Block(l1ref eth.L1BlockRef) RecordLatestL1Block(l1ref eth.L1BlockRef)
RecordL2BlocksLoaded(l2ref eth.L2BlockRef) RecordL2BlocksLoaded(l2ref eth.L2BlockRef)
RecordChannelOpened(id derive.ChannelID, numPendingBlocks int) RecordChannelOpened(id derive.ChannelID, numPendingBlocks int)
...@@ -43,6 +47,7 @@ type Metrics struct { ...@@ -43,6 +47,7 @@ type Metrics struct {
factory opmetrics.Factory factory opmetrics.Factory
opmetrics.RefMetrics opmetrics.RefMetrics
txmetrics.TxMetrics
Info prometheus.GaugeVec Info prometheus.GaugeVec
Up prometheus.Gauge Up prometheus.Gauge
...@@ -80,6 +85,7 @@ func NewMetrics(procName string) *Metrics { ...@@ -80,6 +85,7 @@ func NewMetrics(procName string) *Metrics {
factory: factory, factory: factory,
RefMetrics: opmetrics.MakeRefMetrics(ns, factory), RefMetrics: opmetrics.MakeRefMetrics(ns, factory),
TxMetrics: txmetrics.MakeTxMetrics(ns, factory),
Info: *factory.NewGaugeVec(prometheus.GaugeOpts{ Info: *factory.NewGaugeVec(prometheus.GaugeOpts{
Namespace: ns, Namespace: ns,
......
...@@ -4,9 +4,13 @@ import ( ...@@ -4,9 +4,13 @@ import (
"github.com/ethereum-optimism/optimism/op-node/eth" "github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive" "github.com/ethereum-optimism/optimism/op-node/rollup/derive"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics" opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
txmetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
) )
type noopMetrics struct{ opmetrics.NoopRefMetrics } type noopMetrics struct {
opmetrics.NoopRefMetrics
txmetrics.NoopTxMetrics
}
var NoopMetrics Metricer = new(noopMetrics) var NoopMetrics Metricer = new(noopMetrics)
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics" opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
txmetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
) )
const Namespace = "op_proposer" const Namespace = "op_proposer"
...@@ -22,6 +23,9 @@ type Metricer interface { ...@@ -22,6 +23,9 @@ type Metricer interface {
// Records all L1 and L2 block events // Records all L1 and L2 block events
opmetrics.RefMetricer opmetrics.RefMetricer
// Record Tx metrics
txmetrics.TxMetricer
RecordL2BlocksProposed(l2ref eth.L2BlockRef) RecordL2BlocksProposed(l2ref eth.L2BlockRef)
} }
...@@ -31,6 +35,7 @@ type Metrics struct { ...@@ -31,6 +35,7 @@ type Metrics struct {
factory opmetrics.Factory factory opmetrics.Factory
opmetrics.RefMetrics opmetrics.RefMetrics
txmetrics.TxMetrics
Info prometheus.GaugeVec Info prometheus.GaugeVec
Up prometheus.Gauge Up prometheus.Gauge
...@@ -53,6 +58,7 @@ func NewMetrics(procName string) *Metrics { ...@@ -53,6 +58,7 @@ func NewMetrics(procName string) *Metrics {
factory: factory, factory: factory,
RefMetrics: opmetrics.MakeRefMetrics(ns, factory), RefMetrics: opmetrics.MakeRefMetrics(ns, factory),
TxMetrics: txmetrics.MakeTxMetrics(ns, factory),
Info: *factory.NewGaugeVec(prometheus.GaugeOpts{ Info: *factory.NewGaugeVec(prometheus.GaugeOpts{
Namespace: ns, Namespace: ns,
......
...@@ -3,9 +3,13 @@ package metrics ...@@ -3,9 +3,13 @@ package metrics
import ( import (
"github.com/ethereum-optimism/optimism/op-node/eth" "github.com/ethereum-optimism/optimism/op-node/eth"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics" opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
txmetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
) )
type noopMetrics struct{ opmetrics.NoopRefMetrics } type noopMetrics struct {
opmetrics.NoopRefMetrics
txmetrics.NoopTxMetrics
}
var NoopMetrics Metricer = new(noopMetrics) var NoopMetrics Metricer = new(noopMetrics)
......
...@@ -42,7 +42,7 @@ func Main(version string, cliCtx *cli.Context) error { ...@@ -42,7 +42,7 @@ func Main(version string, cliCtx *cli.Context) error {
m := metrics.NewMetrics("default") m := metrics.NewMetrics("default")
l.Info("Initializing L2 Output Submitter") l.Info("Initializing L2 Output Submitter")
proposerConfig, err := NewL2OutputSubmitterConfigFromCLIConfig(cfg, l) proposerConfig, err := NewL2OutputSubmitterConfigFromCLIConfig(cfg, l, m)
if err != nil { if err != nil {
l.Error("Unable to create the L2 Output Submitter", "error", err) l.Error("Unable to create the L2 Output Submitter", "error", err)
return err return err
...@@ -138,7 +138,7 @@ type L2OutputSubmitter struct { ...@@ -138,7 +138,7 @@ type L2OutputSubmitter struct {
// NewL2OutputSubmitterFromCLIConfig creates a new L2 Output Submitter given the CLI Config // NewL2OutputSubmitterFromCLIConfig creates a new L2 Output Submitter given the CLI Config
func NewL2OutputSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metricer) (*L2OutputSubmitter, error) { func NewL2OutputSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metricer) (*L2OutputSubmitter, error) {
proposerConfig, err := NewL2OutputSubmitterConfigFromCLIConfig(cfg, l) proposerConfig, err := NewL2OutputSubmitterConfigFromCLIConfig(cfg, l, m)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -146,7 +146,7 @@ func NewL2OutputSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Me ...@@ -146,7 +146,7 @@ func NewL2OutputSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Me
} }
// NewL2OutputSubmitterConfigFromCLIConfig creates the proposer config from the CLI config. // NewL2OutputSubmitterConfigFromCLIConfig creates the proposer config from the CLI config.
func NewL2OutputSubmitterConfigFromCLIConfig(cfg CLIConfig, l log.Logger) (*Config, error) { func NewL2OutputSubmitterConfigFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metricer) (*Config, error) {
l2ooAddress, err := parseAddress(cfg.L2OOAddress) l2ooAddress, err := parseAddress(cfg.L2OOAddress)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -156,7 +156,7 @@ func NewL2OutputSubmitterConfigFromCLIConfig(cfg CLIConfig, l log.Logger) (*Conf ...@@ -156,7 +156,7 @@ func NewL2OutputSubmitterConfigFromCLIConfig(cfg CLIConfig, l log.Logger) (*Conf
if err != nil { if err != nil {
return nil, err return nil, err
} }
txManager := txmgr.NewSimpleTxManager("proposer", l, txManagerConfig) txManager := txmgr.NewSimpleTxManager("proposer", l, m, txManagerConfig)
// Connect to L1 and L2 providers. Perform these last since they are the most expensive. // Connect to L1 and L2 providers. Perform these last since they are the most expensive.
ctx := context.Background() ctx := context.Background()
......
package metrics
import "github.com/ethereum/go-ethereum/core/types"
type NoopTxMetrics struct{}
func (*NoopTxMetrics) RecordL1GasFee(*types.Receipt) {}
package metrics
import (
"github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/prometheus/client_golang/prometheus"
)
type TxMetricer interface {
RecordL1GasFee(receipt *types.Receipt)
}
type TxMetrics struct {
TxL1GasFee prometheus.Gauge
}
var _ TxMetricer = (*TxMetrics)(nil)
func MakeTxMetrics(ns string, factory metrics.Factory) TxMetrics {
return TxMetrics{
TxL1GasFee: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "tx_fee_gwei",
Help: "L1 gas fee for transactions in GWEI",
Subsystem: "txmgr",
}),
}
}
func (t *TxMetrics) RecordL1GasFee(receipt *types.Receipt) {
t.TxL1GasFee.Set(float64(receipt.EffectiveGasPrice.Uint64() * receipt.GasUsed / params.GWei))
}
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"math/big" "math/big"
"strings" "strings"
"sync" "sync"
...@@ -15,6 +16,8 @@ import ( ...@@ -15,6 +16,8 @@ import (
"github.com/ethereum/go-ethereum/core/txpool" "github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
) )
// Geth defaults the priceBump to 10 // Geth defaults the priceBump to 10
...@@ -80,10 +83,11 @@ type SimpleTxManager struct { ...@@ -80,10 +83,11 @@ type SimpleTxManager struct {
backend ETHBackend backend ETHBackend
l log.Logger l log.Logger
metr metrics.TxMetricer
} }
// NewSimpleTxManager initializes a new SimpleTxManager with the passed Config. // NewSimpleTxManager initializes a new SimpleTxManager with the passed Config.
func NewSimpleTxManager(name string, l log.Logger, cfg Config) *SimpleTxManager { func NewSimpleTxManager(name string, l log.Logger, m metrics.TxMetricer, cfg Config) *SimpleTxManager {
if cfg.NumConfirmations == 0 { if cfg.NumConfirmations == 0 {
panic("txmgr: NumConfirmations cannot be zero") panic("txmgr: NumConfirmations cannot be zero")
} }
...@@ -97,6 +101,7 @@ func NewSimpleTxManager(name string, l log.Logger, cfg Config) *SimpleTxManager ...@@ -97,6 +101,7 @@ func NewSimpleTxManager(name string, l log.Logger, cfg Config) *SimpleTxManager
cfg: cfg, cfg: cfg,
backend: cfg.Backend, backend: cfg.Backend,
l: l.New("service", name), l: l.New("service", name),
metr: m,
} }
} }
...@@ -281,6 +286,7 @@ func (m *SimpleTxManager) publishAndWaitForTx(ctx context.Context, tx *types.Tra ...@@ -281,6 +286,7 @@ func (m *SimpleTxManager) publishAndWaitForTx(ctx context.Context, tx *types.Tra
} }
select { select {
case receiptChan <- receipt: case receiptChan <- receipt:
m.metr.RecordL1GasFee(receipt)
default: default:
} }
} }
......
...@@ -12,6 +12,8 @@ import ( ...@@ -12,6 +12,8 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-node/testlog" "github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
...@@ -39,7 +41,7 @@ func newTestHarnessWithConfig(t *testing.T, cfg Config) *testHarness { ...@@ -39,7 +41,7 @@ func newTestHarnessWithConfig(t *testing.T, cfg Config) *testHarness {
g := newGasPricer(3) g := newGasPricer(3)
backend := newMockBackend(g) backend := newMockBackend(g)
cfg.Backend = backend cfg.Backend = backend
mgr := NewSimpleTxManager("TEST", testlog.Logger(t, log.LvlCrit), cfg) mgr := NewSimpleTxManager("TEST", testlog.Logger(t, log.LvlCrit), &metrics.NoopTxMetrics{}, cfg)
return &testHarness{ return &testHarness{
cfg: cfg, cfg: cfg,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment