From 8a42644218862a68bd663bfb28a11f239856adfb Mon Sep 17 00:00:00 2001 From: ucwong Date: Sat, 10 Dec 2022 13:25:37 +0800 Subject: [PATCH] pass block into collectLogs --- core/blockchain.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 065cbcbe38..544504c5d6 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1375,6 +1375,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. bc.futureBlocks.Remove(block.Hash()) if status == CanonStatTy { + logs := bc.collectLogs(block, false) bc.chainFeed.Send(ChainEvent{Block: block, Hash: block.Hash(), Logs: logs}) if len(logs) > 0 { bc.logsFeed.Send(logs) @@ -1923,12 +1924,9 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i // 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) +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()) var logs []*types.Log for _, receipt := range receipts { @@ -2068,7 +2066,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 { @@ -2083,7 +2081,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 {