Skip to content

feat(stellar): retry + exponential backoff for Soroban RPC#28

Closed
gregemax wants to merge 1 commit into
wraith-protocol:developfrom
gregemax:main
Closed

feat(stellar): retry + exponential backoff for Soroban RPC#28
gregemax wants to merge 1 commit into
wraith-protocol:developfrom
gregemax:main

Conversation

@gregemax
Copy link
Copy Markdown

Summary

Implements task #2 — a shared retry primitive for all Stellar HTTP calls, wiring it into StellarSend and StellarReceive.

Changes

src/lib/stellar/retry.ts (new)

  • StellarRetryExhaustedError — typed error carrying the last underlying error as .cause
  • withRetry(fn, opts) — generic retry wrapper:
    • Up to 4 attempts (configurable)
    • Exponential backoff with jitter: 200 → 400 → 800 → 1600 ms ±25%
    • Retries on: HTTP 408, 429, 502, 503, 504 · TypeError (network/fetch) · SyntaxError (JSON parse — RPC returns HTML on overload)
    • Does not retry on: other 4xx · AbortError · StellarRetryExhaustedError itself
    • AbortSignal support — cancels cleanly mid-backoff
    • onRetry telemetry hook — emits { attempt, error, delayMs } on each retry (ready for PostHog)

src/lib/stellar/retry.test.ts (new)

  • 16 unit tests with vitest + fake timers covering every retry/no-retry path

src/components/StellarSend.tsx

  • All Horizon and Soroban fetches wrapped with withRetry
  • StellarRetryExhaustedError caught → shows "Network unstable — try again." + inline Retry button

src/components/StellarReceive.tsx

  • Probe fetch, paginated getEvents loop, balance fetch, and withdraw fetches all wrapped with withRetry
  • Same user-facing error UI on exhaustion

Test results

✓ src/lib/stellar/retry.test.ts (16 tests) 33ms
Test Files  1 passed (1)
      Tests  16 passed (16)

Closes #2

- Add withRetry(fn, opts) helper with 4 attempts, exponential backoff
  (200/400/800/1600ms ±25% jitter), and AbortSignal support
- Retry on HTTP 408/429/502/503/504, TypeError (network), SyntaxError (JSON)
- Skip retry on other 4xx, AbortError, and StellarRetryExhaustedError
- Emit onRetry telemetry hook for future PostHog integration
- Wire withRetry into all Stellar fetches in StellarSend and StellarReceive
- Show 'Network unstable — try again.' + retry button on exhaustion
- 16 unit tests covering all retry/no-retry paths
@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

@gregemax is attempting to deploy a commit to the truthixify's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 27, 2026

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

@truthixify truthixify changed the base branch from main to develop June 1, 2026 15:40
@truthixify
Copy link
Copy Markdown
Contributor

Closing as duplicate. Issue #2 is being handled in #15 which was opened first (currently waiting on a rebase).

If #15 doesn't include the specific retry classifications you have here (your 133 lines of tests look more thorough than what's in #15), you could push them as a follow-up PR once #15 lands.

Other open Stellar Wave issues you'd be a fit for: https://github.com/wraith-protocol/demo/issues?q=is%3Aopen+label%3A%22Stellar+Wave%22

Thanks @gregemax.

@truthixify truthixify closed this Jun 1, 2026
@gregemax
Copy link
Copy Markdown
Author

gregemax commented Jun 2, 2026

@truthixify i could't find any free issue to apply

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.

Retry + exponential backoff for Soroban RPC

2 participants