Skip to content

Commit

Permalink
eth/gasprice: sanitize max header and block history (#23886)
Browse files Browse the repository at this point in the history
Fixes #23452
  • Loading branch information
courtier committed Nov 18, 2021
1 parent 16341e0 commit c52def7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
if percent < 0 {
percent = 0
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
}
if percent > 100 {
} else if percent > 100 {
percent = 100
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
}
Expand All @@ -104,6 +103,16 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
} else if ignorePrice.Int64() > 0 {
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)
headEvent := make(chan core.ChainHeadEvent, 1)
Expand All @@ -125,8 +134,8 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
ignorePrice: ignorePrice,
checkBlocks: blocks,
percentile: percent,
maxHeaderHistory: params.MaxHeaderHistory,
maxBlockHistory: params.MaxBlockHistory,
maxHeaderHistory: maxHeaderHistory,
maxBlockHistory: maxBlockHistory,
historyCache: cache,
}
}
Expand Down

0 comments on commit c52def7

Please sign in to comment.