aboutsummaryrefslogtreecommitdiffstats
path: root/core/bloombits/matcher.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-09-27 18:14:52 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-09-27 18:14:52 +0800
commit2ab2a9f13116748ca343892f851e3632861c994e (patch)
tree97e5cc5dc3b07dbcdc6a73adfbfb07acf816d35f /core/bloombits/matcher.go
parent860e697b00c25b8f47371f8b8c7342d0230cee84 (diff)
downloaddexon-2ab2a9f13116748ca343892f851e3632861c994e.tar.gz
dexon-2ab2a9f13116748ca343892f851e3632861c994e.tar.zst
dexon-2ab2a9f13116748ca343892f851e3632861c994e.zip
core/bloombits, eth/filters: handle null topics (#15195)
When implementing the new bloombits based filter, I've accidentally broke null topics by removing the special casing of common.Hash{} filter rules, which acted as the wildcard topic until now. This PR fixes the regression, but instead of using the magic hash common.Hash{} as the null wildcard, the PR reworks the code to handle nil topics during parsing, converting a JSON null into nil []common.Hash topic.
Diffstat (limited to 'core/bloombits/matcher.go')
-rw-r--r--core/bloombits/matcher.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/core/bloombits/matcher.go b/core/bloombits/matcher.go
index f3ed405a6..e33de018a 100644
--- a/core/bloombits/matcher.go
+++ b/core/bloombits/matcher.go
@@ -80,7 +80,8 @@ type Matcher struct {
}
// NewMatcher creates a new pipeline for retrieving bloom bit streams and doing
-// address and topic filtering on them.
+// address and topic filtering on them. Setting a filter component to `nil` is
+// allowed and will result in that filter rule being skipped (OR 0x11...1).
func NewMatcher(sectionSize uint64, filters [][][]byte) *Matcher {
// Create the matcher instance
m := &Matcher{
@@ -95,11 +96,22 @@ func NewMatcher(sectionSize uint64, filters [][][]byte) *Matcher {
m.filters = nil
for _, filter := range filters {
+ // Gather the bit indexes of the filter rule, special casing the nil filter
+ if len(filter) == 0 {
+ continue
+ }
bloomBits := make([]bloomIndexes, len(filter))
for i, clause := range filter {
+ if clause == nil {
+ bloomBits = nil
+ break
+ }
bloomBits[i] = calcBloomIndexes(clause)
}
- m.filters = append(m.filters, bloomBits)
+ // Accumulate the filter rules if no nil rule was within
+ if bloomBits != nil {
+ m.filters = append(m.filters, bloomBits)
+ }
}
// For every bit, create a scheduler to load/download the bit vectors
for _, bloomIndexLists := range m.filters {