@@ -36,6 +36,7 @@ import (
36
36
"github.com/ethereum/go-ethereum/internal/ethapi"
37
37
"github.com/ethereum/go-ethereum/params"
38
38
"github.com/ethereum/go-ethereum/rpc"
39
+ "github.com/ethereum/go-ethereum/triedb"
39
40
)
40
41
41
42
type testBackend struct {
@@ -424,7 +425,7 @@ func TestInvalidLogFilterCreation(t *testing.T) {
424
425
425
426
var (
426
427
db = rawdb .NewMemoryDatabase ()
427
- _ , sys = newTestFilterSystem (db , Config {})
428
+ _ , sys = newTestFilterSystem (db , Config {LogQueryLimit : 1000 })
428
429
api = NewFilterAPI (sys )
429
430
)
430
431
@@ -435,7 +436,7 @@ func TestInvalidLogFilterCreation(t *testing.T) {
435
436
1 : {FromBlock : big .NewInt (rpc .PendingBlockNumber .Int64 ()), ToBlock : big .NewInt (100 )},
436
437
2 : {FromBlock : big .NewInt (rpc .LatestBlockNumber .Int64 ()), ToBlock : big .NewInt (100 )},
437
438
3 : {Topics : [][]common.Hash {{}, {}, {}, {}, {}}},
438
- 4 : {Addresses : make ([]common.Address , maxAddresses + 1 )},
439
+ 4 : {Addresses : make ([]common.Address , api . logQueryLimit + 1 )},
439
440
}
440
441
441
442
for i , test := range testCases {
@@ -455,7 +456,7 @@ func TestInvalidGetLogsRequest(t *testing.T) {
455
456
BaseFee : big .NewInt (params .InitialBaseFee ),
456
457
}
457
458
db , blocks , _ = core .GenerateChainWithGenesis (genesis , ethash .NewFaker (), 10 , func (i int , gen * core.BlockGen ) {})
458
- _ , sys = newTestFilterSystem (db , Config {})
459
+ _ , sys = newTestFilterSystem (db , Config {LogQueryLimit : 10 })
459
460
api = NewFilterAPI (sys )
460
461
blockHash = blocks [0 ].Hash ()
461
462
unknownBlockHash = common .HexToHash ("0x1111111111111111111111111111111111111111111111111111111111111111" )
@@ -500,8 +501,8 @@ func TestInvalidGetLogsRequest(t *testing.T) {
500
501
err : errExceedMaxTopics ,
501
502
},
502
503
{
503
- f : FilterCriteria {BlockHash : & blockHash , Addresses : make ([]common.Address , maxAddresses + 1 )},
504
- err : errExceedMaxAddresses ,
504
+ f : FilterCriteria {BlockHash : & blockHash , Addresses : make ([]common.Address , api . logQueryLimit + 1 )},
505
+ err : errExceedLogQueryLimit ,
505
506
},
506
507
}
507
508
@@ -528,6 +529,92 @@ func TestInvalidGetRangeLogsRequest(t *testing.T) {
528
529
}
529
530
}
530
531
532
+ // TestExceedLogQueryLimit tests getLogs with too many addresses or topics
533
+ func TestExceedLogQueryLimit (t * testing.T ) {
534
+ t .Parallel ()
535
+
536
+ // Test with custom config (LogQueryLimit = 5 for easier testing)
537
+ var (
538
+ db = rawdb .NewMemoryDatabase ()
539
+ backend , sys = newTestFilterSystem (db , Config {LogQueryLimit : 5 })
540
+ api = NewFilterAPI (sys )
541
+ gspec = & core.Genesis {
542
+ Config : params .TestChainConfig ,
543
+ Alloc : types.GenesisAlloc {},
544
+ BaseFee : big .NewInt (params .InitialBaseFee ),
545
+ }
546
+ )
547
+
548
+ _ , err := gspec .Commit (db , triedb .NewDatabase (db , nil ))
549
+ if err != nil {
550
+ t .Fatal (err )
551
+ }
552
+ chain , _ := core .GenerateChain (gspec .Config , gspec .ToBlock (), ethash .NewFaker (), db , 1000 , func (i int , gen * core.BlockGen ) {})
553
+
554
+ options := core .DefaultConfig ().WithStateScheme (rawdb .HashScheme )
555
+ options .TxLookupLimit = 0 // index all txs
556
+ bc , err := core .NewBlockChain (db , gspec , ethash .NewFaker (), options )
557
+ if err != nil {
558
+ t .Fatal (err )
559
+ }
560
+ _ , err = bc .InsertChain (chain [:600 ])
561
+ if err != nil {
562
+ t .Fatal (err )
563
+ }
564
+
565
+ backend .startFilterMaps (200 , false , filtermaps .RangeTestParams )
566
+ defer backend .stopFilterMaps ()
567
+
568
+ addresses := make ([]common.Address , 6 )
569
+ for i := range addresses {
570
+ addresses [i ] = common .HexToAddress ("0x1234567890123456789012345678901234567890" )
571
+ }
572
+
573
+ topics := make ([]common.Hash , 6 )
574
+ for i := range topics {
575
+ topics [i ] = common .HexToHash ("0x123456789012345678901234567890123456789001234567890012345678901234" )
576
+ }
577
+
578
+ // Test that 5 addresses do not result in error
579
+ // Add FromBlock and ToBlock to make it similar to other invalid tests
580
+ if _ , err := api .GetLogs (context .Background (), FilterCriteria {
581
+ FromBlock : big .NewInt (0 ),
582
+ ToBlock : big .NewInt (100 ),
583
+ Addresses : addresses [:5 ],
584
+ }); err != nil {
585
+ t .Errorf ("Expected GetLogs with 5 addresses to return with no error, got: %v" , err )
586
+ }
587
+
588
+ // Test that 6 addresses fails with correct error
589
+ if _ , err := api .GetLogs (context .Background (), FilterCriteria {
590
+ FromBlock : big .NewInt (0 ),
591
+ ToBlock : big .NewInt (100 ),
592
+ Addresses : addresses ,
593
+ }); err != errExceedLogQueryLimit {
594
+ t .Errorf ("Expected GetLogs with 6 addresses to return errExceedLogQueryLimit, got: %v" , err )
595
+ }
596
+
597
+ // Test that 5 topics at one position do not result in error
598
+ if _ , err := api .GetLogs (context .Background (), FilterCriteria {
599
+ FromBlock : big .NewInt (0 ),
600
+ ToBlock : big .NewInt (100 ),
601
+ Addresses : addresses [:1 ],
602
+ Topics : [][]common.Hash {topics [:5 ]},
603
+ }); err != nil {
604
+ t .Errorf ("Expected GetLogs with 5 topics at one position to return with no error, got: %v" , err )
605
+ }
606
+
607
+ // Test that 6 topics at one position fails with correct error
608
+ if _ , err := api .GetLogs (context .Background (), FilterCriteria {
609
+ FromBlock : big .NewInt (0 ),
610
+ ToBlock : big .NewInt (100 ),
611
+ Addresses : addresses [:1 ],
612
+ Topics : [][]common.Hash {topics },
613
+ }); err != errExceedLogQueryLimit {
614
+ t .Errorf ("Expected GetLogs with 6 topics at one position to return errExceedLogQueryLimit, got: %v" , err )
615
+ }
616
+ }
617
+
531
618
// TestLogFilter tests whether log filters match the correct logs that are posted to the event feed.
532
619
func TestLogFilter (t * testing.T ) {
533
620
t .Parallel ()
0 commit comments