mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
eth/gasprice: added security checks for gpo params
This commit is contained in:
parent
4e9415637f
commit
ab698a5912
1 changed files with 15 additions and 4 deletions
|
|
@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue