@@ -63,9 +63,9 @@ func BenchmarkFilters(b *testing.B) {
6363 addr4 = common .BytesToAddress ([]byte ("random addresses please" ))
6464
6565 gspec = & core.Genesis {
66- Config : params .TestChainConfig ,
6766 Alloc : core.GenesisAlloc {addr1 : {Balance : big .NewInt (1000000 )}},
6867 BaseFee : big .NewInt (1 ),
68+ Config : params .TestChainConfig ,
6969 }
7070 )
7171 defer db .Close ()
@@ -94,6 +94,7 @@ func BenchmarkFilters(b *testing.B) {
9494 // and then import blocks. TODO(rjl493456442) try to get rid of the
9595 // manual database writes.
9696 gspec .MustCommit (db )
97+
9798 for i , block := range chain {
9899 rawdb .WriteBlock (db , block )
99100 rawdb .WriteCanonicalHash (db , block .Hash (), block .NumberU64 ())
@@ -102,8 +103,7 @@ func BenchmarkFilters(b *testing.B) {
102103 }
103104 b .ResetTimer ()
104105
105- filter , err := sys .NewRangeFilter (0 , int64 (rpc .LatestBlockNumber ), []common.Address {addr1 , addr2 , addr3 , addr4 }, nil )
106- require .NoError (b , err )
106+ filter := sys .NewRangeFilter (0 , int64 (rpc .LatestBlockNumber ), []common.Address {addr1 , addr2 , addr3 , addr4 }, nil )
107107
108108 for i := 0 ; i < b .N ; i ++ {
109109 filter .begin = 0
@@ -191,8 +191,12 @@ func TestFilters(t *testing.T) {
191191 rawdb .WriteReceipts (db , block .Hash (), block .NumberU64 (), receipts [i ])
192192 }
193193
194- filter , err := sys .NewRangeFilter (0 , int64 (rpc .LatestBlockNumber ), []common.Address {addr }, [][]common.Hash {{hash1 , hash2 , hash3 , hash4 }})
194+ // Set block 998 as Finalized (-3)
195+ // rawdb.WriteFinalizedBlockHash(db, chain[998].Hash())
196+ err = rawdb .WriteAcceptorTip (db , chain [998 ].Hash ())
195197 require .NoError (t , err )
198+
199+ filter := sys .NewRangeFilter (0 , int64 (rpc .LatestBlockNumber ), []common.Address {addr }, [][]common.Hash {{hash1 , hash2 , hash3 , hash4 }})
196200 logs , _ := filter .Logs (context .Background ())
197201 if len (logs ) != 4 {
198202 t .Error ("expected 4 log, got" , len (logs ))
@@ -203,46 +207,39 @@ func TestFilters(t *testing.T) {
203207 wantHashes []common.Hash
204208 }{
205209 {
206- mustNewRangeFilter ( t , sys , 900 , 999 , []common.Address {addr }, [][]common.Hash {{hash3 }}),
210+ sys . NewRangeFilter ( 900 , 999 , []common.Address {addr }, [][]common.Hash {{hash3 }}),
207211 []common.Hash {hash3 },
208212 }, {
209- mustNewRangeFilter ( t , sys , 990 , int64 (rpc .LatestBlockNumber ), []common.Address {addr }, [][]common.Hash {{hash3 }}),
213+ sys . NewRangeFilter ( 990 , int64 (rpc .LatestBlockNumber ), []common.Address {addr }, [][]common.Hash {{hash3 }}),
210214 []common.Hash {hash3 },
211215 }, {
212- mustNewRangeFilter ( t , sys , 1 , 10 , nil , [][]common.Hash {{hash1 , hash2 }}),
216+ sys . NewRangeFilter ( 1 , 10 , nil , [][]common.Hash {{hash1 , hash2 }}),
213217 []common.Hash {hash1 , hash2 },
214218 }, {
215- mustNewRangeFilter ( t , sys , 0 , int64 (rpc .LatestBlockNumber ), nil , [][]common.Hash {{common .BytesToHash ([]byte ("fail" ))}}),
219+ sys . NewRangeFilter ( 0 , int64 (rpc .LatestBlockNumber ), nil , [][]common.Hash {{common .BytesToHash ([]byte ("fail" ))}}),
216220 nil ,
217221 }, {
218- mustNewRangeFilter ( t , sys , 0 , int64 (rpc .LatestBlockNumber ), []common.Address {common .BytesToAddress ([]byte ("failmenow" ))}, nil ),
222+ sys . NewRangeFilter ( 0 , int64 (rpc .LatestBlockNumber ), []common.Address {common .BytesToAddress ([]byte ("failmenow" ))}, nil ),
219223 nil ,
220224 }, {
221- mustNewRangeFilter ( t , sys , 0 , int64 (rpc .LatestBlockNumber ), nil , [][]common.Hash {{common .BytesToHash ([]byte ("fail" ))}, {hash1 }}),
225+ sys . NewRangeFilter ( 0 , int64 (rpc .LatestBlockNumber ), nil , [][]common.Hash {{common .BytesToHash ([]byte ("fail" ))}, {hash1 }}),
222226 nil ,
223227 }, {
224- mustNewRangeFilter ( t , sys , int64 (rpc .LatestBlockNumber ), int64 (rpc .LatestBlockNumber ), nil , nil ), []common.Hash {hash4 },
228+ sys . NewRangeFilter ( int64 (rpc .LatestBlockNumber ), int64 (rpc .LatestBlockNumber ), nil , nil ), []common.Hash {hash4 },
225229 }, {
226- // Note: modified from go-ethereum since we don't have FinalizedBlock
227- mustNewRangeFilter (t , sys , int64 (rpc .AcceptedBlockNumber ), int64 (rpc .LatestBlockNumber ), nil , nil ), []common.Hash {hash4 },
230+ sys .NewRangeFilter (int64 (rpc .FinalizedBlockNumber ), int64 (rpc .LatestBlockNumber ), nil , nil ), []common.Hash {hash3 , hash4 },
228231 }, {
229- // Note: modified from go-ethereum since we don't have FinalizedBlock
230- mustNewRangeFilter (t , sys , int64 (rpc .AcceptedBlockNumber ), int64 (rpc .AcceptedBlockNumber ), nil , nil ), []common.Hash {hash4 },
232+ sys .NewRangeFilter (int64 (rpc .FinalizedBlockNumber ), int64 (rpc .FinalizedBlockNumber ), nil , nil ), []common.Hash {hash3 },
231233 }, {
232- // Note: modified from go-ethereum since we don't have FinalizedBlock
233- mustNewRangeFilter (t , sys , int64 (rpc .LatestBlockNumber ), - 3 , nil , nil ), []common.Hash {hash4 },
234+ sys .NewRangeFilter (int64 (rpc .LatestBlockNumber ), int64 (rpc .FinalizedBlockNumber ), nil , nil ), nil ,
234235 }, {
235- // Note: modified from go-ethereum since we don't have SafeBlock
236- mustNewRangeFilter (t , sys , int64 (rpc .AcceptedBlockNumber ), int64 (rpc .LatestBlockNumber ), nil , nil ), []common.Hash {hash4 },
236+ sys .NewRangeFilter (int64 (rpc .SafeBlockNumber ), int64 (rpc .LatestBlockNumber ), nil , nil ), nil ,
237237 }, {
238- // Note: modified from go-ethereum since we don't have SafeBlock
239- mustNewRangeFilter (t , sys , int64 (rpc .AcceptedBlockNumber ), int64 (rpc .AcceptedBlockNumber ), nil , nil ), []common.Hash {hash4 },
238+ sys .NewRangeFilter (int64 (rpc .SafeBlockNumber ), int64 (rpc .SafeBlockNumber ), nil , nil ), nil ,
240239 }, {
241- // Note: modified from go-ethereum since we don't have SafeBlock
242- mustNewRangeFilter (t , sys , int64 (rpc .LatestBlockNumber ), int64 (rpc .AcceptedBlockNumber ), nil , nil ), []common.Hash {hash4 },
243- },
244- {
245- mustNewRangeFilter (t , sys , int64 (rpc .PendingBlockNumber ), int64 (rpc .PendingBlockNumber ), nil , nil ), nil ,
240+ sys .NewRangeFilter (int64 (rpc .LatestBlockNumber ), int64 (rpc .SafeBlockNumber ), nil , nil ), nil ,
241+ }, {
242+ sys .NewRangeFilter (int64 (rpc .PendingBlockNumber ), int64 (rpc .PendingBlockNumber ), nil , nil ), nil ,
246243 },
247244 } {
248245 logs , _ := tc .f .Logs (context .Background ())
@@ -261,10 +258,3 @@ func TestFilters(t *testing.T) {
261258 }
262259 }
263260}
264-
265- func mustNewRangeFilter (t * testing.T , sys * FilterSystem , begin , end int64 , addresses []common.Address , topics [][]common.Hash ) * Filter {
266- t .Helper ()
267- f , err := sys .NewRangeFilter (begin , end , addresses , topics )
268- require .NoError (t , err )
269- return f
270- }
0 commit comments