diff --git a/core/chainio/avs_writer.go b/core/chainio/avs_writer.go index cd379ee236..050fa8b3bf 100644 --- a/core/chainio/avs_writer.go +++ b/core/chainio/avs_writer.go @@ -148,7 +148,7 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe if receipt == nil { receipt, _ = w.ClientFallback.TransactionReceipt(context.Background(), tx.Hash()) if receipt != nil { - w.checkIfAggregatorHadToPaidForBatcher(tx, batchIdentifierHash) + w.updateAggregatorGasCostMetrics(tx, batchIdentifierHash) return receipt, nil } } @@ -183,7 +183,7 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe w.logger.Infof("Transaction sent, waiting for receipt", "merkle root", batchMerkleRootHashString) receipt, err := utils.WaitForTransactionReceiptRetryable(w.Client, w.ClientFallback, realTx.Hash(), retry.WaitForTxRetryParams(timeToWaitBeforeBump)) if receipt != nil { - w.checkIfAggregatorHadToPaidForBatcher(realTx, batchIdentifierHash) + w.updateAggregatorGasCostMetrics(realTx, batchIdentifierHash) return receipt, nil } @@ -204,10 +204,10 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe return retry.RetryWithData(respondToTaskV2Func, retry.RespondToTaskV2()) } -// Calculates the transaction cost from the receipt and compares it with the batcher respondToTaskFeeLimit -// if the tx cost was higher, then it means the aggregator has paid the difference for the batcher (txCost - respondToTaskFeeLimit) and so metrics are updated accordingly. -// otherwise nothing is done. -func (w *AvsWriter) checkIfAggregatorHadToPaidForBatcher(tx *types.Transaction, batchIdentifierHash [32]byte) { +// Calculates the transaction cost from the receipt and updates the total amount paid by the aggregator metric +// Then, it compares that tx cost with the batcher respondToTaskFeeLimit. +// If the tx cost was higher, it means the aggregator has paid the difference for the batcher (txCost - respondToTaskFeeLimit) and so metrics are updated accordingly. +func (w *AvsWriter) updateAggregatorGasCostMetrics(tx *types.Transaction, batchIdentifierHash [32]byte) { batchState, err := w.BatchesStateRetryable(&bind.CallOpts{}, batchIdentifierHash, retry.NetworkRetryParams()) if err != nil { return @@ -217,6 +217,9 @@ func (w *AvsWriter) checkIfAggregatorHadToPaidForBatcher(tx *types.Transaction, // NOTE we are not using tx.Cost() because tx.Cost() includes tx.Value() txCost := new(big.Int).Mul(big.NewInt(int64(tx.Gas())), tx.GasPrice()) + txCostInEth := utils.WeiToEth(txCost) + w.metrics.AddAggregatorGasCostPaidTotal(txCostInEth) + if respondToTaskFeeLimit.Cmp(txCost) < 0 { aggregatorDifferencePaid := new(big.Int).Sub(txCost, respondToTaskFeeLimit) aggregatorDifferencePaidInEth := utils.WeiToEth(aggregatorDifferencePaid) diff --git a/grafana/provisioning/dashboards/aligned/aggregator_batcher.json b/grafana/provisioning/dashboards/aligned/aggregator_batcher.json index 71167098a8..e11a694a3a 100644 --- a/grafana/provisioning/dashboards/aligned/aggregator_batcher.json +++ b/grafana/provisioning/dashboards/aligned/aggregator_batcher.json @@ -788,6 +788,77 @@ "title": "Accumulated Aggregator Extra Cost Paid [ETH]", "type": "stat" }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "description": "Accumulated gas cost in ETH the Aggregator paid when sending RespondToTask transactions.", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "ETH" + }, + "overrides": [] + }, + "gridPos": { + "h": 3, + "w": 7, + "x": 7, + "y": 14 + }, + "id": 48, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "10.1.10", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "disableTextWrap": false, + "editorMode": "code", + "expr": "increase(aligned_aggregator_gas_cost_paid_total_count{bot=\"aggregator\"}[10y])", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Accumulated Aggregator Gas Cost Paid [ETH]", + "type": "stat" + }, { "datasource": { "type": "prometheus", @@ -3114,4 +3185,4 @@ "uid": "aggregator", "version": 7, "weekStart": "" -} \ No newline at end of file +} diff --git a/metrics/metrics.go b/metrics/metrics.go index ba0c187fce..743e7862d0 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -21,6 +21,7 @@ type Metrics struct { aggregatorGasCostPaidForBatcherTotal prometheus.Gauge aggregatorNumTimesPaidForBatcher prometheus.Counter numBumpedGasPriceForAggregatedResponse prometheus.Counter + aggregatorGasCostPaidTotal prometheus.Counter aggregatorRespondToTaskLatency prometheus.Gauge aggregatorTaskQuorumReachedLatency prometheus.Gauge } @@ -56,6 +57,11 @@ func NewMetrics(ipPortAddress string, reg prometheus.Registerer, logger logging. Name: "aggregator_num_times_paid_for_batcher_count", Help: "Number of times the aggregator paid for the batcher when the tx cost was higher than the respondToTaskFeeLimit", }), + aggregatorGasCostPaidTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Namespace: alignedNamespace, + Name: "aggregator_gas_cost_paid_total_count", + Help: "Total amount of gas paid by the aggregator while responding to tasks", + }), numBumpedGasPriceForAggregatedResponse: promauto.With(reg).NewCounter(prometheus.CounterOpts{ Namespace: alignedNamespace, Name: "respond_to_task_gas_price_bumped_count", @@ -125,6 +131,10 @@ func (m *Metrics) AddAggregatorGasPaidForBatcher(value float64) { m.aggregatorGasCostPaidForBatcherTotal.Add(value) } +func (m *Metrics) AddAggregatorGasCostPaidTotal(value float64) { + m.aggregatorGasCostPaidTotal.Add(value) +} + func (m *Metrics) IncBumpedGasPriceForAggregatedResponse() { m.numBumpedGasPriceForAggregatedResponse.Inc() }