From aba779504795f8ea00d9d651ff51d1150dd18daf Mon Sep 17 00:00:00 2001 From: Sebastian Stammler Date: Wed, 20 Dec 2023 23:29:16 +0100 Subject: [PATCH] op-service/txmgr: Bump fees by at least 1 wei Edge-case during near-zero network fee conditions. --- op-service/txmgr/txmgr.go | 7 ++++++- op-service/txmgr/txmgr_test.go | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/op-service/txmgr/txmgr.go b/op-service/txmgr/txmgr.go index 252f63d2c189..c3e13db317dd 100644 --- a/op-service/txmgr/txmgr.go +++ b/op-service/txmgr/txmgr.go @@ -604,9 +604,14 @@ func (m *SimpleTxManager) checkLimits(tip, basefee, bumpedTip, bumpedFee *big.In } // calcThresholdValue returns x * priceBumpPercent / 100 +// It guarantees that x is increased by at least 1 func calcThresholdValue(x *big.Int) *big.Int { 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 } diff --git a/op-service/txmgr/txmgr_test.go b/op-service/txmgr/txmgr_test.go index dd47cfeb233a..d14331601d7a 100644 --- a/op-service/txmgr/txmgr_test.go +++ b/op-service/txmgr/txmgr_test.go @@ -838,6 +838,14 @@ func TestIncreaseGasPrice(t *testing.T) { name string 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", run: func(t *testing.T) {