fix(backend): retry playground mess steps on stale-sequence rejection#38
Merged
Conversation
Consecutive playground mess steps submit from the same demo account in quick succession. When the Soroban RPC serves a sequence number that lags a just-confirmed tx, the next step builds with an already-used sequence and the network rejects it as txBadSeq - surfacing as "The transaction was rejected by the network" on a random step. This is the same RPC ingestion lag as the account-not-found case, but on the sequence number, so it slips past the existing not-found retry. - buildSignSubmit now retries on tx_bad_seq, re-reading the source account after a short backoff so it picks up the advanced sequence, then rebuilds and resubmits (BAD_SEQ_MAX_ATTEMPTS / BAD_SEQ_RETRY_DELAY_MS); deps are injectable so the loop is unit-testable without a live RPC - submitAndWait throws a typed TxSubmitError carrying the decoded result code, letting callers branch on tx_bad_seq instead of string-matching messages - fix translateRpcError to decode the TransactionResult XDR before the generic ERROR/FAILED fallback - those codes had map entries that short-circuited the lookup and hid the real reason (e.g. tx_bad_seq) from users and callers - unit tests for the retry loop and the now-specific error translation Verified end-to-end on testnet: a mess step hit txBadSeq twice, the retry re-read and resubmitted, and the step confirmed - the full Standard run completed with every step returning 200.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Problem
The playground still showed "The transaction was rejected by the network" on a random mess step (after the account-not-found fix landed). Captured the raw rejection from the Soroban RPC:
Root cause is the same RPC ingestion lag, but on the sequence number: consecutive mess steps submit from the same demo account in quick succession; when the RPC serves a sequence that lags a just-confirmed tx, the next step builds with an already-used sequence →
txBadSeq. It's intermittent and hits whichever step reads the lagging sequence. The previous retry only covered the "account not found" first-read case.Also found a second issue:
translateRpcErrorreturned the generic"ERROR"message before decoding the result XDR, so the real reason (tx_bad_seq) never surfaced to users or callers.Changes
buildSignSubmitretries ontx_bad_seq: re-reads the source account after a short backoff (picks up the advanced sequence), rebuilds and resubmits (BAD_SEQ_MAX_ATTEMPTS/BAD_SEQ_RETRY_DELAY_MS). Deps are injectable so the loop is unit-tested without a live RPC.submitAndWaitthrows a typedTxSubmitErrorcarrying the decoded result code, so callers branch ontx_bad_seqinstead of string-matching messages.translateRpcErrordecodes theTransactionResultXDR before the generic ERROR/FAILED fallback, so the specific code (e.g. tx_bad_seq) surfaces app-wide.Verification
bun type-check✅ ·bun lint✅ ·bun test tests/unit✅ (246 pass)txBadSeqtwice, the retry re-read the account and resubmitted, and the step confirmed (200). The full Standard run (trustlines, airdrops, data entries, DEX offers, signer) completed with every step returning 200.