Commit edec19f0 authored by Michael de Hoog's avatar Michael de Hoog Committed by GitHub

Ensure that fee is increased by at least 10% (#8747)

parent 8b197bc0
...@@ -30,6 +30,7 @@ const ( ...@@ -30,6 +30,7 @@ const (
var ( var (
priceBumpPercent = big.NewInt(100 + priceBump) priceBumpPercent = big.NewInt(100 + priceBump)
oneHundred = big.NewInt(100) oneHundred = big.NewInt(100)
ninetyNine = big.NewInt(99)
) )
// TxManager is an interface that allows callers to reliably publish txs, // TxManager is an interface that allows callers to reliably publish txs,
...@@ -603,15 +604,12 @@ func (m *SimpleTxManager) checkLimits(tip, basefee, bumpedTip, bumpedFee *big.In ...@@ -603,15 +604,12 @@ func (m *SimpleTxManager) checkLimits(tip, basefee, bumpedTip, bumpedFee *big.In
return nil return nil
} }
// calcThresholdValue returns x * priceBumpPercent / 100 // calcThresholdValue returns ceil(x * priceBumpPercent / 100)
// It guarantees that x is increased by at least 1 // It guarantees that x is increased by at least 1
func calcThresholdValue(x *big.Int) *big.Int { func calcThresholdValue(x *big.Int) *big.Int {
threshold := new(big.Int).Mul(priceBumpPercent, x) threshold := new(big.Int).Mul(priceBumpPercent, x)
threshold.Add(threshold, ninetyNine)
threshold.Div(threshold, oneHundred) threshold.Div(threshold, oneHundred)
// Guarantee to add at least 1 wei. Edge-case during near-zero fee conditions.
if threshold.Cmp(x) == 0 {
threshold.Add(threshold, big.NewInt(1))
}
return threshold return threshold
} }
......
...@@ -907,15 +907,15 @@ func TestIncreaseGasPrice(t *testing.T) { ...@@ -907,15 +907,15 @@ func TestIncreaseGasPrice(t *testing.T) {
func TestIncreaseGasPriceLimits(t *testing.T) { func TestIncreaseGasPriceLimits(t *testing.T) {
t.Run("no-threshold", func(t *testing.T) { t.Run("no-threshold", func(t *testing.T) {
testIncreaseGasPriceLimit(t, gasPriceLimitTest{ testIncreaseGasPriceLimit(t, gasPriceLimitTest{
expTipCap: 36, expTipCap: 46,
expFeeCap: 493, // just below 5*100 expFeeCap: 354, // just below 5*100
}) })
}) })
t.Run("with-threshold", func(t *testing.T) { t.Run("with-threshold", func(t *testing.T) {
testIncreaseGasPriceLimit(t, gasPriceLimitTest{ testIncreaseGasPriceLimit(t, gasPriceLimitTest{
thr: big.NewInt(params.GWei), thr: big.NewInt(params.GWei),
expTipCap: 61_265_017, expTipCap: 131_326_987,
expFeeCap: 957_582_949, // just below 1 gwei expFeeCap: 933_286_308, // just below 1 gwei
}) })
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment