Skip to content

Commit

Permalink
Ensure that fee is increased by at least 10% (#8747)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdehoog committed Dec 22, 2023
1 parent 8b197bc commit edec19f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions op-service/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
var (
priceBumpPercent = big.NewInt(100 + priceBump)
oneHundred = big.NewInt(100)
ninetyNine = big.NewInt(99)
)

// TxManager is an interface that allows callers to reliably publish txs,
Expand Down Expand Up @@ -603,15 +604,12 @@ func (m *SimpleTxManager) checkLimits(tip, basefee, bumpedTip, bumpedFee *big.In
return nil
}

// calcThresholdValue returns x * priceBumpPercent / 100
// calcThresholdValue returns ceil(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.Add(threshold, ninetyNine)
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
}

Expand Down
8 changes: 4 additions & 4 deletions op-service/txmgr/txmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,15 +907,15 @@ func TestIncreaseGasPrice(t *testing.T) {
func TestIncreaseGasPriceLimits(t *testing.T) {
t.Run("no-threshold", func(t *testing.T) {
testIncreaseGasPriceLimit(t, gasPriceLimitTest{
expTipCap: 36,
expFeeCap: 493, // just below 5*100
expTipCap: 46,
expFeeCap: 354, // just below 5*100
})
})
t.Run("with-threshold", func(t *testing.T) {
testIncreaseGasPriceLimit(t, gasPriceLimitTest{
thr: big.NewInt(params.GWei),
expTipCap: 61_265_017,
expFeeCap: 957_582_949, // just below 1 gwei
expTipCap: 131_326_987,
expFeeCap: 933_286_308, // just below 1 gwei
})
})
}
Expand Down

0 comments on commit edec19f

Please sign in to comment.