@@ -15,7 +15,6 @@ 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"
1918 "github.com/yetanotherco/aligned_layer/core/config"
2019 "github.com/yetanotherco/aligned_layer/core/utils"
2120)
@@ -94,49 +93,25 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
9493 txNonce := new (big.Int ).SetUint64 (tx .Nonce ())
9594 txOpts .NoSend = false
9695 txOpts .Nonce = txNonce
97- i := 0
98- sendTransaction := func () (* types.Receipt , error ) {
99- // bump the fee here
100- gasPrice := utils .CalculateGasPriceBumpBasedOnRetry (tx .GasPrice (), i )
96+
97+ beforeTransaction := func (gasPrice * big.Int ) error {
10198 txOpts .GasPrice = gasPrice
102- w .logger .Infof ("Sending ResponseToTask transaction for %vth with a gas price of %v" , i , txOpts .GasPrice )
103- i ++
99+ w .logger .Infof ("Sending ResponseToTask transaction with a gas price of %v" , txOpts .GasPrice )
104100 err = w .checkRespondToTaskFeeLimit (tx , txOpts , batchIdentifierHash , senderAddress )
105- if err != nil {
106- return nil , err
107- }
101+ return err
102+ }
108103
104+ executeTransaction := func (gasPrice * big.Int ) (* types.Transaction , error ) {
109105 tx , err = w .AvsContractBindings .ServiceManager .RespondToTaskV2 (& txOpts , batchMerkleRoot , senderAddress , nonSignerStakesAndSignature )
110106 if err != nil {
111107 // Retry with fallback
112108 tx , err = w .AvsContractBindings .ServiceManagerFallback .RespondToTaskV2 (& txOpts , batchMerkleRoot , senderAddress , nonSignerStakesAndSignature )
113- if err != nil {
114- return nil , err
115- }
109+ return tx , err
116110 }
117- ctx , cancel := context .WithTimeout (context .Background (), time .Second * 36 )
118- defer cancel ()
119- receipt , err := utils .WaitForTransactionReceipt (w .Client , ctx , tx .Hash ())
120-
121- if receipt != nil {
122- return receipt , nil
123- }
124-
125- // if we are here, this means we have reached the timeout (after three blocks it hasn't been included)
126- // so we try again by bumping the fee to make sure its included
127- if err != nil {
128- return nil , err
129- }
130- return nil , fmt .Errorf ("transaction failed" )
111+ return tx , err
131112 }
132- receipt , err := connection .RetryWithData (sendTransaction , 1000 , 2 , 3 )
133113
134- if receipt .Status == 0 {
135- return receipt , fmt .Errorf ("transaction failed" )
136- } else {
137- // transaction was included in block
138- return receipt , nil
139- }
114+ return utils .SendTransactionWithInfiniteRetryAndBumpingGasPrice (beforeTransaction , executeTransaction , w .Client , tx .GasPrice ())
140115}
141116
142117func (w * AvsWriter ) checkRespondToTaskFeeLimit (tx * types.Transaction , txOpts bind.TransactOpts , batchIdentifierHash [32 ]byte , senderAddress [20 ]byte ) error {
0 commit comments