Skip to content

Commit

Permalink
feat: aggregator total gas paid metric (#1592)
Browse files Browse the repository at this point in the history
Co-authored-by: Julian Ventura <[email protected]>
  • Loading branch information
JulianVentura and Julian Ventura authored Dec 10, 2024
1 parent 5b6aca1 commit 010e93d
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 7 deletions.
15 changes: 9 additions & 6 deletions core/chainio/avs_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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)
Expand Down
73 changes: 72 additions & 1 deletion grafana/provisioning/dashboards/aligned/aggregator_batcher.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -3114,4 +3185,4 @@
"uid": "aggregator",
"version": 7,
"weekStart": ""
}
}
10 changes: 10 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 010e93d

Please sign in to comment.