core: fix txLookupLock mutex leak on error returns in reorg()

txLookupLock.Lock() was acquired without a matching defer, so any of the
multiple early error returns inside reorg() left the mutex permanently
locked. Subsequent reorgs or transaction lookups would deadlock.

Replace the manual Unlock() at the happy-path exit with a deferred call
placed immediately after Lock(), so all return paths release the lock.
This commit is contained in:
Mayveskii 2026-03-18 02:40:54 +03:00
parent ab357151da
commit 855cf6bb96

View file

@ -2628,6 +2628,7 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Header) error
// as the txlookups should be changed atomically, and all subsequent
// reads should be blocked until the mutation is complete.
bc.txLookupLock.Lock()
defer bc.txLookupLock.Unlock()
// Reorg can be executed, start reducing the chain's old blocks and appending
// the new blocks
@ -2730,9 +2731,6 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Header) error
// Reset the tx lookup cache to clear stale txlookup cache.
bc.txLookupCache.Purge()
// Release the tx-lookup lock after mutation.
bc.txLookupLock.Unlock()
return nil
}