Skip to content

Commit 2b25d45

Browse files
committed
fix: address review comments
1 parent f0e58cf commit 2b25d45

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

core/chainio/avs_writer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.E
8181
// Sends AggregatedResponse and waits for the receipt for three blocks, if not received
8282
// it will try again bumping the last tx gas price based on `CalculateGasPriceBump`
8383
// This process happens indefinitely until the transaction is included.
84-
// Note: If the rpc endpoints fail, the retry will stop, as it will infinitely try
84+
//
85+
// Note: If the rpc endpoints fail, the retry will stop it returning a permanent error.
86+
// This is because the retries are infinite and we want to prevent increasing the time between them too much as it is exponential.
87+
// And we might also if the rpc is down for a good period of time, we might fall into an infinite waiting.
8588
func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMerkleRoot [32]byte, senderAddress [20]byte, nonSignerStakesAndSignature servicemanager.IBLSSignatureCheckerNonSignerStakesAndSignature, onRetry func()) (*types.Receipt, error) {
8689
txOpts := *w.Signer.GetTxOpts()
8790
txOpts.NoSend = true // simulate the transaction
@@ -125,7 +128,6 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
125128

126129
w.logger.Infof("Sending ResponseToTask transaction with a gas price of %v", txOpts.GasPrice)
127130
err = w.checkRespondToTaskFeeLimit(tx, txOpts, batchIdentifierHash, senderAddress)
128-
129131
if err != nil {
130132
return nil, connection.PermanentError{Inner: err}
131133
}

core/utils/eth_client_utils.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ func WaitForTransactionReceipt(client eth.InstrumentedClient, ctx context.Contex
2525
// if context has timed out, return
2626
if ctx.Err() != nil {
2727
return nil, ctx.Err()
28-
} else {
29-
time.Sleep(sleepTime)
3028
}
29+
time.Sleep(sleepTime)
3130
}
3231
return nil, fmt.Errorf("transaction receipt not found for txHash: %s", txHash.String())
3332
}
@@ -48,13 +47,21 @@ func BytesToQuorumThresholdPercentages(quorumThresholdPercentagesBytes []byte) e
4847
return quorumThresholdPercentages
4948
}
5049

51-
// Very basic algorithm to calculate the gasPrice bump based on the currentGasPrice a constant percentage and the retry number.
52-
// It adds a the percentage to the current gas price and a 5% * i, where i is the iteration number. That is:
53-
func CalculateGasPriceBumpBasedOnRetry(currentGasPrice *big.Int, percentage int, i int) *big.Int {
54-
retryPercentage := new(big.Int).Mul(big.NewInt(5), big.NewInt(int64(i)))
55-
percentageBump := new(big.Int).Add(big.NewInt(int64(percentage)), retryPercentage)
56-
bumpAmount := new(big.Int).Mul(currentGasPrice, percentageBump)
50+
// Simple algorithm to calculate the gasPrice bump based on:
51+
// the currentGasPrice, a base bump percentage, and the retry count.
52+
// Formula: currentGasPrice + (currentGasPrice * (baseBumpPercentage + retryCount * incrementalRetryPercentage) / 100)
53+
func CalculateGasPriceBumpBasedOnRetry(currentGasPrice *big.Int, baseBumpPercentage int, retryCount int) *big.Int {
54+
// Incremental percentage increase for each retry attempt (5%)
55+
incrementalRetryPercentage := new(big.Int).Mul(big.NewInt(5), big.NewInt(int64(retryCount)))
56+
57+
// Total bump percentage: base bump + incremental percentage based on retry count
58+
totalBumpPercentage := new(big.Int).Add(big.NewInt(int64(baseBumpPercentage)), incrementalRetryPercentage)
59+
60+
// Calculate the bump amount: currentGasPrice * totalBumpPercentage / 100
61+
bumpAmount := new(big.Int).Mul(currentGasPrice, totalBumpPercentage)
5762
bumpAmount = new(big.Int).Div(bumpAmount, big.NewInt(100))
63+
64+
// Final bumped gas price: currentGasPrice + bumpAmount
5865
bumpedGasPrice := new(big.Int).Add(currentGasPrice, bumpAmount)
5966

6067
return bumpedGasPrice

0 commit comments

Comments
 (0)