Skip to content

Commit af46f3f

Browse files
committed
cache receipts
1 parent 9e3c25a commit af46f3f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

core/blockchain.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,6 +2347,14 @@ func (bc *BlockChain) recoverAncestors(block *types.Block, makeWitness bool) (co
23472347
// collectLogs collects the logs that were generated or removed during the
23482348
// processing of a block. These logs are later announced as deleted or reborn.
23492349
func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log {
2350+
receipts, logs := bc.collectLogsAndReceipts(b, removed)
2351+
_ = receipts // receipts are not used here, but retrieved for efficiency in other callers
2352+
return logs
2353+
}
2354+
2355+
// collectLogsAndReceipts retrieves receipts from the database and returns both receipts and logs.
2356+
// This avoids duplicate database reads when both are needed.
2357+
func (bc *BlockChain) collectLogsAndReceipts(b *types.Block, removed bool) ([]*types.Receipt, []*types.Log) {
23502358
var blobGasPrice *big.Int
23512359
if b.ExcessBlobGas() != nil {
23522360
blobGasPrice = eip4844.CalcBlobFee(bc.chainConfig, b.Header())
@@ -2364,7 +2372,7 @@ func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log {
23642372
logs = append(logs, log)
23652373
}
23662374
}
2367-
return logs
2375+
return receipts, logs
23682376
}
23692377

23702378
// 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) {
25932601
bc.writeHeadBlock(head)
25942602

25952603
// Emit events
2596-
logs := bc.collectLogs(head, false)
2604+
receipts, logs := bc.collectLogsAndReceipts(head, false)
25972605

25982606
bc.chainFeed.Send(ChainEvent{
25992607
Header: head.Header(),
2600-
Receipts: bc.GetReceiptsByHash(head.Hash()),
2608+
Receipts: receipts,
26012609
Transactions: head.Transactions(),
26022610
})
26032611

0 commit comments

Comments
 (0)