@@ -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