eth/gasprice: remove default from config (#30080)

* eth/gasprice: remove default from config

* eth/gasprice: sanitize startPrice
pull/30203/head
Marius van der Wijden 4 months ago committed by GitHub
parent 944718bf16
commit 380688c636
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      eth/backend.go
  2. 2
      eth/gasprice/feehistory_test.go
  3. 8
      eth/gasprice/gasprice.go
  4. 3
      eth/gasprice/gasprice_test.go

@ -264,11 +264,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if eth.APIBackend.allowUnprotectedTxs { if eth.APIBackend.allowUnprotectedTxs {
log.Info("Unprotected transactions allowed") log.Info("Unprotected transactions allowed")
} }
gpoParams := config.GPO eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, config.GPO, config.Miner.GasPrice)
if gpoParams.Default == nil {
gpoParams.Default = config.Miner.GasPrice
}
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
// Setup DNS discovery iterators. // Setup DNS discovery iterators.
dnsclient := dnsdisc.NewClient(dnsdisc.Config{}) dnsclient := dnsdisc.NewClient(dnsdisc.Config{})

@ -59,7 +59,7 @@ func TestFeeHistory(t *testing.T) {
MaxBlockHistory: c.maxBlock, MaxBlockHistory: c.maxBlock,
} }
backend := newTestBackend(t, big.NewInt(16), big.NewInt(28), c.pending) backend := newTestBackend(t, big.NewInt(16), big.NewInt(28), c.pending)
oracle := NewOracle(backend, config) oracle := NewOracle(backend, config, nil)
first, reward, baseFee, ratio, blobBaseFee, blobRatio, err := oracle.FeeHistory(context.Background(), c.count, c.last, c.percent) first, reward, baseFee, ratio, blobBaseFee, blobRatio, err := oracle.FeeHistory(context.Background(), c.count, c.last, c.percent)
backend.teardown() backend.teardown()

@ -45,7 +45,6 @@ type Config struct {
Percentile int Percentile int
MaxHeaderHistory uint64 MaxHeaderHistory uint64
MaxBlockHistory uint64 MaxBlockHistory uint64
Default *big.Int `toml:",omitempty"`
MaxPrice *big.Int `toml:",omitempty"` MaxPrice *big.Int `toml:",omitempty"`
IgnorePrice *big.Int `toml:",omitempty"` IgnorePrice *big.Int `toml:",omitempty"`
} }
@ -79,7 +78,7 @@ type Oracle struct {
// NewOracle returns a new gasprice oracle which can recommend suitable // NewOracle returns a new gasprice oracle which can recommend suitable
// gasprice for newly created transaction. // gasprice for newly created transaction.
func NewOracle(backend OracleBackend, params Config) *Oracle { func NewOracle(backend OracleBackend, params Config, startPrice *big.Int) *Oracle {
blocks := params.Blocks blocks := params.Blocks
if blocks < 1 { if blocks < 1 {
blocks = 1 blocks = 1
@ -115,6 +114,9 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
maxBlockHistory = 1 maxBlockHistory = 1
log.Warn("Sanitizing invalid gasprice oracle max block history", "provided", params.MaxBlockHistory, "updated", maxBlockHistory) log.Warn("Sanitizing invalid gasprice oracle max block history", "provided", params.MaxBlockHistory, "updated", maxBlockHistory)
} }
if startPrice == nil {
startPrice = new(big.Int)
}
cache := lru.NewCache[cacheKey, processedFees](2048) cache := lru.NewCache[cacheKey, processedFees](2048)
headEvent := make(chan core.ChainHeadEvent, 1) headEvent := make(chan core.ChainHeadEvent, 1)
@ -131,7 +133,7 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
return &Oracle{ return &Oracle{
backend: backend, backend: backend,
lastPrice: params.Default, lastPrice: startPrice,
maxPrice: maxPrice, maxPrice: maxPrice,
ignorePrice: ignorePrice, ignorePrice: ignorePrice,
checkBlocks: blocks, checkBlocks: blocks,

@ -235,7 +235,6 @@ func TestSuggestTipCap(t *testing.T) {
config := Config{ config := Config{
Blocks: 3, Blocks: 3,
Percentile: 60, Percentile: 60,
Default: big.NewInt(params.GWei),
} }
var cases = []struct { var cases = []struct {
fork *big.Int // London fork number fork *big.Int // London fork number
@ -249,7 +248,7 @@ func TestSuggestTipCap(t *testing.T) {
} }
for _, c := range cases { for _, c := range cases {
backend := newTestBackend(t, c.fork, nil, false) backend := newTestBackend(t, c.fork, nil, false)
oracle := NewOracle(backend, config) oracle := NewOracle(backend, config, big.NewInt(params.GWei))
// The gas price sampled is: 32G, 31G, 30G, 29G, 28G, 27G // The gas price sampled is: 32G, 31G, 30G, 29G, 28G, 27G
got, err := oracle.SuggestTipCap(context.Background()) got, err := oracle.SuggestTipCap(context.Background())

Loading…
Cancel
Save