@@ -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
122141func (w * AvsWriter ) checkRespondToTaskFeeLimit (tx * types.Transaction , txOpts bind.TransactOpts , batchIdentifierHash [32 ]byte , senderAddress [20 ]byte ) error {
0 commit comments