contrib: add jitter to tx-status retry logic - #349
Merged
davedumto merged 1 commit intoAug 31, 2026
Conversation
Adds computeJitteredDelay (full jitter: uniform in [0, intervalMs * (1 + jitterFactor)], capped by a configurable maxDelayMs) and waitForTransactionJittered, a drop-in replacement for waitForTransaction in src/tx-status.ts that uses it between polls instead of a fixed interval. Prevents many consumer instances polling the same RPC endpoint from retrying in lockstep after a synchronized start (e.g. a fleet of workers submitting right after a deploy). closes Vellar-Wallet#280
|
@Elizabethxxx Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@Elizabethxxx is attempting to deploy a commit to the david's projects Team on Vercel. A member of the Team first needs to authorize it. |
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
Adds randomized jitter to the polling delay used by
waitForTransaction(src/tx-status.ts), which currently sleeps a fixedintervalMsbetween every poll and can cause synchronized retry spikes across many consumer instances (e.g. a fleet of workers all submitting transactions right after a deploy, then polling in lockstep).closes #280
What's included
computeJitteredDelay(intervalMs, options)— "full jitter": each delay is drawn uniformly from[0, intervalMs * (1 + jitterFactor)], then capped at a configurablemaxDelayMs(defaults tointervalMs * 10), so a largejitterFactorcan never produce an unbounded wait.randomis injectable for deterministic tests.waitForTransactionJittered(reader, hash, options)— a drop-in replacement forwaitForTransactionwith the sameTxStatus/TxStatusReadertypes (re-exported fromsrc/tx-status.ts) and the sameTransactionTimeoutErrorbehavior, except the sleep between polls comes fromcomputeJitteredDelay. The timeout deadline check accounts for the actual jittered delay used, so a run of unlucky (large) delays still respectstimeoutMs.computeJitteredDelayproduces a real distribution (not one fixed value) across 50 draws, stays within its computed range across 200 draws, is exactly deterministic given an injectedrandom, respectsmaxDelayMseven with an extremejitterFactor, defaultsmaxDelayMsto10x intervalMs, and rejects negative inputs;waitForTransactionJitteredresolves success/failure correctly, times out correctly under worst-case (maximum) jitter, propagates reader errors, uses varying delays across a multi-poll run rather than a fixed interval, and never exceeds a configuredmaxDelayMs.Placement note
Submitted under
contrib/examples/issue-280-tx-status-retry-jitter/per the contributor scope rule (contributor PRs may only touchcontrib/) as a drop-in-compatible companion tosrc/tx-status.tsrather than editing it directly.Test plan
npx vitest run contrib/examples/issue-280-tx-status-retry-jitter— 13/13 passing