Repository navigation
fix(client-pull): one receive loop — verify every chunk group as it lands on every path - #1994
Merged
Merged
Conversation
…ands on every path The buffered `stream_fetch*` receiver drained the whole wire stream into a buffer, releasing a 1 MiB reveal per chunk as bytes landed, and only ran the bao decoder after `StreamEnd`. A provider that signed an inflated `total_bytes` and streamed framed garbage was therefore paid for the whole claim (bounded only by `max_blob_size_mb`) before a single byte verified. The progressive path verified each group as it arrived, so exposure depended on which receiver a caller happened to use. Delete the buffered receiver (`fetch_inner_once`, `receive_and_pay`, `decode_verified_range`). The `stream_fetch*` family survives only as `test-util` in-memory wrappers over the one receive loop (`open_progressive_pull` → `UpstreamPull` → `PullReader` → the bao `ResponseDecoder`), so a corrupt group aborts the pull at that group on every path; what a lying peer can bill is the bytes that arrived before its first unverifiable group, never its claim. `UpstreamPull::next_chunk` absorbs the two guards only the buffered loop had: the received-byte ceiling (#1895) as a wire bound checked before the crossing chunk is paid (`open_progressive_pull` takes `max_blob_size_bytes`; every caller passes its ceiling), and the voucher-write recovery that prefers a terminal `StreamEnd` / `StreamError` over the opaque write failure a node's end-of-stream `STOP_SENDING(0)` produces. `bao_encoded_size` gains an `O(log groups)` closed form for the group-aligned contiguous ranges `align_range` produces, property-tested against the encoder walk. The walk is `O(groups)` — 67M groups for the CLI's default 1 TiB ceiling or for any peer-claimed `total_bytes` in that range — and stalled the pull past the node's voucher wait before the first byte. Tests: two loopback tests pin the exposure bound against an inflated-garbage provider (zero paid below one metering interval; ≤ one frame above it), one pins the empty-claim-for-a-non-empty-hash rejection, and the `decode_verified_range` unit tests port onto the shared in-memory decoder. Stale prose naming the buffered path, `stream_fetch` as the production requester, or wire-byte progress units is rewritten to describe the one loop. Closes #1985 Co-Authored-By: Claude Opus 5 <[email protected]>
Coverage reportTotal: 82.68% (was 82.67%, ▲ +0.01%) — 76508/92538 lines
History
|
…guard, exposure tests Tag the hash-chain rollover contradiction as a local fault so the voucher-write recovery can never rescue it into a clean completion; carry what the recovery read saw into the write error's context; state the resume-offset-past-ceiling check directly instead of mapping every alignment error to `BlobTooLarge`. `driver::drive` proves a `total_bytes == 0` claim against the empty root before the empty store can be finalized — the one verify site the gap-driven path had none of, so a holder could complete `decdn fetch <non-empty hash>` with an empty file. Tests: honest-prefix-then-garbage exposure bound (payment for verified groups coexists with the cut-off), the mid-stream straddling overrun guard, the received-byte ceiling on a gap-scoped leg anchored at its own offset, a multi-group exact-ceiling blob, the driver's empty-claim guard both ways; the window pull-through ceiling bound tightens to the ceiling's own wire; the progress test pins content bytes as the unit. Prose: the CLI progress bar and `ProgressCallback` consumers describe content bytes; `HashMismatch` names its actual returners; stale `stream_fetch` / buffered-path references in tests, `sink.rs`, and ADR 038 §Receive side describe the one receive loop. Co-Authored-By: Claude Opus 5 <[email protected]>
alpergundogdu
added a commit
that referenced
this pull request
Sep 11, 2026
…e pull Copilot review of #1996: `ClientFetchArgs::validate()` still errored with "the hard cap bounds the whole exchange," contradicting the updated docs that the delivery pull is uncapped. The contradiction ran wider than the one message — the `--timeout-ms` field help, the `hard_cap()` getter doc, and several validate-related test docs/names were all premised on `--timeout-ms` capping the blob fetch, which it has not since the pull path stopped consulting `PullDeadlines::hard_cap` (#1134/#1994). Bring all of them to the current truth: `--timeout-ms` bounds the CapacityBond registry read (discovery, `discovery_cap`); the delivery pull carries no overall wall-clock cap and is bounded only by `--stall-timeout-ms` and `--min-throughput-bps`, which together catch a dead or drip-feeding provider (#1797). The `validate()` check (`timeout > 2 × stall`) is preserved exactly — only its rationale is restated as a misconfiguration guard rather than a stall-detection one. Test assertions are unchanged; two tests are renamed off the old "hard cap disables stall detection" framing. Co-Authored-By: Claude Opus 4.8 <[email protected]>
alpergundogdu
added a commit
that referenced
this pull request
Sep 11, 2026
…d pull cap (#1996) * refactor(client-pull): dedup empty-claim guard; drop the CLI's ignored pull cap Two review follow-ups from #1994. Share the empty-claim guard. The `total_bytes == 0 && hash != empty-root -> HashMismatch` check (#1054) lived hand-copied in `driver::drive` and the in-memory `fetch_in_memory_once` path. Extract one crate-private `reject_empty_claim_for_nonempty_root` both call, so the two verify sites for the trivial-empty-range bypass cannot drift. Drop the CLI's ignored pull hard-cap. Since #1994 the production pull path (`open_progressive_pull` / `driver::drive`) never consults `PullDeadlines`' `hard_cap`: a progressing pull is bounded only by the open bound and the stall window (#1134). The CLI's `fetch` and `bundle pull` still built `capped` deadlines carrying a `hard_cap` the pull ignores, and re-ran the cap-outlasts- stages validation `common.validate()` already performs at parse time. Switch both to `PullDeadlines::new` (functionally inert — the pull was never hard-capped) and rewrite the now-stale comments plus `ClientFetchArgs::validate` docs to state the truth: `--timeout-ms` bounds discovery, not the pull. `PullDeadlines::capped` / `hard_cap` / `whole_transfer` / `with_hard_cap` stay: the test-util in-memory wrappers still cap the whole exchange through them. Fully retiring `--timeout-ms` as a pull cap (and thus `capped`) is a separate design question, left out here. Co-Authored-By: Claude Opus 4.8 <[email protected]> * docs(common): correct --timeout-ms docs — it bounds discovery, not the pull Copilot review of #1996: `ClientFetchArgs::validate()` still errored with "the hard cap bounds the whole exchange," contradicting the updated docs that the delivery pull is uncapped. The contradiction ran wider than the one message — the `--timeout-ms` field help, the `hard_cap()` getter doc, and several validate-related test docs/names were all premised on `--timeout-ms` capping the blob fetch, which it has not since the pull path stopped consulting `PullDeadlines::hard_cap` (#1134/#1994). Bring all of them to the current truth: `--timeout-ms` bounds the CapacityBond registry read (discovery, `discovery_cap`); the delivery pull carries no overall wall-clock cap and is bounded only by `--stall-timeout-ms` and `--min-throughput-bps`, which together catch a dead or drip-feeding provider (#1797). The `validate()` check (`timeout > 2 × stall`) is preserved exactly — only its rationale is restated as a misconfiguration guard rather than a stall-detection one. Test assertions are unchanged; two tests are renamed off the old "hard cap disables stall detection" framing. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1985.
Problem
crates/client-pullhad two receivers forcdn/client/v1paid pulls. The buffered one (stream_fetch*→fetch_inner_once→receive_and_pay→decode_verified_range) drained the whole wire stream into a buffer, releasing a 1 MiB reveal per chunk as bytes landed, and only ran the bao decoder afterStreamEnd. A provider that signed an inflatedtotal_bytesand streamed framed garbage was paidmin(claim, max_blob_size_mb-wire) × ratebefore a single byte verified. The progressive one (open_progressive_pull→UpstreamPull→PullReader→ResponseDecoder) verified each 16 KiB group as it arrived. Exposure depended on which receiver a caller used — and two comments inlib.rsclaimed the buffered path had production callers and verified before paying; neither was true.Change
fetch_inner_once,receive_and_pay,decode_verified_range,TerminalAfterWriteare gone. Thestream_fetch*family (zero production callers; used bycrates/e2eand the node integration suites) survives only astest-util-gated in-memory wrappers over the one receive loop:fetch_in_memory_onceopens a progressive pull, feeds it throughPullReaderinto a newdecode_to_vec(same loop shape asClientRangedStore::ingest_stream), andfinishes. The reseed retry loop is kept. A corrupt group now aborts at that group on every path (ADR 038 AC 2); what a lying peer can bill is the bytes that arrived before its first unverifiable group.UpstreamPull::next_chunkabsorbs the two guards only the buffered loop had: the received-byte ceiling (Node-to-node size-claim gate lets a holder centralize traffic (refuse-on-claim → refuse-on-received-bytes) #1895) as a wire bound checked before the crossing chunk is paid —open_progressive_pulltakesmax_blob_size_bytes(its doc already claimednext_chunkenforced it; now it does) and all five callers pass their ceiling — and the voucher-write recovery that prefers a terminalStreamEnd/StreamErrorover the opaque write failure a node's end-of-streamSTOP_SENDING(0)produces. The production leg gets both.bao_encoded_sizegains anO(log groups)closed form for the group-aligned contiguous rangesalign_rangeproduces, property-tested byte-for-byte against the encoder walk across every tree shape up to nine groups and deep offsets in multi-GiB trees. Found while verifying: the walk isO(groups)— 67M groups for the CLI's default 1 TiB--max-blob-mb— and stalled the CLI fetch past the node's voucher wait before the first byte (cli_fetch_resumee2e). The same walk already ran on every open against the peer-claimedtotal_bytes; that e2e now completes in 7 s vs 39 s onmain.crates/e2e's normaldecdn-client-pulldep enablestest-util(its lib fixture callsstream_fetch_tracked);ProgressCallbackis one unit everywhere (content bytes); stale prose acrossclient-pull,node,cli,e2e, andCLAUDE.mdis rewritten to describe the one loop.Tests
client_pays_nothing_for_an_inflated_garbage_claim: 32 MiB signed claim, 64 KiB garbage frames →HashMismatch, nothing paid (first group fails before a metering interval accrues).client_spend_on_a_garbage_stream_is_bounded_by_one_frame: same lie with a 3 MiB first frame → paid ≤ that frame, ≪ the claim — pins the bound so the pay-then-verify shape cannot return.client_rejects_an_empty_claim_for_a_non_empty_hash(cdn/client/v1: empty (0-byte) blob delivery errors on the bao path #1054 guard, now on the live path).client_rejects_a_server_that_oversends_past_the_promised_lengthaccepts both over-delivery messages: the decoder consumes exactly the promised wire, so the extra frame now surfaces atfinish(node_origin'sis_bao_corruptionalready classifies both as one).decode_verified_range_*unit tests ported ontodecode_to_vec; two newbao-rangeproperty tests for the closed form.Verification
cargo clippy --workspace --all-targets -- -D warnings,cargo clippy -p decdn-client-pull/-p decdn-cli(non-test-utilbuilds),cargo fmt --check,RUSTDOCFLAGS=-D warnings cargo doc --workspace --no-deps --document-private-items,cargo nextest run --workspace --no-fail-fast(3406 passed),check_crate_edges.py,cargo tree -p decdn-cli -e normal -i iroh-blobs(empty). Anvil-gated:anvil_settlement_e2e(4/4) anddecdn-e2esmoke,cli_fetch_resume,cli_fetch_multi_source,cli_fetch_topup,cli_bundle_pull_shared_chunk,node_pull_topup,coalesce_two_clients,origin_stream_while_store(all pass).Review round (second commit)
driver::driveproves atotal_bytes == 0claim against the empty root before the empty store can be finalized — the gap-driven path had no verify site for it, so a holder could completedecdn fetch <non-empty hash>with an empty output file (pre-existing; found by the coverage review).LocalPullFaultso it can never be rescued into a clean completion; the recovery's own observation (peer kept streaming / read failed / timed out) rides along as context on the write error; the resume-offset-past-ceiling check is stated directly.≥ 2 MiBpaid for the verified prefix,≤ corrupt offset + one frame), mid-stream straddling overrun guard, gap-scoped leg ceiling anchored at its own offset viaopen_progressive_pulldirectly, multi-group exact-ceiling blob, driver empty-claim guard both ways.window_pull_through_oversized_upstream_aborts_on_received_bytesnow bounds spend by the ceiling's own wire (noPULL_WINDOW_FLOORslack).drivepath).Out of scope
max_blob_size_mb: 0= unlimited warning wording) — docs, separate PR.PullDeadlines::hard_cap/capped()are now consumed only by thetest-utilwrappers (the CLI still buildscappeddeadlines) — separate cleanup.🤖 Generated with Claude Code