Skip to content

Commit 7b8ca73

Browse files
authored
Merge pull request #1166 from OpensrcLord/fix/1096-indexer-naming-docs
docs: clarify indexer ownership and naming (indexerService.ts / soroban-indexer.service.ts)
2 parents f71359b + 590e7e7 commit 7b8ca73

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

backend/src/services/indexerService.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/**
2+
* Indexer control-plane helpers (status / reset / replay).
3+
*
4+
* NOTE ON NAMING: Despite the `indexerService` name, this file is NOT an
5+
* indexer. It is the admin/control-plane helper for the source-of-truth
6+
* indexer, `SorobanEventWorker` (backend/src/workers/soroban-event-worker.ts).
7+
* The functions here only read/reset the shared `IndexerState` cursor row and
8+
* trigger the worker's poll loop. It is intentionally named like the legacy
9+
* indexer below to document that this helper is the "other" indexer entry
10+
* point — see backend/src/services/soroban-indexer.service.ts, which is the
11+
* LEGACY indexer being phased out. See docs/ARCHITECTURE.md for the full
12+
* indexer ownership model.
13+
*
14+
* NAMING CONVENTION PLAN: once the functional consolidation of the two
15+
* indexers lands (issue #801), this file is expected to be renamed to
16+
* `indexer.service.ts` so every service is kebab-case with a `.service.ts`
17+
* suffix.
18+
*/
119
import { prisma } from '../lib/prisma.js';
220
import { INDEXER_STATE_ID } from '../lib/indexer-state.js';
321
import { sorobanEventWorker } from '../workers/soroban-event-worker.js';

backend/src/services/soroban-indexer.service.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* LEGACY indexer — being phased out.
3+
*
4+
* The source of truth for event indexing is `SorobanEventWorker`
5+
* (backend/src/workers/soroban-event-worker.ts). That worker handles the full
6+
* event surface (created / topped_up / withdrawn / paused / resumed /
7+
* cancelled / completed / fee_collected / fee_config_updated /
8+
* admin_transferred), uses cursor-based pagination, persists the `IndexerState`
9+
* cursor, and broadcasts SSE updates.
10+
*
11+
* This service is a simpler, second indexer that polls the Soroban RPC on its
12+
* own interval and writes to the same rows as the worker, which means both run
13+
* concurrently and can race on the same Stream / StreamEvent rows (see issue
14+
* #801). It is kept only for backwards compatibility and is being phased out.
15+
* Until the functional consolidation (issue #801) lands, do not extend this
16+
* service with new behavior — mirror any changes in `SorobanEventWorker`
17+
* instead. Once consolidation lands, this file is expected to be removed.
18+
*
19+
* NAMING CONVENTION PLAN: this file already follows the kebab-case `.service.ts`
20+
* convention. The helper file backend/src/services/indexerService.ts (which is
21+
* NOT an indexer) is expected to be renamed to `indexer.service.ts` to match.
22+
*/
123
import { prisma } from '../lib/prisma.js';
224
import logger from '../logger.js';
325
import { withRpcRetry, withRpcTimeout } from './sorobanService.js';

docs/ARCHITECTURE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,24 @@ Frontend useStreamEvents hook (frontend/src/hooks/useStreamEvents.ts)
193193
Dashboard / NotificationDropdown re-render with live data
194194
```
195195

196+
### Indexer Ownership & Naming
197+
198+
Three files with overlapping names live next to each other, but only one of them is the indexer that writes stream state. This section documents which is the source of truth and which is legacy so contributors know where to start when debugging indexing.
199+
200+
| File | Role | Status |
201+
|------|------|--------|
202+
| `backend/src/workers/soroban-event-worker.ts` (`SorobanEventWorker`) | **Source-of-truth indexer.** Polls Soroban RPC, decodes XDR, persists `Stream` / `StreamEvent`, advances the `IndexerState` cursor, and broadcasts SSE. | Active / source of truth. Started by `backend/src/workers/index.ts` |
203+
| `backend/src/services/soroban-indexer.service.ts` (`SorobanIndexerService`) | **Legacy indexer being phased out.** A simpler duplicate poller that writes to the same rows and races with the worker. | **Legacy — do not extend.** Removal tracked with the functional consolidation (issue #801). Started directly from `backend/src/index.ts` |
204+
| `backend/src/services/indexerService.ts` | **Not an indexer at all.** Admin control-plane helpers (`getIndexerStatus`, `resetIndexer`, `replayFromLedger`) that read/reset `IndexerState` and trigger the worker's poll loop. | Active. The name is misleading; it was kept alongside the legacy indexer above |
205+
206+
Key points:
207+
208+
1. **When debugging indexing, read `backend/src/workers/soroban-event-worker.ts` first.** It is the only file that persists canonical stream state.
209+
2. **Do not add new behavior to `soroban-indexer.service.ts`.** It exists only for backwards compatibility while the double-indexer race (issue #801) is consolidated.
210+
3. **`indexerService.ts` is control-plane only** — it never reads the chain; it manages the shared cursor and triggers replays.
211+
212+
**Naming convention plan:** the team convention is kebab-case with a `.service.ts` suffix (e.g. `soroban-indexer.service.ts`, `claimable.service.ts`, `sse.service.ts`). The helper file `indexerService.ts` breaks that convention and is also a misleading name. Once the functional consolidation (issue #801) lands, `indexerService.ts` is expected to be renamed to `indexer.service.ts`.
213+
196214
### Deduplication
197215

198216
`StreamEvent` rows carry a compound unique constraint:

0 commit comments

Comments
 (0)