Skip to content

Commit 3315bad

Browse files
authored
core: pass block into collectLogs (#26335)
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.
1 parent 711afbc commit 3315bad

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

core/blockchain.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,14 +1996,10 @@ func (bc *BlockChain) recoverAncestors(block *types.Block) (common.Hash, error)
19961996
}
19971997

19981998
// collectLogs collects the logs that were generated or removed during
1999-
// the processing of the block that corresponds with the given hash.
2000-
// These logs are later announced as deleted or reborn.
2001-
func (bc *BlockChain) collectLogs(hash common.Hash, removed bool) []*types.Log {
2002-
number := bc.hc.GetBlockNumber(hash)
2003-
if number == nil {
2004-
return nil
2005-
}
2006-
receipts := rawdb.ReadReceipts(bc.db, hash, *number, bc.chainConfig)
1999+
// the processing of a block. These logs are later announced as deleted or reborn.
2000+
func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log {
2001+
receipts := rawdb.ReadRawReceipts(bc.db, b.Hash(), b.NumberU64())
2002+
receipts.DeriveFields(bc.chainConfig, b.Hash(), b.NumberU64(), b.Transactions())
20072003

20082004
var logs []*types.Log
20092005
for _, receipt := range receipts {
@@ -2150,7 +2146,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
21502146
bc.chainSideFeed.Send(ChainSideEvent{Block: oldChain[i]})
21512147

21522148
// Collect deleted logs for notification
2153-
if logs := bc.collectLogs(oldChain[i].Hash(), true); len(logs) > 0 {
2149+
if logs := bc.collectLogs(oldChain[i], true); len(logs) > 0 {
21542150
deletedLogs = append(deletedLogs, logs...)
21552151
}
21562152
if len(deletedLogs) > 512 {
@@ -2165,7 +2161,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
21652161
// New logs:
21662162
var rebirthLogs []*types.Log
21672163
for i := len(newChain) - 1; i >= 1; i-- {
2168-
if logs := bc.collectLogs(newChain[i].Hash(), false); len(logs) > 0 {
2164+
if logs := bc.collectLogs(newChain[i], false); len(logs) > 0 {
21692165
rebirthLogs = append(rebirthLogs, logs...)
21702166
}
21712167
if len(rebirthLogs) > 512 {
@@ -2220,7 +2216,7 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) {
22202216
bc.writeHeadBlock(head)
22212217

22222218
// Emit events
2223-
logs := bc.collectLogs(head.Hash(), false)
2219+
logs := bc.collectLogs(head, false)
22242220
bc.chainFeed.Send(ChainEvent{Block: head, Hash: head.Hash(), Logs: logs})
22252221
if len(logs) > 0 {
22262222
bc.logsFeed.Send(logs)

0 commit comments

Comments
 (0)