@@ -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)
@@ -93,19 +94,13 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
9394 txNonce := new (big.Int ).SetUint64 (tx .Nonce ())
9495 txOpts .NoSend = false
9596 txOpts .Nonce = txNonce
96-
97- // Send the transaction
98- var maxRetries uint64 = 5
99- var i uint64
100- for i = 1 ; i < maxRetries ; i ++ {
97+ i := 0
98+ sendTransaction := func () (* types.Receipt , error ) {
10199 // bump the fee here
102- // factor = (100 + i * 10) / 100, so 1,1 <= x <= 1,5
103- factor := (new (big.Int ).Add (big .NewInt (100 ), new (big.Int ).Mul (big .NewInt (int64 (i )), big .NewInt (10 ))))
104- gasPrice := new (big.Int ).Mul (tx .GasPrice (), factor )
105- gasPrice = gasPrice .Div (gasPrice , big .NewInt (100 ))
100+ gasPrice := utils .CalculateGasPriceBumpBasedOnRetry (tx .GasPrice (), i )
106101 txOpts .GasPrice = gasPrice
107-
108102 w .logger .Infof ("Sending ResponseToTask transaction for %vth with a gas price of %v" , i , txOpts .GasPrice )
103+ i ++
109104 err = w .checkRespondToTaskFeeLimit (tx , txOpts , batchIdentifierHash , senderAddress )
110105 if err != nil {
111106 return nil , err
@@ -124,23 +119,24 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
124119 receipt , err := utils .WaitForTransactionReceipt (w .Client , ctx , tx .Hash ())
125120
126121 if receipt != nil {
127- if receipt .Status == 0 {
128- return receipt , fmt .Errorf ("transaction failed" )
129- } else {
130- // transaction was included in block
131- return receipt , nil
132- }
122+ return receipt , nil
133123 }
134124
135- // this means we have reached the timeout (after three blocks it hasn't been included)
125+ // if we are here, this means we have reached the timeout (after three blocks it hasn't been included)
136126 // so we try again by bumping the fee to make sure its included
137127 if err != nil {
138- continue
128+ return nil , err
139129 }
140-
130+ return nil , fmt . Errorf ( "transaction failed" )
141131 }
132+ receipt , err := connection .RetryWithData (sendTransaction , 1000 , 2 , 3 )
142133
143- return nil , fmt .Errorf ("could not send transaction" )
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+ }
144140}
145141
146142func (w * AvsWriter ) checkRespondToTaskFeeLimit (tx * types.Transaction , txOpts bind.TransactOpts , batchIdentifierHash [32 ]byte , senderAddress [20 ]byte ) error {
0 commit comments