fix(#13): persist Stellar event listener cursor in Postgres, add contract-events processor with idempotency#38
Open
d3vobed wants to merge 1 commit into
Conversation
…gres, add contract-events processor with idempotency
Replace Redis TTL-backed cursor storage (60s default eviction) with
persistent Postgres storage. The cursor is now stored in an event_cursors
table keyed by network (testnet/mainnet), surviving restarts and eliminating
the silent cursor-loss bug.
Changes:
- Add EventCursor Prisma model with unique constraint on network
- Add ProcessedEvent Prisma model for idempotency key (txHash, eventType)
- Replace cacheManager.get/set with prisma.eventCursor.findUnique/upsert
- Infer network from Horizon URL ("testnet" / "mainnet"),
overridable via STELLAR_NETWORK env var
- Create ContractEventsProcessor to consume contract-events queue
- Processor idempotency: skips already-processed (txHash, eventType) pairs
- Handles DonationReceived → confirms donation (status CONFIRMED)
- Handles MilestoneReleased → completes milestone (status COMPLETED)
- 9 new tests cover cursor bootstrapping, network detection, processor
idempotency, DonationReceived routing, MilestoneReleased routing,
and unknown event fallback
Closes OrbitChainLabs#13
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.
Summary
Replaces Redis TTL-backed cursor storage (60 s default eviction) with persistent Postgres storage. The cursor is now stored in an
event_cursorstable keyed by network (testnet/mainnet), surviving restarts and eliminating the silent cursor-loss bug that caused duplicate event processing and missed donations.Changes
Cursor persistence (core fix)
EventCursorPrisma model — unique onnetwork, persists cursor across restartscacheManager.get/set→prisma.eventCursor.findUnique/upsertinStellarEventService"testnet"/"mainnet"from Horizon URL; overridable viaSTELLAR_NETWORKenv varContract-events processor (new)
ContractEventsProcessor— consumes thecontract-eventsBull queue (previously no processor existed)(txHash, eventType)pairs viaProcessedEventtableDonationReceived→ updates matching pending donations toCONFIRMEDMilestoneReleased→ updates matching pending milestones toCOMPLETEDRedis dependency removed
CACHE_MANAGER/Cachetype removed fromStellarEventService— cursor no longer stored in Redis@nestjs/cache-manager/@keyv/redisdependencies no longer needed for cursor reading; can be cleaned up separatelyTesting
"now"when no cursor existsSTELLAR_NETWORKtxHash+eventType)DonationReceivedroutes to donation confirmationMilestoneReleasedroutes to milestone completionCloses #13