Skip to content

fix(indexer): remove duplicate soroban indexer service (#801)#980

Open
Banx17 wants to merge 1 commit into
LabsCrypt:mainfrom
Banx17:fix/801-remove-duplicate-indexer
Open

fix(indexer): remove duplicate soroban indexer service (#801)#980
Banx17 wants to merge 1 commit into
LabsCrypt:mainfrom
Banx17:fix/801-remove-duplicate-indexer

Conversation

@Banx17

@Banx17 Banx17 commented Jul 1, 2026

Copy link
Copy Markdown

[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.service and soroban-event-worker) were running concurrently, leading to a double-counting of withdrawnAmount for the same events. The legacy service has been removed so that only the SorobanEventWorker polls 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

  • [DELETE] backend/src/services/soroban-indexer.service.ts
  • Removed the legacy indexer service to ensure only a single indexer processes events.
  • [MODIFY] backend/src/index.ts
  • Removed the sorobanIndexerService.start() call and related graceful shutdown logic.

🛡️ Idempotency Improvements

  • [MODIFY] backend/src/workers/soroban-event-worker.ts
  • Updated handleTokensWithdrawn to check for the existing StreamEvent record before applying the balance increment, preventing double-counting if the same event is processed twice.

🧪 Tests

  • [DELETE] backend/tests/soroban-indexer.test.ts
  • Removed obsolete tests for the legacy service.
  • [ADD] backend/tests/single-indexer.regression.test.ts
  • Added a regression test asserting only one indexer instance polls the contract.
  • Added a test to verify withdrawnAmount is not double-incremented when the same WITHDRAWN event is observed.

Verification Results

Acceptance Criteria Status
Remove sorobanIndexerService.start()/stop() from index.ts
Delete or disable services/soroban-indexer.service.ts
Add a regression test asserting only one indexer instance polls the contract
Verify withdrawnAmount is not double-incremented when the same WITHDRAWN event is observed
Backend tests pass successfully

- Removed legacy `sorobanIndexerService` from `index.ts`.
- Made `SorobanEventWorker.handleTokensWithdrawn` idempotent.
- Deleted obsolete tests for legacy service.
- Added regression test for single indexer LabsCrypt#801.
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.

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

1 participant