Skip to content

Commit 5abc31e

Browse files
committed
refactor: gas price bump based on last bump
1 parent 527489b commit 5abc31e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

core/chainio/avs_writer.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import (
2020
"github.com/yetanotherco/aligned_layer/core/utils"
2121
)
2222

23+
const (
24+
gasBumpPercentage int = 10
25+
)
26+
2327
type AvsWriter struct {
2428
*avsregistry.ChainWriter
2529
AvsContractBindings *AvsServiceBindings
@@ -98,11 +102,11 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
98102
// Sends a transaction and waits for the receipt for three blocks, if not received
99103
// it will try again bumping the gas price based on `CalculateGasPriceBumpBasedOnRetry`
100104
// This process happens indefinitely until we sendTransaction does not return err.
101-
i := 0
105+
lastTxGasPrice := tx.GasPrice()
102106
sendTransaction := func() (*types.Receipt, error) {
103-
i++
104-
gasPrice := utils.CalculateGasPriceBumpBasedOnRetry(tx.GasPrice(), i)
105-
txOpts.GasPrice = gasPrice
107+
bumpedGasPrice := utils.CalculateGasPriceBump(lastTxGasPrice, gasBumpPercentage)
108+
lastTxGasPrice = bumpedGasPrice
109+
txOpts.GasPrice = bumpedGasPrice
106110

107111
w.logger.Infof("Sending ResponseToTask transaction with a gas price of %v", txOpts.GasPrice)
108112
err = w.checkRespondToTaskFeeLimit(tx, txOpts, batchIdentifierHash, senderAddress)

core/utils/eth_client_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func BytesToQuorumThresholdPercentages(quorumThresholdPercentagesBytes []byte) e
5050

5151
// Very basic algorithm to calculate the gasPrice bump based on the currentGasPrice and retry iteration.
5252
// It adds a i/10 percentage to the current prices, where i represents the iteration.
53-
func CalculateGasPriceBumpBasedOnRetry(currentGasPrice *big.Int, iteration int) *big.Int {
54-
percentageBump := new(big.Int).Div(big.NewInt(int64(iteration)), big.NewInt(10))
53+
func CalculateGasPriceBump(currentGasPrice *big.Int, percentage int) *big.Int {
54+
percentageBump := new(big.Int).Div(big.NewInt(int64(percentage)), big.NewInt(100))
5555
bumpAmount := new(big.Int).Mul(currentGasPrice, percentageBump)
5656
bumpedGasPrice := new(big.Int).Add(currentGasPrice, bumpAmount)
5757

0 commit comments

Comments
 (0)