Skip to content

Commit c52def7

Browse files
author
courtier
authored
eth/gasprice: sanitize max header and block history (#23886)
Fixes #23452
1 parent 16341e0 commit c52def7

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
@@ -87,8 +87,7 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
8787
if percent < 0 {
8888
percent = 0
8989
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
90-
}
91-
if percent > 100 {
90+
} else if percent > 100 {
9291
percent = 100
9392
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
9493
}
@@ -104,6 +103,16 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
104103
} else if ignorePrice.Int64() > 0 {
105104
log.Info("Gasprice oracle is ignoring threshold set", "threshold", ignorePrice)
106105
}
106+
maxHeaderHistory := params.MaxHeaderHistory
107+
if maxHeaderHistory < 1 {
108+
maxHeaderHistory = 1
109+
log.Warn("Sanitizing invalid gasprice oracle max header history", "provided", params.MaxHeaderHistory, "updated", maxHeaderHistory)
110+
}
111+
maxBlockHistory := params.MaxBlockHistory
112+
if maxBlockHistory < 1 {
113+
maxBlockHistory = 1
114+
log.Warn("Sanitizing invalid gasprice oracle max block history", "provided", params.MaxBlockHistory, "updated", maxBlockHistory)
115+
}
107116

108117
cache, _ := lru.New(2048)
109118
headEvent := make(chan core.ChainHeadEvent, 1)
@@ -125,8 +134,8 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
125134
ignorePrice: ignorePrice,
126135
checkBlocks: blocks,
127136
percentile: percent,
128-
maxHeaderHistory: params.MaxHeaderHistory,
129-
maxBlockHistory: params.MaxBlockHistory,
137+
maxHeaderHistory: maxHeaderHistory,
138+
maxBlockHistory: maxBlockHistory,
130139
historyCache: cache,
131140
}
132141
}

0 commit comments

Comments
 (0)