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

This commit is contained in:
Daniel Liu 2024-11-13 09:30:55 +08:00
parent d3eaeb9381
commit de7203ac88
5 changed files with 9 additions and 16 deletions

View file

@ -225,11 +225,7 @@ func New(ctx *node.ServiceContext, config *ethconfig.Config, XDCXServ *XDCx.XDCX
} else { } else {
eth.ApiBackend = &EthApiBackend{eth, nil, nil} eth.ApiBackend = &EthApiBackend{eth, nil, nil}
} }
gpoParams := config.GPO eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, config.GPO, config.GasPrice)
if gpoParams.Default == nil {
gpoParams.Default = config.GasPrice
}
eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams)
// Set global ipc endpoint. // Set global ipc endpoint.
eth.blockchain.IPCEndpoint = ctx.GetConfig().IPCEndpoint() eth.blockchain.IPCEndpoint = ctx.GetConfig().IPCEndpoint()

View file

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

View file

@ -44,7 +44,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"`
} }
@ -78,7 +77,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
@ -114,6 +113,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)
@ -130,7 +132,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,

View file

@ -174,7 +174,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 // Eip1559 fork number fork *big.Int // Eip1559 fork number
@ -188,7 +187,7 @@ func TestSuggestTipCap(t *testing.T) {
} }
for _, c := range cases { for _, c := range cases {
backend := newTestBackend(t, c.fork, false) backend := newTestBackend(t, c.fork, 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())

View file

@ -131,11 +131,7 @@ func New(ctx *node.ServiceContext, config *ethconfig.Config) (*LightEthereum, er
return nil, err return nil, err
} }
leth.ApiBackend = &LesApiBackend{leth, nil} leth.ApiBackend = &LesApiBackend{leth, nil}
gpoParams := config.GPO leth.ApiBackend.gpo = gasprice.NewOracle(leth.ApiBackend, config.GPO, config.GasPrice)
if gpoParams.Default == nil {
gpoParams.Default = config.GasPrice
}
leth.ApiBackend.gpo = gasprice.NewOracle(leth.ApiBackend, gpoParams)
return leth, nil return leth, nil
} }