mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
Merge pull request #911 from gzliudan/improve_fee_history
eth/gasprice: improve function FeeHistory
This commit is contained in:
commit
e258b875d6
2 changed files with 10 additions and 0 deletions
|
|
@ -42,6 +42,8 @@ const (
|
|||
// maxBlockFetchers is the max number of goroutines to spin up to pull blocks
|
||||
// for the fee history calculation (mostly relevant for LES).
|
||||
maxBlockFetchers = 4
|
||||
// maxQueryLimit is the max number of requested percentiles.
|
||||
maxQueryLimit = 100
|
||||
)
|
||||
|
||||
// blockFees represents a single block for processing
|
||||
|
|
@ -221,6 +223,9 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks uint64, unresolvedL
|
|||
if len(rewardPercentiles) != 0 {
|
||||
maxFeeHistory = oracle.maxBlockHistory
|
||||
}
|
||||
if len(rewardPercentiles) > maxQueryLimit {
|
||||
return common.Big0, nil, nil, nil, fmt.Errorf("%w: over the query limit %d", errInvalidPercentile, maxQueryLimit)
|
||||
}
|
||||
if blocks > maxFeeHistory {
|
||||
log.Warn("Sanitizing fee history length", "requested", blocks, "truncated", maxFeeHistory)
|
||||
blocks = maxFeeHistory
|
||||
|
|
|
|||
|
|
@ -83,6 +83,11 @@ func TestFeeHistory(t *testing.T) {
|
|||
if len(ratio) != c.expCount {
|
||||
t.Fatalf("Test case %d: gasUsedRatio array length mismatch, want %d, got %d", i, c.expCount, len(ratio))
|
||||
}
|
||||
for _, ratio := range ratio {
|
||||
if ratio > 1 {
|
||||
t.Fatalf("Test case %d: gasUsedRatio greater than 1, got %f", i, ratio)
|
||||
}
|
||||
}
|
||||
if err != c.expErr && !errors.Is(err, c.expErr) {
|
||||
t.Fatalf("Test case %d: error mismatch, want %v, got %v", i, c.expErr, err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue