Skip to content

Commit

Permalink
gpo: add min gas tip, crosscheck against txpool's min gas tip
Browse files Browse the repository at this point in the history
  • Loading branch information
uprendis committed Sep 14, 2023
1 parent fbce84d commit 08f71d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 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
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 08f71d1

Please sign in to comment.