From 856d00d308e526a1e57dbf908f7e72663e1b3645 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Thu, 6 Apr 2017 15:51:10 +0200 Subject: [PATCH] eth/gasprice: max limit, maxEmpty --- cmd/utils/flags.go | 2 +- eth/gasprice/gasprice.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index f0e80fd10d..c2aa3c5fa1 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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", diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index 3cf2146c20..bac048c88a 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -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,8 +45,8 @@ type Oracle struct { cacheLock sync.RWMutex fetchLock sync.Mutex - checkBlocks, minBlocks, maxBlocks int - percentile int + checkBlocks, maxEmpty, maxBlocks int + percentile int } // NewOracle returns a new oracle. @@ -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