mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
cache receipts
This commit is contained in:
parent
9e3c25a676
commit
af46f3f544
1 changed files with 11 additions and 3 deletions
|
|
@ -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
|
// collectLogs collects the logs that were generated or removed during the
|
||||||
// processing of a block. These logs are later announced as deleted or reborn.
|
// processing of a block. These logs are later announced as deleted or reborn.
|
||||||
func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log {
|
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
|
var blobGasPrice *big.Int
|
||||||
if b.ExcessBlobGas() != nil {
|
if b.ExcessBlobGas() != nil {
|
||||||
blobGasPrice = eip4844.CalcBlobFee(bc.chainConfig, b.Header())
|
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)
|
logs = append(logs, log)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return logs
|
return receipts, logs
|
||||||
}
|
}
|
||||||
|
|
||||||
// reorg takes two blocks, an old chain and a new chain and will reconstruct the
|
// 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)
|
bc.writeHeadBlock(head)
|
||||||
|
|
||||||
// Emit events
|
// Emit events
|
||||||
logs := bc.collectLogs(head, false)
|
receipts, logs := bc.collectLogsAndReceipts(head, false)
|
||||||
|
|
||||||
bc.chainFeed.Send(ChainEvent{
|
bc.chainFeed.Send(ChainEvent{
|
||||||
Header: head.Header(),
|
Header: head.Header(),
|
||||||
Receipts: bc.GetReceiptsByHash(head.Hash()),
|
Receipts: receipts,
|
||||||
Transactions: head.Transactions(),
|
Transactions: head.Transactions(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue