From 79404e072c8e27c1f7093bd2b0eb7434e8ac71dd Mon Sep 17 00:00:00 2001 From: aladuru001 Date: Tue, 24 Nov 2026 17:52:06 +0000 Subject: [PATCH] feat(timeout): bound every external request with one shared default SDK, keeper, appraisal and Drand clients each had their own (or no) request timeout, so a hung peer could stall a component indefinitely. Add DEFAULT_REQUEST_TIMEOUT_MS (10s), resolveRequestTimeoutMs (integer, 100-300000ms; invalid values throw rather than disabling the bound), RequestTimeoutError and fetchWithTimeout to @sub-rosa/time, and use them: - SubRosaClient passes the timeout to every rpc.Server (new rpcTimeoutMs) - mainnet-readiness RPC servers use the default - StatusClient default now references the shared constant - createPaidFetch bounds the probe and paid retry (new requestTimeoutMs) - drand-tools quicknet requests are bounded Documented in docs/INTEGRATION.md and the keeper README. Closes #534 Co-Authored-By: Claude Sonnet 5.5 --- docs/INTEGRATION.md | 21 +++++ packages/sdk/src/client.ts | 24 ++++- packages/sdk/src/errors.test.ts | 15 ++++ packages/sdk/src/mainnet-readiness.ts | 5 +- packages/sdk/src/status-client.ts | 4 +- packages/time/package.json | 2 +- packages/time/src/index.ts | 9 ++ packages/time/src/request-timeout.test.ts | 103 ++++++++++++++++++++++ packages/time/src/request-timeout.ts | 92 +++++++++++++++++++ pnpm-lock.yaml | 3 + services/appraisal-api/src/client.test.ts | 32 +++++++ services/appraisal-api/src/client.ts | 22 +++-- services/drand-tools/package.json | 1 + services/drand-tools/src/quicknet.ts | 6 +- services/keeper/README.md | 6 ++ 15 files changed, 330 insertions(+), 15 deletions(-) create mode 100644 packages/time/src/request-timeout.test.ts create mode 100644 packages/time/src/request-timeout.ts diff --git a/docs/INTEGRATION.md b/docs/INTEGRATION.md index 3669ff46..f2859cae 100644 --- a/docs/INTEGRATION.md +++ b/docs/INTEGRATION.md @@ -112,6 +112,27 @@ Preflight results include: Existing submit methods are unchanged; preflight is optional and does not require live signing credentials beyond a source `publicKey` (or `secretKey`). +## External request timeouts + +Every external request the SDK, keeper, appraisal client and Drand tooling +make is bounded by one shared default, `DEFAULT_REQUEST_TIMEOUT_MS` +(**10 000 ms**, exported from `@sub-rosa/time`), so a hung peer cannot stall a +component indefinitely. A per-call override must be an integer between +**100 and 300 000 ms**; `0`, `NaN` and out-of-range values are rejected +rather than silently disabling the bound. + +| Client | Where the bound applies | Override | +| ------ | ----------------------- | -------- | +| `SubRosaClient` (Soroban RPC, also used by the keeper) | each RPC request | `rpcTimeoutMs` | +| `StatusClient` (keeper status API) | each status request | `timeoutMs` | +| `createPaidFetch` (appraisal API) | the probe and the paid retry | `requestTimeoutMs` | +| `drand-tools` quicknet helpers | each Drand HTTP request | none (default) | + +`fetchWithTimeout` aborts the request and rejects with `RequestTimeoutError` +(never including the URL, which may carry credentials). The timer covers +connecting and receiving response headers; `confirmTimeout` is a separate, +longer bound on transaction finality polling. + ## Auditor identity recovery CLI For pilots that need machine-readable selective-disclosure evidence, recover diff --git a/packages/sdk/src/client.ts b/packages/sdk/src/client.ts index 03e78d30..af6f843a 100644 --- a/packages/sdk/src/client.ts +++ b/packages/sdk/src/client.ts @@ -67,6 +67,7 @@ import { type PasskeySessionBinding, } from "./network.js"; import { + resolveRequestTimeoutMs, resolveTimeContext, systemTime, type Clock, @@ -106,6 +107,11 @@ export interface SubRosaClientConfig { * using an external submitter. Must be at least 100. Default: 1_500. */ pollInterval?: number; + /** + * Timeout (ms) for each Soroban RPC request. Integer between 100 and 300_000. + * Default: the shared `DEFAULT_REQUEST_TIMEOUT_MS` (10_000). + */ + rpcTimeoutMs?: number; /** Injectable wall clock and scheduler. Default: systemTime. */ time?: PartialTimeContext; /** @@ -204,6 +210,7 @@ export class SubRosaClient { readonly #submitter?: TransactionSubmitter; readonly #confirmTimeout: number; readonly #pollInterval: number; + readonly #rpcTimeoutMs: number; readonly #assetConfig?: import("./asset-config.js").AssetConfig; readonly #clock: Clock; readonly #scheduler: Scheduler; @@ -235,6 +242,15 @@ export class SubRosaClient { ); } + let rpcTimeoutMs: number; + try { + rpcTimeoutMs = resolveRequestTimeoutMs(config.rpcTimeoutMs); + } catch (error) { + throw new SubRosaClientConfigError( + `rpcTimeoutMs: ${error instanceof Error ? error.message : String(error)}`, + ); + } + const keypair = config.secretKey ? Keypair.fromSecret(config.secretKey) : undefined; @@ -251,13 +267,14 @@ export class SubRosaClient { this.#submitter = config.submitter; this.#confirmTimeout = confirmTimeout; this.#pollInterval = pollInterval; + this.#rpcTimeoutMs = rpcTimeoutMs; this.#assetConfig = config.assetConfig; const time = resolveTimeContext(systemTime, config.time); this.#clock = time.clock; this.#scheduler = time.scheduler; this.#session = config.session; - this.#server = config._server ?? new rpc.Server(config.rpcUrl, { allowHttp }); + this.#server = config._server ?? new rpc.Server(config.rpcUrl, { allowHttp, timeout: rpcTimeoutMs }); if (config._sleep) this.#sleep = config._sleep; else this.#sleep = (ms) => this.#scheduler.sleep(ms); @@ -393,7 +410,10 @@ export class SubRosaClient { { cause: e }, ); } - const server = new rpc.Server(this.#rpcUrl, { allowHttp: this.#allowHttp }); + const server = new rpc.Server(this.#rpcUrl, { + allowHttp: this.#allowHttp, + timeout: this.#rpcTimeoutMs, + }); const deadline = this.#clock.nowMs() + this.#confirmTimeout; let lastStatus = "NOT_FOUND"; while (this.#clock.nowMs() < deadline) { diff --git a/packages/sdk/src/errors.test.ts b/packages/sdk/src/errors.test.ts index 7ac7b2e2..6205161f 100644 --- a/packages/sdk/src/errors.test.ts +++ b/packages/sdk/src/errors.test.ts @@ -169,6 +169,21 @@ describe("SubRosaClientConfig validation", () => { } }); + it("rejects an rpcTimeoutMs outside the shared 100-300000 ms range", () => { + for (const rpcTimeoutMs of [0, 99, 1.5, Number.NaN, 300_001]) { + assert.throws( + () => new SubRosaClient({ ...BASE_CONFIG, rpcTimeoutMs }), + (e) => e instanceof SubRosaClientConfigError && /rpcTimeoutMs/.test(e.message), + String(rpcTimeoutMs), + ); + } + }); + + it("accepts the default and an explicit rpcTimeoutMs", () => { + assert.doesNotThrow(() => new SubRosaClient(BASE_CONFIG)); + assert.doesNotThrow(() => new SubRosaClient({ ...BASE_CONFIG, rpcTimeoutMs: 2_500 })); + }); + it("accepts confirmTimeout = 1000", () => { assert.doesNotThrow( () => new SubRosaClient({ ...BASE_CONFIG, confirmTimeout: 1000 }), diff --git a/packages/sdk/src/mainnet-readiness.ts b/packages/sdk/src/mainnet-readiness.ts index e02a57ab..50d1cb49 100644 --- a/packages/sdk/src/mainnet-readiness.ts +++ b/packages/sdk/src/mainnet-readiness.ts @@ -10,6 +10,7 @@ import { TransactionBuilder, } from "@stellar/stellar-sdk"; import type { BidState, GlobalConfig, Round, Status } from "@sub-rosa/round-bindings"; +import { DEFAULT_REQUEST_TIMEOUT_MS } from "@sub-rosa/time"; import type { SubRosaClient } from "./client.js"; import { @@ -465,7 +466,7 @@ export function createSacBalanceReader( tokenSacId: string, sourcePublicKey: string, ): (address: string) => Promise { - const server = new rpc.Server(rpcUrl); + const server = new rpc.Server(rpcUrl, { timeout: DEFAULT_REQUEST_TIMEOUT_MS }); const sac = new Contract(tokenSacId); return async (address: string): Promise => { const source = new Account(sourcePublicKey, "0"); @@ -967,7 +968,7 @@ export async function runMainnetReadiness( } // ── Live: read the deployment through the read-only client ─────────────── - const rpcServer = deps.rpc ?? new rpc.Server(input.rpcUrl); + const rpcServer = deps.rpc ?? new rpc.Server(input.rpcUrl, { timeout: DEFAULT_REQUEST_TIMEOUT_MS }); try { await rpcServer.getHealth(); diff --git a/packages/sdk/src/status-client.ts b/packages/sdk/src/status-client.ts index 90a736ba..904fc62c 100644 --- a/packages/sdk/src/status-client.ts +++ b/packages/sdk/src/status-client.ts @@ -5,7 +5,7 @@ // and return stable typed JSON (see ../status.ts). import { normalizeError } from "@sub-rosa/logging/errors"; -import { systemScheduler, type Scheduler } from "@sub-rosa/time"; +import { DEFAULT_REQUEST_TIMEOUT_MS, systemScheduler, type Scheduler } from "@sub-rosa/time"; import { assertNoUrlCredentials } from "./network.js"; import type { KeeperHealthResponse, @@ -120,7 +120,7 @@ export class KeeperStatusClient { this.baseURL = opts.baseURL; this.fetchImpl = opts.fetchImpl ?? globalThis.fetch; this.headers = opts.headers ?? {}; - this.timeoutMs = opts.timeoutMs ?? 10_000; + this.timeoutMs = opts.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS; this.scheduler = opts.scheduler ?? systemScheduler; this.contractId = opts.contractId; this.roundId = opts.roundId === undefined ? undefined : String(opts.roundId); diff --git a/packages/time/package.json b/packages/time/package.json index 6efcbd07..901a35ea 100644 --- a/packages/time/package.json +++ b/packages/time/package.json @@ -15,7 +15,7 @@ ".": "./src/index.ts" }, "scripts": { - "test": "node --import tsx --test src/clock.test.ts src/scheduler.test.ts src/fake.test.ts src/boundary.test.ts", + "test": "node --import tsx --test src/clock.test.ts src/scheduler.test.ts src/fake.test.ts src/boundary.test.ts src/request-timeout.test.ts", "typecheck": "tsc --noEmit -p tsconfig.json" }, "devDependencies": { diff --git a/packages/time/src/index.ts b/packages/time/src/index.ts index 978259c3..c2beebd9 100644 --- a/packages/time/src/index.ts +++ b/packages/time/src/index.ts @@ -8,3 +8,12 @@ export { } from "./system.js"; export { FakeClock } from "./fake-clock.js"; export { FakeScheduler, createFakeTime } from "./fake-scheduler.js"; +export { + DEFAULT_REQUEST_TIMEOUT_MS, + MAX_REQUEST_TIMEOUT_MS, + MIN_REQUEST_TIMEOUT_MS, + RequestTimeoutError, + fetchWithTimeout, + resolveRequestTimeoutMs, +} from "./request-timeout.js"; +export type { FetchWithTimeoutOptions } from "./request-timeout.js"; diff --git a/packages/time/src/request-timeout.test.ts b/packages/time/src/request-timeout.test.ts new file mode 100644 index 00000000..e8969c65 --- /dev/null +++ b/packages/time/src/request-timeout.test.ts @@ -0,0 +1,103 @@ +import { describe, it } from "node:test"; +import assert from "node:assert/strict"; + +import { + DEFAULT_REQUEST_TIMEOUT_MS, + RequestTimeoutError, + createFakeTime, + fetchWithTimeout, + resolveRequestTimeoutMs, +} from "./index.js"; + +/** A fetch that never answers and rejects when its signal aborts. */ +const hangingFetch: typeof fetch = (_input, init) => + new Promise((_resolve, reject) => { + init?.signal?.addEventListener("abort", () => reject(init.signal?.reason), { once: true }); + }); + +describe("shared request timeout", () => { + it("defaults to a single 10s bound", () => { + assert.equal(DEFAULT_REQUEST_TIMEOUT_MS, 10_000); + assert.equal(resolveRequestTimeoutMs(), 10_000); + assert.equal(resolveRequestTimeoutMs(2_500), 2_500); + }); + + it("rejects values that would disable or distort the bound", () => { + for (const bad of [0, -1, 99, 1.5, Number.NaN, Number.POSITIVE_INFINITY, 300_001]) { + assert.throws(() => resolveRequestTimeoutMs(bad), RangeError, String(bad)); + } + }); + + it("aborts a hung request with RequestTimeoutError after the default timeout", async () => { + const { scheduler } = createFakeTime(); + const pending = fetchWithTimeout("https://example.invalid/x", {}, { fetchImpl: hangingFetch, scheduler }); + const outcome = pending.then( + () => "resolved", + (e: unknown) => e, + ); + + scheduler.advance(DEFAULT_REQUEST_TIMEOUT_MS - 1); + await Promise.resolve(); + assert.equal(scheduler.pendingCount(), 1, "still waiting just before the deadline"); + + scheduler.advance(1); + const error = await outcome; + assert.ok(error instanceof RequestTimeoutError); + assert.equal(error.timeoutMs, DEFAULT_REQUEST_TIMEOUT_MS); + assert.match(error.message, /timed out after 10000ms/); + assert.doesNotMatch(error.message, /example\.invalid/, "must not leak the URL"); + }); + + it("honours a per-call timeout override", async () => { + const { scheduler } = createFakeTime(); + const outcome = fetchWithTimeout("https://x.invalid", {}, { fetchImpl: hangingFetch, scheduler, timeoutMs: 250 }).then( + () => "resolved", + (e: unknown) => e, + ); + scheduler.advance(250); + const error = await outcome; + assert.ok(error instanceof RequestTimeoutError); + assert.equal(error.timeoutMs, 250); + }); + + it("clears the timer when the request succeeds", async () => { + const { scheduler } = createFakeTime(); + const ok: typeof fetch = async () => new Response("{}", { status: 200 }); + const res = await fetchWithTimeout("https://x.invalid", {}, { fetchImpl: ok, scheduler }); + assert.equal(res.status, 200); + assert.equal(scheduler.pendingCount(), 0); + }); + + it("clears the timer and rethrows a non-timeout failure unchanged", async () => { + const { scheduler } = createFakeTime(); + const boom = new Error("connect refused"); + const failing: typeof fetch = async () => { + throw boom; + }; + await assert.rejects(fetchWithTimeout("https://x.invalid", {}, { fetchImpl: failing, scheduler }), (e) => e === boom); + assert.equal(scheduler.pendingCount(), 0); + }); + + it("preserves a caller abort instead of reporting a timeout", async () => { + const { scheduler } = createFakeTime(); + const caller = new AbortController(); + const reason = new Error("caller cancelled"); + const outcome = fetchWithTimeout("https://x.invalid", { signal: caller.signal }, { fetchImpl: hangingFetch, scheduler }).then( + () => "resolved", + (e: unknown) => e, + ); + caller.abort(reason); + assert.equal(await outcome, reason); + assert.equal(scheduler.pendingCount(), 0); + }); + + it("rejects immediately when the caller signal is already aborted", async () => { + const { scheduler } = createFakeTime(); + const caller = new AbortController(); + caller.abort(); + await assert.rejects( + fetchWithTimeout("https://x.invalid", { signal: caller.signal }, { fetchImpl: hangingFetch, scheduler }), + ); + assert.equal(scheduler.pendingCount(), 0); + }); +}); diff --git a/packages/time/src/request-timeout.ts b/packages/time/src/request-timeout.ts new file mode 100644 index 00000000..0a0cf1a9 --- /dev/null +++ b/packages/time/src/request-timeout.ts @@ -0,0 +1,92 @@ +import { systemScheduler } from "./system.js"; +import type { Scheduler } from "./types.js"; + +/** + * Shared default timeout (ms) for every external request the SDK, keeper, + * appraisal client and Drand tooling make. One value, so a hung peer cannot + * stall one component indefinitely while another gives up. + */ +export const DEFAULT_REQUEST_TIMEOUT_MS = 10_000; + +/** Smallest accepted per-request timeout override (ms). */ +export const MIN_REQUEST_TIMEOUT_MS = 100; + +/** Largest accepted per-request timeout override (ms). */ +export const MAX_REQUEST_TIMEOUT_MS = 300_000; + +/** Raised when an external request does not answer within its timeout. */ +export class RequestTimeoutError extends Error { + readonly name = "RequestTimeoutError"; + readonly timeoutMs: number; + + constructor(timeoutMs: number) { + super(`request timed out after ${timeoutMs}ms`); + this.timeoutMs = timeoutMs; + } +} + +/** + * Resolve a timeout override. `undefined` yields the shared default; anything + * that is not a finite integer within [MIN, MAX] throws a `RangeError` so a + * typo (`0`, `NaN`, `1e9`) can never silently disable the bound. + */ +export function resolveRequestTimeoutMs(value?: number): number { + if (value === undefined) return DEFAULT_REQUEST_TIMEOUT_MS; + if ( + !Number.isInteger(value) || + value < MIN_REQUEST_TIMEOUT_MS || + value > MAX_REQUEST_TIMEOUT_MS + ) { + throw new RangeError( + `request timeout must be an integer between ${MIN_REQUEST_TIMEOUT_MS} and ${MAX_REQUEST_TIMEOUT_MS} ms, got ${value}`, + ); + } + return value; +} + +export interface FetchWithTimeoutOptions { + /** Timeout in ms. Default: {@link DEFAULT_REQUEST_TIMEOUT_MS}. */ + timeoutMs?: number; + /** Fetch implementation. Default: `globalThis.fetch`. */ + fetchImpl?: typeof fetch; + /** Scheduler used for the timer. Default: the system scheduler. */ + scheduler?: Scheduler; +} + +/** + * `fetch` bounded by a timeout. The timer covers connecting and receiving the + * response headers; it aborts the request and rejects with + * {@link RequestTimeoutError}. A caller `init.signal` still cancels the request + * and its own abort reason is preserved. The error never includes the URL, + * which may carry credentials. + */ +export async function fetchWithTimeout( + input: Parameters[0], + init: RequestInit = {}, + options: FetchWithTimeoutOptions = {}, +): Promise { + const timeoutMs = resolveRequestTimeoutMs(options.timeoutMs); + const scheduler = options.scheduler ?? systemScheduler; + const fetchImpl = options.fetchImpl ?? globalThis.fetch; + const callerSignal = init.signal ?? undefined; + + if (callerSignal?.aborted) { + throw callerSignal.reason ?? new DOMException("Aborted", "AbortError"); + } + + const controller = new AbortController(); + const timeoutError = new RequestTimeoutError(timeoutMs); + const onCallerAbort = () => controller.abort(callerSignal?.reason); + callerSignal?.addEventListener("abort", onCallerAbort, { once: true }); + const timer = scheduler.setTimeout(() => controller.abort(timeoutError), timeoutMs); + + try { + return await fetchImpl(input, { ...init, signal: controller.signal }); + } catch (error) { + if (controller.signal.reason === timeoutError) throw timeoutError; + throw error; + } finally { + scheduler.clear(timer); + callerSignal?.removeEventListener("abort", onCallerAbort); + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dc95928c..6a87fb69 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -300,6 +300,9 @@ importers: '@sub-rosa/logging': specifier: workspace:* version: link:../../packages/logging + '@sub-rosa/time': + specifier: workspace:* + version: link:../../packages/time devDependencies: '@sub-rosa/tlock': specifier: workspace:* diff --git a/services/appraisal-api/src/client.test.ts b/services/appraisal-api/src/client.test.ts index cbe39e33..9f3607ad 100644 --- a/services/appraisal-api/src/client.test.ts +++ b/services/appraisal-api/src/client.test.ts @@ -3,6 +3,7 @@ import { createHash } from "node:crypto"; import { x402HTTPClient } from "@x402/core/client"; import { Keypair } from "@stellar/stellar-sdk"; import { describe, test } from "node:test"; +import { RequestTimeoutError } from "@sub-rosa/time"; import { createPaidFetch, X402PaymentError, AppraisalResponseParseError, MAX_PAYMENT_ERROR_DIAGNOSTIC_LENGTH, sanitizePaymentErrorDiagnostic } from "./client.js"; @@ -294,3 +295,34 @@ describe("createPaidFetch response parsing", () => { } }); }); + +describe("createPaidFetch request timeout", () => { + test("a hung probe request fails with RequestTimeoutError instead of hanging", async () => { + const paidFetch = createPaidFetch({ secret: TEST_SECRET, requestTimeoutMs: 100 }); + const originalFetch = globalThis.fetch; + globalThis.fetch = (_url, init) => + new Promise((_resolve, reject) => { + init?.signal?.addEventListener("abort", () => reject(init.signal?.reason), { once: true }); + }); + try { + await assert.rejects( + paidFetch("https://example.com/appraise", { method: "POST", body: "{}" }), + (error: unknown) => + error instanceof RequestTimeoutError && error.timeoutMs === 100, + ); + } finally { + globalThis.fetch = originalFetch; + } + }); + + test("rejects an invalid requestTimeoutMs rather than disabling the bound", async () => { + const paidFetch = createPaidFetch({ secret: TEST_SECRET, requestTimeoutMs: 0 }); + const originalFetch = globalThis.fetch; + globalThis.fetch = async () => buildResponse(200, "{}"); + try { + await assert.rejects(paidFetch("https://example.com/appraise", { method: "POST", body: "{}" }), RangeError); + } finally { + globalThis.fetch = originalFetch; + } + }); +}); diff --git a/services/appraisal-api/src/client.ts b/services/appraisal-api/src/client.ts index a6cd1cfe..36c54a3a 100644 --- a/services/appraisal-api/src/client.ts +++ b/services/appraisal-api/src/client.ts @@ -11,7 +11,7 @@ import { x402Client, x402HTTPClient } from "@x402/core/client"; import type { Network, PaymentRequired, SettleResponse } from "@x402/core/types"; import { createEd25519Signer } from "@x402/stellar"; import { ExactStellarScheme as ClientStellarScheme } from "@x402/stellar/exact/client"; -import { systemClock } from "@sub-rosa/time"; +import { fetchWithTimeout, systemClock } from "@sub-rosa/time"; import { assertAppraisalBodyBytes, @@ -26,6 +26,12 @@ export interface PaidClientConfig { network?: Network; /** Optional custom Soroban RPC URL. */ rpcUrl?: string; + /** + * Timeout (ms) applied to each HTTP request the client makes (the probe and + * the paid retry). Integer between 100 and 300_000. Default: the shared + * `DEFAULT_REQUEST_TIMEOUT_MS` (10_000). + */ + requestTimeoutMs?: number; /** * Expected payment quote. When set, the 402 offer is validated before any * signed payment is built: asset/destination must match, amount must be @@ -509,7 +515,7 @@ export function createPaidFetch(config: PaidClientConfig) { // oversized / credential-like bodies still fail here with no payment. assertPaidRequestBodyAllowed(init, { requireBody: false }); - const first = await fetch(url, init); + const first = await fetchWithTimeout(url, init, { timeoutMs: config.requestTimeoutMs }); if (first.status !== 402) { return { status: first.status, body: await parseJsonResponse(first) }; } @@ -562,10 +568,14 @@ export function createPaidFetch(config: PaidClientConfig) { const payload = await http.createPaymentPayload(paymentRequired); const payHeaders = http.encodePaymentSignatureHeader(payload); - const paid = await fetch(url, { - ...init, - headers: { ...(init.headers ?? {}), ...payHeaders }, - }); + const paid = await fetchWithTimeout( + url, + { + ...init, + headers: { ...(init.headers ?? {}), ...payHeaders }, + }, + { timeoutMs: config.requestTimeoutMs }, + ); const body = await parseJsonResponse(paid); if (paid.status !== 200) { diff --git a/services/drand-tools/package.json b/services/drand-tools/package.json index b0c1d6f1..c2a71ba9 100644 --- a/services/drand-tools/package.json +++ b/services/drand-tools/package.json @@ -16,6 +16,7 @@ }, "dependencies": { "@sub-rosa/logging": "workspace:*", + "@sub-rosa/time": "workspace:*", "@noble/curves": "^2.2.0", "@noble/hashes": "^2.2.0" }, diff --git a/services/drand-tools/src/quicknet.ts b/services/drand-tools/src/quicknet.ts index 768a4c52..a5464d2c 100644 --- a/services/drand-tools/src/quicknet.ts +++ b/services/drand-tools/src/quicknet.ts @@ -2,6 +2,8 @@ // Live Drand quicknet access. No hardcoded beacons — everything is fetched from // the public API so the harness validates against the real network. +import { fetchWithTimeout } from "@sub-rosa/time"; + export const QUICKNET_HASH = "52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971"; @@ -22,13 +24,13 @@ export interface Beacon { } export async function getChainInfo(): Promise { - const res = await fetch(`${API}/${QUICKNET_HASH}/info`); + const res = await fetchWithTimeout(`${API}/${QUICKNET_HASH}/info`); if (!res.ok) throw new Error(`info HTTP ${res.status}`); return (await res.json()) as ChainInfo; } export async function getBeacon(round: number | "latest"): Promise { - const res = await fetch(`${API}/${QUICKNET_HASH}/public/${round}`); + const res = await fetchWithTimeout(`${API}/${QUICKNET_HASH}/public/${round}`); if (!res.ok) throw new Error(`beacon ${round} HTTP ${res.status}`); return (await res.json()) as Beacon; } diff --git a/services/keeper/README.md b/services/keeper/README.md index 6b56e660..06431e87 100644 --- a/services/keeper/README.md +++ b/services/keeper/README.md @@ -114,6 +114,12 @@ Response shape (typed in `@sub-rosa/sdk` as `KeeperStatusResponse`): - `/healthz` returns `200` only when both RPC and Drand respond. Any error → `503`. Cheap enough for a liveness probe. - `/status/health` returns the same health shape plus a timestamp, but runs the full round-building pass (more RPC load — use for readiness, not liveness). +## Request timeouts + +The keeper reaches Soroban RPC through `SubRosaClient`, so each RPC request is +bounded by the shared default of 10 000 ms (`rpcTimeoutMs` overrides it, 100 to +300 000 ms). See [External request timeouts](../../docs/INTEGRATION.md#external-request-timeouts). + ## Pilot deployment notes 1. **Run `serve`, not `watch`, in production.** The combined process gives you the status API alongside the keeper loop. Both share the same RPC budget and the same persisted store.