Skip to content

Commit 61a64df

Browse files
committed
fix: gas limit calculation
1 parent dceaa0a commit 61a64df

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

core/chainio/avs_writer.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
9999
var maxRetries uint64 = 5
100100
var i uint64
101101
for i = 1; i < maxRetries; i++ {
102+
// bump the fee here
102103
// factor = (100 + i * 10) / 100, so 1,1 <= x <= 1,5
103-
factor := new(big.Int).Div(new(big.Int).Add(big.NewInt(100), new(big.Int).Mul(big.NewInt(int64(i)), big.NewInt(10))), big.NewInt(100))
104-
txOpts.GasFeeCap = new(big.Int).Mul(new(big.Int).Sub(tx.GasFeeCap(), big.NewInt(int64(1000))), factor)
105-
w.logger.Infof("Sending ResponseToTask transaction for %vth with a gas limit of %v", i, txOpts.GasLimit)
104+
factor := (new(big.Int).Add(big.NewInt(100), new(big.Int).Mul(big.NewInt(int64(i)), big.NewInt(10))))
105+
gasPrice := new(big.Int).Mul(tx.GasPrice(), factor)
106+
gasPrice = gasPrice.Div(gasPrice, big.NewInt(100))
107+
txOpts.GasPrice = gasPrice
108+
109+
w.logger.Infof("Sending ResponseToTask transaction for %vth with a gas price of %v", i, txOpts.GasPrice)
106110
err = w.checkRespondToTaskFeeLimit(tx, txOpts, batchIdentifierHash, senderAddress)
107111
if err != nil {
108112
return nil, err
@@ -116,7 +120,8 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
116120
return nil, err
117121
}
118122
}
119-
ctx, _ := context.WithTimeout(context.Background(), time.Second*20)
123+
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*10)
124+
defer cancel()
120125
receipt, err := utils.WaitForTransactionReceipt(w.Client, ctx, tx.Hash())
121126

122127
if receipt != nil {
@@ -132,6 +137,8 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
132137
if err == ethereum.NotFound {
133138
w.logger.Infof("Transaction not included in block will try again bumping the fee")
134139
continue
140+
} else if err == context.DeadlineExceeded {
141+
continue
135142
} else {
136143
return receipt, err
137144
}

0 commit comments

Comments
 (0)