feat: index Soroban contract events into Postgres within 2s - #22
Open
testersweb wants to merge 1 commit into
Open
feat: index Soroban contract events into Postgres within 2s#22testersweb wants to merge 1 commit into
testersweb wants to merge 1 commit into
Conversation
Poll Stellar RPC getEvents by contract ID on a 1s interval, decode PaymentStreamed XDR payloads, and persist transactions without completing the session so expert earnings can be queried off-chain.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Index Stellar/Soroban contract events into PostgreSQL so expert earnings and session history can be queried off-chain as soon as they are visible to RPC.
The indexer polls
getEventsfiltered by contract ID, decodes Soroban XDR topics/data (includingPaymentStreamed), and writesTransaction/ session rows via Prisma in the same poll tick. Default poll interval is 1000ms, which satisfies the 2 second freshness acceptance criterion.What changed
backend/src/indexer.ts— 1s poll loop (invalid/<100msintervals fall back to 1000ms); logs combined ingest + recovery processing counts.backend/src/sorobanIndexer.ts—getEventswith contract ID filters, cursor pagination, exact topic classification, XDR decode, ledger/cursor persistence.backend/src/eventListener.ts—PAYMENT_STREAMEDhandler: insertPAYMENT_RELEASEDtransaction, keep sessionACTIVE; ledger time fromledgerClosedAt; ingest handles unique-constraint races (P2002).backend/prisma/schema.prisma+ migration —IndexerState.lastCursorfor RPC pagination.docker-compose.yml/backend/.env.example—INDEXER_INTERVAL_MS=1000,SOROBAN_RPC_URL,ESCROW_CONTRACT_ID.Key implementation details
getEventsuses eitherstartLedgerorcursor, matching Stellar RPC /@stellar/stellar-sdkv16 (the two must not be mixed).ESCROW_CONTRACT_ID,DISPUTE_CONTRACT_ID,SOROBAN_CONTRACT_IDS, or constructor options. Filters respect the 5 IDs per filter / 5 filters limits.PaymentStreamed→PAYMENT_STREAMED). Generic"payment"is not treated as session completion.PaymentStreamedrecords earnings without setting session status toCOMPLETED.IndexerState.lastLedgeris only fast-forwarded to RPClatestLedgeron an empty page so truncated scans are not skipped.EventLog/Transactionby the StellartxHash.Test plan
cd backend && npx prisma generate && npx tsc --noEmitcd backend && npm testPaymentStreameddecode does not classify asSESSION_COMPLETEDTransaction(PAYMENT_RELEASED) and session staysACTIVEgetEventsis called withfilters[].contractIdsstartLedgeron the next request)npx prisma migrate deploy(addsIndexerState.lastCursor)ESCROW_CONTRACT_ID(andSOROBAN_RPC_URL) before running the indexer in a real environmentPaymentStreamedon testnet and confirm the row appears in Postgres within ~2s of RPC visibilityTesting / verification performed
npx prisma generate— successnpx tsc --noEmitandnpx tsc --noEmit -p tsconfig.test.json— successnpm test— 128 passed (coverage thresholds met)Notes / considerations
EventLog.txHashis unique per Stellar transaction. If one tx emits multiple contract events, only the first ingested row is kept.ESCROW_CONTRACT_ID; an empty value logs a warning and indexes all contract events.Related Issue
Closes #19