@@ -24,7 +24,6 @@ import (
2424 "sync/atomic"
2525 "time"
2626
27- "github.com/ethereum/go-ethereum/common"
2827 "github.com/ethereum/go-ethereum/common/bitutil"
2928 "github.com/ethereum/go-ethereum/crypto"
3029)
@@ -68,8 +67,7 @@ type Retrieval struct {
6867type Matcher struct {
6968 sectionSize uint64 // Size of the data batches to filter on
7069
71- addresses []bloomIndexes // Addresses the system is filtering for
72- topics [][]bloomIndexes // Topics the system is filtering for
70+ filters [][]bloomIndexes // Filter the system is matching for
7371 schedulers map [uint ]* scheduler // Retrieval schedulers for loading bloom bits
7472
7573 retrievers chan chan uint // Retriever processes waiting for bit allocations
@@ -82,7 +80,8 @@ type Matcher struct {
8280
8381// NewMatcher creates a new pipeline for retrieving bloom bit streams and doing
8482// address and topic filtering on them.
85- func NewMatcher (sectionSize uint64 , addresses []common.Address , topics [][]common.Hash ) * Matcher {
83+ func NewMatcher (sectionSize uint64 , filters [][][]byte ) * Matcher {
84+ // Create the matcher instance
8685 m := & Matcher {
8786 sectionSize : sectionSize ,
8887 schedulers : make (map [uint ]* scheduler ),
@@ -91,48 +90,25 @@ func NewMatcher(sectionSize uint64, addresses []common.Address, topics [][]commo
9190 retrievals : make (chan chan * Retrieval ),
9291 deliveries : make (chan * Retrieval ),
9392 }
94- m .setAddresses (addresses )
95- m .setTopics (topics )
96- return m
97- }
93+ // Calculate the bloom bit indexes for the groups we're interested in
94+ m .filters = nil
9895
99- // setAddresses configures the matcher to only return logs that are generated
100- // from addresses that are included in the given list.
101- func (m * Matcher ) setAddresses (addresses []common.Address ) {
102- // Calculate the bloom bit indexes for the addresses we're interested in
103- m .addresses = make ([]bloomIndexes , len (addresses ))
104- for i , address := range addresses {
105- m .addresses [i ] = calcBloomIndexes (address .Bytes ())
106- }
107- // For every bit, create a scheduler to load/download the bit vectors
108- for _ , bloomIndexList := range m .addresses {
109- for _ , bloomIndex := range bloomIndexList {
110- m .addScheduler (bloomIndex )
96+ for _ , filter := range filters {
97+ bloomBits := make ([]bloomIndexes , len (filter ))
98+ for i , clause := range filter {
99+ bloomBits [i ] = calcBloomIndexes (clause )
111100 }
112- }
113- }
114-
115- // setTopics configures the matcher to only return logs that have topics matching
116- // the given list.
117- func (m * Matcher ) setTopics (topicsList [][]common.Hash ) {
118- // Calculate the bloom bit indexes for the topics we're interested in
119- m .topics = nil
120-
121- for _ , topics := range topicsList {
122- bloomBits := make ([]bloomIndexes , len (topics ))
123- for i , topic := range topics {
124- bloomBits [i ] = calcBloomIndexes (topic .Bytes ())
125- }
126- m .topics = append (m .topics , bloomBits )
101+ m .filters = append (m .filters , bloomBits )
127102 }
128103 // For every bit, create a scheduler to load/download the bit vectors
129- for _ , bloomIndexLists := range m .topics {
104+ for _ , bloomIndexLists := range m .filters {
130105 for _ , bloomIndexList := range bloomIndexLists {
131106 for _ , bloomIndex := range bloomIndexList {
132107 m .addScheduler (bloomIndex )
133108 }
134109 }
135110 }
111+ return m
136112}
137113
138114// addScheduler adds a bit stream retrieval scheduler for the given bit index if
@@ -250,14 +226,10 @@ func (m *Matcher) run(begin, end uint64, buffer int, session *MatcherSession) ch
250226 }
251227 }()
252228 // Assemble the daisy-chained filtering pipeline
253- blooms := m .topics
254- if len (m .addresses ) > 0 {
255- blooms = append ([][]bloomIndexes {m .addresses }, blooms ... )
256- }
257229 next := source
258230 dist := make (chan * request , buffer )
259231
260- for _ , bloom := range blooms {
232+ for _ , bloom := range m . filters {
261233 next = m .subMatch (next , dist , bloom , session )
262234 }
263235 // Start the request distribution
0 commit comments