-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1993,14 +1993,10 @@ func (bc *BlockChain) recoverAncestors(block *types.Block) (common.Hash, error) | |
} | ||
|
||
// collectLogs collects the logs that were generated or removed during | ||
// the processing of the block that corresponds with the given hash. | ||
// These logs are later announced as deleted or reborn. | ||
func (bc *BlockChain) collectLogs(hash common.Hash, removed bool) []*types.Log { | ||
number := bc.hc.GetBlockNumber(hash) | ||
if number == nil { | ||
return nil | ||
} | ||
receipts := rawdb.ReadReceipts(bc.db, hash, *number, bc.chainConfig) | ||
// 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. No it's not a behavioral change! The previous version used |
||
|
||
var logs []*types.Log | ||
for _, receipt := range receipts { | ||
|
@@ -2147,7 +2143,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { | |
bc.chainSideFeed.Send(ChainSideEvent{Block: oldChain[i]}) | ||
|
||
// Collect deleted logs for notification | ||
if logs := bc.collectLogs(oldChain[i].Hash(), true); len(logs) > 0 { | ||
if logs := bc.collectLogs(oldChain[i], true); len(logs) > 0 { | ||
deletedLogs = append(deletedLogs, logs...) | ||
} | ||
if len(deletedLogs) > 512 { | ||
|
@@ -2162,7 +2158,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { | |
// New logs: | ||
var rebirthLogs []*types.Log | ||
for i := len(newChain) - 1; i >= 1; i-- { | ||
if logs := bc.collectLogs(newChain[i].Hash(), false); len(logs) > 0 { | ||
if logs := bc.collectLogs(newChain[i], false); len(logs) > 0 { | ||
rebirthLogs = append(rebirthLogs, logs...) | ||
} | ||
if len(rebirthLogs) > 512 { | ||
|
@@ -2217,7 +2213,7 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) { | |
bc.writeHeadBlock(head) | ||
|
||
// Emit events | ||
logs := bc.collectLogs(head.Hash(), false) | ||
logs := bc.collectLogs(head, false) | ||
bc.chainFeed.Send(ChainEvent{Block: head, Hash: head.Hash(), Logs: logs}) | ||
if len(logs) > 0 { | ||
bc.logsFeed.Send(logs) | ||
|
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 inGetLogs
.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?