From 96f2ace6b3b658e0b9b4a3f780f27f475357cfef Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Tue, 22 Oct 2024 16:06:22 -0300 Subject: [PATCH] feat: metrics for bumped gas price --- aggregator/internal/pkg/aggregator.go | 3 ++- core/chainio/avs_writer.go | 6 ++++++ metrics/metrics.go | 20 +++++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/aggregator/internal/pkg/aggregator.go b/aggregator/internal/pkg/aggregator.go index 6568d2106..71ab6540f 100644 --- a/aggregator/internal/pkg/aggregator.go +++ b/aggregator/internal/pkg/aggregator.go @@ -301,7 +301,8 @@ func (agg *Aggregator) sendAggregatedResponse(batchIdentifierHash [32]byte, batc "senderAddress", hex.EncodeToString(senderAddress[:]), "batchIdentifierHash", hex.EncodeToString(batchIdentifierHash[:])) - receipt, err := agg.avsWriter.SendAggregatedResponse(batchIdentifierHash, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature) + onRetry := func() { agg.metrics.IncBumpedGasPriceForAggregatedResponse() } + receipt, err := agg.avsWriter.SendAggregatedResponse(batchIdentifierHash, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature, onRetry) if err != nil { agg.walletMutex.Unlock() agg.logger.Infof("- Unlocked Wallet Resources: Error sending aggregated response for batch %s. Error: %s", hex.EncodeToString(batchIdentifierHash[:]), err) diff --git a/core/chainio/avs_writer.go b/core/chainio/avs_writer.go index da1554751..d025a9ae1 100644 --- a/core/chainio/avs_writer.go +++ b/core/chainio/avs_writer.go @@ -103,7 +103,13 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe txOpts.Nonce = txNonce lastTxGasPrice := tx.GasPrice() + i := 0 sendTransaction := func() (*types.Receipt, error) { + if i > 0 { + onRetry() + } + i++ + bumpedGasPrice := utils.CalculateGasPriceBump(lastTxGasPrice, gasBumpPercentage) lastTxGasPrice = bumpedGasPrice txOpts.GasPrice = bumpedGasPrice diff --git a/metrics/metrics.go b/metrics/metrics.go index 11c0829c4..efe5f3135 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -12,11 +12,12 @@ import ( ) type Metrics struct { - ipPortAddress string - logger logging.Logger - numAggregatedResponses prometheus.Counter - numAggregatorReceivedTasks prometheus.Counter - numOperatorTaskResponses prometheus.Counter + ipPortAddress string + logger logging.Logger + numAggregatedResponses prometheus.Counter + numAggregatorReceivedTasks prometheus.Counter + numOperatorTaskResponses prometheus.Counter + numBumpedGasPriceForAggregatedResponse prometheus.Counter } const alignedNamespace = "aligned" @@ -40,6 +41,11 @@ func NewMetrics(ipPortAddress string, reg prometheus.Registerer, logger logging. Name: "aggregator_received_tasks", Help: "Number of tasks received by the Service Manager", }), + numBumpedGasPriceForAggregatedResponse: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Namespace: alignedNamespace, + Name: "respond_to_task_gas_price_bumped", + Help: "Number of times gas price was bumped while sending aggregated response", + }), } } @@ -74,3 +80,7 @@ func (m *Metrics) IncAggregatedResponses() { func (m *Metrics) IncOperatorTaskResponses() { m.numOperatorTaskResponses.Inc() } + +func (m *Metrics) IncBumpedGasPriceForAggregatedResponse() { + m.numBumpedGasPriceForAggregatedResponse.Inc() +}