-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
all: derive log fields only after filtering #23655
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5a42262
all: filter logs before fetching body
s1na 7c794a6
core/rawdb: minor fix
s1na dd210af
core/rawdb: fix readlogs test
s1na 832d3dd
eth: revert backend GetLogs to baseline
s1na cd1df75
eth,core: code cleanup
s1na e7693f0
accounts,les: minor
s1na File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -716,7 +716,7 @@ func deriveLogFields(receipts []*receiptLogs, hash common.Hash, number uint64, t | |
// 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 { | ||
func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64, fn func([]*types.Log) []*types.Log) []*types.Log { | ||
// Retrieve the flattened receipt slice | ||
data := ReadReceiptsRLP(db, hash, number) | ||
if len(data) == 0 { | ||
|
@@ -727,21 +727,36 @@ func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64) [][]*types.Log { | |
log.Error("Invalid receipt array RLP", "hash", hash, "err", err) | ||
return nil | ||
} | ||
|
||
body := ReadBody(db, hash, number) | ||
if body == nil { | ||
log.Error("Missing body but have receipt", "hash", hash, "number", number) | ||
return nil | ||
} | ||
if err := deriveLogFields(receipts, hash, number, body.Transactions); err != nil { | ||
log.Error("Failed to derive block receipts fields", "hash", hash, "number", number, "err", err) | ||
return nil | ||
} | ||
logs := make([][]*types.Log, len(receipts)) | ||
id := uint(0) | ||
for i, receipt := range receipts { | ||
logs[i] = receipt.Logs | ||
for _, log := range logs[i] { | ||
log.TxIndex = uint(i) | ||
log.Index = id | ||
id++ | ||
} | ||
} | ||
var flatLogs []*types.Log | ||
for _, l := range logs { | ||
flatLogs = append(flatLogs, l...) | ||
} | ||
filtered := fn(flatLogs) | ||
if len(filtered) > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
|
||
body := ReadBody(db, hash, number) | ||
if body == nil { | ||
log.Error("Missing body but have receipt", "hash", hash, "number", number) | ||
return nil | ||
} | ||
for _, log := range filtered { | ||
log.BlockNumber = number | ||
log.BlockHash = hash | ||
log.TxHash = body.Transactions[log.TxIndex].Hash() | ||
} | ||
return filtered | ||
} else { | ||
return []*types.Log{} | ||
} | ||
return logs | ||
} | ||
|
||
// ReadBlock retrieves an entire block corresponding to the hash, assembling it | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Perhaps replace
fn
withfilterFn
, 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) intofunc(*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, letnil
mean "no filter", which IMO is even nicer from api perspective