feat: implement 4 event processing tasks in indexer (market_resolved, bet_placed, market_created, resume) - #1164
Merged
Merged
Conversation
- Remove duplicate imports and conflicting variable declarations from merge - Consolidate all DB access through shared 'db' instance - Fix tsconfig rootDir from ./src to . to allow __tests__/ and tests/ inclusion
- Add EventLog table with unique constraint on (txHash, eventType) - Tracks processedAt timestamp for every successfully handled event - Enables idempotent replay and restart-safe event deduplication
Task 1 — out-of-order market_resolved rejection: - Check market exists before applying resolution; throw to retry later Task 2 — atomic bet_placed insertion + pool update: - Both recordBet and updateMarketPools execute in single $transaction Task 3 — idempotent market_created upsert + EventLog.processedAt: - Delegates idempotency to createMarketRecord (upsert) - Creates EventLog entry with processedAt after every successful handler Task 4 — resume from last ledger, never reprocess on restart: - Checks EventLog via (txHash, eventType) unique key before processing - Skips already-processed events silently
…ut-of-order market_resolved rejection with graceful retry, Task 2 atomic bet+pool update with rollback, Task 3 EventLog.processedAt marking and idempotent upsert, Task 4 restart mid-stream dedup via EventLog
…tasks feat: implement 4 event processing tasks in indexer (market_resolved, bet_placed, market_created, resume)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1065
Closes #1066
Closes #1067
Closes #1068
Summary
Implements four event processing tasks in the blockchain indexer:
Task 1 — Decode market_resolved events and update MarketModel status/outcome
handleMarketResolvedEventResolvedstatus with the decoded outcome (FighterA, FighterB, Draw, NoContest)Task 2 — Decode bet_placed events, insert BetModel, update pool totals
handleBetPlacedEventrecordBetandupdateMarketPoolsexecute within the same$transactionwrappingprocessLedger— fully atomicTask 3 — Decode market_created events and upsert MarketModel
handleMarketCreatedEventcreateMarketRecordwhich uses Prisma upsert — re-processing the same event never duplicates rowsEventLogentry withprocessedAttimestampEventLogmodel has a unique constraint on(txHash, eventType)for deduplicationTask 4 — Resume polling from last processed ledger on startup
startIndexerreadsgetLastIndexedLedger()and polls fromfromLedger + 1EventLog— if(txHash, eventType)already exists, skips itFiles Changed
backend/prisma/schema.prismaEventLogmodelbackend/prisma/migrations/20260726000000_add_event_log/migration.sqlbackend/src/services/indexer.service.tsbackend/src/services/market.service.tsdbconsistentlybackend/tsconfig.jsonbackend/src/services/__tests__/indexer.service.test.tsTest Results
39 tests, 0 failures