ReorgDetector
interface ReorgDetector
Detects and handles blockchain reorganizations (reorgs).
What is a Reorg? When two competing blocks are mined at same height, blockchain temporarily forks. Eventually one fork becomes canonical, invalidating events in the other fork.
Example:
Before Reorg:
... → Block 100 → Block 101A → Block 102A
After Reorg (longer chain found):
... → Block 100 → Block 101B → Block 102B → Block 103B
Events in 101A and 102A are now INVALID and must be discarded.Content copied to clipboard
Why This Matters:
Without reorg handling, wallet shows incorrect balance
User may spend funds they don't actually have
Double-spend attacks possible
Detection Strategy:
Track latest block hash we've seen
When new block arrives, verify parent hash matches our latest
If mismatch, reorg detected at that height
Roll back to last common ancestor
Re-sync from that point forward