Skip to content

Commit

Permalink
fix: block cache pruning
Browse files Browse the repository at this point in the history
Block was never pruned from the `blockDataByNumber` cache.
  • Loading branch information
ptrus committed Dec 27, 2023
1 parent 910cadf commit 66a796d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions indexer/backend_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,20 +427,19 @@ func (cb *cachingBackend) pruneCache(
panic("indexer: cached entry block height != queried height")
}

cb.blockByHashHex.Delete(bd.Block.Hash)
cb.logsByBlockNumber.Delete(bd.Block.Round)

// Note: Load followed by delete is safe since the only routine that
// mutates those caches is the caller.
// Prune transaction cache.
for i := range bd.UniqueTxes {
txHash := bd.UniqueTxes[i].Hash
// Note: Load followed by delete is safe since the only routine that
// mutates those caches is the caller.
if untypedTxEntry, ok := cb.txByHashHex.Load(txHash); ok {
txEntry := untypedTxEntry.(*txCacheEntry)
if txEntry.blockNumber == blockNumber {
cb.txByHashHex.Delete(txHash)
}
}
}
// Prune receipts cache.
for i := range bd.Receipts {
txHash := bd.Receipts[i].TransactionHash
if untypedReceiptEntry, ok := cb.receiptByTxHashHex.Load(txHash); ok {
Expand All @@ -451,6 +450,11 @@ func (cb *cachingBackend) pruneCache(
}
}

// Prune block caches.
cb.blockByHashHex.Delete(bd.Block.Hash)
cb.logsByBlockNumber.Delete(bd.Block.Round)
cb.blockDataByNumber.Delete(blockNumber)

cb.cacheSize--
}

Expand Down

0 comments on commit 66a796d

Please sign in to comment.