Skip to content
1 change: 1 addition & 0 deletions op-batcher/batcher/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (c *channel) TxFailed(id string, failoverToEthDA bool) {
// TODO: figure out how to switch to blobs/auto instead. Might need to make
// batcherService.initChannelConfig function stateless so that we can reuse it.
c.cfg.DaType = DaTypeCalldata
c.metr.RecordFailoverToEthDA()
}
c.metr.RecordBatchTxFailed()
}
Expand Down
8 changes: 7 additions & 1 deletion op-batcher/batcher/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type txRef struct {
id txID
isCancel bool
isBlob bool
daType DaType
size int
}

func (r txRef) String() string {
Expand Down Expand Up @@ -910,7 +912,7 @@ func (l *BatchSubmitter) sendTx(txdata txData, isCancel bool, candidate *txmgr.T
candidate.GasLimit = floorDataGas
}

queue.Send(txRef{id: txdata.ID(), isCancel: isCancel, isBlob: txdata.daType == DaTypeBlob}, *candidate, receiptsCh)
queue.Send(txRef{id: txdata.ID(), isCancel: isCancel, isBlob: txdata.daType == DaTypeBlob, daType: txdata.daType, size: txdata.Len()}, *candidate, receiptsCh)
}

// Copypaste from upstream geth
Expand Down Expand Up @@ -963,6 +965,10 @@ func (l *BatchSubmitter) handleReceipt(r txmgr.TxReceipt[txRef]) {
l.recordFailedTx(r.ID.id, r.Err)
} else if r.Receipt != nil {
l.recordConfirmedTx(r.ID.id, r.Receipt)
if !r.ID.isCancel {
l.Metr.RecordBatchDaType(r.ID.daType.Name())
l.Metr.RecordBatchDataSizeBytes(r.ID.daType.Name(), r.ID.size)
}
}
// Both r.Err and r.Receipt can be nil, in which case we do nothing.
}
Expand Down
13 changes: 13 additions & 0 deletions op-batcher/batcher/tx_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ const (
DaTypeAltDA
)

func (t DaType) Name() string {
switch t {
case DaTypeCalldata:
return "calldata"
case DaTypeBlob:
return "blob"
case DaTypeAltDA:
return "altda"
default:
return "unknown"
}
}

// txData represents the data for a single transaction.
//
// Note: The batcher currently sends exactly one frame per transaction. This
Expand Down
39 changes: 39 additions & 0 deletions op-batcher/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ type Metricer interface {

RecordBlobUsedBytes(num int)

RecordBatchDaType(daType string)
RecordBatchDataSizeBytes(daType string, size int)
RecordFailoverToEthDA()

Document() []opmetrics.DocumentedMetric

PendingDABytes() float64
Expand Down Expand Up @@ -89,6 +93,10 @@ type Metrics struct {
channelOutputBytesTotal prometheus.Counter
channelQueueLength prometheus.Gauge

batchSentDATypeTotal prometheus.CounterVec
batchStoredDataSizeBytesTotal prometheus.CounterVec
altDaFailoverTotal prometheus.Counter

batcherTxEvs opmetrics.EventVec

blobUsedBytes prometheus.Histogram
Expand Down Expand Up @@ -198,6 +206,25 @@ func NewMetrics(procName string) *Metrics {
Name: "channel_queue_length",
Help: "The number of channels currently in memory.",
}),
batchSentDATypeTotal: *factory.NewCounterVec(prometheus.CounterOpts{
Namespace: ns,
Name: "batch_sent_da_type_total",
Help: "Total number of batches successfully stored, categorized by DA type.",
},
[]string{"da_type"},
),
batchStoredDataSizeBytesTotal: *factory.NewCounterVec(prometheus.CounterOpts{
Namespace: ns,
Name: "batch_stored_data_size_bytes_total",
Help: "Total batch size stored in each DA type (in bytes).",
},
[]string{"da_type"},
),
altDaFailoverTotal: factory.NewCounter(prometheus.CounterOpts{
Namespace: ns,
Name: "alt_da_failover_total",
Help: "Total number of batches that could not be stored in AltDA and were sent to L1 instead",
}),
blobUsedBytes: factory.NewHistogram(prometheus.HistogramOpts{
Namespace: ns,
Name: "blob_used_bytes",
Expand Down Expand Up @@ -345,6 +372,18 @@ func (m *Metrics) RecordBlobUsedBytes(num int) {
m.blobUsedBytes.Observe(float64(num))
}

func (m *Metrics) RecordBatchDaType(daType string) {
m.batchSentDATypeTotal.With(prometheus.Labels{"da_type": daType}).Inc()
}

func (m *Metrics) RecordBatchDataSizeBytes(daType string, size int) {
m.batchStoredDataSizeBytesTotal.WithLabelValues(daType).Add(float64(size))
}

func (m *Metrics) RecordFailoverToEthDA() {
m.altDaFailoverTotal.Inc()
}

func (m *Metrics) RecordChannelQueueLength(len int) {
m.channelQueueLength.Set(float64(len))
}
Expand Down
5 changes: 5 additions & 0 deletions op-batcher/metrics/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func (*noopMetrics) RecordBatchTxSubmitted() {}
func (*noopMetrics) RecordBatchTxSuccess() {}
func (*noopMetrics) RecordBatchTxFailed() {}
func (*noopMetrics) RecordBlobUsedBytes(int) {}

func (*noopMetrics) RecordBatchDaType(string) {}
func (*noopMetrics) RecordBatchDataSizeBytes(string, int) {}
func (*noopMetrics) RecordFailoverToEthDA() {}

func (*noopMetrics) StartBalanceMetrics(log.Logger, *ethclient.Client, common.Address) io.Closer {
return nil
}
Expand Down