Skip to content

Commit dceaa0a

Browse files
committed
fix: gas limit for gas fee cap
1 parent 896b98c commit dceaa0a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

core/chainio/avs_writer.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
7676
txOpts := *w.Signer.GetTxOpts()
7777
txOpts.NoSend = true // simulate the transaction
7878
tx, err := w.AvsContractBindings.ServiceManager.RespondToTaskV2(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
79+
7980
if err != nil {
8081
// Retry with fallback
8182
tx, err = w.AvsContractBindings.ServiceManagerFallback.RespondToTaskV2(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
@@ -98,9 +99,10 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
9899
var maxRetries uint64 = 5
99100
var i uint64
100101
for i = 1; i < maxRetries; i++ {
101-
// Add x% to the gas limit, where x 10 <= x <= 50
102-
txOpts.GasLimit = tx.Gas() * (100 + i*10) / 100
103-
w.logger.Debugf("Sending ResponseToTask transaction for %vth with a gas limit of %v", i, txOpts.GasLimit)
102+
// 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)
104106
err = w.checkRespondToTaskFeeLimit(tx, txOpts, batchIdentifierHash, senderAddress)
105107
if err != nil {
106108
return nil, err
@@ -122,14 +124,13 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
122124
return receipt, fmt.Errorf("transaction failed")
123125
} else {
124126
// transaction was included in block
125-
w.logger.Debugf("Sending ResponseToTask transaction for %vth with a gas limit of %v", i, txOpts.GasLimit)
126127
return receipt, nil
127128
}
128129
}
129130

130131
// transaction not included in block, try again
131132
if err == ethereum.NotFound {
132-
w.logger.Debugf("Transaction not included in block will try again")
133+
w.logger.Infof("Transaction not included in block will try again bumping the fee")
133134
continue
134135
} else {
135136
return receipt, err

0 commit comments

Comments
 (0)