Repository navigation
feat(gateway,client): prove a raw blob's size before its first byte - #2654
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Proof-triggered pool replacement can leave retries and later requests using stale funding state, and the proof helper can exceed the configured --max-sources cap.
2 open issues
What changed in this PR
This PR adds size proofs for previously unverified raw blobs, enabling the gateway to serve their first response with a verified length and support byte ranges without trusting a node’s size claim.
Changes:
- Adds
Streamer::prove_sizeand integrates proof-only requests into CLI fetch handling. - Proves unknown blob sizes before gateway responses, including paid cold
HEADrequests and allowance accounting. - Updates tests, documentation, the public API snapshot, and the TypeScript SDK pin.
| File | Description |
|---|---|
crates/e2e/tests/gateway_public.rs |
Checks first-request ranges and accounts for proof traffic. |
crates/client/tests/snapshots/public_api__public_api.snap |
Records the new public prove_size API. |
crates/client/src/streamer/tests.rs |
Tests size claims, proof failures, and size caps. |
crates/client/src/streamer.rs |
Implements final-chunk-group size proofs. |
crates/cli/src/commands/gateway/worker/tests.rs |
Updates fetch fixtures for the proof flag. |
crates/cli/src/commands/gateway/worker.rs |
Clarifies that size lookups include proven sizes. |
crates/cli/src/commands/gateway/tests.rs |
Covers cold requests, proof charging, and funding failures. |
crates/cli/src/commands/gateway.rs |
Integrates proofs, cold HEAD handling, and allowance charges. |
crates/cli/src/commands/fetch/tests.rs |
Tests which proof errors end a fetch. |
crates/cli/src/commands/fetch.rs |
Adds proof-only fetches and shared streamer setup. |
CHANGELOG.md |
Describes first-request size and range support. |
adr/appendix-gateway.md |
Documents proof costs, fallback behavior, and HEAD semantics. |
.github/sdk-typescript.sha |
Advances the SDK pin for sized raw-blob responses. |
Review effort: Balanced
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 7 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
|
The |
A raw blob that no pull on the gateway had verified streamed with no Content-Length, ignored Range, and its HEAD had no length. A node's size claim cannot give a length: the server stops reading a body at its length, so a claim below the real size would end a short pull as a whole response. - Client: Streamer::prove_size pays for the last chunk group under a size claim and returns the size a leg proved. Only the true size verifies a final chunk (ADR 039), so a claim off by less than one group proves the true size, and any other claim proves nothing. A claim past the cap on held bytes opens nothing. - CLI fetch: BlobFetch::prove runs the proof in fetch_on and records a proven size with the verified sizes. A fault the following pull would reach again (classify: command-fatal, or a give-up) ends the fetch; any other leaves the size unproven. A pool replacement reruns the proof, which writes no byte. - Gateway: blob() proves an unknown size first, then takes the sized path (length, one Range 206/416, 402 when it does not fit, capped pull). A cold HEAD goes through paid() and pays for its proof, refused or failed as its GET would be. Each proof counts PROOF_BYTES (one chunk group) against the allowance, a request dropped mid-proof included (ProofCharge). A proof that proves nothing streams unsized, as before. - Tests: client proof cases (true, low, high, within the last group, past the cap, a lying source), proof error classification, gateway cold GET/Range/416/402/HEAD/drop/bucket/funding/loopback/retired-capability cases, and gateway_public opens a never-fetched blob with a Range. - ADR appendix-gateway, CHANGELOG, and the TypeScript SDK pin (decdn/sdk-typescript#9: the fake answers a raw blob with its size). Closes #2645 Closes #2616 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…p its lanes - A size proof no longer runs its pass again on a pool replacement. The gateway's pool payer shares one RunFunding across fetches, and its pool is written once, so a rerun paid from stale funding facts, and the worker, which never saw the PoolReplaced, kept the retired payer for later requests. The replacement now ends the proof's fetch as it ends a pull's, and the worker rebuilds the pool payer. - The proof runs on at most --max-sources lanes, as the stream does, instead of the client's default lane cap. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ndow fixes Co-Authored-By: Claude Opus 5.5 <[email protected]>
12df0f8 to
cdb2cb0
Compare
…dk-typescript#9) Co-Authored-By: Claude Opus 5.5 <[email protected]>


What
A raw blob that no pull on the gateway had verified (
GET/HEAD /<hash>,/_decdn/<hash>) streamed with noContent-Length, ignoredRange, and itsHEADhad no length. A node's size claim cannot give a length: hyper stops reading a body at itsContent-Length, so a claim below the real size would end a short pull as a whole response. #2646 covered blobs a whole pull had verified; this covers the first request.Before it answers such a blob, the gateway now proves its size: it pays for the last chunk group under the first node's size claim, and only the true size verifies a final chunk (ADR 039 § Failure handling). The proven size joins the verified sizes, and the existing sized path does the rest (length, one
Range206/416, 402 when it does not fit, capped pull).Streamer::prove_size(new public API). A claim off by less than one chunk group proves the true size; any other claim proves nothing; a claim past--max-blob-mbopens nothing, so a hostile claim never sizes the work.BlobFetch::proveruns the proof insidefetch_on. A fault the following pull would reach again (classify→ command-fatal, or a give-up) ends the fetch; any other only leaves the size unproven. A pool replacement ends the proof's fetch as it ends a pull's, so the worker rebuilds the pool payer. The proof runs on at most--max-sourceslanes.blob()proves an unknown size first. A coldHEADgoes throughpaid(), pays for its proof, and is refused or fails as itsGETwould (402 / 502 / 503). Each proof countsPROOF_BYTES(16 KiB) against the allowance, including a request dropped mid-proof (ProofCharge). A proof that proves nothing streams unsized, as before.adr/appendix-gateway.md(allowance, Ranges, HEAD), CHANGELOG..github/sdk-typescript.sha→ test(fake-gateway): answer a raw blob with its proven size, as the gateway does sdk-typescript#9 (its fake answers a raw blob with its size). It points at ADR 003: Legacy PaymentChannel interaction during migration is underspecified #9's merge commit (16ff1cb).Closes #2645
Closes #2616
Reviewer notes
Streamer::prove_size(crates/client/src/streamer.rs), then the prove branch andproof_ends_fetchincrates/cli/src/commands/fetch.rs, thenGateway::prove/ProofCharge/blob/head_blobingateway.rs.Content-Length; the existing no-length tests stay and now mean "the proof proved nothing".GETof a new blob pays its last chunk group twice (proof, then pull) plus one extra open. A proof that proves nothing keeps nothing, and concurrent cold requests each prove (no coalescing).HEADuntil give-up (a whole pull from it stalls the same way); with no probe size hint, the whole-blob open that learns the claim is closed unread by the proof (same class as client: a streamed fetch with no size hint still drops the pull it opened for the size #2644).Verification
cargo denyreports the existing advisories onlyCARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features— cleancargo nextest run -p decdn-client -p decdn-cli— 2340 passed (full workspace run left to CI)cargo nextest run -p decdn-e2e --features anvil-e2e,sdk-e2e -E 'binary(gateway_public) | binary(gateway_concurrent_pulls) | binary(gateway_pointer) | binary(gateway_sdk)'withDECDN_SDK_DIRat sdk-typescript#9 — 5 passedCARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items— cleanfeat, lowercase subjectdecdn-client:.snapregenerated (prove_size)adr/:make -C adr check-refsCHANGELOG.mdentry🤖 Generated with Claude Code