Skip to content

Commit a994e6c

Browse files
authored
Merge pull request #512 from uprendis/feature/fix-zero-gpo-zero-tip
Fix GPO suggesting top lower than txpool's limit
2 parents 438f216 + 08f71d1 commit a994e6c

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

cmd/opera/launcher/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"errors"
66
"fmt"
7+
"math/big"
78
"os"
89
"path"
910
"path/filepath"
@@ -540,6 +541,13 @@ func mayMakeAllConfigs(ctx *cli.Context) (*config, error) {
540541

541542
// Process DBs defaults in the end because they are applied only in absence of config or flags
542543
cfg = setDBConfigDefault(cfg, cacheRatio)
544+
// Sanitize GPO config
545+
if cfg.Opera.GPO.MinGasTip == nil || cfg.Opera.GPO.MinGasTip.Sign() == 0 {
546+
cfg.Opera.GPO.MinGasTip = new(big.Int).SetUint64(cfg.TxPool.PriceLimit)
547+
}
548+
if cfg.Opera.GPO.MinGasTip.Cmp(new(big.Int).SetUint64(cfg.TxPool.PriceLimit)) < 0 {
549+
log.Warn(fmt.Sprintf("GPO minimum gas tip (Opera.GPO.MinGasTip=%s) is lower than txpool minimum gas tip (TxPool.PriceLimit=%d)", cfg.Opera.GPO.MinGasTip.String(), cfg.TxPool.PriceLimit))
550+
}
543551

544552
if err := cfg.Opera.Validate(); err != nil {
545553
return nil, err

evmcore/tx_pool.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ type TxPoolConfig struct {
153153
Journal string // Journal of local transactions to survive node restarts
154154
Rejournal time.Duration // Time interval to regenerate the local transaction journal
155155

156-
PriceLimit uint64 // Minimum gas price to enforce for acceptance into the pool
156+
PriceLimit uint64 // Minimum gas tip to enforce for acceptance into the pool
157157
PriceBump uint64 // Minimum price bump percentage to replace an already existing transaction (nonce)
158158

159159
AccountSlots uint64 // Number of executable transaction slots guaranteed per account
@@ -170,7 +170,7 @@ var DefaultTxPoolConfig = TxPoolConfig{
170170
Journal: "transactions.rlp",
171171
Rejournal: time.Hour,
172172

173-
PriceLimit: 1,
173+
PriceLimit: 0,
174174
PriceBump: 10,
175175

176176
AccountSlots: 16,
@@ -189,10 +189,6 @@ func (config *TxPoolConfig) sanitize() TxPoolConfig {
189189
log.Warn("Sanitizing invalid txpool journal time", "provided", conf.Rejournal, "updated", time.Second)
190190
conf.Rejournal = time.Second
191191
}
192-
if conf.PriceLimit < 1 {
193-
log.Warn("Sanitizing invalid txpool price limit", "provided", conf.PriceLimit, "updated", DefaultTxPoolConfig.PriceLimit)
194-
conf.PriceLimit = DefaultTxPoolConfig.PriceLimit
195-
}
196192
if conf.PriceBump < 1 {
197193
log.Warn("Sanitizing invalid txpool price bump", "provided", conf.PriceBump, "updated", DefaultTxPoolConfig.PriceBump)
198194
conf.PriceBump = DefaultTxPoolConfig.PriceBump

gossip/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func DefaultConfig(scale cachescale.Func) Config {
213213
GPO: gasprice.Config{
214214
MaxGasPrice: gasprice.DefaultMaxGasPrice,
215215
MinGasPrice: new(big.Int),
216+
MinGasTip: new(big.Int),
216217
DefaultCertainty: 0.5 * gasprice.DecimalUnit,
217218
},
218219

gossip/gasprice/gasprice.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const (
4949
type Config struct {
5050
MaxGasPrice *big.Int `toml:",omitempty"`
5151
MinGasPrice *big.Int `toml:",omitempty"`
52+
MinGasTip *big.Int `toml:",omitempty"`
5253
DefaultCertainty uint64 `toml:",omitempty"`
5354
}
5455

@@ -107,7 +108,8 @@ func sanitizeBigInt(val, min, max, _default *big.Int, name string) *big.Int {
107108
// gasprice for newly created transaction.
108109
func NewOracle(params Config) *Oracle {
109110
params.MaxGasPrice = sanitizeBigInt(params.MaxGasPrice, nil, nil, DefaultMaxGasPrice, "MaxGasPrice")
110-
params.MinGasPrice = sanitizeBigInt(params.MinGasPrice, nil, nil, new(big.Int), "MinGasPrice")
111+
params.MinGasPrice = sanitizeBigInt(params.MinGasPrice, nil, params.MaxGasPrice, new(big.Int), "MinGasPrice")
112+
params.MinGasTip = sanitizeBigInt(params.MinGasTip, nil, new(big.Int).Sub(params.MaxGasPrice, params.MinGasPrice), new(big.Int), "MinGasTip")
111113
params.DefaultCertainty = sanitizeBigInt(new(big.Int).SetUint64(params.DefaultCertainty), big.NewInt(0), DecimalUnitBn, big.NewInt(DecimalUnit/2), "DefaultCertainty").Uint64()
112114
tCache, _ := lru.New(100)
113115
return &Oracle{
@@ -148,8 +150,8 @@ func (gpo *Oracle) suggestTip(certainty uint64) *big.Int {
148150
}
149151

150152
tip := new(big.Int).Sub(combined, minPrice)
151-
if tip.Sign() < 0 {
152-
return new(big.Int)
153+
if tip.Cmp(gpo.cfg.MinGasTip) < 0 {
154+
return new(big.Int).Set(gpo.cfg.MinGasTip)
153155
}
154156
return tip
155157
}

0 commit comments

Comments
 (0)