Skip to content

Commit 978d841

Browse files
committed
rpc: add a rpc.rangelimit flag for limiting block range size for log requests
1 parent 3d2a4cb commit 978d841

File tree

8 files changed

+86
-26
lines changed

8 files changed

+86
-26
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ var (
191191
utils.BatchResponseMaxSize,
192192
utils.RPCTxSyncDefaultTimeoutFlag,
193193
utils.RPCTxSyncMaxTimeoutFlag,
194+
utils.RPCGlobalRangeLimitFlag,
194195
}
195196

196197
metricsFlags = []cli.Flag{

cmd/utils/flags.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,12 @@ var (
631631
Value: ethconfig.Defaults.TxSyncMaxTimeout,
632632
Category: flags.APICategory,
633633
}
634+
RPCGlobalRangeLimitFlag = &cli.Uint64Flag{
635+
Name: "rpc.rangelimit",
636+
Usage: "Maximum block range allowed for range queries (0 = unlimited)",
637+
Value: ethconfig.Defaults.RangeLimit,
638+
Category: flags.APICategory,
639+
}
634640
// Authenticated RPC HTTP settings
635641
AuthListenFlag = &cli.StringFlag{
636642
Name: "authrpc.addr",
@@ -1734,6 +1740,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17341740
if ctx.IsSet(RPCTxSyncMaxTimeoutFlag.Name) {
17351741
cfg.TxSyncMaxTimeout = ctx.Duration(RPCTxSyncMaxTimeoutFlag.Name)
17361742
}
1743+
if ctx.IsSet(RPCGlobalRangeLimitFlag.Name) {
1744+
cfg.RangeLimit = ctx.Uint64(RPCGlobalRangeLimitFlag.Name)
1745+
}
17371746
if !ctx.Bool(SnapshotFlag.Name) || cfg.SnapshotCache == 0 {
17381747
// If snap-sync is requested, this flag is also required
17391748
if cfg.SyncMode == ethconfig.SnapSync {
@@ -2070,6 +2079,7 @@ func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconf
20702079
filterSystem := filters.NewFilterSystem(backend, filters.Config{
20712080
LogCacheSize: ethcfg.FilterLogCacheSize,
20722081
LogQueryLimit: ethcfg.LogQueryLimit,
2082+
RangeLimit: ethcfg.RangeLimit,
20732083
})
20742084
stack.RegisterAPIs([]rpc.API{{
20752085
Namespace: "eth",

eth/ethconfig/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var Defaults = Config{
7272
RPCTxFeeCap: 1, // 1 ether
7373
TxSyncDefaultTimeout: 20 * time.Second,
7474
TxSyncMaxTimeout: 1 * time.Minute,
75+
RangeLimit: 0,
7576
}
7677

7778
//go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go
@@ -189,6 +190,9 @@ type Config struct {
189190
// EIP-7966: eth_sendRawTransactionSync timeouts
190191
TxSyncDefaultTimeout time.Duration `toml:",omitempty"`
191192
TxSyncMaxTimeout time.Duration `toml:",omitempty"`
193+
194+
// RangeLimit restricts the maximum range (end - start) for range queries.
195+
RangeLimit uint64 `toml:",omitempty"`
192196
}
193197

194198
// CreateConsensusEngine creates a consensus engine for the given chain config.

eth/filters/api.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type FilterAPI struct {
7777
filters map[rpc.ID]*filter
7878
timeout time.Duration
7979
logQueryLimit int
80+
rangeLimit uint64
8081
}
8182

8283
// NewFilterAPI returns a new FilterAPI instance.
@@ -87,6 +88,7 @@ func NewFilterAPI(system *FilterSystem) *FilterAPI {
8788
filters: make(map[rpc.ID]*filter),
8889
timeout: system.cfg.Timeout,
8990
logQueryLimit: system.cfg.LogQueryLimit,
91+
rangeLimit: system.cfg.RangeLimit,
9092
}
9193
go api.timeoutLoop(system.cfg.Timeout)
9294

@@ -467,7 +469,7 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*type
467469
return nil, &history.PrunedHistoryError{}
468470
}
469471
// Construct the range filter
470-
filter = api.sys.NewRangeFilter(begin, end, crit.Addresses, crit.Topics)
472+
filter = api.sys.NewRangeFilter(begin, end, crit.Addresses, crit.Topics, api.rangeLimit)
471473
}
472474

473475
// Run the filter and return all the logs
@@ -519,7 +521,7 @@ func (api *FilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*types.Lo
519521
end = f.crit.ToBlock.Int64()
520522
}
521523
// Construct the range filter
522-
filter = api.sys.NewRangeFilter(begin, end, f.crit.Addresses, f.crit.Topics)
524+
filter = api.sys.NewRangeFilter(begin, end, f.crit.Addresses, f.crit.Topics, api.rangeLimit)
523525
}
524526
// Run the filter and return all the logs
525527
logs, err := filter.Logs(ctx)

eth/filters/filter.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package filters
1919
import (
2020
"context"
2121
"errors"
22+
"fmt"
2223
"math"
2324
"math/big"
2425
"slices"
@@ -44,15 +45,17 @@ type Filter struct {
4445
begin, end int64 // Range interval if filtering multiple blocks
4546

4647
rangeLogsTestHook chan rangeLogsTestEvent
48+
rangeLimit uint64
4749
}
4850

4951
// NewRangeFilter creates a new filter which uses a bloom filter on blocks to
5052
// figure out whether a particular block is interesting or not.
51-
func (sys *FilterSystem) NewRangeFilter(begin, end int64, addresses []common.Address, topics [][]common.Hash) *Filter {
53+
func (sys *FilterSystem) NewRangeFilter(begin, end int64, addresses []common.Address, topics [][]common.Hash, rangeLimit uint64) *Filter {
5254
// Create a generic filter and convert it into a range filter
5355
filter := newFilter(sys, addresses, topics)
5456
filter.begin = begin
5557
filter.end = end
58+
filter.rangeLimit = rangeLimit
5659

5760
return filter
5861
}
@@ -143,6 +146,9 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) {
143146
if err != nil {
144147
return nil, err
145148
}
149+
if f.rangeLimit != 0 && (end-begin) > f.rangeLimit {
150+
return nil, fmt.Errorf("exceed maximum block range: %d", f.rangeLimit)
151+
}
146152
return f.rangeLogs(ctx, begin, end)
147153
}
148154

@@ -491,7 +497,7 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) ([]*typ
491497

492498
// filterLogs creates a slice of logs matching the given criteria.
493499
func filterLogs(logs []*types.Log, fromBlock, toBlock *big.Int, addresses []common.Address, topics [][]common.Hash) []*types.Log {
494-
var check = func(log *types.Log) bool {
500+
check := func(log *types.Log) bool {
495501
if fromBlock != nil && fromBlock.Int64() >= 0 && fromBlock.Uint64() > log.BlockNumber {
496502
return false
497503
}

eth/filters/filter_system.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Config struct {
4444
LogCacheSize int // maximum number of cached blocks (default: 32)
4545
Timeout time.Duration // how long filters stay active (default: 5min)
4646
LogQueryLimit int // maximum number of addresses allowed in filter criteria (default: 1000)
47+
RangeLimit uint64 // maximum block range allowed in filter criteria (default: 0)
4748
}
4849

4950
func (cfg Config) withDefaults() Config {

eth/filters/filter_test.go

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func benchmarkFilters(b *testing.B, history uint64, noHistory bool) {
109109
backend.startFilterMaps(history, noHistory, filtermaps.DefaultParams)
110110
defer backend.stopFilterMaps()
111111

112-
filter := sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), []common.Address{addr1, addr2, addr3, addr4}, nil)
112+
filter := sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), []common.Address{addr1, addr2, addr3, addr4}, nil, 0)
113113
for b.Loop() {
114114
filter.begin = 0
115115
logs, _ := filter.Logs(context.Background())
@@ -317,70 +317,70 @@ func testFilters(t *testing.T, history uint64, noHistory bool) {
317317
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0xdefe471992a07a02acdfbe33edaae22fbb86d7d3cec3f1b8e4e77702fb3acc1d","transactionIndex":"0x0","blockHash":"0x7a7556792ca7d37882882e2b001fe14833eaf81c2c7f865c9c771ec37a024f6b","blockTimestamp":"0x1e","logIndex":"0x0","removed":false}]`,
318318
},
319319
{
320-
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), []common.Address{contract}, [][]common.Hash{{hash1, hash2, hash3, hash4}}),
320+
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), []common.Address{contract}, [][]common.Hash{{hash1, hash2, hash3, hash4}}, 0),
321321
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x2","transactionHash":"0xa8028c655b6423204c8edfbc339f57b042d6bec2b6a61145d76b7c08b4cccd42","transactionIndex":"0x0","blockHash":"0x24417bb49ce44cfad65da68f33b510bf2a129c0d89ccf06acb6958b8585ccf34","blockTimestamp":"0x14","logIndex":"0x0","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0xdefe471992a07a02acdfbe33edaae22fbb86d7d3cec3f1b8e4e77702fb3acc1d","transactionIndex":"0x0","blockHash":"0x7a7556792ca7d37882882e2b001fe14833eaf81c2c7f865c9c771ec37a024f6b","blockTimestamp":"0x1e","logIndex":"0x0","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696334"],"data":"0x","blockNumber":"0x3e8","transactionHash":"0x9a87842100a638dfa5da8842b4beda691d2fd77b0c84b57f24ecfa9fb208f747","transactionIndex":"0x0","blockHash":"0xb360bad5265261c075ece02d3bf0e39498a6a76310482cdfd90588748e6c5ee0","blockTimestamp":"0x2710","logIndex":"0x0","removed":false}]`,
322322
},
323323
{
324-
f: sys.NewRangeFilter(900, 999, []common.Address{contract}, [][]common.Hash{{hash3}}),
324+
f: sys.NewRangeFilter(900, 999, []common.Address{contract}, [][]common.Hash{{hash3}}, 0),
325325
},
326326
{
327-
f: sys.NewRangeFilter(990, int64(rpc.LatestBlockNumber), []common.Address{contract2}, [][]common.Hash{{hash3}}),
327+
f: sys.NewRangeFilter(990, int64(rpc.LatestBlockNumber), []common.Address{contract2}, [][]common.Hash{{hash3}}, 0),
328328
want: `[{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696333"],"data":"0x","blockNumber":"0x3e7","transactionHash":"0x53e3675800c6908424b61b35a44e51ca4c73ca603e58a65b32c67968b4f42200","transactionIndex":"0x0","blockHash":"0x2e4620a2b426b0612ec6cad9603f466723edaed87f98c9137405dd4f7a2409ff","blockTimestamp":"0x2706","logIndex":"0x0","removed":false}]`,
329329
},
330330
{
331-
f: sys.NewRangeFilter(1, 10, []common.Address{contract}, [][]common.Hash{{hash2}, {hash1}}),
331+
f: sys.NewRangeFilter(1, 10, []common.Address{contract}, [][]common.Hash{{hash2}, {hash1}}, 0),
332332
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0xdefe471992a07a02acdfbe33edaae22fbb86d7d3cec3f1b8e4e77702fb3acc1d","transactionIndex":"0x0","blockHash":"0x7a7556792ca7d37882882e2b001fe14833eaf81c2c7f865c9c771ec37a024f6b","blockTimestamp":"0x1e","logIndex":"0x0","removed":false}]`,
333333
},
334334
{
335-
f: sys.NewRangeFilter(1, 10, nil, [][]common.Hash{{hash1, hash2}}),
335+
f: sys.NewRangeFilter(1, 10, nil, [][]common.Hash{{hash1, hash2}}, 0),
336336
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x2","transactionHash":"0xa8028c655b6423204c8edfbc339f57b042d6bec2b6a61145d76b7c08b4cccd42","transactionIndex":"0x0","blockHash":"0x24417bb49ce44cfad65da68f33b510bf2a129c0d89ccf06acb6958b8585ccf34","blockTimestamp":"0x14","logIndex":"0x0","removed":false},{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x2","transactionHash":"0xdba3e2ea9a7d690b722d70ee605fd67ba4c00d1d3aecd5cf187a7b92ad8eb3df","transactionIndex":"0x1","blockHash":"0x24417bb49ce44cfad65da68f33b510bf2a129c0d89ccf06acb6958b8585ccf34","blockTimestamp":"0x14","logIndex":"0x1","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0xdefe471992a07a02acdfbe33edaae22fbb86d7d3cec3f1b8e4e77702fb3acc1d","transactionIndex":"0x0","blockHash":"0x7a7556792ca7d37882882e2b001fe14833eaf81c2c7f865c9c771ec37a024f6b","blockTimestamp":"0x1e","logIndex":"0x0","removed":false}]`,
337337
},
338338
{
339-
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), nil, [][]common.Hash{{common.BytesToHash([]byte("fail"))}}),
339+
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), nil, [][]common.Hash{{common.BytesToHash([]byte("fail"))}}, 0),
340340
},
341341
{
342-
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), []common.Address{common.BytesToAddress([]byte("failmenow"))}, nil),
342+
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), []common.Address{common.BytesToAddress([]byte("failmenow"))}, nil, 0),
343343
},
344344
{
345-
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), nil, [][]common.Hash{{common.BytesToHash([]byte("fail"))}, {hash1}}),
345+
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), nil, [][]common.Hash{{common.BytesToHash([]byte("fail"))}, {hash1}}, 0),
346346
},
347347
{
348-
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.LatestBlockNumber), nil, nil),
348+
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.LatestBlockNumber), nil, nil, 0),
349349
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696334"],"data":"0x","blockNumber":"0x3e8","transactionHash":"0x9a87842100a638dfa5da8842b4beda691d2fd77b0c84b57f24ecfa9fb208f747","transactionIndex":"0x0","blockHash":"0xb360bad5265261c075ece02d3bf0e39498a6a76310482cdfd90588748e6c5ee0","blockTimestamp":"0x2710","logIndex":"0x0","removed":false}]`,
350350
},
351351
{
352-
f: sys.NewRangeFilter(int64(rpc.FinalizedBlockNumber), int64(rpc.LatestBlockNumber), nil, nil),
352+
f: sys.NewRangeFilter(int64(rpc.FinalizedBlockNumber), int64(rpc.LatestBlockNumber), nil, nil, 0),
353353
want: `[{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696333"],"data":"0x","blockNumber":"0x3e7","transactionHash":"0x53e3675800c6908424b61b35a44e51ca4c73ca603e58a65b32c67968b4f42200","transactionIndex":"0x0","blockHash":"0x2e4620a2b426b0612ec6cad9603f466723edaed87f98c9137405dd4f7a2409ff","blockTimestamp":"0x2706","logIndex":"0x0","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696334"],"data":"0x","blockNumber":"0x3e8","transactionHash":"0x9a87842100a638dfa5da8842b4beda691d2fd77b0c84b57f24ecfa9fb208f747","transactionIndex":"0x0","blockHash":"0xb360bad5265261c075ece02d3bf0e39498a6a76310482cdfd90588748e6c5ee0","blockTimestamp":"0x2710","logIndex":"0x0","removed":false}]`,
354354
},
355355
{
356-
f: sys.NewRangeFilter(int64(rpc.FinalizedBlockNumber), int64(rpc.FinalizedBlockNumber), nil, nil),
356+
f: sys.NewRangeFilter(int64(rpc.FinalizedBlockNumber), int64(rpc.FinalizedBlockNumber), nil, nil, 0),
357357
want: `[{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696333"],"data":"0x","blockNumber":"0x3e7","transactionHash":"0x53e3675800c6908424b61b35a44e51ca4c73ca603e58a65b32c67968b4f42200","transactionIndex":"0x0","blockHash":"0x2e4620a2b426b0612ec6cad9603f466723edaed87f98c9137405dd4f7a2409ff","blockTimestamp":"0x2706","logIndex":"0x0","removed":false}]`,
358358
},
359359
{
360-
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.FinalizedBlockNumber), nil, nil),
360+
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.FinalizedBlockNumber), nil, nil, 0),
361361
},
362362
{
363-
f: sys.NewRangeFilter(int64(rpc.SafeBlockNumber), int64(rpc.LatestBlockNumber), nil, nil),
363+
f: sys.NewRangeFilter(int64(rpc.SafeBlockNumber), int64(rpc.LatestBlockNumber), nil, nil, 0),
364364
err: "safe header not found",
365365
},
366366
{
367-
f: sys.NewRangeFilter(int64(rpc.SafeBlockNumber), int64(rpc.SafeBlockNumber), nil, nil),
367+
f: sys.NewRangeFilter(int64(rpc.SafeBlockNumber), int64(rpc.SafeBlockNumber), nil, nil, 0),
368368
err: "safe header not found",
369369
},
370370
{
371-
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.SafeBlockNumber), nil, nil),
371+
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.SafeBlockNumber), nil, nil, 0),
372372
err: "safe header not found",
373373
},
374374
{
375-
f: sys.NewRangeFilter(int64(rpc.PendingBlockNumber), int64(rpc.PendingBlockNumber), nil, nil),
375+
f: sys.NewRangeFilter(int64(rpc.PendingBlockNumber), int64(rpc.PendingBlockNumber), nil, nil, 0),
376376
err: errPendingLogsUnsupported.Error(),
377377
},
378378
{
379-
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.PendingBlockNumber), nil, nil),
379+
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.PendingBlockNumber), nil, nil, 0),
380380
err: errPendingLogsUnsupported.Error(),
381381
},
382382
{
383-
f: sys.NewRangeFilter(int64(rpc.PendingBlockNumber), int64(rpc.LatestBlockNumber), nil, nil),
383+
f: sys.NewRangeFilter(int64(rpc.PendingBlockNumber), int64(rpc.LatestBlockNumber), nil, nil, 0),
384384
err: errPendingLogsUnsupported.Error(),
385385
},
386386
} {
@@ -403,7 +403,7 @@ func testFilters(t *testing.T, history uint64, noHistory bool) {
403403
}
404404

405405
t.Run("timeout", func(t *testing.T) {
406-
f := sys.NewRangeFilter(0, rpc.LatestBlockNumber.Int64(), nil, nil)
406+
f := sys.NewRangeFilter(0, rpc.LatestBlockNumber.Int64(), nil, nil, 0)
407407
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(-time.Hour))
408408
defer cancel()
409409
_, err := f.Logs(ctx)
@@ -464,7 +464,7 @@ func TestRangeLogs(t *testing.T) {
464464
newFilter := func(begin, end int64) {
465465
testCase++
466466
event = 0
467-
filter = sys.NewRangeFilter(begin, end, addresses, nil)
467+
filter = sys.NewRangeFilter(begin, end, addresses, nil, 0)
468468
filter.rangeLogsTestHook = make(chan rangeLogsTestEvent)
469469
go func(filter *Filter) {
470470
filter.Logs(context.Background())
@@ -601,3 +601,39 @@ func TestRangeLogs(t *testing.T) {
601601
expEvent(rangeLogsTestReorg, 400, 901)
602602
expEvent(rangeLogsTestDone, 0, 0)
603603
}
604+
605+
func TestRangeLimit(t *testing.T) {
606+
db := rawdb.NewMemoryDatabase()
607+
backend, sys := newTestFilterSystem(db, Config{})
608+
defer db.Close()
609+
610+
gspec := &core.Genesis{
611+
Config: params.TestChainConfig,
612+
Alloc: types.GenesisAlloc{},
613+
BaseFee: big.NewInt(params.InitialBaseFee),
614+
}
615+
_, err := gspec.Commit(db, triedb.NewDatabase(db, nil))
616+
if err != nil {
617+
t.Fatal(err)
618+
}
619+
chain, _ := core.GenerateChain(gspec.Config, gspec.ToBlock(), ethash.NewFaker(), db, 10, func(i int, gen *core.BlockGen) {})
620+
options := core.DefaultConfig().WithStateScheme(rawdb.HashScheme)
621+
options.TxLookupLimit = 0
622+
bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options)
623+
if err != nil {
624+
t.Fatal(err)
625+
}
626+
_, err = bc.InsertChain(chain)
627+
if err != nil {
628+
t.Fatal(err)
629+
}
630+
backend.startFilterMaps(0, false, filtermaps.DefaultParams)
631+
defer backend.stopFilterMaps()
632+
633+
// Set rangeLimit to 5, but request 10 blocks
634+
filter := sys.NewRangeFilter(0, 9, nil, nil, 5)
635+
_, err = filter.Logs(context.Background())
636+
if err == nil || !strings.Contains(err.Error(), "exceed maximum block range") {
637+
t.Fatalf("expected range limit error, got %v", err)
638+
}
639+
}

graphql/graphql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ func (r *Resolver) Logs(ctx context.Context, args struct{ Filter FilterCriteria
14271427
topics = *args.Filter.Topics
14281428
}
14291429
// Construct the range filter
1430-
filter := r.filterSystem.NewRangeFilter(begin, end, addresses, topics)
1430+
filter := r.filterSystem.NewRangeFilter(begin, end, addresses, topics, 0)
14311431
return runFilter(ctx, r, filter)
14321432
}
14331433

0 commit comments

Comments
 (0)