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{
Name: "gpoblocks",
Usage: "Number of recent blocks to check for gas prices",
Value: 5,
Value: 10,
}
GpoPercentileFlag = cli.IntFlag{
Name: "gpopercentile",

View file

@ -24,9 +24,12 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
)
var maxPrice = big.NewInt(500 * params.Shannon)
type Config struct {
Blocks int
Percentile int
@ -42,7 +45,7 @@ type Oracle struct {
cacheLock sync.RWMutex
fetchLock sync.Mutex
checkBlocks, minBlocks, maxBlocks int
checkBlocks, maxEmpty, maxBlocks int
percentile int
}
@ -63,7 +66,7 @@ func NewOracle(backend ethapi.Backend, params Config) *Oracle {
backend: backend,
lastPrice: params.Default,
checkBlocks: blocks,
minBlocks: (blocks + 1) / 2,
maxEmpty: blocks / 2,
maxBlocks: blocks * 5,
percentile: percent,
}
@ -105,7 +108,7 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
exp++
blockNum--
}
maxEmpty := gpo.checkBlocks - gpo.minBlocks
maxEmpty := gpo.maxEmpty
for exp > 0 {
res := <-ch
if res.err != nil {
@ -132,6 +135,9 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
sort.Sort(bigIntArray(txPrices))
price = txPrices[(len(txPrices)-1)*gpo.percentile/100]
}
if price.Cmp(maxPrice) > 0 {
price = new(big.Int).Set(maxPrice)
}
gpo.cacheLock.Lock()
gpo.lastHead = headHash