From ac0dcc68a913bd676241286667941de724822275 Mon Sep 17 00:00:00 2001 From: Julian Ventura Date: Fri, 6 Dec 2024 18:51:09 -0300 Subject: [PATCH 1/3] Add aggregator total gas paid --- core/chainio/avs_writer.go | 15 +- .../aligned/aggregator_batcher.json | 304 +++++++++++++++++- metrics/metrics.go | 10 + 3 files changed, 320 insertions(+), 9 deletions(-) diff --git a/core/chainio/avs_writer.go b/core/chainio/avs_writer.go index cd379ee236..4b2535a59d 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 aggregaot 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 929ff29eac..6707bced1c 100644 --- a/grafana/provisioning/dashboards/aligned/aggregator_batcher.json +++ b/grafana/provisioning/dashboards/aligned/aggregator_batcher.json @@ -18,7 +18,7 @@ "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, - "id": 4, + "id": 2, "links": [], "liveNow": false, "panels": [ @@ -789,6 +789,77 @@ "title": "Accumulated Aggregator Extra Cost Paid [ETH]", "type": "stat" }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "description": "Accumulated gas cost the aggregator paid for the batcher when the tx cost was higher than the respondToTaskFeeLimit.", + "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": 46, + "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_sum{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", @@ -2625,6 +2696,233 @@ } ], "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 48, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "ms" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 69 + }, + "id": 43, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "disableTextWrap": false, + "editorMode": "code", + "expr": "s3_latency * 10 ^ (-3)", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "S3 Latency", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 48, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 77 + }, + "id": 45, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "disableTextWrap": false, + "editorMode": "code", + "expr": "cancel_create_new_task_latency * 10 ^ (-3)", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "cancel_new_task", + "range": true, + "refId": "A", + "useBackend": false + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "disableTextWrap": false, + "editorMode": "code", + "expr": "create_new_task_latency * 10 ^(-3)", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "create_new_task", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "CreateNewTask Latency", + "transformations": [ + { + "id": "calculateField", + "options": { + "alias": "total", + "mode": "reduceRow", + "reduce": { + "include": [ + "cancel_new_task", + "create_new_task" + ], + "reducer": "sum" + } + } + } + ], + "type": "timeseries" } ], "refresh": "5s", @@ -2642,6 +2940,6 @@ "timezone": "browser", "title": "System Data", "uid": "aggregator", - "version": 9, + "version": 39, "weekStart": "" -} \ No newline at end of file +} diff --git a/metrics/metrics.go b/metrics/metrics.go index dda2f7a04a..7b0301ba94 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.Gauge } const alignedNamespace = "aligned" @@ -54,6 +55,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).NewGauge(prometheus.GaugeOpts{ + Namespace: alignedNamespace, + Name: "aggregator_gas_cost_paid_total_sum", + 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", @@ -113,6 +119,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() } From a91e067fd7fb8028fea5c750d5dcb8fe9499cdc2 Mon Sep 17 00:00:00 2001 From: Julian Ventura Date: Mon, 9 Dec 2024 10:57:06 -0300 Subject: [PATCH 2/3] Fix typo --- core/chainio/avs_writer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/chainio/avs_writer.go b/core/chainio/avs_writer.go index 4b2535a59d..050fa8b3bf 100644 --- a/core/chainio/avs_writer.go +++ b/core/chainio/avs_writer.go @@ -204,7 +204,7 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe return retry.RetryWithData(respondToTaskV2Func, retry.RespondToTaskV2()) } -// Calculates the transaction cost from the receipt and updates the total amount paid by the aggregaot metric +// 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) { From d55ccac60d98cc8ac0ebe597f4d628655259b3c4 Mon Sep 17 00:00:00 2001 From: Julian Ventura Date: Tue, 10 Dec 2024 17:27:20 -0300 Subject: [PATCH 3/3] Change gauge for counter and grafana dashboard description --- .../provisioning/dashboards/aligned/aggregator_batcher.json | 6 +++--- metrics/metrics.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/grafana/provisioning/dashboards/aligned/aggregator_batcher.json b/grafana/provisioning/dashboards/aligned/aggregator_batcher.json index 6707bced1c..8ffb72255f 100644 --- a/grafana/provisioning/dashboards/aligned/aggregator_batcher.json +++ b/grafana/provisioning/dashboards/aligned/aggregator_batcher.json @@ -794,7 +794,7 @@ "type": "prometheus", "uid": "prometheus" }, - "description": "Accumulated gas cost the aggregator paid for the batcher when the tx cost was higher than the respondToTaskFeeLimit.", + "description": "Accumulated gas cost in ETH the Aggregator paid when sending RespondToTask transactions.", "fieldConfig": { "defaults": { "color": { @@ -847,7 +847,7 @@ }, "disableTextWrap": false, "editorMode": "code", - "expr": "increase(aligned_aggregator_gas_cost_paid_total_sum{bot=\"aggregator\"}[10y])", + "expr": "increase(aligned_aggregator_gas_cost_paid_total_count{bot=\"aggregator\"}[10y])", "fullMetaSearch": false, "includeNullMetadata": true, "instant": false, @@ -2940,6 +2940,6 @@ "timezone": "browser", "title": "System Data", "uid": "aggregator", - "version": 39, + "version": 47, "weekStart": "" } diff --git a/metrics/metrics.go b/metrics/metrics.go index 7b0301ba94..074a536b6c 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -21,7 +21,7 @@ type Metrics struct { aggregatorGasCostPaidForBatcherTotal prometheus.Gauge aggregatorNumTimesPaidForBatcher prometheus.Counter numBumpedGasPriceForAggregatedResponse prometheus.Counter - aggregatorGasCostPaidTotal prometheus.Gauge + aggregatorGasCostPaidTotal prometheus.Counter } const alignedNamespace = "aligned" @@ -55,9 +55,9 @@ 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).NewGauge(prometheus.GaugeOpts{ + aggregatorGasCostPaidTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ Namespace: alignedNamespace, - Name: "aggregator_gas_cost_paid_total_sum", + 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{