Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions packages/sdk/src/wasm-client-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,15 @@ export function createSyncController(ctx: Pick<WasmClientContext, "onProgress" |
}
}
const tuned = syncTuning(ctx.localLight, ctx.syncOpts);
const shieldedPrefetch = ctx.grpcWeb
? grpcWebPrefetch(scanWorkerRuntime()?.threads, runtime.radioConstrained())
: ctx.lwdPipe
? pipePrefetch(runtime.radioConstrained())
: tuned.prefetch;
// Private Cloud can send two 500-block reads for each batch. Allow up to
// eight batches while the prefetch byte budget limits memory in flight.
const shieldedPrefetch = ctx.transport.kind === "private-cloud"
? 8
: ctx.grpcWeb
? grpcWebPrefetch(scanWorkerRuntime()?.threads, runtime.radioConstrained())
: ctx.lwdPipe
? pipePrefetch(runtime.radioConstrained())
: tuned.prefetch;
// Dense all-pool ranges can exceed 14 MB per 1k blocks. Sixteen requests
// queue behind browser sockets/Zaino and exhaust their response deadlines.
// Bound both range size and concurrency, keeping the same checkpoint span.
Expand Down
33 changes: 33 additions & 0 deletions packages/sdk/test/lifecycle-review.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,39 @@ test("a sync event cancelling progress prevents its subsequent balance event", a
assert.deepEqual(emitted, ["progress", "sync"]);
});

test("Private Cloud keeps fetching through a slow scan within the bounded queue", { timeout: 5000 }, async t => {
fixture(t);
const scanner = new CrashScanFixture();
await attachScanWorker(scanner as unknown as Worker, { threads: 1, preferMulticore: false });
const requests: Array<[number, number]> = [];
const c = client({
kind: "private-cloud",
label: "Private Cloud",
maxBlocksPerRequest: 1000,
tip: async () => 30_010,
blocks: async (start, end) => {
requests.push([start, end]);
return new Uint8Array([1]);
},
});
await c.restore("private-cloud-prefetch", "regtest", 1);
scanner.hold = "applyBlob";
const syncing = c.sync();
const rejected = assert.rejects(syncing, /cancelled|aborted|AbortError/i);
try {
for (let i = 0; i < 10 && requests.length < 12; i++) await turn();
assert.ok(scanner.held, "the sequential scan is still applying its first block range");
assert.deepEqual(requests.slice(0, 12), Array.from({ length: 12 }, (_, i) =>
[11 + 1000 * i, 1010 + 1000 * i],
));
assert.ok(requests.length <= 17, "the sixteen-range queue and one yielded range bound work");
} finally {
cancelWasmSync();
if (scanner.held) scanner.release();
await rejected;
}
});

test("post-scan mempool cancellation rejects promptly and discards a late provider result", async t => {
const { db } = fixture(t);
const scanner = new ScanFixture();
Expand Down
Loading