aboutsummaryrefslogtreecommitdiffstats
path: root/eth/filters/filter.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 /eth/filters/filter.go
parent860e697b00c25b8f47371f8b8c7342d0230cee84 (diff)
downloadgo-tangerine-2ab2a9f13116748ca343892f851e3632861c994e.tar
go-tangerine-2ab2a9f13116748ca343892f851e3632861c994e.tar.gz
go-tangerine-2ab2a9f13116748ca343892f851e3632861c994e.tar.bz2
go-tangerine-2ab2a9f13116748ca343892f851e3632861c994e.tar.lz
go-tangerine-2ab2a9f13116748ca343892f851e3632861c994e.tar.xz
go-tangerine-2ab2a9f13116748ca343892f851e3632861c994e.tar.zst
go-tangerine-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 'eth/filters/filter.go')
-rw-r--r--eth/filters/filter.go22
1 files changed, 7 insertions, 15 deletions
diff --git a/eth/filters/filter.go b/eth/filters/filter.go
index 4f6c30058..026cbf95c 100644
--- a/eth/filters/filter.go
+++ b/eth/filters/filter.go
@@ -60,7 +60,9 @@ type Filter struct {
// New creates a new filter which uses a bloom filter on blocks to figure out whether
// a particular block is interesting or not.
func New(backend Backend, begin, end int64, addresses []common.Address, topics [][]common.Hash) *Filter {
- // Flatten the address and topic filter clauses into a single filter system
+ // Flatten the address and topic filter clauses into a single bloombits filter
+ // system. Since the bloombits are not positional, nil topics are permitted,
+ // which get flattened into a nil byte slice.
var filters [][][]byte
if len(addresses) > 0 {
filter := make([][]byte, len(addresses))
@@ -235,32 +237,24 @@ Logs:
if len(addresses) > 0 && !includes(addresses, log.Address) {
continue
}
-
- logTopics := make([]common.Hash, len(topics))
- copy(logTopics, log.Topics)
-
// If the to filtered topics is greater than the amount of topics in logs, skip.
if len(topics) > len(log.Topics) {
continue Logs
}
-
for i, topics := range topics {
- var match bool
+ match := len(topics) == 0 // empty rule set == wildcard
for _, topic := range topics {
- // common.Hash{} is a match all (wildcard)
- if (topic == common.Hash{}) || log.Topics[i] == topic {
+ if log.Topics[i] == topic {
match = true
break
}
}
-
if !match {
continue Logs
}
}
ret = append(ret, log)
}
-
return ret
}
@@ -273,16 +267,15 @@ func bloomFilter(bloom types.Bloom, addresses []common.Address, topics [][]commo
break
}
}
-
if !included {
return false
}
}
for _, sub := range topics {
- var included bool
+ included := len(sub) == 0 // empty rule set == wildcard
for _, topic := range sub {
- if (topic == common.Hash{}) || types.BloomLookup(bloom, topic) {
+ if types.BloomLookup(bloom, topic) {
included = true
break
}
@@ -291,6 +284,5 @@ func bloomFilter(bloom types.Bloom, addresses []common.Address, topics [][]commo
return false
}
}
-
return true
}