fix(backend): await on-chain transaction finality before committing DB state - #1308
Merged
K1NGD4VID merged 1 commit intoAug 29, 2026
Conversation
…B state Poll Soroban RPC getTransaction for terminal status (SUCCESS/FAILED) before resolving submitContractCall, preventing DB and on-chain state divergence.
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
Resolves optimistic database state mutations in
backend/src/services/sorobanService.tsby pollinggetTransactionfor on-chain finality (SUCCESS/FAILED) before resolvingsubmitContractCall. Downstream controllers (cancelStreamHandler,topUpStreamHandler) now only commit DB updates after the on-chain transaction has confirmed.Problem
In
submitContractCall, the response fromgetServer().sendTransaction()was only checked forresponse.status !== 'ERROR'(meaning accepted into the transaction queue / mempool, not confirmed on-chain) before immediately returningresponse.hash. Handlers likecancelStreamHandlerandtopUpStreamHandlerthen immediately mutated the PostgreSQL database (setting stream status toCANCELLEDor updatingdepositedAmount) before knowing whether the transaction succeeded on-chain. If the transaction was dropped or failed on-chain, the database permanently diverged from ledger state.Scenarios
CANCELLEDor incrementeddepositedAmount; DB and ledger permanently divergesubmitContractCalldetectsFAILEDstatus, throws on-chain failure error, DB mutation is skippedpollTransactionStatuswaits up to timeout; aborts DB mutation on timeoutSUCCESSon-chainSolution
pollTransactionStatus):getServer().getTransaction(txHash)wrapped inwithRpcRetryandwithRpcTimeout.rpc.Api.GetTransactionStatus.SUCCESS.rpc.Api.GetTransactionStatus.FAILED(including transaction result XDR when present).rpc.Api.GetTransactionStatus.NOT_FOUNDwith configurable interval (SOROBAN_TX_POLL_INTERVAL_MS, default 1s).SOROBAN_TX_CONFIRMATION_TIMEOUT_MS, default 30s).submitContractCallawaitspollTransactionStatus(response.hash)before returning.submitContractCallthrows, preventingstreamRepository.updateStatus()andprisma.stream.update()from executing.Changes by File
backend/src/services/sorobanService.ts:getTxConfirmationTimeoutMs()andgetTxPollIntervalMs()for configurable confirmation deadlines.pollTransactionStatus().submitContractCall()to awaitpollTransactionStatus(response.hash)before returningresponse.hash.backend/tests/soroban.service.test.ts:getTransactionmock to RPC server mock setup.NOT_FOUNDstatuses, failure onFAILEDstatus, and timeout handling.backend/tests/cancel.controller.test.ts:cancelStreamleaves the DB status untouched (streamRepository.updateStatusis not called).backend/tests/integration/top-up.test.ts:topUpStreamleaves the DB untouched (prisma.stream.updateis not called).Regression Tests
backend/tests/cancel.controller.test.ts:leaves DB unchanged and does not update status when cancelStream fails on-chainbackend/tests/integration/top-up.test.ts:leaves DB unchanged when topUpStream fails on-chainsubmitContractCallawaits terminal statusbackend/tests/soroban.service.test.ts:polls getTransaction and returns tx hash when transaction succeeds on-chainsubmitContractCallpolls through pending statusbackend/tests/soroban.service.test.ts:polls across pending NOT_FOUND statuses until SUCCESSsubmitContractCallthrows on terminal failurebackend/tests/soroban.service.test.ts:throws when getTransaction returns FAILED after mempool acceptancebackend/tests/soroban.service.test.ts:throws when transaction confirmation times outTesting
Literal vitest output:
Typecheck:
Notes for Reviewers
SOROBAN_TX_POLL_INTERVAL_MS(default 1,000 ms) andSOROBAN_TX_CONFIRMATION_TIMEOUT_MS(default 30,000 ms).Closes #1218