Description
lib/indexer.ts advances its cursor purely forward and only deduplicates by network:id:type; it has no detection for ledger gaps or chain reorganizations, so a reorg silently leaves processed events that no longer exist on-chain. Add reorg/gap handling so indexed stream events stay consistent with Horizon truth. This is a backend on-chain indexing feature.
Requirements and Context
- Detect gaps when
event.ledger > cursor + 1 + overlapWindow and trigger a bounded backfill from the last safe ledger.
- Detect reorgs by tracking a short window of recent ledger hashes and rolling the cursor back when a hash mismatch is observed; re-emit affected events idempotently.
- Replace the
console.error stall "alert" with structured logging via the project logger and a metric counter.
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested Execution
- Fork the repo and create a branch
git checkout -b feature/indexer-reorg-handling
- Implement changes
lib/indexer.ts — gap detection, reorg rollback, hash window
lib/indexer.test.ts — extend coverage
- Test and commit
npm test -- lib/indexer.test.ts
- Cover edge cases: ledger gap, reorg rollback + replay, duplicate suppression
- Include test output and notes in the PR
Example commit message
feat: handle ledger gaps and reorgs in Horizon indexer
Acceptance Criteria
Guidelines
- Minimum 90% test coverage including reorg/gap simulations
- Clear documentation and inline comments
- Timeframe: 96 hours
Description
lib/indexer.tsadvances its cursor purely forward and only deduplicates bynetwork:id:type; it has no detection for ledger gaps or chain reorganizations, so a reorg silently leaves processed events that no longer exist on-chain. Add reorg/gap handling so indexed stream events stay consistent with Horizon truth. This is a backend on-chain indexing feature.Requirements and Context
event.ledger > cursor + 1 + overlapWindowand trigger a bounded backfill from the last safe ledger.console.errorstall "alert" with structured logging via the project logger and a metric counter.Suggested Execution
lib/indexer.ts— gap detection, reorg rollback, hash windowlib/indexer.test.ts— extend coveragenpm test -- lib/indexer.test.tsExample commit message
Acceptance Criteria
lib/indexer.tsGuidelines