Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Apply the bloom filter when query the ethlogs with range of blocks #570

Closed
wants to merge 2 commits into from

Conversation

JayT106
Copy link
Contributor

@JayT106 JayT106 commented Sep 17, 2021

Closes: #303

Description

This PR revised the implementation in the filter, uses Bloom index&value sets instead of bloombits.Matcher which doesn't have the bloom indexer DB implementation in the Ethermint project.

Therefore, eth_getLogs can skip extra data check overhead by only checking the bloom of the block header, and then returns the transaction logs that fit the query criteria.


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@orijbot
Copy link

orijbot commented Sep 17, 2021

@github-actions github-actions bot added C:JSON-RPC JSON-RPC client Type: Tests issues and PR related to tests labels Sep 17, 2021
@JayT106
Copy link
Contributor Author

JayT106 commented Sep 17, 2021

also ref: #563

@JayT106
Copy link
Contributor Author

JayT106 commented Sep 17, 2021

Will extend the test cases to enlarge the coverage.

@JayT106 JayT106 changed the title Apply the bloom filter when query the ethlogs with a range of blocks Apply the bloom filter when query the ethlogs with range of blocks Sep 20, 2021
Comment on lines +768 to +779
// checkMatches revised the function from
// https://github.com/ethereum/go-ethereum/blob/401354976bb44f0ad4455ca1e0b5c0dc31d9a5f5/core/types/bloom9.go#L88
func checkMatches(bloom ethtypes.Bloom, filter []filters.BloomIV) bool {
for _, bloomIV := range filter {
if bloomIV.V[0] == bloomIV.V[0]&bloom[bloomIV.I[0]] &&
bloomIV.V[1] == bloomIV.V[1]&bloom[bloomIV.I[1]] &&
bloomIV.V[2] == bloomIV.V[2]&bloom[bloomIV.I[2]] {
return true
}
}
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use the BloomLookup func instead?

Copy link
Contributor Author

@JayT106 JayT106 Sep 22, 2021

Choose a reason for hiding this comment

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

The reason I didn't use BloomLookup is trying to avoid the calculation in https://github.com/ethereum/go-ethereum/blob/401354976bb44f0ad4455ca1e0b5c0dc31d9a5f5/core/types/bloom9.go#L139
If we use it, the bloom for the addresses and the topics in the filter will be calculated against every block.

Also this PR I can put the one-time bloom calculation when the RPC layer creates the filter.

@JayT106
Copy link
Contributor Author

JayT106 commented Sep 22, 2021

close this PR and open it in #587

@fedekunze fedekunze deleted the getLog-withBloomFilter branch September 23, 2021 09:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C:JSON-RPC JSON-RPC client Type: Tests issues and PR related to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize eth_getLogs efficiency
3 participants