fix(indexer): remove duplicate soroban indexer service (#801)#980
fix(indexer): remove duplicate soroban indexer service (#801)#980Banx17 wants to merge 1 commit into
Conversation
- Removed legacy `sorobanIndexerService` from `index.ts`. - Made `SorobanEventWorker.handleTokensWithdrawn` idempotent. - Deleted obsolete tests for legacy service. - Added regression test for single indexer LabsCrypt#801.
|
this is the right, complete fix. it deletes the legacy services/soroban-indexer.service.ts (a second poller of STREAM_CONTRACT_ID that did its own read-then-add on withdrawnAmount in a separate transaction, the actual root cause of the double-counting in #801), removes its wiring from index.ts + its obsolete test, and makes handleTokensWithdrawn idempotent (guard-first + an applied flag that also skips the duplicate SSE broadcast). the SorobanEventWorker stays as the single indexer covering CREATED/CANCELLED/WITHDRAWN/COMPLETED, so nothing's dropped, and the regression test asserts the old file is gone and unimported. one thing: it's conflicting with main. please rebase (git fetch origin && git rebase origin/main && git push --force-with-lease) and i'll merge. this supersedes #968 (which only hardens the worker but leaves the legacy indexer running), so i'll close that in favor of yours. |
[npm run lint ✅ completed (existing repo warnings only)
npm run typecheck ✅ passed
npm run build ✅ passed]
Overview
This PR resolves a race condition where two indexers (
soroban-indexer.serviceandsoroban-event-worker) were running concurrently, leading to a double-counting ofwithdrawnAmountfor the same events. The legacy service has been removed so that only theSorobanEventWorkerpolls the contract. Additionally, the WITHDRAWN handler has been made idempotent to guarantee that the same event cannot increment the balance more than once.Related Issue
Closes #801
Changes
⚙️ Indexer Consolidation
backend/src/services/soroban-indexer.service.tsbackend/src/index.tssorobanIndexerService.start()call and related graceful shutdown logic.🛡️ Idempotency Improvements
backend/src/workers/soroban-event-worker.tshandleTokensWithdrawnto check for the existingStreamEventrecord before applying the balance increment, preventing double-counting if the same event is processed twice.🧪 Tests
backend/tests/soroban-indexer.test.tsbackend/tests/single-indexer.regression.test.tswithdrawnAmountis not double-incremented when the same WITHDRAWN event is observed.Verification Results
sorobanIndexerService.start()/stop()fromindex.tsservices/soroban-indexer.service.tswithdrawnAmountis not double-incremented when the same WITHDRAWN event is observed