Skip to content

Commit bdf64cf

Browse files
authored
fix(GPO): make default gas tip configurable (#1096)
* fix(GPO): increase min suggested tip to 100 wei * chore: auto version bump [bot] * make DefaultGasTip configurable * revert a comment change * fix unit tests * rename GasTip to GasTipCap, more consistent with geth naming conventions * yet another comment tweak * tweak * address comments * another * make defaultGasTipCap.Int64 >0 --------- Co-authored-by: colinlyguo <[email protected]>
1 parent a5ecce2 commit bdf64cf

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

cmd/utils/flags.go

+7
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,10 @@ var (
741741
Usage: "Number of pending transactions to consider the network congested and suggest a minimum tip cap",
742742
Value: ethconfig.Defaults.GPO.CongestedThreshold,
743743
}
744+
GpoDefaultGasTipCapFlag = cli.Int64Flag{
745+
Name: "gpo.defaultgastipcap",
746+
Usage: "Default minimum gas tip cap (in wei) to be used after Curie fork (EIP-1559) (default: 100)",
747+
}
744748

745749
// Metrics flags
746750
MetricsEnabledFlag = cli.BoolFlag{
@@ -1450,6 +1454,9 @@ func setGPO(ctx *cli.Context, cfg *gasprice.Config, light bool) {
14501454
if ctx.GlobalIsSet(GpoCongestionThresholdFlag.Name) {
14511455
cfg.CongestedThreshold = ctx.GlobalInt(GpoCongestionThresholdFlag.Name)
14521456
}
1457+
if ctx.GlobalIsSet(GpoDefaultGasTipCapFlag.Name) {
1458+
cfg.DefaultGasTipCap = big.NewInt(ctx.GlobalInt64(GpoDefaultGasTipCapFlag.Name))
1459+
}
14531460
}
14541461

14551462
func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {

eth/gasprice/gasprice.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ var (
4040
DefaultMaxPrice = big.NewInt(500 * params.GWei)
4141
DefaultIgnorePrice = big.NewInt(1 * params.Wei)
4242
DefaultBasePrice = big.NewInt(0)
43+
// DefaultGasTipCap is set to 100 wei instead of 1 wei for the following reasons:
44+
// 1. Very low tip values (e.g. 1 wei) can cause issues because transaction pools often reject replacing transactions
45+
// with the same gas tip cap. This becomes problematic when low tips like 1 wei fail to increase due to rounding
46+
// in some SDK implementations (e.g. 1 wei * 1.5 = 1 wei).
47+
// 2. The cost of a gas tip cap of 100 wei is negligible compared to the base fee in most cases.
48+
DefaultGasTipCap = big.NewInt(100) // Default minimum gas tip cap in wei (used after Curie/EIP-1559).
4349
)
4450

4551
type Config struct {
@@ -52,6 +58,7 @@ type Config struct {
5258
IgnorePrice *big.Int `toml:",omitempty"`
5359
CongestedThreshold int // Number of pending transactions to consider the network congested and suggest a minimum tip cap.
5460
DefaultBasePrice *big.Int `toml:",omitempty"` // Base price to set when CongestedThreshold is reached before Curie (EIP 1559).
61+
DefaultGasTipCap *big.Int `toml:",omitempty"` // Default minimum gas tip cap to use after Curie (EIP 1559).
5562
}
5663

5764
// OracleBackend includes all necessary background APIs for oracle.
@@ -82,6 +89,7 @@ type Oracle struct {
8289
maxHeaderHistory, maxBlockHistory int
8390
congestedThreshold int // Number of pending transactions to consider the network congested and suggest a minimum tip cap.
8491
defaultBasePrice *big.Int // Base price to set when CongestedThreshold is reached before Curie (EIP 1559).
92+
defaultGasTipCap *big.Int // Default gas tip cap to suggest after Curie (EIP 1559) when the network is not congested.
8593
historyCache *lru.Cache
8694
}
8795

@@ -133,6 +141,11 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
133141
defaultBasePrice = DefaultBasePrice
134142
log.Warn("Sanitizing invalid gasprice oracle default base price", "provided", params.DefaultBasePrice, "updated", defaultBasePrice)
135143
}
144+
defaultGasTipCap := params.DefaultGasTipCap
145+
if defaultGasTipCap == nil || defaultGasTipCap.Int64() <= 0 {
146+
defaultGasTipCap = DefaultGasTipCap
147+
log.Warn("Sanitizing invalid gasprice oracle default gas tip cap", "provided", params.DefaultGasTipCap, "updated", DefaultGasTipCap)
148+
}
136149

137150
cache, _ := lru.New(2048)
138151
headEvent := make(chan core.ChainHeadEvent, 1)
@@ -158,6 +171,7 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
158171
maxBlockHistory: maxBlockHistory,
159172
congestedThreshold: congestedThreshold,
160173
defaultBasePrice: defaultBasePrice,
174+
defaultGasTipCap: defaultGasTipCap,
161175
historyCache: cache,
162176
}
163177
}
@@ -195,13 +209,9 @@ func (oracle *Oracle) SuggestTipCap(ctx context.Context) (*big.Int, error) {
195209
// high-priced txs are causing the suggested tip cap to be high.
196210
pendingTxCount, _ := oracle.backend.StatsWithMinBaseFee(head.BaseFee)
197211
if pendingTxCount < oracle.congestedThreshold {
198-
// Before Curie (EIP-1559), we need to return the total suggested gas price. After Curie we return 2 wei as the tip cap,
212+
// Before Curie (EIP-1559), we need to return the total suggested gas price. After Curie we return defaultGasTipCap wei as the tip cap,
199213
// as the base fee is set separately or added manually for legacy transactions.
200-
// 1. Set price to at least 1 as otherwise tx with a 0 tip might be filtered out by the default mempool config.
201-
// 2. Since oracle.ignoreprice was set to 2 (DefaultIgnorePrice) before by default, we need to set the price
202-
// to 2 to avoid filtering in oracle.getBlockValues() by nodes that did not yet update to this version.
203-
// In the future we can set the price to 1 wei.
204-
price := big.NewInt(2)
214+
price := oracle.defaultGasTipCap
205215
if !oracle.backend.ChainConfig().IsCurie(head.Number) {
206216
price = oracle.defaultBasePrice
207217
}

eth/gasprice/gasprice_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func TestSuggestTipCap(t *testing.T) {
213213

214214
func TestSuggestTipCapCongestedThreshold(t *testing.T) {
215215
expectedDefaultBasePricePreCurie := big.NewInt(2000)
216-
expectedDefaultBasePricePostCurie := big.NewInt(1)
216+
expectedDefaultBasePricePostCurie := big.NewInt(100)
217217

218218
config := Config{
219219
Blocks: 3,

params/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 7 // Minor version component of the current release
27-
VersionPatch = 28 // Patch version component of the current release
27+
VersionPatch = 29 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)