Skip to content

fix: add txlookup lock to prevent reorg race and deadlock (ethereum#29343, #34039) - #127

Merged
hmlee-wm merged 2 commits into
devfrom
fix/txlookup-lock-reorg-race
Sep 15, 2026
Merged

hmlee-wm merged 2 commits into
devfrom
fix/txlookup-lock-reorg-race

Conversation

@hmlee-wm

@hmlee-wm hmlee-wm commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Ports ethereum#29343 and ethereum#34039. During reorg, a concurrent GetTransactionLookup() call could read stale DB data between Purge() and the new chain write, caching a wrong block hash/number. Additionally, #29343 introduced txLookupLock without defer, leaving early-error return paths in reorg() unlocked and causing permanent deadlock.

Upstream References

PR Description
#29343 core: add txlookup lock
#34039 core: fix txLookupLock mutex leak on error returns in reorg()

Problem

Race condition (#29343): Purge() was called before writing new chain data. A concurrent RPC call hitting GetTransactionLookup() during this window read stale reorged data from DB and cached it, causing eth_getTransactionReceipt / eth_getTransaction to return wrong block hash and number until node restart.

Deadlock (#34039): reorg() acquired txLookupLock.Lock() but released it only on the happy path. Early returns on errInvalidOldChain / errInvalidNewChain leaked the lock, permanently deadlocking all future transaction lookups and reorg attempts.

Changes

  • core/blockchain.go: add txLookupLock sync.RWMutex to BlockChain; in reorg(), acquire lock before mutation and use defer Unlock() to protect all return paths; move Purge() to after DB writes complete
  • core/blockchain_reader.go: add txLookupLock.RLock() / defer RUnlock() in GetTransactionLookup() to block reads during reorg

rjl493456442 and others added 2 commits September 4, 2026 14:43
This change adds a lock to the transaction lookup cache, to avoid the case where reorgs make the lookup return inconsistent results.

(cherry picked from commit 1126c6d8a57f1b7d9af0b39ac52f6eeb435f66f9)
@hmlee-wm hmlee-wm self-assigned this Sep 4, 2026
@hmlee-wm hmlee-wm added the bug Something isn't working label Sep 4, 2026

@colinkim colinkim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eomti-wm eomti-wm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hmlee-wm
hmlee-wm merged commit 650722d into dev Sep 15, 2026
3 checks passed
@hmlee-wm
hmlee-wm deleted the fix/txlookup-lock-reorg-race branch September 15, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants