eth/gasprice: sanitize max header and block history (#23886)

Fixes #23452
This commit is contained in:
courtier 2021-11-18 19:20:36 +01:00 committed by GitHub
parent 16341e0563
commit c52def7f11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,8 +87,7 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
if percent < 0 { if percent < 0 {
percent = 0 percent = 0
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent) log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
} } else if percent > 100 {
if percent > 100 {
percent = 100 percent = 100
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent) log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
} }
@ -104,6 +103,16 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
} else if ignorePrice.Int64() > 0 { } else if ignorePrice.Int64() > 0 {
log.Info("Gasprice oracle is ignoring threshold set", "threshold", ignorePrice) log.Info("Gasprice oracle is ignoring threshold set", "threshold", ignorePrice)
} }
maxHeaderHistory := params.MaxHeaderHistory
if maxHeaderHistory < 1 {
maxHeaderHistory = 1
log.Warn("Sanitizing invalid gasprice oracle max header history", "provided", params.MaxHeaderHistory, "updated", maxHeaderHistory)
}
maxBlockHistory := params.MaxBlockHistory
if maxBlockHistory < 1 {
maxBlockHistory = 1
log.Warn("Sanitizing invalid gasprice oracle max block history", "provided", params.MaxBlockHistory, "updated", maxBlockHistory)
}
cache, _ := lru.New(2048) cache, _ := lru.New(2048)
headEvent := make(chan core.ChainHeadEvent, 1) headEvent := make(chan core.ChainHeadEvent, 1)
@ -125,8 +134,8 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
ignorePrice: ignorePrice, ignorePrice: ignorePrice,
checkBlocks: blocks, checkBlocks: blocks,
percentile: percent, percentile: percent,
maxHeaderHistory: params.MaxHeaderHistory, maxHeaderHistory: maxHeaderHistory,
maxBlockHistory: params.MaxBlockHistory, maxBlockHistory: maxBlockHistory,
historyCache: cache, historyCache: cache,
} }
} }