Repository navigation
refactor(client,node)!: a size claim only picks the verification shape - #2874
alpergundogdu wants to merge 8 commits into
Conversation
A size past u32::MAX discovery blocks (256 PiB at 64 MiB blocks) names u32::MAX blocks rather than a count that wraps to near zero. Refs #2843 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…claim The pull leg planned over num_blocks(upstream claim) before any byte verified, so an inflated signed size made it walk billions of blocks. The plan now ends at the request's end and at max_blob_size_bytes (plus one chunk group, so the held-bytes meter still ends an oversized pull) from the pull's offset, in the assembly and in the serve's coverage gate, and the coverage planners walk only the blocks a gap touches. The pull-leg handshake no longer reads the probe's size hint: the first-leg handshake opens the leg cut for an unbounded blob and keeps the prime only when it is the first run's leg under the signed size, and the covered-block handshake and the handshake order need no size. Origin- sourced probe coverage is clamped to the largest discoverable blob. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The serviceability check read the first chunk group, which proves nothing about the origin's stated size. It now reads and verifies the last group under that size: only the true size verifies a final chunk, so the serve signs, gates and reads on a proven size. The proof is memoized per hash in a bounded map, replacing the per-origin latch. The engine's pre-stream size_hint > max_blob_bytes fast-fail and the S3 Content-Length > max refusal are gone: the cap binds on the bytes the stream delivers. Refs #2827 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A size claim never sets a cap, plans or splits work, allocates, sizes a payment, or decides an end. The acquire loop plans from verified knowledge and grows: - first bound: an exact range to its own end, a tail one seed (64 MiB) past its start; the first leg's claim only shortens it, and a resumed record counts only through the store's verified floor; - root split: the first leaf a leg verifies under a claim proves the claim's top split, so the store's floor and bound rise to the left subtree; - tail proof: once the first leg has verified a byte, one lane fetches the last chunk group under the first claim beside it, so an honest claim plans the whole blob about one round trip after the first byte; - growth: with no claim left to prove, the bound grows to twice the verified frontier once it passes half the bound, beside the ranges in flight. A tail is only a zero-length range (#2865), exact ranges regain their end as the bound grows, and a range past the bound is clipped, never refused. The past-end fault class reads the verified floor, the paid frontier is priced under the leg's own signed size, and bytes proven to exist past the cap end the item early. AcquireTarget.bounded becomes declared, and DownloadTarget gains declared: a manifest entry's size or a size the host proved plans the entry from the start. The client reads no size from a probe answer: the probe size-hint plumbing, the pinned --node-id size probe and HashCensus::size_hint are gone, and a download's size open pulls its first seed. decdn quote, decdn get --dry-run and the pre-pull line show nodes and rates only for a raw blob; decdn probe prints no size, so its --json drops total_bytes. Closes #2865 Refs #2843 Co-Authored-By: Claude Opus 5.5 <[email protected]>
ADR 039 gains the rule and the client's first bound, root split, tail proof and growth; ADR 005, 037, appendix-bundles and appendix-gateway follow: the probe size is read only by a node's coverage-union gather, a node's pull plans from the request and its cap, and an own origin's size is proven by its last chunk group before the serve signs it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 10 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟡 Changes recommended
Approval is blocked by two critical unresolved issues: a cache/streaming fast-path can incorrectly treat an origin as range-capable due to cross-origin size memoization, and an untrusted peer size claim can trigger unbounded tail-range cache lookups that may force excessive allocation or scanning.
2 open issues
What changed in this PR
Refactors size handling across client/node/cache/protocol so untrusted size claims only select the Bao verification tree shape, while planning/capping/ending/pricing grow from verified bytes (with authenticated “declared” sizes used when available).
Changes:
- Client planning: seed-based first bounds, verified-floor/root-split semantics, optional tail proof, and bound growth driven by verified progress; removes probe size-hint plumbing.
- Node/cache hardening: clamp pull planning and coverage gating against absurd upstream/origin claims; prove origin size by verifying the last chunk group and memoize the proof.
- Protocol/CLI/docs: saturating
num_blocks, updated probe/quote/fetch outputs to avoid presenting probe-derived blob sizes, and ADR updates to document the new rule.
| File | Description |
|---|---|
| crates/protocol/src/message.rs | Updates protocol message documentation to clarify that total_bytes is an unsigned size claim and does not drive planning/capping/ending semantics. |
| crates/protocol/src/coverage/tests.rs | Adds regression coverage tests ensuring block-count computation saturates instead of wrapping on huge sizes. |
| crates/protocol/src/coverage.rs | Changes num_blocks to saturate at u32::MAX and adjusts documentation around the practical size limits. |
| crates/node/tests/partial_serve.rs | Updates partial-serve tests to match new origin range-serviceability behavior that proves size by reading/verifying the last chunk group. |
| crates/node/tests/origin_range_pull.rs | Adjusts origin-range pull tests/helpers to request the last chunk group and align with size-proof semantics. |
| crates/node/src/selection.rs | Clarifies node selection metadata so size hints are treated as non-planning hints rather than authoritative sizes. |
| crates/node/src/node_origin/ranged_pull/tests.rs | Adds tests asserting ranged-pull planning is clamped to request bounds and configured caps even under inflated upstream claims. |
| crates/node/src/node_origin/ranged_pull.rs | Introduces/uses a planned_len clamp to keep pull planning within request end and max-blob limits (with minimal reach for metering). |
| crates/node/src/node_origin/pull_leg/prime_tests.rs | Updates pull-leg priming/handshake tests after removing dependencies on probe-provided size hints. |
| crates/node/src/node_origin/pull_leg.rs | Refactors pull-leg handshake and priming so it no longer relies on probe size, using unbounded sizing for initial opens where appropriate. |
| crates/node/src/node_origin/mod.rs | Wires in/re-exports ranged-pull planning helpers and updates comments around where size hints are still consumed. |
| crates/node/src/handlers/probe.rs | Clamps origin-sourced probe coverage generation to a discoverable maximum to avoid building oversized bitmaps from absurd origin sizes. |
| crates/node/src/handlers/client/window.rs | Adjusts serve window coverage gating to use clamped planned lengths rather than letting untrusted size claims inflate planned gaps. |
| crates/node/src/handlers/client/dispatch.rs | Updates dispatch/serviceability path documentation and behavior to align with proven-size handling and claim-only sizing. |
| crates/node/src/dht/probe_cache.rs | Updates probe-cache semantics/docs to reflect that cached size hints are not used for pull planning and are limited to specific gather logic. |
| crates/common/src/cli/fetch.rs | Updates CLI fetch help/text to match the new invariant that claims don’t allocate/plan and caps bind on delivered/verified bytes. |
| crates/client/tests/snapshots/public_api__public_api.snap | Refreshes the client public API snapshot for removed size-hint fields and the introduction of declared-size plumbing. |
| crates/client/src/targets/tests.rs | Updates target-resolution tests to remove probe-derived size expectations and reflect new declared/unknown-size behavior. |
| crates/client/src/targets/tests_support.rs | Adjusts target test fixtures to remove size-hint fields and support the new planning model. |
| crates/client/src/targets.rs | Removes probe size-hint propagation in target resolution and threads declared sizes where they are authenticated (e.g., manifests). |
| crates/client/src/streamer/tests.rs | Updates streamer tests to ensure windows and termination are driven by verified bytes rather than peer-signed size claims. |
| crates/client/src/streamer.rs | Refactors streaming to avoid using claims as caps/ends, adjusts tail handling and caching interactions, and documents signed-size usage. |
| crates/client/src/source.rs | Adds/clarifies store floor semantics so a verified prefix can be exposed and used for planning decisions. |
| crates/client/src/segment/tests.rs | Updates segment/range tests to match new behavior that clips ranges past current bounds instead of erroring. |
| crates/client/src/segment.rs | Changes range canonicalization and split-stealing to clip work past the current bound rather than treating it as a hard error. |
| crates/client/src/scheduler/tests.rs | Adds/updates scheduler tests for first-bound rules, growth behavior, tail proofing, and verified-floor interactions. |
| crates/client/src/ranged_store/tests.rs | Updates ranged-store persistence/reopen tests to validate the new derived floor and bound behavior. |
| crates/client/src/ranged_store.rs | Implements verified floor/root-split logic and bound updates driven by verified knowledge rather than persisted or claimed sizes. |
| crates/client/src/quote/tests.rs | Updates quote tests to reflect that raw blobs no longer expose size-based totals/estimates when size is untrusted or unknown. |
| crates/client/src/quote.rs | Refactors quoting to avoid probe/claim-based sizing for raw blobs while preserving manifest-based estimates for declared bundle sizes. |
| crates/client/src/probe.rs | Simplifies probing flows to remove now-unused size-hint plumbing and keep probe results focused on coverage/holders. |
| crates/client/src/lib.rs | Updates crate-level docs and exposed types to align with the “size is a claim” rule and declared-size concept. |
| crates/client/src/lane_sources/tests.rs | Updates lane-source tests for the new first-leg open behavior and the removal of probe size-hint influence. |
| crates/client/src/lane_sources.rs | Refactors lane source setup so first claims come from header/open behavior (or empty special case) rather than probe-derived sizing. |
| crates/client/src/driver.rs | Updates payment/pricing accounting so paid frontier is priced under each leg’s signed claim rather than store-derived bounds. |
| crates/client/src/downloader/tests.rs | Updates downloader tests to thread the new declared flag and tail-based whole-blob planning semantics. |
| crates/client/src/downloader.rs | Adds declared to download targets and plans whole-blob downloads as tails without treating claims as hard bounds. |
| crates/client/src/discovery/tests.rs | Updates discovery tests to remove total_bytes-based expectations from probe/discovery results. |
| crates/client/src/discovery.rs | Removes probe-reported total_bytes from discovery outputs to prevent consumers from treating it as authoritative. |
| crates/client/src/coverage_plan/tests.rs | Adds tests ensuring coverage planning only iterates blocks touched by gaps, avoiding huge-claim linear walks. |
| crates/client/src/coverage_plan.rs | Optimizes coverage planning by computing and walking only the blocks intersecting a gap rather than claim-sized spans. |
| crates/client/src/bundle/engine/tests.rs | Updates bundle engine tests for declared manifest sizes and new download target fields. |
| crates/client/src/bundle/engine.rs | Refactors bundle acquisition to treat manifest entry sizes as declared/authenticated and removes pinned probe-for-size behavior. |
| crates/client/examples/stream.rs | Updates the streaming example to work without assuming probes provide a trustworthy size (using claim=0 paths). |
| crates/client/examples/download.rs | Updates the download example to plan/fetch without relying on probe size hints and to pass declared appropriately. |
| crates/client/examples/common/mod.rs | Updates shared example helpers to align with holder/coverage-only probing and remove size-hint dependencies. |
| crates/cli/src/commands/quote/tests.rs | Updates CLI quote tests so raw blobs show nodes/rates without total-size estimates unless a declared size is available. |
| crates/cli/src/commands/quote.rs | Adjusts quote output to avoid presenting totals/estimates for unknown-size blobs while preserving bundle estimates from manifest sizes. |
| crates/cli/src/commands/probe/tests.rs | Updates probe CLI output tests for the removal of total_bytes from JSON and human-readable formats. |
| crates/cli/src/commands/probe.rs | Removes printing/returning total_bytes in probe CLI outputs to discourage treating size claims as authoritative. |
| crates/cli/src/commands/fetch.rs | Updates fetch command output to use declared sizes for estimates when available and otherwise print rates-only for unknown-size blobs. |
| crates/cache/src/origin/s3.rs | Removes pre-stream Content-Length max checks so caps bind on delivered bytes rather than origin-advertised sizes. |
| crates/cache/src/engine/tests.rs | Updates/adds cache engine tests validating size proof via last-chunk-group verification and memoization behavior. |
| crates/cache/src/engine.rs | Refactors origin range-serviceability to prove size by verifying the last chunk group and memoize proven sizes, removing earlier pre-stream size gating. |
| adr/appendix-gateway.md | Updates gateway appendix documentation to align with claim-only sizing and proven/declared size usage. |
| adr/appendix-bundles.md | Clarifies that bundle manifest entry sizes are authenticated/declared and can be used for initial planning bounds. |
| adr/039-multi-source-parallel-fetch.md | Adds/updates ADR content documenting the “size is a claim” rule and the verification-driven planning model. |
| adr/037-regional-proxy-warming.md | Updates ADR narrative for node upstream pulls to reflect the new claim-only sizing and clamped planning behavior. |
| adr/005-protocol.md | Updates protocol ADR text to clarify size-claim semantics and related probe/pull planning constraints. |
Review effort: Balanced
A download with no size opened one holder's size leg, and the planner seeded the whole first leg on that lane alone. Its sibling could not steal under MIN_SPLIT_SIZE, so a small blob billed one holder. A download now opens no size leg. Across several holders it plans one chunk group; the first verified leaf proves the root split, the bound rises to bytes that exist, and every lane splits those. A lone holder takes the tail as one leg. The claim of the first verified leaf (`verified_claim`) drives the tail proof, which skips a claim whose last byte a requested range already reaches. The bound reports progress when it shrinks to a proven size. A whole-blob coverage bitmap spans at most the larger of MAX_DISCOVERABLE_BLOB_BYTES and the verified floor, and the streamed tail's cache lookup reads no more than the cap, so no path sizes either from a claim (#2843). `decdn quote` shows nodes and rates for a raw blob, and its e2e test asserts that shape. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The serviceability memo answered for a hash whatever origin a later draw started at. It now keeps the proving origin's index beside the size, and a probe takes the memo only while the outboard (and so the draw) comes from that origin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ProbeResponseExt.total_bytes` leaves the wire: a probe answer is the signed body plus its coverage bitmap. The probe handler, the probe cache and the selection candidate carry no size. The ranged pull's coverage-union gather probes up to its fanout, since no answer can say a union spans the blob. The span check runs after the header handshake and counts blocks from the size the upstream signs; a union that does not span it probes the origin-directory candidates the first round did not, and a probe-cache hit that does not span it counts as a miss. ADR 005, 013 and 022 follow. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Converted to draft and on hold for #2879. #2879 proposes that a node proves the blob size on the wire, so The parts of this PR that do not depend on the size being trusted are still wanted and should merge with the proof: |

The rule
A size claim (the signed
StreamResponse.total_bytes, an origin's HEAD/HeadObject/stat size) only picks the tree shape a leg verifies under. It never sets a cap, plans or splits work, allocates, sizes a payment, or decides an end. Everything else plans from verified knowledge and grows. Root-authenticated sizes (a bundle manifest entry's, or a size an earlier fetch on the host proved) are "declared" and plan the entry from the start.What changed
decdn-client
scheduler::first_bound): an exact range plans to its own end; a tail (len == 0) plans oneSEED(64 MiB) past its start under a claim, and one chunk group with no claim. The first claim only shortens it. A resumed record's bound counts only through the store's verified floor.ClientRangedStore::floor,IngestStore::floor): the first leaf a leg verifies under claimSprovesS's top split, so every byte of the left subtree exists; the floor and an unproven bound rise to it. Each durable checkpoint lifts the floor to its prefix.prove_tail): once the first leg has verified a byte (or a worker ended), one lane fetches the last chunk group under the first claim beside it, at most once per fetch, with a 30 s deadline, never when the store holds that group. An honest claim plans the whole blob about one RTT after the first byte; time to first byte is unchanged.max(bound + SEED, 2 × frontier); the new region is planned beside the ranges in flight (Work::extend), no barrier.Want: a tail is onlylen == 0(client: cap-0 explicit ranges longer than the 1 TiB sizing ceiling truncate or overfetch #2865); exact ranges keep their requested end and regain it as the bound grows.AcquireTarget.boundedis replaced bydeclared;DownloadTargetgainsdeclared.past_endfault class reads the verified floor / proven / declared size, never the claim.BlobTooLarge).DriveCounters::leg_claim), not the store bound.canonicalize_ranges/steal_splitclip a range past the bound instead of erroring.verified_claim) drives the tail proof, which skips a claim whose last byte a requested range already reaches. A stream's first leg and--provestill open a first leg. Bundle entries with no manifest size do the same.claim_reach, the probe size-hint plumbing,ResolvedTargets::size_hint,ProbeOpts::known_size,HashCensus::size_hintand the pinned--node-idsize probe are gone.Work::whole_coverage): a whole-blob lane's bitmap spans at mostmax(MAX_DISCOVERABLE_BLOB_BYTES, verified floor), so no path sizes it from a claim (client: with max_blob_bytes = 0 the planner sizes its work from an unsigned peer size claim #2843).MAX_DISCOVERABLE_BLOB_BYTES), never a claim-sized range.set_len(manifest size)stays: it is a manifest size, which the rule keeps.decdn-protocol
num_blockssaturates atu32::MAXinstead of wrapping; its doc names the real limit (256 PiB).ProbeResponseExt.total_bytesis deleted from the wire (breaking). A probe carries coverage only.decdn-node
num_blocks(upstream claim)with no clamp.planned_lencuts the plan to the request end and tomax_blob_size_bytes(plus one chunk group, so the held-bytes meter still ends an oversized pull withBlobTooLarge) from the pull's offset, inrun_pull_legand in the serve's coverage gate.probe_fanout.CoverageUnionTrackeris gone: with no probe size, the ranged gather probes up to its fanout. The span check (coverage_spans(hash, candidates, total_bytes)) runs after the header handshake and counts blocks from the size the upstream signs. A non-spanning union probes the origin-directory candidates the first round did not (supplement_from_directory); a non-spanning probe-cache hit counts as a miss. The probe handler and the probe cache no longer carry a size.MAX_DISCOVERABLE_BLOB_BYTES(an absurd origin size no longer builds a bitmap the client rejects).decdn-cache
origin_range_serviceablereads and verifies the last chunk group under the origin's stated size, which proves it; the proof is memoized per hash together with the origin that proved it (bounded map), so a later probe answers from the memo only when the same origin still serves the range. The serve-miss path therefore signs, gates and reads on a proven size.size_hint > max_blob_bytesfast-fail and S3'sContent-Length > maxrefusal are deleted; the cap binds on delivered bytes.decdn-cli / decdn-common
decdn quoteanddecdn get --dry-runshow node count and rates only (no total, no estimate) for a raw blob; bundles keep their manifest-based size and estimate. The pre-pull line printsRates: …for a raw blob of unknown size, and the estimate when a size is known.decdn probeprints no size (--jsondrops thetotal_byteskey).--max-blob-mbhelp no longer claims an outboardset_len; the size-proof log line names all its no-proof cases.ADRs
005, 013, 022, 037, 039 (new § The size is a claim), appendix-bundles, appendix-gateway.
Left out / follow-ups
gateway_public::a_public_gateway_serves_anyone_from_its_own_poolfails on this branch (and on 6adfaa7). With no probe size,decdn get --prove(the gateway's size proof of a raw blob) learns its claim from a first-leg size open, then proves the tail with a separate open; the size open's primed pull is closed unread, and the node wrote one chunk group (65920 bytes) into it. Needs a design call: make the size open the proof's own leg, read and pay the primed group, or accept one header open per raw-blob proof and update the test.HashOutboard,fill_session.rs): allocation happens only after the root pair verifies, so a lie inflates it at most 2x; a sparse map is a larger change. Follow-up.outboard_with_origin's cache: the untrusted .obao4 outboard read is capped by the origin's own size claim #2842 clamp andfetch_to_memory's manifest cap: in fix: cap manifest fetches, clamp outboard reads, and small hardening #2872.Overlaps
scheduler.rs/streamer.rs/coverage.rslines, so it conflicts.cache/src/engine.rsandnode/.../dispatch.rs, in different functions.client/src/bundle/engine.rsand the client public_api snapshot.window.rschange is only the coverage gate's signature.Closes #2865
Closes #2843
Refs #2827 #2869
Testing
CI's
anvil e2e (journeys)failure on 6adfaa7:cli_quoteasserted the removed size and estimate (now nodes and rates), andcli_fetch_engages_multi_source_across_two_holdersbilled one holder because the size-open leg's lane was seeded with the whole first leg alone and its sibling could not steal underMIN_SPLIT_SIZE(fixed by the claimless plan above).New tests: a 2^60 claim plans at most one seed and completes (
a_huge_claim_plans_no_more_than_one_seed); an honest 70 MiB claim is proven by its tail with no bound past the true size and the tail fetched once; with no claim the bound grows from verified bytes; root-split and first-bound unit tests; a short claim's window streams from verified bytes; a node pull leg against a 2^60 claim plans only the requested block, andplanned_lencaps at the request and the cap; origin serviceability proves the size, memoizes it, and proves no wrong size;num_blockssaturates; with no claim and two holders every source opens a range below the true size (with_no_claim_the_lanes_split_only_verified_bytes); a claimed bound sizes no whole-blob bitmap (a_claimed_bound_sizes_no_whole_coverage_bitmap); an inflated claim sizes no cache read (an_inflated_claim_sizes_no_cache_read); the size memo answers only for the proving origin (origin_range_serviceable_memo_answers_for_the_proving_origin,..._memo_ignores_another_origins_proof);coverage_spanscounts blocks of the signed size.cargo fmt -- --check: cleancargo clippy --workspace --all-targets --all-features -- -D warnings: cleancargo nextest run -p decdn-client -p decdn-cache -p decdn-cli -p decdn-protocol -p decdn-node -p decdn-common: all passCARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items: cleancargo test --no-run -p decdn-e2e --features anvil-e2e: buildscargo nextest run -p decdn-e2e --features anvil-e2e --test-threads 2(afterforge build,cargo build -p decdn-node -p decdn-cli): 140 of 141 pass;gateway_publicfails as above.ProbeResponseExt::total_bytes.🤖 Generated with Claude Code