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,eth: avoid unnecessary receipt processing for log filtering #23058

Closed
wants to merge 5 commits into from

Conversation

s1na
Copy link
Contributor

@s1na s1na commented Jun 16, 2021

When filtering logs, after a matching block has been found a slim version of the receipts is fetched from the database. These slim receipts have to be processed to fill in some metadata. Specifically a bloom filter has to be created which adds some unnecessary overhead because this bloom is not used for filtering purposes.

In this PR we add some new methods that only try to process the underlying logs of a receipt and not much more. Note that this also means we lose the ability to cache the receipts in Blockchain.

In a very simple test (fetching Transfer events of an erc20 token for a few thousand blocks) the runtime went from ~12s to ~7s on my machine.

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

I don't see where you actually make use of this optimization?

core/rawdb/accessors_chain_test.go Outdated Show resolved Hide resolved
core/rawdb/accessors_chain_test.go Outdated Show resolved Hide resolved
logs := make([][]*types.Log, len(receipts))
for i, receipt := range receipts {
logs[i] = receipt.Logs
logs := rawdb.ReadLogs(db, hash, *number)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@holiman Changed the backend's GetLogs here to utilize the new methods. GetLogs is in turn called by Filter.checkMatches

s1na and others added 2 commits June 22, 2021 09:42
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Martin Holst Swende <martin@swende.se>
// ReadLogs retrieves the logs for all transactions in a block. The log fields
// are populated with metadata. In case the receipts or the block body
// are not found, a nil is returned.
func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64) [][]*types.Log {
Copy link
Contributor

Choose a reason for hiding this comment

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

Triage discussion, something like

Suggested change
func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64) [][]*types.Log {
type LogFilterFn func(receipts []*types.ReceiptLogs) bool
func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64, filterFn LogFilterFn) [][]*types.Log {

If the filter function returns false, we can omit the ReadBody and deriving the fields.

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.

2 participants