flowfi icon indicating copy to clipboard operation
flowfi copied to clipboard

[Backend] Two indexers run concurrently - soroban-indexer.service + soroban-event-worker race on the same rows and double-count withdrawnAmount

Open grantfox-oss[bot] opened this issue 5 months ago • 5 comments

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 withdrawnAmount more than once

Done when

  • [ ] sorobanIndexerService.start()/stop() removed from index.ts so only SorobanEventWorker indexes
  • [ ] services/soroban-indexer.service.ts deleted or disabled
  • [ ] Regression test asserts only one indexer instance polls the contract
  • [ ] Verified withdrawnAmount isn'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.

grantfox-oss[bot] avatar Jun 27 '26 20:06 grantfox-oss[bot]

@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.

Gogo-Eng avatar Jun 29 '26 21:06 Gogo-Eng

@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.

Caneryy avatar Jun 29 '26 22:06 Caneryy

🦊 GrantFox — @Banx17 has been assigned to this issue!

Next steps:

  1. Open a Pull Request referencing this issue (e.g., Closes #801)
  2. Your PR will be reviewed by the LabsCrypt maintainers

Good luck! Track your progress on GrantFox.

grantfox-oss[bot] avatar Jun 29 '26 22:06 grantfox-oss[bot]

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 🌊

drips-wave[bot] avatar Jun 29 '26 22:06 drips-wave[bot]

@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.

Horlarolowo123 avatar Aug 30 '26 20:08 Horlarolowo123

@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 between services/soroban-indexer.service.ts and the event worker in backend/src/index.ts, and make WITHDRAWN event processing idempotent (unique cursor/tx guard) so withdrawnAmount is never double-counted under concurrent or retried runs. I'll verify with concurrency/idempotency unit tests and typecheck before opening the PR. Ready to start immediately!

ℹ️ Repo Maintainers: To accept this application, review their application or assign @markankamaransheogarat-sys to this issue.