-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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
Conversation
There was a problem hiding this 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?
logs := make([][]*types.Log, len(receipts)) | ||
for i, receipt := range receipts { | ||
logs[i] = receipt.Logs | ||
logs := rawdb.ReadLogs(db, hash, *number) |
There was a problem hiding this comment.
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
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Triage discussion, something like
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.
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.