Skip to content

feat: Indexer reorg / gap detection & automatic reconciliation #558

Description

@joelpeace48-cell

Background & current state

The indexer (NEW-024) ingests events from Soroban RPC, but transient RPC errors, endpoint switches (rpcPool.js), or rollbacks can produce gaps or duplicate/inconsistent rows. Without reconciliation, downstream leaderboards/analytics drift from chain truth.

Goal

Add reorg/gap detection and automatic reconciliation so the indexed state self-heals after RPC hiccups or ledger inconsistencies.

Technical design

  • Track per-ledger ingestion with contiguous-range invariants; on detecting a gap (missing ledger range) or a hash/cursor mismatch, re-fetch and reconcile the affected range idempotently.
  • Quarantine unparseable events into a dead_events table for inspection rather than crashing.
  • Periodic consistency sweep comparing indexed counts vs. on-chain getters (e.g., get_participant_count).

Edge cases

  • Large gap after long downtime → bounded backfill (NEW-028) instead of infinite loop.
  • Duplicate delivery → idempotent upserts make reconciliation safe.
  • Persistent parse failure → quarantine + alert, keep indexing.
  • RPC returns inconsistent data across endpoints → prefer canonical + log divergence.

Task breakdown

  • Gap/mismatch detection over the cursor stream.
  • Reconcile-range routine (idempotent re-fetch).
  • dead_events quarantine + metrics/alerts.
  • Consistency sweep vs. on-chain getters.
  • Fault-injection tests.

Acceptance criteria

  • An injected gap/duplicate is reconciled automatically with no manual intervention.
  • Unparseable events are quarantined, not fatal.

Testing & verification

  • Fault-injection: drop/duplicate/corrupt ledger ranges; assert eventual consistency.

Out of scope

  • Initial indexer build (NEW-024); rollups (NEW-026).

Dependencies / related

  • Builds on NEW-024; uses NEW-028 for large gaps.

Difficulty: medium · Effort: M · indexer

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programarea: backendBackend API (Node/Express)difficulty: mediumModerate complexityenhancementNew feature or requestindexerOn-chain event indexingstellarStellar/Soroban integration

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions