Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/bloombits, eth/filters: handle null topics #15195

Merged
merged 4 commits into from Sep 27, 2017

Conversation

karalabe
Copy link
Member

@karalabe karalabe commented Sep 25, 2017

When implementing the new bloombits based filter, I've accidentally broke null topics by removing the special casing of common.Hash{} filter rules (f585f9e#diff-398162818e80393efa0b6f121150278bL205), 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.

Copy link
Contributor

@zsfelfoldi zsfelfoldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

bloomBits[i] = calcBloomIndexes(clause)
}
m.filters = append(m.filters, bloomBits)
// Accumulate the filter rules if no nil rule was within
if bloomBits != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could drop this check if you continue-d the outer loop instead of just break-ing out of the inner loop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like it when multiple nestings are broken out of. Seems a lot harder to follow what's going on, especially since the label can be arbitrarily far away.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of agree with both positions, but in this case personally I think it'd be clearer if it did continue the outer loop; the code is compact, so it's clear what the label is referring to. Alternately, you could refactor the inner loop and append into a separate function.

bloomBits[i] = calcBloomIndexes(clause)
}
m.filters = append(m.filters, bloomBits)
// Accumulate the filter rules if no nil rule was within
if bloomBits != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of agree with both positions, but in this case personally I think it'd be clearer if it did continue the outer loop; the code is compact, so it's clear what the label is referring to. Alternately, you could refactor the inner loop and append into a separate function.

interfaces.go Outdated
@@ -146,7 +146,7 @@ type FilterQuery struct {
// {{}, {B}} matches any topic in first position, B in second position
// {{A}}, {B}} matches topic A in first position, B in second position
// {{A, B}}, {C, D}} matches topic (A OR B) in first position, (C OR D) in second position
Topics [][]common.Hash
Topics [][]*common.Hash
Copy link
Contributor

@fjl fjl Sep 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why this change is needed. The wildcard for a topic is the empty slice as documented just above this line. Since (anything OR XXX) is the same as anything, the new possibility of including a nil hash as a wildcard is useless.

Copy link
Member Author

@karalabe karalabe Sep 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g. [2][2]common.Hash means

[t1 OR t2] AND [t3 or t4]

You can't set t1 or t2 or t3 or t4 to nil, only the entire group.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you mean interpreting the nulls already during parsing and getting rid of them.

@karalabe
Copy link
Member Author

Simplified according to @fjl's request. @Arachnid @fjl @zsfelfoldi PTAL

Copy link
Member

@bas-vk bas-vk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fjl fjl merged commit 2ab2a9f into ethereum:master Sep 27, 2017
vincentserpoul pushed a commit to vincentserpoul/go-ethereum that referenced this pull request Oct 4, 2017
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.
@karalabe karalabe mentioned this pull request Oct 5, 2017
vincentserpoul pushed a commit to vincentserpoul/go-ethereum that referenced this pull request Oct 28, 2017
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.
vincentserpoul pushed a commit to vincentserpoul/go-ethereum that referenced this pull request Nov 22, 2017
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants