eth/gasprice: added security checks for gpo params

This commit is contained in:
Zsolt Felfoldi 2017-03-30 14:16:24 +02:00
parent 4e9415637f
commit ab698a5912

View file

@ -48,13 +48,24 @@ type GasPriceOracle struct {
// NewGasPriceOracle returns a new oracle. // NewGasPriceOracle returns a new oracle.
func NewGasPriceOracle(backend ethapi.Backend, params GpoParams) *GasPriceOracle { func NewGasPriceOracle(backend ethapi.Backend, params GpoParams) *GasPriceOracle {
blocks := params.GpoBlocks
if blocks < 1 {
blocks = 1
}
percent := params.GpoPercentile
if percent < 0 {
percent = 0
}
if percent > 100 {
percent = 100
}
return &GasPriceOracle{ return &GasPriceOracle{
backend: backend, backend: backend,
lastPrice: params.GpoDefault, lastPrice: params.GpoDefault,
checkBlocks: params.GpoBlocks, checkBlocks: blocks,
minBlocks: (params.GpoBlocks + 1) / 2, minBlocks: (blocks + 1) / 2,
maxBlocks: params.GpoBlocks * 5, maxBlocks: blocks * 5,
percentile: params.GpoPercentile, percentile: percent,
} }
} }