@@ -2188,6 +2188,12 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error {
2188
2188
// rewind the canonical chain to a lower point.
2189
2189
log .Error ("Impossible reorg, please file an issue" , "oldnum" , oldBlock .Number (), "oldhash" , oldBlock .Hash (), "oldblocks" , len (oldChain ), "newnum" , newBlock .Number (), "newhash" , newBlock .Hash (), "newblocks" , len (newChain ))
2190
2190
}
2191
+ // Reset the tx lookup cache in case to clear stale txlookups.
2192
+ // This is done before writing any new chain data to avoid the
2193
+ // weird scenario that canonical chain is changed while the
2194
+ // stale lookups are still cached.
2195
+ bc .txLookupCache .Purge ()
2196
+
2191
2197
// Insert the new chain(except the head block(reverse order)),
2192
2198
// taking care of the proper incremental order.
2193
2199
for i := len (newChain ) - 1 ; i >= 1 ; i -- {
@@ -2202,11 +2208,13 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error {
2202
2208
2203
2209
// Delete useless indexes right now which includes the non-canonical
2204
2210
// transaction indexes, canonical chain indexes which above the head.
2205
- indexesBatch := bc .db .NewBatch ()
2206
- for _ , tx := range types .HashDifference (deletedTxs , addedTxs ) {
2211
+ var (
2212
+ indexesBatch = bc .db .NewBatch ()
2213
+ diffs = types .HashDifference (deletedTxs , addedTxs )
2214
+ )
2215
+ for _ , tx := range diffs {
2207
2216
rawdb .DeleteTxLookupEntry (indexesBatch , tx )
2208
2217
}
2209
-
2210
2218
// Delete all hash markers that are not part of the new canonical chain.
2211
2219
// Because the reorg function does not handle new chain head, all hash
2212
2220
// markers greater than or equal to new chain head should be deleted.
0 commit comments