indexer/follower: refresh OgmiosSource intersect on each saved cursor

The mainnet marketplace-indexer was stuck in an event-replay loop since
2026-05-14. Diagnosis: OgmiosSource.intersectAt is captured ONCE in
start() from the cursor at process startup. On every WebSocket reconnect
(Cloudflare-fronted WS times out at ~100s idle, plus periodic Ogmios
server restarts), scheduleReconnect calls sendFindIntersection with the
stale start-time intersect, never the latest persisted cursor. Ogmios
seeks to that old point, sends nextBlock forward from there, the worker
re-processes the same blocks and writes saveCursor over the advanced
cursor with the old slot — DB cursor effectively never moves past the
startup point, and events get duplicated each iteration.

Fix:
- Add ChainSyncSource.updateIntersect({ slot, id }) to the interface.
- OgmiosSource.updateIntersect mutates this.intersectAt, so the next
  reconnect's findIntersection picks up from the latest saved cursor.
- worker.handleBlock calls source.updateIntersect after every saveCursor.
- worker.handleRollback also calls it so a WS drop right after a rollback
  doesn't resume past the rollback point.
- MockChainSyncSource implements as no-op (no reconnect path in tests).

Verified: same shape as the testnet projection-gap bug (memory 95fe6946),
manifesting differently. After this fix the cursor will only ever advance,
and reconnects resume from the freshest persisted point.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
david
2026-05-19 14:59:25 +02:00
parent e7a231cafd
commit 7a806ff1e2
4 changed files with 21 additions and 0 deletions

View File

@@ -50,6 +50,11 @@ export class MockChainSyncSource extends EventEmitter implements ChainSyncSource
// Subclasses that need step-by-step control can override.
}
updateIntersect(_point: { slot: number; id: string }): void {
// No-op in mock mode; the source has no reconnect path. Kept to satisfy
// the ChainSyncSource interface contract.
}
private _drainAll(): void {
while (this.eventIndex < this.events.length) {
const ev = this.events[this.eventIndex++];