Skip to content

Commit ebd2cd2

Browse files
committed
ethrpc: add 10k block hard limit for auto-split FilterLogs
Reject requests with a total block range exceeding 10,000 when auto-split is enabled, to prevent hammering nodes with hundreds of sub-queries. Only applies when the feature is opted into — disabled mode is a direct pass-through as before.
1 parent 223520c commit ebd2cd2

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

ethrpc/filter_logs.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ethrpc
22

33
import (
44
"context"
5+
"fmt"
56
"math"
67
"math/big"
78
"strings"
@@ -10,6 +11,12 @@ import (
1011
"github.com/0xsequence/ethkit/go-ethereum/core/types"
1112
)
1213

14+
// maxFilterLogsBlockRange is the hard upper limit on the total block range that
15+
// filterLogsAutoSplit will process. This prevents callers from accidentally
16+
// issuing hundreds of sub-queries for unreasonably large ranges (e.g. 0 to 1M).
17+
// Callers needing larger ranges should paginate at the application level.
18+
const maxFilterLogsBlockRange = uint64(10_000)
19+
1320
// filterLogs executes a standard eth_getLogs JSON-RPC call for the given query.
1421
func (p *Provider) filterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) {
1522
var logs []types.Log
@@ -42,6 +49,12 @@ func (p *Provider) filterLogsAutoSplit(ctx context.Context, q ethereum.FilterQue
4249
}
4350

4451
totalRange := to - from
52+
53+
// Safety limit: reject unreasonably large ranges to prevent hammering the node
54+
// with hundreds of sub-queries. Callers should paginate at the application level.
55+
if totalRange > maxFilterLogsBlockRange {
56+
return nil, fmt.Errorf("ethrpc: FilterLogs block range of %d exceeds maximum of %d", totalRange, maxFilterLogsBlockRange)
57+
}
4558
batchRange := p.effectiveFilterLogsBatchRange(totalRange)
4659

4760
// Additive factor: 10% of the starting batch range, minimum 1

0 commit comments

Comments
 (0)