eth/gasprice: add query limit for FeeHistory to defend DDOS attack (#29644)
* eth/gasprice: add query limit for FeeHistory to defend DDOS attack * fix return values after cherry-pick --------- Co-authored-by: Eric <45141191+zlacfzy@users.noreply.github.com>
This commit is contained in:
parent
3e896c875a
commit
e4b8058d5a
|
@ -44,6 +44,7 @@ const (
|
||||||
// maxBlockFetchers is the max number of goroutines to spin up to pull blocks
|
// maxBlockFetchers is the max number of goroutines to spin up to pull blocks
|
||||||
// for the fee history calculation (mostly relevant for LES).
|
// for the fee history calculation (mostly relevant for LES).
|
||||||
maxBlockFetchers = 4
|
maxBlockFetchers = 4
|
||||||
|
maxQueryLimit = 100
|
||||||
)
|
)
|
||||||
|
|
||||||
// blockFees represents a single block for processing
|
// blockFees represents a single block for processing
|
||||||
|
@ -240,6 +241,9 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks uint64, unresolvedL
|
||||||
if len(rewardPercentiles) != 0 {
|
if len(rewardPercentiles) != 0 {
|
||||||
maxFeeHistory = oracle.maxBlockHistory
|
maxFeeHistory = oracle.maxBlockHistory
|
||||||
}
|
}
|
||||||
|
if len(rewardPercentiles) > maxQueryLimit {
|
||||||
|
return common.Big0, nil, nil, nil, nil, nil, fmt.Errorf("%w: over the query limit %d", errInvalidPercentile, maxQueryLimit)
|
||||||
|
}
|
||||||
if blocks > maxFeeHistory {
|
if blocks > maxFeeHistory {
|
||||||
log.Warn("Sanitizing fee history length", "requested", blocks, "truncated", maxFeeHistory)
|
log.Warn("Sanitizing fee history length", "requested", blocks, "truncated", maxFeeHistory)
|
||||||
blocks = maxFeeHistory
|
blocks = maxFeeHistory
|
||||||
|
|
Loading…
Reference in New Issue