Skip to content

contrib: add jitter to tx-status retry logic - #349

Merged
davedumto merged 1 commit into
Vellar-Wallet:devfrom
Elizabethxxx:issue-280-tx-status-retry-jitter
Aug 31, 2026
Merged

contrib: add jitter to tx-status retry logic#349
davedumto merged 1 commit into
Vellar-Wallet:devfrom
Elizabethxxx:issue-280-tx-status-retry-jitter

Conversation

@Elizabethxxx

Copy link
Copy Markdown

Summary

Adds randomized jitter to the polling delay used by waitForTransaction (src/tx-status.ts), which currently sleeps a fixed intervalMs between 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 configurable maxDelayMs (defaults to intervalMs * 10), so a large jitterFactor can never produce an unbounded wait. random is injectable for deterministic tests.
  • waitForTransactionJittered(reader, hash, options) — a drop-in replacement for waitForTransaction with the same TxStatus/TxStatusReader types (re-exported from src/tx-status.ts) and the same TransactionTimeoutError behavior, except the sleep between polls comes from computeJitteredDelay. The timeout deadline check accounts for the actual jittered delay used, so a run of unlucky (large) delays still respects timeoutMs.
  • 13 tests: computeJitteredDelay produces a real distribution (not one fixed value) across 50 draws, stays within its computed range across 200 draws, is exactly deterministic given an injected random, respects maxDelayMs even with an extreme jitterFactor, defaults maxDelayMs to 10x intervalMs, and rejects negative inputs; waitForTransactionJittered resolves 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 configured maxDelayMs.
  • Code comments explain the full-jitter approach and cite the reasoning it follows (AWS Architecture Blog's "Exponential Backoff And Jitter" — the same principle applies to a fixed-interval poll, not just exponential backoff).

Placement note

Submitted under contrib/examples/issue-280-tx-status-retry-jitter/ per the contributor scope rule (contributor PRs may only touch contrib/) as a drop-in-compatible companion to src/tx-status.ts rather than editing it directly.

Test plan

  • npx vitest run contrib/examples/issue-280-tx-status-retry-jitter — 13/13 passing
  • Standalone strict typecheck of the new files passes with no errors

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
@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

@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.

@davedumto
davedumto merged commit 12fc304 into Vellar-Wallet:dev Aug 31, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants