diff --git a/core/blockchain.go b/core/blockchain.go index dd4ea3fe91..0f1f5d6eea 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2347,6 +2347,14 @@ func (bc *BlockChain) recoverAncestors(block *types.Block, makeWitness bool) (co // collectLogs collects the logs that were generated or removed during 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, logs := bc.collectLogsAndReceipts(b, removed) + _ = receipts // receipts are not used here, but retrieved for efficiency in other callers + return logs +} + +// collectLogsAndReceipts retrieves receipts from the database and returns both receipts and logs. +// This avoids duplicate database reads when both are needed. +func (bc *BlockChain) collectLogsAndReceipts(b *types.Block, removed bool) ([]*types.Receipt, []*types.Log) { var blobGasPrice *big.Int if b.ExcessBlobGas() != nil { blobGasPrice = eip4844.CalcBlobFee(bc.chainConfig, b.Header()) @@ -2364,7 +2372,7 @@ func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log { logs = append(logs, log) } } - return logs + return receipts, logs } // reorg takes two blocks, an old chain and a new chain and will reconstruct the @@ -2593,11 +2601,11 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) { bc.writeHeadBlock(head) // Emit events - logs := bc.collectLogs(head, false) + receipts, logs := bc.collectLogsAndReceipts(head, false) bc.chainFeed.Send(ChainEvent{ Header: head.Header(), - Receipts: bc.GetReceiptsByHash(head.Hash()), + Receipts: receipts, Transactions: head.Transactions(), })