Skip to content

feat(indexer): reorg-aware event ingestion with ledger rollback (#724) - #1184

Merged
Chucks1093 merged 3 commits into
accesslayerorg:mainfrom
DanbabaJr:freebuff/6731e6c1c61eeee7ae9ef674
Oct 22, 2026
Merged

Chucks1093 merged 3 commits into
accesslayerorg:mainfrom
DanbabaJr:freebuff/6731e6c1c61eeee7ae9ef674

Conversation

@DanbabaJr

Copy link
Copy Markdown

PR: Implement Reorg-Aware Stellar Event Ingestion Pipeline

Closes #724

Summary

Implements a reorg-aware Stellar event ingestion pipeline that detects ledger rollbacks, identifies fork points, and restores database consistency before re-ingesting affected events.

Changes

  • Added "LedgerCheckpoint" to persist ledger sequences and hashes for ingested events.
  • Implemented previous ledger hash validation to detect chain mismatches.
  • Added fork-point detection by walking backwards through stored checkpoints.
  • Implemented atomic rollback of reorged events and their database side effects, including key balances, holder counts, and transaction history.
  • Added automatic re-ingestion of events from the identified fork point.
  • Added structured warn-level logging with fork point, reorged ledger count, and affected event count.
  • Gated buy/sell API responses on a minimum confirmed ledger depth of 2.
  • Added integration tests covering checkpoint progression, reorg detection, rollback, balance reversal, and consistent final state after re-ingestion.

Testing

  • Verified clean ledger ingestion and checkpoint updates.
  • Tested simulated ledger forks and rollback handling.
  • Verified database side effects are reversed atomically.
  • Confirmed re-ingested events produce the expected final state.
  • Tested buy/sell confirmation-depth requirements.

Expected Outcome

The ingestion pipeline now handles Stellar ledger reorganizations safely, prevents stale event data from affecting application state, and reduces exposure to unconfirmed ledger changes.

…sslayerorg#724)

Detect Stellar ledger rollbacks by anchoring every ingested ledger and
event to its hash (LedgerCheckpoint + new IngestedEvent table), walk back
to the fork point on a previousLedgerHash mismatch, reverse all affected
database side effects in one atomic transaction, emit a warn log with the
fork point and affected counts, re-ingest the canonical chain from the
fork point, and gate buy/sell confirmations on confirmed ledger depth >= 2.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@DanbabaJr Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

…rorg#724)

Bring the branch up to date with main so the new ledger-depth gate and
checkpoint model are validated against main's invoice-protocol suite.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
The accesslayerorg#724 ledger-depth gate reads latestLedger from getTransaction, which a
real Soroban node always returns. The invoice-protocol integration stub
omitted it, so every buy/sell waited out the full 120s poll budget and CI
timed out; report a head two ledgers past inclusion instead.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@Chucks1093
Chucks1093 merged commit 3e3f8bd into accesslayerorg:main Oct 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement a reorg-aware Stellar event ingestion pipeline that detects ledger rollbacks and reverses affected database state

3 participants