Skip to content

Conversation

@s1na
Copy link
Contributor

@s1na s1na commented Sep 29, 2021

This PR includes Optim2 mentioned here: #23147 (comment)
We want to avoid deriving log fields like tx hash which require reading the block body from disk unless there are actually matching logs in that block.

Not super happy with the implementation. I added a new method to Backend GetLogsFiltered only to avoid breaking other places which use GetLogs like LES. Might re-write if I think of a better solution

// 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 {
func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64, fn func([]*types.Log) []*types.Log) []*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.

Perhaps replace fn with filterFn, and document it.
Also, is it required to be func([]*types.Log) []*types.Log, or could it be simplified (without any meaningful loss of performance) into func(*types.Log) bool ?
If so, I think that would be cleaner.
Then you could also define allLogsFilter := func(*types.Log) bool { return true } , maybe, if that's common. Or, let nil mean "no filter", which IMO is even nicer from api perspective

flatLogs = append(flatLogs, l...)
}
filtered := fn(flatLogs)
if len(filtered) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

This clause can be de-indented, if you check the return-case first.

if len(filtered) == 0{
  return nil
}

@fjl
Copy link
Contributor

fjl commented Oct 11, 2021

We discussed this today. GetLogsFiltered is not a good idea, we should instead add the filter function parameter to GetLogs. Also, GetLogs should take the block number as argument because both of its call sites use it like

GetLogs(..., header.Hash())

@fjl
Copy link
Contributor

fjl commented Oct 11, 2021

WTF

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.

3 participants