Skip to content

feat(sdk): add diagnostics, retry classification, tx recovery, and structured tx logging (#277) - #290

Open
hieuk48 wants to merge 14 commits into
JointSave-org:feat/sdk-contract-clientsfrom
hieuk48:feat/sdk-diagnostics-recovery
Open

hieuk48 wants to merge 14 commits into
JointSave-org:feat/sdk-contract-clientsfrom
hieuk48:feat/sdk-diagnostics-recovery

Conversation

@hieuk48

@hieuk48 hieuk48 commented Nov 5, 2026

Copy link
Copy Markdown

🎯 Overview & Context

Resolves #277 by adding the SDK's reliability layer: retry classification, transaction recovery/lookup, simulation diagnostics, and structured transaction logging with automatic secret redaction.

Stacked on #284 (feat/sdk-contract-clients → #283 → #282 → #281). Retargets to main as the stack merges.


📦 Key Features Added

1. RPC Retry Classification & Backoff (sdk/src/recovery/retry.ts)

  • isRetryable(error): boolean: Distinguishes transient RPC/network/sequencing failures (503, rate limit, txBadSeq, ETIMEDOUT) from deterministic rejections (insufficient funds, unauthorized, validation).
  • mayHaveReachedServer(error): boolean: Detects ambiguous timeouts (504 Gateway Timeout, ECONNRESET, fetch failed) where a transaction may have been accepted into the mempool.
  • withRpcRetry(fn, options): Robust exponential backoff with full jitter and onRetry callback hooks.

2. Transaction Recovery (sdk/src/recovery/lookup.ts)

  • lookupTransaction(hash, { server, timeoutMs, pollIntervalMs }): Recovers transaction outcome (pending | success | failed | timeout | not_found) without throwing raw RPC exceptions.
  • Provides standard guidance: after an ambiguous failure, callers safely check status via lookupTransaction before blindly submitting again.

3. Simulation Diagnostics (sdk/src/diagnostics/simulation.ts & diagnostics.ts)

  • summarizeSimulation(simulation): SimulationEstimate: Produces log-safe numeric summaries ({ instructions, readBytes, writeBytes, feeStroops }) while explicitly stripping raw XDR payloads to avoid leaking ledger arguments into telemetry.
  • classifyContractError(err): ContractErrorDiagnostic | null: Maps raw Soroban host error asserts to normalized typed codes (POOL_PAUSED, NOT_A_MEMBER, DEADLINE_PASSED, etc.) adhering to existing repository taxonomy.

4. Structured Transaction Logging & Redaction (sdk/src/diagnostics/logger.ts)

  • TxLogger interface & TxLogEvent covering all transaction phases: "build" | "simulate" | "sign" | "submit" | "confirm" | "error".
  • redactSensitiveData() & createSafeLogEvent(): Strips Stellar secret keys (S...) and Bearer tokens by default.
  • Reference consoleTxLogger implementation for development and testing.

🧪 Verification & Acceptance Criteria

  • All 14 test suites passed: 139/139 unit tests green (pnpm test)
  • Strict TypeScript check passed (pnpm typecheck)
  • Clean compilation output (pnpm build)
  • Public API verification passed: 173 symbols exported (pnpm check:api)

@vercel

vercel Bot commented Nov 5, 2026

Copy link
Copy Markdown

@hieuk48 is attempting to deploy a commit to the Sendi John's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

1 participant