Skip to content

fix: harden input validation, pagination clamping, and reconnect backoff - #657

Merged
Jaydbrown merged 5 commits into
conduit-protocol:mainfrom
TheCodingChef-eth:fix/reconnect-backoff-validation-issues
Sep 1, 2026
Merged

fix: harden input validation, pagination clamping, and reconnect backoff#657
Jaydbrown merged 5 commits into
conduit-protocol:mainfrom
TheCodingChef-eth:fix/reconnect-backoff-validation-issues

Conversation

@TheCodingChef-eth

Copy link
Copy Markdown
Contributor

Summary

Addresses several input-validation and resilience issues across the SDK:

  • durationSecs validation in calculateRate / calculateYield — both helpers now reject non-positive or non-integer durations early instead of silently producing incorrect rate/yield values.
  • Pagination offset clampingFactoryModule.streams_by_sender and streams_by_recipient now clamp the caller-supplied offset to a valid u32 range via the new clampOffset helper, preventing an invalid Stellar SDK conversion.
  • Batch-item amount validationvalidatePayload now accepts bigint or a decimal string parseable by toStroops (e.g. "1000" or "1.5"), instead of coercing through Number, which silently lost precision for large values.
  • WebSocket reconnect backoff — the relayer now uses exponential backoff with jitter (delay = min(maxDelay, base * 2^attempts) * random(0.5, 1)) instead of linear delay * attempts, reducing thundering-herd collisions on reconnect. A new maxReconnectDelayMs option caps the upper bound (default 30 s).

Changed files

File Change
src/utils.ts Throw on non-positive / non-integer durationSecs
src/constants.ts Add clampOffset() helper
src/factory.ts Apply clampOffset() to pagination queries
src/builder.ts Validate batch-item amount as bigint or decimal string
src/relayer/WebSocketRelayer.ts Exponential backoff + jitter; new maxReconnectDelayMs option

closes #536
closes #537
closes #538
closes #539

…uit-protocol#539)

Replace linear reconnect delay (delay * attempt) with exponential backoff
capped at maxReconnectDelayMs and randomized jitter (0.5-1.0x). Prevents
thundering herd when multiple clients reconnect after a server restart.
…onduit-protocol#538)

Replace Number-based amount validation with toStroops-based validation that
accepts bigint or decimal strings. Rejects Number inputs and scientific
notation strings that lose precision for large stroop amounts.
…tocol#537)

Add clampOffset() to validate and clamp the offset parameter in
streamsBySender/streamsByRecipient. Prevents raw stellar-sdk conversion
errors from non-integer, negative, or >2^32-1 offset values.
…nduit-protocol#536)

Add guard to reject non-integer, negative, zero, NaN, or Infinity
durationSecs inputs. Prevents raw RangeError from BigInt conversion
and negative rate/yield outputs.
@drips-wave

drips-wave Bot commented Sep 1, 2026

Copy link
Copy Markdown

@TheCodingChef-eth 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

@Jaydbrown
Jaydbrown merged commit cc52871 into conduit-protocol:main Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment