Emit Confirmed Chain Events Exactly Once Under Reorgs
Last updated: November 29, 2026
Quick Overview
Implement a tracker that consumes block headers (hash, parent, height, events) possibly out of order and across forks, follows the heaviest-height canonical chain, and emits each block's events exactly once when it is k blocks deep, raising if a reorg deeper than k is observed.
Circle
November 29, 20260
0
0 solved
Implement a tracker that consumes block headers (hash, parent, height, events) possibly out of order and across forks, follows the heaviest-height canonical chain, and emits each block's events exactly once when it is k blocks deep, raising if a reorg deeper than k is observed.
Every Circle product that reacts to chain activity (CCTP attestations, deposit crediting in Mint and wallets) depends on an indexer that does not act on blocks that later disappear. The interviewer probes tree reasoning, out-of-order buffering and exactly-once guarantees under forks.
What the Interviewer Expects
- Stores blocks as a tree keyed by hash with parent pointers
- Buffers orphan blocks until their parent arrives
- Selects the canonical head and walks back to the confirmation depth
- Emits events for every newly confirmed block in order and never twice
- Detects a reorg that rewrites already confirmed history
- Analyses complexity and how to prune old blocks
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you prune the block map so memory stays bounded?
- Arc and many PoS chains offer deterministic finality; how does the tracker simplify there?
- How do you persist confirmed_hash so a restart resumes without re-emitting?
- How should downstream consumers handle a DeepReorgError in production?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Each block:
hash,parent,height,events. Blocks can arrive before their parent and from competing forks. - Canonical chain: the highest block seen (first seen wins ties), a simplification o...
High-Level Design
Keep blocks: hash -> (parent, height, events), an orphans map from missing parent to waiting blocks, the current head, and the last confirmed (hash, height). On each insert, attach the block a...