Skip to content

Commit e258b87

Browse files
authored
Merge pull request #911 from gzliudan/improve_fee_history
eth/gasprice: improve function FeeHistory
2 parents bdd7cf1 + 5ef815a commit e258b87

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

eth/gasprice/feehistory.go

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const (
4242
// maxBlockFetchers is the max number of goroutines to spin up to pull blocks
4343
// for the fee history calculation (mostly relevant for LES).
4444
maxBlockFetchers = 4
45+
// maxQueryLimit is the max number of requested percentiles.
46+
maxQueryLimit = 100
4547
)
4648

4749
// blockFees represents a single block for processing
@@ -221,6 +223,9 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks uint64, unresolvedL
221223
if len(rewardPercentiles) != 0 {
222224
maxFeeHistory = oracle.maxBlockHistory
223225
}
226+
if len(rewardPercentiles) > maxQueryLimit {
227+
return common.Big0, nil, nil, nil, fmt.Errorf("%w: over the query limit %d", errInvalidPercentile, maxQueryLimit)
228+
}
224229
if blocks > maxFeeHistory {
225230
log.Warn("Sanitizing fee history length", "requested", blocks, "truncated", maxFeeHistory)
226231
blocks = maxFeeHistory

eth/gasprice/feehistory_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ func TestFeeHistory(t *testing.T) {
8383
if len(ratio) != c.expCount {
8484
t.Fatalf("Test case %d: gasUsedRatio array length mismatch, want %d, got %d", i, c.expCount, len(ratio))
8585
}
86+
for _, ratio := range ratio {
87+
if ratio > 1 {
88+
t.Fatalf("Test case %d: gasUsedRatio greater than 1, got %f", i, ratio)
89+
}
90+
}
8691
if err != c.expErr && !errors.Is(err, c.expErr) {
8792
t.Fatalf("Test case %d: error mismatch, want %v, got %v", i, c.expErr, err)
8893
}

0 commit comments

Comments
 (0)