Skip to content

feat(gateway,client): prove a raw blob's size before its first byte - #2654

Merged
thiras merged 4 commits into
mainfrom
feat/gateway-cold-blob-size-proof
Oct 28, 2026
Merged

thiras merged 4 commits into
mainfrom
feat/gateway-cold-blob-size-proof

Conversation

@thiras

@thiras thiras commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What

A raw blob that no pull on the gateway had verified (GET/HEAD /<hash>, /_decdn/<hash>) streamed with no Content-Length, ignored Range, and its HEAD had no length. A node's size claim cannot give a length: hyper stops reading a body at its Content-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 Range 206/416, 402 when it does not fit, capped pull).

  • Client: 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-mb opens nothing, so a hostile claim never sizes the work.
  • CLI fetch: BlobFetch::prove runs the proof inside fetch_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-sources lanes.
  • Gateway: blob() proves an unknown size first. A cold HEAD goes through paid(), pays for its proof, and is refused or fails as its GET would (402 / 502 / 503). Each proof counts PROOF_BYTES (16 KiB) against the allowance, including a request dropped mid-proof (ProofCharge). A proof that proves nothing streams unsized, as before.
  • Docs: adr/appendix-gateway.md (allowance, Ranges, HEAD), CHANGELOG.
  • SDK pin: .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

  • Read Streamer::prove_size (crates/client/src/streamer.rs), then the prove branch and proof_ends_fetch in crates/cli/src/commands/fetch.rs, then Gateway::prove / ProofCharge / blob / head_blob in gateway.rs.
  • Invariant kept: an unproven size never becomes Content-Length; the existing no-length tests stay and now mean "the proof proved nothing".
  • Cost: a whole GET of 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).
  • Known limits, not addressed: a lone holder that signs a wrong size stalls a cold HEAD until 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).
  • The SDK contract suite gains no raw-blob assertions: it also runs against the 0.3.0 floor and the latest release, which do not prove sizes.

Verification

  • pre-commit hooks on commit (staged files); cargo deny reports the existing advisories only
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features — clean
  • cargo 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)' with DECDN_SDK_DIR at sdk-typescript#9 — 5 passed
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items — clean
  • PR title type feat, lowercase subject
  • Public API of decdn-client: .snap regenerated (prove_size)
  • adr/: make -C adr check-refs
  • CHANGELOG.md entry

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings October 27, 2026 22:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_size and integrates proof-only requests into CLI fetch handling.
  • Proves unknown blob sizes before gateway responses, including paid cold HEAD requests 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

Comment thread crates/cli/src/commands/fetch.rs Resolved
Comment thread crates/cli/src/commands/fetch.rs Resolved
@github-code-quality

github-code-quality Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main ad3672a feat/gateway-cold-bl... e8849bf +/-
77% 77% 0%
View coverage of the 7 most impacted files.
File main ad3672a feat/gateway-cold-bl... e8849bf +/-
crates/cli/src/...mmands/fetch.rs 49% 46% -3%
crates/client/s...c/source_set.rs 94% 94% 0%
crates/client/src/scheduler.rs 94% 94% 0%
crates/node/src...gin/pull_leg.rs 84% 84% 0%
crates/node/src...nt/serve_leg.rs 90% 91% +1%
crates/client/src/streamer.rs 87% 88% +1%
crates/cli/src/...ands/gateway.rs 79% 81% +2%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 28, 2026 00:15 UTC

@thiras

thiras commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

The anvil e2e (journeys) failure was cli_fetch_topup under-paying by about 2 MiB. Cause: #2635 bumped noq-proto to 1.4.0, past the iroh/noq hold, and its stream-buffer cap (#2585) drops the connection mid-leg. main fails it locally too. The fix is #2655; this branch carries it as 12df0f8 until #2655 lands, then a rebase drops the duplicate.

thiras and others added 3 commits October 28, 2026 02:53
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]>
@thiras
thiras force-pushed the feat/gateway-cold-blob-size-proof branch from 12df0f8 to cdb2cb0 Compare October 27, 2026 23:58
@thiras
thiras merged commit a67b76e into main Oct 28, 2026
37 checks passed
@thiras
thiras deleted the feat/gateway-cold-blob-size-proof branch October 28, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants