fix(indexer): keep same-ledger REMOVE so deletes are never lost - #687
Merged
Conversation
JiahuiWho
requested review from
aditya1702 and
aristidesstaffieri
and
a balanced review from Copilot
August 18, 2026 16:30
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes stale indexed balance rows by preserving the highest-order change, including trailing deletes.
Changes:
- Replaces tombstone-based netting with highest-order deduplication.
- Preserves same-ledger trailing removals.
- Updates regression tests and documentation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
internal/indexer/indexer.go |
Clarifies deterministic operation ordering. |
internal/indexer/indexer_test.go |
Updates operation-order regression expectations. |
internal/indexer/indexer_buffer.go |
Implements highest-order change retention. |
internal/indexer/indexer_buffer_test.go |
Covers retained deletes and ordering behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
JiahuiWho
marked this pull request as ready for review
August 18, 2026 16:45
aditya1702
approved these changes
Aug 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix a bug where the indexer could permanently keep a stale balance row when a trustline (or account / SAC / liquidity-pool balance) was deleted and re-created within a single ledger. The buffer now keeps the last change per key instead of cancelling out a same-ledger create+delete pair, so a trailing delete is always applied.
Changes are:
pushWithTombstonefunction and its five*IsNoopRemovehelpers, the logic that cancelled a same-ledger create+delete pair down to no write.pushHighestOrder, which simply keeps whichever change has the highest operation order per key, i.e. the last operation to touch that key.Why
The indexer collapses each ledger's balance changes into one write per account+asset, and dropped a same-ledger "create then delete" pair as a no-op.
That was only safe if the row didn't already exist in the database, but it never checked. So a transaction that in one ledger deletes an existing trustline and then re-creates and re-deletes it (delete → create → delete) wrote nothing: the re-create overwrote the pending delete, and the final create+delete cancelled out. The old row was never removed.
Known limitations
Rows already corrupted on main are not repaired by this PR, a one-off backfill/cleanup is needed separately.
Also the
live-ingest-processor-perfandlive-ingest-persist-pathbranches touch the same file and will re-introduce the bug on merge unless rebase or same fix is applied there.Issue that this PR addresses
Reported via HackerOne #3941742.
Checklist
PR Structure
allif the changes are broad or impact many packages.Thoroughness
Release