Skip to content

Commit 527489b

Browse files
committed
refactor: remove SendTransactionWithInfiniteRetryAndBumpingGasPrice
1 parent b614916 commit 527489b

File tree

2 files changed

+24
-39
lines changed

2 files changed

+24
-39
lines changed

core/chainio/avs_writer.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,15 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
9595
txOpts.NoSend = false
9696
txOpts.Nonce = txNonce
9797

98-
executeTransaction := func(bumpedGasPrices *big.Int) (*types.Transaction, error) {
99-
txOpts.GasPrice = bumpedGasPrices
98+
// Sends a transaction and waits for the receipt for three blocks, if not received
99+
// it will try again bumping the gas price based on `CalculateGasPriceBumpBasedOnRetry`
100+
// This process happens indefinitely until we sendTransaction does not return err.
101+
i := 0
102+
sendTransaction := func() (*types.Receipt, error) {
103+
i++
104+
gasPrice := utils.CalculateGasPriceBumpBasedOnRetry(tx.GasPrice(), i)
105+
txOpts.GasPrice = gasPrice
106+
100107
w.logger.Infof("Sending ResponseToTask transaction with a gas price of %v", txOpts.GasPrice)
101108
err = w.checkRespondToTaskFeeLimit(tx, txOpts, batchIdentifierHash, senderAddress)
102109

@@ -111,12 +118,24 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
111118
if err != nil {
112119
return nil, connection.PermanentError{Inner: err}
113120
}
114-
return tx, nil
115121
}
116-
return tx, nil
122+
123+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*36)
124+
defer cancel()
125+
receipt, err := utils.WaitForTransactionReceipt(w.Client, ctx, tx.Hash())
126+
127+
if receipt != nil {
128+
return receipt, nil
129+
}
130+
// if we are here, this means we have reached the timeout (after three blocks it hasn't been included)
131+
// so we try again by bumping the fee to make sure its included
132+
if err != nil {
133+
return nil, err
134+
}
135+
return nil, fmt.Errorf("transaction failed")
117136
}
118137

119-
return utils.SendTransactionWithInfiniteRetryAndBumpingGasPrice(executeTransaction, w.Client, tx.GasPrice())
138+
return connection.RetryWithData(sendTransaction, 1000, 2, 0)
120139
}
121140

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

core/utils/eth_client_utils.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
eigentypes "github.com/Layr-Labs/eigensdk-go/types"
1212
gethcommon "github.com/ethereum/go-ethereum/common"
1313
"github.com/ethereum/go-ethereum/core/types"
14-
connection "github.com/yetanotherco/aligned_layer/core"
1514
)
1615

1716
const maxRetries = 25
@@ -58,36 +57,3 @@ func CalculateGasPriceBumpBasedOnRetry(currentGasPrice *big.Int, iteration int)
5857

5958
return bumpedGasPrice
6059
}
61-
62-
// Sends a transaction and waits for the receipt for three blocks, if not received
63-
// it will try again bumping the gas price based on `CalculateGasPriceBumpBasedOnRetry`
64-
// and pass it to executeTransaction (make sure you update the txOpts with the new gasPrice)
65-
// This process happens indefinitely until we get the receipt or the receipt status is an err.
66-
func SendTransactionWithInfiniteRetryAndBumpingGasPrice(executeTransaction func(*big.Int) (*types.Transaction, error), client eth.InstrumentedClient, baseGasPrice *big.Int) (*types.Receipt, error) {
67-
i := 0
68-
sendTransaction := func() (*types.Receipt, error) {
69-
i++
70-
gasPrice := CalculateGasPriceBumpBasedOnRetry(baseGasPrice, i)
71-
72-
tx, err := executeTransaction(gasPrice)
73-
if err != nil {
74-
return nil, err
75-
}
76-
77-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*36)
78-
defer cancel()
79-
receipt, err := WaitForTransactionReceipt(client, ctx, tx.Hash())
80-
81-
if receipt != nil {
82-
return receipt, nil
83-
}
84-
// if we are here, this means we have reached the timeout (after three blocks it hasn't been included)
85-
// so we try again by bumping the fee to make sure its included
86-
if err != nil {
87-
return nil, err
88-
}
89-
return nil, fmt.Errorf("transaction failed")
90-
91-
}
92-
return connection.RetryWithData(sendTransaction, 1000, 2, 0)
93-
}

0 commit comments

Comments
 (0)