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: pass block into collectLogs #26335

Merged
merged 4 commits into from
Dec 9, 2022
Merged

Conversation

fjl
Copy link
Contributor

@fjl fjl commented Dec 8, 2022

While investigating another issue, I found that all callers of collectLogs have the complete block available.
There is no need to read it back from the database.

@fjl fjl changed the title core: pass block number into collectLogs core: pass block into collectLogs Dec 8, 2022
@s1na
Copy link
Contributor

s1na commented Dec 8, 2022

Note: we can use the ReadLogs method after #25199 is merged.

// the processing of a block. These logs are later announced as deleted or reborn.
func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log {
receipts := rawdb.ReadRawReceipts(bc.db, b.Hash(), b.NumberU64())
receipts.DeriveFields(bc.chainConfig, b.Hash(), b.NumberU64(), b.Transactions())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a behavioural change. How come you are adding this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it's not a behavioral change! The previous version used ReadReceipts, which calls DeriveFields internally after loading the block from disk. My change is to avoid loading the block since we already have it in memory here.

// the processing of a block. These logs are later announced as deleted or reborn.
func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log {
receipts := rawdb.ReadRawReceipts(bc.db, b.Hash(), b.NumberU64())
receipts.DeriveFields(bc.chainConfig, b.Hash(), b.NumberU64(), b.Transactions())
Copy link
Member

Choose a reason for hiding this comment

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

Good catch.

Btw, in normal block execution, the extra fields are not filled properly for the generated logs https://github.com/ethereum/go-ethereum/blob/master/core/state/statedb.go#L209

Specifically, the blockNumber is not filled. I think we should fix it, make sure everything is aligned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The context is filled in, it's just done in AddLog instead of at the end in GetLogs.

Copy link
Member

Choose a reason for hiding this comment

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

But in AddLog blockNumber is not filled?

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.

LGTM

Copy link
Contributor

@s1na s1na left a comment

Choose a reason for hiding this comment

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

LGTM

@fjl fjl added this to the 1.11.0 milestone Dec 9, 2022
@fjl fjl merged commit 3315bad into ethereum:master Dec 9, 2022
shekhirin pushed a commit to shekhirin/go-ethereum that referenced this pull request Jun 6, 2023
While investigating another issue, I found that all callers of collectLogs have the
complete block available. rawdb.ReadReceipts loads the block from the database,
so it is better to use ReadRawReceipts here, and derive the receipt information using
the block which is already in memory.
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.

4 participants