Skip to content

feat: implement SorobanEventWorker with idempotency logic and unit tests#705

Merged
ogazboiz merged 2 commits into
LabsCrypt:mainfrom
sweetesty:fix/paused-resumed-dedup-guard
Jun 1, 2026
Merged

feat: implement SorobanEventWorker with idempotency logic and unit tests#705
ogazboiz merged 2 commits into
LabsCrypt:mainfrom
sweetesty:fix/paused-resumed-dedup-guard

Conversation

@sweetesty
Copy link
Copy Markdown
Contributor

Closes #543


This PR fixes handleStreamPaused and handleStreamResumed to use the same find-then-upsert-with-skip dedup guard as every other event handler in the worker.

Root cause
All other handlers (handleStreamCreated, handleTokensWithdrawn, handleFeeCollected, etc.) check tx.streamEvent.findUnique({ where: { transactionHash_eventType } }) and skip or upsert to avoid duplicates on replay. handleStreamPaused and handleStreamResumed called tx.streamEvent.create() directly with no guard, causing a unique-constraint violation (@@unique([transactionHash, eventType]) in schema.prisma) when /v1/admin/indexer/replay replayed a ledger containing pause or resume events.

Fix — backend/src/workers/soroban-event-worker.ts

  • handleStreamPaused updated to use findUnique({ where: { transactionHash_eventType } }) before writing; skips if a matching row already exists, upserts if not
  • handleStreamResumed updated with the same pattern
  • Both handlers now behave identically to the rest of the worker under replay — restart-safe and consistent

Test

  • Worker test extended to replay a ledger containing a pause + resume event twice
  • Asserts no duplicate rows exist after the second replay
  • Asserts no error is thrown on the second replay
  • Confirms the existing dedup behaviour of other handlers is unaffected

Acceptance criteria met:

  • handleStreamPaused uses find-then-upsert-with-skip pattern
  • handleStreamResumed uses find-then-upsert-with-skip pattern
  • ✅ Replay of a pause+resume ledger produces no duplicate rows and no thrown error

@ogazboiz
Copy link
Copy Markdown
Contributor

ogazboiz commented Jun 1, 2026

hey, #706 just merged and fixes the same test-load issue your branch is failing on (5 test files showing '0 tests' due to broken auth mocks). please rebase:

git fetch upstream
git rebase upstream/main
git push --force-with-lease

CI should clear once you pick up the auth mock fix.

@sweetesty sweetesty force-pushed the fix/paused-resumed-dedup-guard branch from 71b497d to aa10dde Compare June 1, 2026 20:15
@ogazboiz ogazboiz merged commit c17bd10 into LabsCrypt:main Jun 1, 2026
9 checks passed
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] PAUSED/RESUMED worker handlers skip the dedup guard used by all other events

2 participants