core/blockchain: improve cache handling at reorg

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2025-12-19 12:10:50 +01:00
parent 1559979671
commit 31a53d15a7
No known key found for this signature in database
GPG key ID: 0FE274EE8C95166E

View file

@ -2573,6 +2573,8 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Header) error
batch := bc.db.NewBatch() batch := bc.db.NewBatch()
for _, tx := range types.HashDifference(deletedTxs, rebirthTxs) { for _, tx := range types.HashDifference(deletedTxs, rebirthTxs) {
rawdb.DeleteTxLookupEntry(batch, tx) rawdb.DeleteTxLookupEntry(batch, tx)
// Handle cache as well (new ones were added in writeHeadBlock).
bc.txOnChainCache.Remove(tx)
} }
// Delete all hash markers that are not part of the new canonical chain. // Delete all hash markers that are not part of the new canonical chain.
// Because the reorg function does not handle new chain head, all hash // Because the reorg function does not handle new chain head, all hash
@ -2593,7 +2595,6 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Header) error
} }
// Reset the tx lookup cache to clear stale txlookup cache. // Reset the tx lookup cache to clear stale txlookup cache.
bc.txLookupCache.Purge() bc.txLookupCache.Purge()
bc.txOnChainCache.Purge()
// Release the tx-lookup lock after mutation. // Release the tx-lookup lock after mutation.
bc.txLookupLock.Unlock() bc.txLookupLock.Unlock()