Skip to content

Commit cc9b765

Browse files
committed
refactor: remove beforeTransaction
1 parent dbc7d60 commit cc9b765

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

core/chainio/avs_writer.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,15 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
9494
txOpts.NoSend = false
9595
txOpts.Nonce = txNonce
9696

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

104-
executeTransaction := func(gasPrice *big.Int) (*types.Transaction, error) {
102+
if err != nil {
103+
return nil, err
104+
}
105+
105106
tx, err = w.AvsContractBindings.ServiceManager.RespondToTaskV2(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
106107
if err != nil {
107108
// Retry with fallback
@@ -111,7 +112,7 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
111112
return tx, err
112113
}
113114

114-
return utils.SendTransactionWithInfiniteRetryAndBumpingGasPrice(beforeTransaction, executeTransaction, w.Client, tx.GasPrice())
115+
return utils.SendTransactionWithInfiniteRetryAndBumpingGasPrice(executeTransaction, w.Client, tx.GasPrice())
115116
}
116117

117118
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: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,12 @@ func CalculateGasPriceBumpBasedOnRetry(currentGasPrice *big.Int, iteration int)
6363
// it will try again bumping the gas price based on `CalculateGasPriceBumpBasedOnRetry`
6464
// and pass it to beforeTransaction and executeTransaction (make sure you update the txOpts with the new price)
6565
// This process happens indefinitely until we get the receipt or the receipt status is an err.
66-
func SendTransactionWithInfiniteRetryAndBumpingGasPrice(beforeTransaction func(*big.Int) error, executeTransaction func(*big.Int) (*types.Transaction, error), client eth.InstrumentedClient, baseGasPrice *big.Int) (*types.Receipt, error) {
66+
func SendTransactionWithInfiniteRetryAndBumpingGasPrice(executeTransaction func(*big.Int) (*types.Transaction, error), client eth.InstrumentedClient, baseGasPrice *big.Int) (*types.Receipt, error) {
6767
i := 0
6868
sendTransaction := func() (*types.Receipt, error) {
6969
i++
7070
gasPrice := CalculateGasPriceBumpBasedOnRetry(baseGasPrice, i)
7171

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

0 commit comments

Comments
 (0)