Skip to content

Commit 4a8a9f5

Browse files
committed
Merge branch '311-aggregator-wait-for-receipt-for-1-minute-if-not-bump-the-fee-v2' into test-aggregator-bump-fee
2 parents 37c5471 + ecaf600 commit 4a8a9f5

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

core/chainio/avs_writer.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/ethereum/go-ethereum/common"
1616
"github.com/ethereum/go-ethereum/core/types"
1717
servicemanager "github.com/yetanotherco/aligned_layer/contracts/bindings/AlignedLayerServiceManager"
18+
connection "github.com/yetanotherco/aligned_layer/core"
1819
"github.com/yetanotherco/aligned_layer/core/config"
1920
"github.com/yetanotherco/aligned_layer/core/utils"
2021
)
@@ -95,26 +96,28 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
9596
txOpts.Nonce = txNonce
9697
var i uint64 = 1
9798

98-
beforeTransaction := func(gasPrice *big.Int) error {
99-
txOpts.GasPrice = gasPrice
99+
executeTransaction := func(bumpedGasPrices *big.Int) (*types.Transaction, error) {
100+
txOpts.GasPrice = bumpedGasPrices
100101
w.logger.Infof("Sending ResponseToTask transaction with a gas price of %v", txOpts.GasPrice)
101102
err = w.checkRespondToTaskFeeLimit(tx, txOpts, batchIdentifierHash, senderAddress)
102-
return err
103-
}
104103

105-
executeTransaction := func(gasPrice *big.Int) (*types.Transaction, error) {
104+
if err != nil {
105+
return nil, connection.PermanentError{Inner: err}
106+
}
107+
106108
tx, err = w.AvsContractBindings.ServiceManager.RespondToTaskV2(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature, new(big.Int).SetUint64(i))
107109
if err != nil {
108110
// Retry with fallback
109111
tx, err = w.AvsContractBindings.ServiceManagerFallback.RespondToTaskV2(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature, new(big.Int).SetUint64(i))
110-
i++
111-
return tx, err
112+
if err != nil {
113+
return nil, connection.PermanentError{Inner: err}
114+
}
115+
return tx, nil
112116
}
113-
i++
114-
return tx, err
117+
return tx, nil
115118
}
116119

117-
return utils.SendTransactionWithInfiniteRetryAndBumpingGasPrice(beforeTransaction, executeTransaction, w.Client, tx.GasPrice())
120+
return utils.SendTransactionWithInfiniteRetryAndBumpingGasPrice(executeTransaction, w.Client, tx.GasPrice())
118121
}
119122

120123
func (w *AvsWriter) checkRespondToTaskFeeLimit(tx *types.Transaction, txOpts bind.TransactOpts, batchIdentifierHash [32]byte, senderAddress [20]byte) error {

core/connection.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ func Retry(functionToRetry func() error, minDelay uint64, factor float64, maxTri
6969
initialRetryOption := backoff.WithInitialInterval(time.Millisecond * time.Duration(minDelay))
7070
multiplierOption := backoff.WithMultiplier(factor)
7171
expBackoff := backoff.NewExponentialBackOff(randomOption, multiplierOption, initialRetryOption)
72-
maxRetriesBackoff := backoff.WithMaxRetries(expBackoff, maxTries)
72+
var maxRetriesBackoff backoff.BackOff
73+
74+
if maxTries > 0 {
75+
maxRetriesBackoff = backoff.WithMaxRetries(expBackoff, maxTries)
76+
} else {
77+
maxRetriesBackoff = expBackoff
78+
}
7379

7480
return backoff.Retry(f, maxRetriesBackoff)
7581
}

core/utils/eth_client_utils.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,14 @@ func CalculateGasPriceBumpBasedOnRetry(currentGasPrice *big.Int, iteration int)
6262

6363
// Sends a transaction and waits for the receipt for three blocks, if not received
6464
// it will try again bumping the gas price based on `CalculateGasPriceBumpBasedOnRetry`
65-
// and pass it to beforeTransaction and executeTransaction (make sure you update the txOpts with the new price)
65+
// and pass it to executeTransaction (make sure you update the txOpts with the new gasPrice)
6666
// This process happens indefinitely until we get the receipt or the receipt status is an err.
67-
func SendTransactionWithInfiniteRetryAndBumpingGasPrice(beforeTransaction func(*big.Int) error, executeTransaction func(*big.Int) (*types.Transaction, error), client eth.InstrumentedClient, baseGasPrice *big.Int) (*types.Receipt, error) {
67+
func SendTransactionWithInfiniteRetryAndBumpingGasPrice(executeTransaction func(*big.Int) (*types.Transaction, error), client eth.InstrumentedClient, baseGasPrice *big.Int) (*types.Receipt, error) {
6868
i := 0
6969
sendTransaction := func() (*types.Receipt, error) {
7070
i++
7171
gasPrice := CalculateGasPriceBumpBasedOnRetry(baseGasPrice, i)
7272

73-
err := beforeTransaction(gasPrice)
74-
if err != nil {
75-
return nil, err
76-
}
77-
7873
tx, err := executeTransaction(gasPrice)
7974
if err != nil {
8075
return nil, err

0 commit comments

Comments
 (0)