mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
eth: Set default GPO percentile to 35%, and count blocks instead of transactions
This commit is contained in:
parent
72e70bcec2
commit
83fe302954
2 changed files with 15 additions and 14 deletions
|
|
@ -49,8 +49,8 @@ var DefaultConfig = Config{
|
||||||
|
|
||||||
TxPool: core.DefaultTxPoolConfig,
|
TxPool: core.DefaultTxPoolConfig,
|
||||||
GPO: gasprice.Config{
|
GPO: gasprice.Config{
|
||||||
Blocks: 10,
|
Blocks: 100,
|
||||||
Percentile: 50,
|
Percentile: 35,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
|
||||||
ch := make(chan getBlockPricesResult, gpo.checkBlocks)
|
ch := make(chan getBlockPricesResult, gpo.checkBlocks)
|
||||||
sent := 0
|
sent := 0
|
||||||
exp := 0
|
exp := 0
|
||||||
var txPrices []*big.Int
|
var blockPrices []*big.Int
|
||||||
for sent < gpo.checkBlocks && blockNum > 0 {
|
for sent < gpo.checkBlocks && blockNum > 0 {
|
||||||
go gpo.getBlockPrices(ctx, blockNum, ch)
|
go gpo.getBlockPrices(ctx, blockNum, ch)
|
||||||
sent++
|
sent++
|
||||||
|
|
@ -115,9 +115,8 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
|
||||||
return lastPrice, res.err
|
return lastPrice, res.err
|
||||||
}
|
}
|
||||||
exp--
|
exp--
|
||||||
if len(res.prices) > 0 {
|
if res.price != nil {
|
||||||
txPrices = append(txPrices, res.prices...)
|
blockPrices = append(blockPrices, res.price)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
if maxEmpty > 0 {
|
if maxEmpty > 0 {
|
||||||
maxEmpty--
|
maxEmpty--
|
||||||
|
|
@ -131,9 +130,9 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
price := lastPrice
|
price := lastPrice
|
||||||
if len(txPrices) > 0 {
|
if len(blockPrices) > 0 {
|
||||||
sort.Sort(bigIntArray(txPrices))
|
sort.Sort(bigIntArray(blockPrices))
|
||||||
price = txPrices[(len(txPrices)-1)*gpo.percentile/100]
|
price = blockPrices[(len(blockPrices)-1)*gpo.percentile/100]
|
||||||
}
|
}
|
||||||
if price.Cmp(maxPrice) > 0 {
|
if price.Cmp(maxPrice) > 0 {
|
||||||
price = new(big.Int).Set(maxPrice)
|
price = new(big.Int).Set(maxPrice)
|
||||||
|
|
@ -147,7 +146,7 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type getBlockPricesResult struct {
|
type getBlockPricesResult struct {
|
||||||
prices []*big.Int
|
price *big.Int
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,11 +159,13 @@ func (gpo *Oracle) getBlockPrices(ctx context.Context, blockNum uint64, ch chan
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
txs := block.Transactions()
|
txs := block.Transactions()
|
||||||
prices := make([]*big.Int, len(txs))
|
var minPrice *big.Int
|
||||||
for i, tx := range txs {
|
for _, tx := range txs {
|
||||||
prices[i] = tx.GasPrice()
|
if minPrice == nil || tx.GasPrice().Cmp(minPrice) < 0 {
|
||||||
|
minPrice = tx.GasPrice()
|
||||||
}
|
}
|
||||||
ch <- getBlockPricesResult{prices, nil}
|
}
|
||||||
|
ch <- getBlockPricesResult{minPrice, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
type bigIntArray []*big.Int
|
type bigIntArray []*big.Int
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue