Commit 4c70fc11 authored by Sebastian Stammler's avatar Sebastian Stammler Committed by GitHub

op-service/txmgr: Bump fees by at least 1 wei (#8713)

Edge-case during near-zero network fee conditions.
parent 71036728
...@@ -604,9 +604,14 @@ func (m *SimpleTxManager) checkLimits(tip, basefee, bumpedTip, bumpedFee *big.In ...@@ -604,9 +604,14 @@ func (m *SimpleTxManager) checkLimits(tip, basefee, bumpedTip, bumpedFee *big.In
} }
// calcThresholdValue returns x * priceBumpPercent / 100 // calcThresholdValue returns x * priceBumpPercent / 100
// 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 = 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
} }
......
...@@ -838,6 +838,14 @@ func TestIncreaseGasPrice(t *testing.T) { ...@@ -838,6 +838,14 @@ func TestIncreaseGasPrice(t *testing.T) {
name string name string
run func(t *testing.T) run func(t *testing.T)
}{ }{
{
name: "bump at least 1",
run: func(t *testing.T) {
tx, newTx := doGasPriceIncrease(t, 1, 3, 1, 1)
require.True(t, newTx.GasFeeCap().Cmp(tx.GasFeeCap()) > 0, "new tx fee cap must be larger")
require.True(t, newTx.GasTipCap().Cmp(tx.GasTipCap()) > 0, "new tx tip must be larger")
},
},
{ {
name: "enforces min bump", name: "enforces min bump",
run: func(t *testing.T) { run: func(t *testing.T) {
......
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