Skip to content

Commit

Permalink
Merge pull request #512 from uprendis/feature/fix-zero-gpo-zero-tip
Browse files Browse the repository at this point in the history
Fix GPO suggesting top lower than txpool's limit
  • Loading branch information
uprendis authored Sep 20, 2023
2 parents 438f216 + 08f71d1 commit a994e6c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
8 changes: 8 additions & 0 deletions cmd/opera/launcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"errors"
"fmt"
"math/big"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -540,6 +541,13 @@ func mayMakeAllConfigs(ctx *cli.Context) (*config, error) {

// Process DBs defaults in the end because they are applied only in absence of config or flags
cfg = setDBConfigDefault(cfg, cacheRatio)
// Sanitize GPO config
if cfg.Opera.GPO.MinGasTip == nil || cfg.Opera.GPO.MinGasTip.Sign() == 0 {
cfg.Opera.GPO.MinGasTip = new(big.Int).SetUint64(cfg.TxPool.PriceLimit)
}
if cfg.Opera.GPO.MinGasTip.Cmp(new(big.Int).SetUint64(cfg.TxPool.PriceLimit)) < 0 {
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))
}

if err := cfg.Opera.Validate(); err != nil {
return nil, err
Expand Down
8 changes: 2 additions & 6 deletions evmcore/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ type TxPoolConfig struct {
Journal string // Journal of local transactions to survive node restarts
Rejournal time.Duration // Time interval to regenerate the local transaction journal

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

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

PriceLimit: 1,
PriceLimit: 0,
PriceBump: 10,

AccountSlots: 16,
Expand All @@ -189,10 +189,6 @@ func (config *TxPoolConfig) sanitize() TxPoolConfig {
log.Warn("Sanitizing invalid txpool journal time", "provided", conf.Rejournal, "updated", time.Second)
conf.Rejournal = time.Second
}
if conf.PriceLimit < 1 {
log.Warn("Sanitizing invalid txpool price limit", "provided", conf.PriceLimit, "updated", DefaultTxPoolConfig.PriceLimit)
conf.PriceLimit = DefaultTxPoolConfig.PriceLimit
}
if conf.PriceBump < 1 {
log.Warn("Sanitizing invalid txpool price bump", "provided", conf.PriceBump, "updated", DefaultTxPoolConfig.PriceBump)
conf.PriceBump = DefaultTxPoolConfig.PriceBump
Expand Down
1 change: 1 addition & 0 deletions gossip/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func DefaultConfig(scale cachescale.Func) Config {
GPO: gasprice.Config{
MaxGasPrice: gasprice.DefaultMaxGasPrice,
MinGasPrice: new(big.Int),
MinGasTip: new(big.Int),
DefaultCertainty: 0.5 * gasprice.DecimalUnit,
},

Expand Down
8 changes: 5 additions & 3 deletions gossip/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
type Config struct {
MaxGasPrice *big.Int `toml:",omitempty"`
MinGasPrice *big.Int `toml:",omitempty"`
MinGasTip *big.Int `toml:",omitempty"`
DefaultCertainty uint64 `toml:",omitempty"`
}

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

tip := new(big.Int).Sub(combined, minPrice)
if tip.Sign() < 0 {
return new(big.Int)
if tip.Cmp(gpo.cfg.MinGasTip) < 0 {
return new(big.Int).Set(gpo.cfg.MinGasTip)
}
return tip
}
Expand Down

0 comments on commit a994e6c

Please sign in to comment.