[Backend] Two indexers run concurrently - soroban-indexer.service + soroban-event-worker race on the same rows and double-count withdrawnAmount
Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0
Labels: bug, backend, Stellar Wave, database, critical
Two indexers run at once and double-count withdrawnAmount, which corrupts claimable balances.
index.ts:32 calls sorobanIndexerService.start() and index.ts:33 startWorkers() starts SorobanEventWorker. Both poll STREAM_CONTRACT_ID and write Stream/StreamEvent. Their WITHDRAWN handlers both read-then-add withdrawnAmount (soroban-indexer.service.ts:216 and soroban-event-worker.ts:631) in separate transactions, so when both pick up the same event before either commits, the increment lands twice. That inflates withdrawnAmount and shrinks claimable. The legacy service also keeps its cursor in memory and ignores IndexerState. One indexer should own this.
What the fix has to hold to
- Only one component indexes contract events
- The same WITHDRAWN event never increments
withdrawnAmountmore than once
Done when
- [ ]
sorobanIndexerService.start()/stop()removed fromindex.tsso onlySorobanEventWorkerindexes - [ ]
services/soroban-indexer.service.tsdeleted or disabled - [ ] Regression test asserts only one indexer instance polls the contract
- [ ] Verified
withdrawnAmountisn't double-incremented for the same event - [ ] Tests + lint pass, CI green
Where to start
backend/src/index.ts (drop the legacy start), then remove backend/src/services/soroban-indexer.service.ts; soroban-event-worker.ts stays as the single indexer. Contract-side and frontend indexer-status UI are out of scope. Medium.
@Gogo-Eng has applied to work on this issue as part of the Stellar Wave Program's 6th wave.
I will love to work on this issue
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Gogo-Eng to this issue.
@Caneryy has applied to work on this issue as part of the Stellar Wave Program's 6th wave.
Hi, I'd like to work on this issue please.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Caneryy to this issue.
🦊 GrantFox — @Banx17 has been assigned to this issue!
Next steps:
- Open a Pull Request referencing this issue (e.g.,
Closes #801) - Your PR will be reviewed by the LabsCrypt maintainers
Good luck! Track your progress on GrantFox.
Congratulations, @Banx17! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on June 30, 2026.
🧑💻 @Banx17: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.
[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.
🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.
🌊 Happy Wave 🌊
@Horlarolowo123 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.
Hello Maintainer, I’ve carefully reviewed the issue and have a clear understanding of the requirements. I’m ready and confident to take it on. Kindly assign the issue to me.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Horlarolowo123 to this issue.
@markankamaransheogarat-sys has applied to work on this issue as part of the Stellar Wave Program's 11th wave.
Hi! I'd like to take
#801(Two indexers run concurrently - soroban-indexer.service + soroban-event-worker race on the same rows). I'll enforce single-writer ownership betweenservices/soroban-indexer.service.tsand the event worker inbackend/src/index.ts, and makeWITHDRAWNevent processing idempotent (unique cursor/tx guard) sowithdrawnAmountis never double-counted under concurrent or retried runs. I'll verify with concurrency/idempotency unit tests andtypecheckbefore opening the PR. Ready to start immediately!
ℹ️ Repo Maintainers: To accept this application, review their application or assign @markankamaransheogarat-sys to this issue.