eth/gasprice: max limit, maxEmpty

This commit is contained in:
Zsolt Felfoldi 2017-04-06 15:51:10 +02:00
parent e8fd5cb5cb
commit 856d00d308
2 changed files with 11 additions and 5 deletions

View file

@ -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",

View file

@ -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,7 +45,7 @@ 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
} }
@ -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