-
Notifications
You must be signed in to change notification settings - Fork 20.3k
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
Conversation
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()) |
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.
This is a behavioural change. How come you are adding this here?
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.
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()) |
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.
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.
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.
The context is filled in, it's just done in AddLog
instead of at the end in GetLogs
.
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.
But in AddLog
blockNumber is not filled?
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.
LGTM
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.
LGTM
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.
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.