mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 22:56:43 +00:00
eth/gasprice: max limit, maxEmpty
This commit is contained in:
parent
e8fd5cb5cb
commit
856d00d308
2 changed files with 11 additions and 5 deletions
|
|
@ -412,7 +412,7 @@ var (
|
||||||
GpoBlocksFlag = cli.IntFlag{
|
GpoBlocksFlag = cli.IntFlag{
|
||||||
Name: "gpoblocks",
|
Name: "gpoblocks",
|
||||||
Usage: "Number of recent blocks to check for gas prices",
|
Usage: "Number of recent blocks to check for gas prices",
|
||||||
Value: 5,
|
Value: 10,
|
||||||
}
|
}
|
||||||
GpoPercentileFlag = cli.IntFlag{
|
GpoPercentileFlag = cli.IntFlag{
|
||||||
Name: "gpopercentile",
|
Name: "gpopercentile",
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,12 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var maxPrice = big.NewInt(500 * params.Shannon)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Blocks int
|
Blocks int
|
||||||
Percentile int
|
Percentile int
|
||||||
|
|
@ -42,8 +45,8 @@ type Oracle struct {
|
||||||
cacheLock sync.RWMutex
|
cacheLock sync.RWMutex
|
||||||
fetchLock sync.Mutex
|
fetchLock sync.Mutex
|
||||||
|
|
||||||
checkBlocks, minBlocks, maxBlocks int
|
checkBlocks, maxEmpty, maxBlocks int
|
||||||
percentile int
|
percentile int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOracle returns a new oracle.
|
// NewOracle returns a new oracle.
|
||||||
|
|
@ -63,7 +66,7 @@ func NewOracle(backend ethapi.Backend, params Config) *Oracle {
|
||||||
backend: backend,
|
backend: backend,
|
||||||
lastPrice: params.Default,
|
lastPrice: params.Default,
|
||||||
checkBlocks: blocks,
|
checkBlocks: blocks,
|
||||||
minBlocks: (blocks + 1) / 2,
|
maxEmpty: blocks / 2,
|
||||||
maxBlocks: blocks * 5,
|
maxBlocks: blocks * 5,
|
||||||
percentile: percent,
|
percentile: percent,
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +108,7 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
|
||||||
exp++
|
exp++
|
||||||
blockNum--
|
blockNum--
|
||||||
}
|
}
|
||||||
maxEmpty := gpo.checkBlocks - gpo.minBlocks
|
maxEmpty := gpo.maxEmpty
|
||||||
for exp > 0 {
|
for exp > 0 {
|
||||||
res := <-ch
|
res := <-ch
|
||||||
if res.err != nil {
|
if res.err != nil {
|
||||||
|
|
@ -132,6 +135,9 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
|
||||||
sort.Sort(bigIntArray(txPrices))
|
sort.Sort(bigIntArray(txPrices))
|
||||||
price = txPrices[(len(txPrices)-1)*gpo.percentile/100]
|
price = txPrices[(len(txPrices)-1)*gpo.percentile/100]
|
||||||
}
|
}
|
||||||
|
if price.Cmp(maxPrice) > 0 {
|
||||||
|
price = new(big.Int).Set(maxPrice)
|
||||||
|
}
|
||||||
|
|
||||||
gpo.cacheLock.Lock()
|
gpo.cacheLock.Lock()
|
||||||
gpo.lastHead = headHash
|
gpo.lastHead = headHash
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue