Skip to content

Commit 66e0efe

Browse files
courtierzzyalbert
authored andcommitted
eth/gasprice: sanitize max header and block history (#23886)
Fixes #23452
1 parent 5f0c85c commit 66e0efe

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

eth/gasprice/gasprice.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
8989
if percent < 0 {
9090
percent = 0
9191
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
92-
}
93-
if percent > 100 {
92+
} else if percent > 100 {
9493
percent = 100
9594
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
9695
}
@@ -106,6 +105,16 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
106105
} else if ignorePrice.Int64() > 0 {
107106
log.Info("Gasprice oracle is ignoring threshold set", "threshold", ignorePrice)
108107
}
108+
maxHeaderHistory := params.MaxHeaderHistory
109+
if maxHeaderHistory < 1 {
110+
maxHeaderHistory = 1
111+
log.Warn("Sanitizing invalid gasprice oracle max header history", "provided", params.MaxHeaderHistory, "updated", maxHeaderHistory)
112+
}
113+
maxBlockHistory := params.MaxBlockHistory
114+
if maxBlockHistory < 1 {
115+
maxBlockHistory = 1
116+
log.Warn("Sanitizing invalid gasprice oracle max block history", "provided", params.MaxBlockHistory, "updated", maxBlockHistory)
117+
}
109118

110119
cache, _ := lru.New(2048)
111120
headEvent := make(chan core.ChainHeadEvent, 1)
@@ -127,8 +136,8 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
127136
ignorePrice: ignorePrice,
128137
checkBlocks: blocks,
129138
percentile: percent,
130-
maxHeaderHistory: params.MaxHeaderHistory,
131-
maxBlockHistory: params.MaxBlockHistory,
139+
maxHeaderHistory: maxHeaderHistory,
140+
maxBlockHistory: maxBlockHistory,
132141
historyCache: cache,
133142
}
134143
}

0 commit comments

Comments
 (0)