Skip to content

Commit 010e93d

Browse files
JulianVenturaJulian Ventura
andauthored
feat: aggregator total gas paid metric (#1592)
Co-authored-by: Julian Ventura <[email protected]>
1 parent 5b6aca1 commit 010e93d

File tree

3 files changed

+91
-7
lines changed

3 files changed

+91
-7
lines changed

core/chainio/avs_writer.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
148148
if receipt == nil {
149149
receipt, _ = w.ClientFallback.TransactionReceipt(context.Background(), tx.Hash())
150150
if receipt != nil {
151-
w.checkIfAggregatorHadToPaidForBatcher(tx, batchIdentifierHash)
151+
w.updateAggregatorGasCostMetrics(tx, batchIdentifierHash)
152152
return receipt, nil
153153
}
154154
}
@@ -183,7 +183,7 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
183183
w.logger.Infof("Transaction sent, waiting for receipt", "merkle root", batchMerkleRootHashString)
184184
receipt, err := utils.WaitForTransactionReceiptRetryable(w.Client, w.ClientFallback, realTx.Hash(), retry.WaitForTxRetryParams(timeToWaitBeforeBump))
185185
if receipt != nil {
186-
w.checkIfAggregatorHadToPaidForBatcher(realTx, batchIdentifierHash)
186+
w.updateAggregatorGasCostMetrics(realTx, batchIdentifierHash)
187187
return receipt, nil
188188
}
189189

@@ -204,10 +204,10 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
204204
return retry.RetryWithData(respondToTaskV2Func, retry.RespondToTaskV2())
205205
}
206206

207-
// Calculates the transaction cost from the receipt and compares it with the batcher respondToTaskFeeLimit
208-
// 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.
209-
// otherwise nothing is done.
210-
func (w *AvsWriter) checkIfAggregatorHadToPaidForBatcher(tx *types.Transaction, batchIdentifierHash [32]byte) {
207+
// Calculates the transaction cost from the receipt and updates the total amount paid by the aggregator metric
208+
// Then, it compares that tx cost with the batcher respondToTaskFeeLimit.
209+
// 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.
210+
func (w *AvsWriter) updateAggregatorGasCostMetrics(tx *types.Transaction, batchIdentifierHash [32]byte) {
211211
batchState, err := w.BatchesStateRetryable(&bind.CallOpts{}, batchIdentifierHash, retry.NetworkRetryParams())
212212
if err != nil {
213213
return
@@ -217,6 +217,9 @@ func (w *AvsWriter) checkIfAggregatorHadToPaidForBatcher(tx *types.Transaction,
217217
// NOTE we are not using tx.Cost() because tx.Cost() includes tx.Value()
218218
txCost := new(big.Int).Mul(big.NewInt(int64(tx.Gas())), tx.GasPrice())
219219

220+
txCostInEth := utils.WeiToEth(txCost)
221+
w.metrics.AddAggregatorGasCostPaidTotal(txCostInEth)
222+
220223
if respondToTaskFeeLimit.Cmp(txCost) < 0 {
221224
aggregatorDifferencePaid := new(big.Int).Sub(txCost, respondToTaskFeeLimit)
222225
aggregatorDifferencePaidInEth := utils.WeiToEth(aggregatorDifferencePaid)

grafana/provisioning/dashboards/aligned/aggregator_batcher.json

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,77 @@
788788
"title": "Accumulated Aggregator Extra Cost Paid [ETH]",
789789
"type": "stat"
790790
},
791+
{
792+
"datasource": {
793+
"type": "prometheus",
794+
"uid": "prometheus"
795+
},
796+
"description": "Accumulated gas cost in ETH the Aggregator paid when sending RespondToTask transactions.",
797+
"fieldConfig": {
798+
"defaults": {
799+
"color": {
800+
"mode": "thresholds"
801+
},
802+
"mappings": [],
803+
"thresholds": {
804+
"mode": "absolute",
805+
"steps": [
806+
{
807+
"color": "green",
808+
"value": null
809+
}
810+
]
811+
},
812+
"unit": "ETH"
813+
},
814+
"overrides": []
815+
},
816+
"gridPos": {
817+
"h": 3,
818+
"w": 7,
819+
"x": 7,
820+
"y": 14
821+
},
822+
"id": 48,
823+
"options": {
824+
"colorMode": "value",
825+
"graphMode": "none",
826+
"justifyMode": "auto",
827+
"orientation": "auto",
828+
"percentChangeColorMode": "standard",
829+
"reduceOptions": {
830+
"calcs": [
831+
"lastNotNull"
832+
],
833+
"fields": "",
834+
"values": false
835+
},
836+
"showPercentChange": false,
837+
"textMode": "auto",
838+
"wideLayout": true
839+
},
840+
"pluginVersion": "10.1.10",
841+
"targets": [
842+
{
843+
"datasource": {
844+
"type": "prometheus",
845+
"uid": "prometheus"
846+
},
847+
"disableTextWrap": false,
848+
"editorMode": "code",
849+
"expr": "increase(aligned_aggregator_gas_cost_paid_total_count{bot=\"aggregator\"}[10y])",
850+
"fullMetaSearch": false,
851+
"includeNullMetadata": true,
852+
"instant": false,
853+
"legendFormat": "__auto",
854+
"range": true,
855+
"refId": "A",
856+
"useBackend": false
857+
}
858+
],
859+
"title": "Accumulated Aggregator Gas Cost Paid [ETH]",
860+
"type": "stat"
861+
},
791862
{
792863
"datasource": {
793864
"type": "prometheus",
@@ -3114,4 +3185,4 @@
31143185
"uid": "aggregator",
31153186
"version": 7,
31163187
"weekStart": ""
3117-
}
3188+
}

metrics/metrics.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Metrics struct {
2121
aggregatorGasCostPaidForBatcherTotal prometheus.Gauge
2222
aggregatorNumTimesPaidForBatcher prometheus.Counter
2323
numBumpedGasPriceForAggregatedResponse prometheus.Counter
24+
aggregatorGasCostPaidTotal prometheus.Counter
2425
aggregatorRespondToTaskLatency prometheus.Gauge
2526
aggregatorTaskQuorumReachedLatency prometheus.Gauge
2627
}
@@ -56,6 +57,11 @@ func NewMetrics(ipPortAddress string, reg prometheus.Registerer, logger logging.
5657
Name: "aggregator_num_times_paid_for_batcher_count",
5758
Help: "Number of times the aggregator paid for the batcher when the tx cost was higher than the respondToTaskFeeLimit",
5859
}),
60+
aggregatorGasCostPaidTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
61+
Namespace: alignedNamespace,
62+
Name: "aggregator_gas_cost_paid_total_count",
63+
Help: "Total amount of gas paid by the aggregator while responding to tasks",
64+
}),
5965
numBumpedGasPriceForAggregatedResponse: promauto.With(reg).NewCounter(prometheus.CounterOpts{
6066
Namespace: alignedNamespace,
6167
Name: "respond_to_task_gas_price_bumped_count",
@@ -125,6 +131,10 @@ func (m *Metrics) AddAggregatorGasPaidForBatcher(value float64) {
125131
m.aggregatorGasCostPaidForBatcherTotal.Add(value)
126132
}
127133

134+
func (m *Metrics) AddAggregatorGasCostPaidTotal(value float64) {
135+
m.aggregatorGasCostPaidTotal.Add(value)
136+
}
137+
128138
func (m *Metrics) IncBumpedGasPriceForAggregatedResponse() {
129139
m.numBumpedGasPriceForAggregatedResponse.Inc()
130140
}

0 commit comments

Comments
 (0)