Repository navigation
fix(node,client-pull): enforce max_blob_size on received bytes, not the peer claim (#1895) - #1899
Merged
Merged
Conversation
…he peer claim (#1895) A relaying node refused a node-to-node cache-miss pull whenever the upstream holder's *claimed* `total_bytes` exceeded `max_blob_size_bytes`, before any bytes flowed. `total_bytes` is peer-controlled and unverified (`StreamResponse::validate()` never bounds it), so a holder over-claims a small blob's size to make every finite-ceiling relay refuse to cache/serve — it monopolises the blob's traffic while ungated clients still pull directly. The claim no longer, on its own, causes a refusal. Removed the four up-front claim gates (peer + own-origin serve legs in window.rs; fetch_inner_once and open_progressive_pull in client-pull). The ceiling now binds on real, BLAKE3-verified received bytes: - Buffered path (`receive_and_pay`): abort once cumulative wire crosses `aligned_wire_len(offset, 0, ceiling)` — the wire size of a ceiling-sized blob, so an exactly-ceiling blob is still accepted. - Gap-driven driver (`fill_gap`): the driver re-opens a fresh `UpstreamPull` per paced leg, so a per-stream counter never accumulates whole-blob bytes. The cap lives at the driver loop-top (`delivered_frontier > ceiling`), plus a Draw clamp so a `BudgetPacer`'s whole-gap draw cannot pull an entire oversized blob before the check runs. The ceiling reaches the driver via a new `BlobSource::max_blob_size_bytes()` (own-origin returns 0 — its cache-engine cap already bounds stored bytes). Payment hygiene: the abort is mid-stream, so it settles through serve_leg's existing note_unpaid + FloorReservation::Drop — charged only for bytes actually delivered, never the reservation (#1598 pre-spend release_unspent sites unchanged). Renamed `BlobTooLargeClaim{claimed}` -> `BlobTooLarge{received, ceiling}` and `PullVerdict::OversizeClaim` -> `Oversize`. `ProbeResponse. total_bytes` stays a pure advisory cost-hint. Independent size re-derivation (to complete a lying over-claim's real small blob) is impossible soundly: total_bytes is authoritative for the bao tree, the wire is header-less, and a byte-free outboard length proof is unsound. The attack is defeated by incentives — removing the free fast refusal makes over-claiming pointless, so a liar's mismatched stream just fails integrity like any bad peer while honest holders complete. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Size the node defaults for the large-file (AI model) wedge, where a node holds many multi-GB shards. `DEFAULT_CACHE_SIZE_MB` rises from 10GB to 100GB, and an unset `max_blob_size_mb` now resolves to `min(50GB, cache_size_mb)` via the new `DEFAULT_MAX_BLOB_SIZE_MB` rather than to the whole disk budget. The clamp keeps the `max_blob_size_mb <= cache_size_mb` invariant satisfied when an operator shrinks the cache below 50GB. In tandem with #1895 this makes the received-byte cap a meaningful bound by default (unset no longer means unlimited). No disk-aware sizing and no startup disk check — surfacing a cache budget that exceeds free space at `cache_dir` is deferred to a future `decdn node doctor`. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR changes the blob-size ceiling (max_blob_size_mb / max_blob_size_bytes) to be enforced on bytes actually received rather than the peer’s unverified total_bytes claim, preventing a provider from wedging relays by over-claiming size while still serving a small blob directly.
Changes:
- Remove up-front “size-claim” refusals and enforce the ceiling during streaming/ingest (buffered receive loop + gap-driven driver).
- Rename the typed sentinel from
BlobTooLargeClaimtoBlobTooLargeand update retry/scoring/metrics behavior accordingly. - Adjust cache defaults so an unset
max_blob_size_mbresolves to a bounded ceiling (50 GB, clamped to cache size) and increase default cache size to 100 GB.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/client-pull/src/lib.rs | Removes claim-gating; adds received-byte ceiling enforcement in buffered receive loop; renames sentinel to BlobTooLarge. |
| crates/client-pull/src/driver.rs | Enforces the ceiling in the gap-driven driver based on delivered frontier and clamps Draw length to keep enforcement timely. |
| crates/client-pull/src/source.rs | Adds BlobSource::max_blob_size_bytes() so the driver can enforce per-source ceilings. |
| crates/client-pull/src/retry.rs | Updates retry classification to treat BlobTooLarge as terminal. |
| crates/node/src/handlers/client/window.rs | Removes claim-based size gates in both peer-miss and own-origin legs; relies on pull-leg enforcement instead. |
| crates/node/src/node_origin/mod.rs | Updates verdict taxonomy (OversizeClaim → Oversize) and logging/metrics around oversize pulls. |
| crates/node/src/node_origin/pull_leg.rs | Removes passing the ceiling into the upstream open stage; relies on downstream enforcement. |
| crates/common/src/config/mod.rs | Increases default cache size; introduces default max-blob ceiling (50 GB) clamped to cache size; adds regression tests. |
| crates/common/src/cli/run.rs | Updates CLI help text to match the new defaults and semantics. |
| crates/cli/src/commands/config.rs | Updates the sample config defaults/comments for cache sizing and blob ceiling. |
| crates/cli/src/commands/fetch.rs | Updates progressive pull open calls to match the new open_progressive_pull signature. |
| crates/node/tests/node_origin_pull.rs | Updates orchestration tests to validate abort-on-received-bytes behavior and bounded upstream spend. |
| crates/node/tests/client_loopback.rs | Adds/updates buyer-side tests for abort behavior and payment watermark expectations under the new semantics. |
| crates/e2e/src/client.rs | Updates retryability rules to treat BlobTooLarge as non-retryable. |
Suppressed comments (1)
crates/client-pull/src/lib.rs:2225
- When the received-byte cap trips,
BlobTooLargeis constructed withceiling: max_received_wire, butmax_received_wireis a wire-byte bound derived frommax_blob_size_bytes. This makes the error/log report the wrong ceiling (and in different units than otherBlobTooLargeconstructions like the driver’s content-based one). It’d be clearer to report the configured content ceiling (max_blob_size_bytes) while still enforcing the wire bound for safety.
if max_received_wire > 0 && cumulative > max_received_wire {
return Err(anyhow::Error::new(BlobTooLarge {
received: cumulative,
ceiling: max_received_wire,
}));
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 82.66% (was 82.64%, ▲ +0.02%) — 71261/86209 lines
History
|
…ll site The BlobTooLarge field docs implied `received`/`ceiling` were always wire bytes / the configured `max_blob_size_bytes`, but the type is built with wire units on the buffered receive loop and content units on the gap-driven driver and the resume-offset guard. Document that the two fields always share a unit within one error (the comparison is apples-to-apples at each site) and spell out which site uses which unit, and drop the misleading "max_blob_size" wording from Display. No behavior change. 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 #1895.
Problem
On a node-to-node cache-miss pull, a relaying node refused with
BlobTooLargewhenever the upstream holder's claimedtotal_bytesexceededmax_blob_size_bytes— before any bytes flowed.total_bytesis peer-controlled and unverified (StreamResponse::validate()never bounds it), so a holder can advertise a huge size on a small blob to make every finite-ceiling relay refuse to pull/cache/serve, monopolising that blob's traffic and revenue while ungated clients still pull directly.Fix (v1)
The claim never, on its own, causes a refusal. The
max_blob_size_bytesceiling is enforced on real, BLAKE3-verified received bytes instead.window.rspeer + own-origin serve legs, andclient-pullfetch_inner_once+open_progressive_pull.receive_and_pay): aborts once cumulative wire crossesaligned_wire_len(offset, 0, ceiling)(the wire size of a ceiling-sized blob, so an exactly-ceiling blob is still accepted).fill_gap): the driver re-opens a freshUpstreamPullper paced leg, so a per-stream counter never accumulates whole-blob bytes. The cap lives at the driver loop-top (delivered_frontier > ceiling) plus a Draw clamp so aBudgetPacer's whole-gap draw can't pull an entire oversized blob before the check runs. The ceiling reaches the driver via a newBlobSource::max_blob_size_bytes()(own-origin returns0— its cache-engine cap already bounds stored bytes).serve_leg's existingnote_unpaid+FloorReservation::Drop— the node is charged only for bytes actually received, never the reservation (the Anvil e2e for the node-to-node reactive mid-pull top-up #1598 pre-spendrelease_unspentsites are unchanged).BlobTooLargeClaim{claimed}→BlobTooLarge{received, ceiling}andPullVerdict::OversizeClaim→Oversize(still terminal in retry, bumpsnode_pull_too_large, not scored against the provider).ProbeResponse.total_bytesstays a pure advisory cost-hint.This changes the documented meaning of
max_blob_size_mbfrom a claim gate to a received-byte cap. An ADR 005 update is a follow-up, not in this PR.Why not verified size at the handshake
Making a lying over-claim's real small blob complete + cache would need independent size re-derivation, which is impossible soundly here:
total_bytesis authoritative for the bao tree (decode_verified_range/BaoTree::new), thecdn/client/v1wire is header-less, and a byte-free outboard length proof is unsound (the issue's own note — a 1500-byte file "proves" length 2049). A sound size proof needs the tail chunk's bytes = the rejected verified-size-at-handshake (leaks paid content on the unpaid leg, tail-first access). The attack is instead defeated by incentives: removing the free fast refusal makes over-claiming pointless — a liar's mismatched stream just fails integrity like any bad peer, while honest holders complete.Config defaults (second commit)
Motivated by the same large-file wedge, and to make the received-byte cap a meaningful bound by default (unset no longer means unlimited):
DEFAULT_CACHE_SIZE_MB: 10 GB → 100 GB.max_blob_size_mb→min(50 GB, cache_size_mb)(newDEFAULT_MAX_BLOB_SIZE_MB), clamped so themax_blob ≤ cache_sizeinvariant holds on smaller caches.decdn node doctor(cache eviction fires at 90% of the config number, not real free space, so a doctor comparingcache_size_mbvs. free space atcache_diris the right home for that).0for unlimited).Out of scope (follow-ups, not built)
max_blob_size_mbmeaning.decdn node doctorconfig/disk diagnostics.Testing
TDD throughout. New/rewritten:
buyer_pays_for_received_bytes_then_aborts_over_ceiling,buyer_aborts_oversized_small_blob_without_paying,buyer_accepts_blob_at_exact_ceiling,window_pull_through_oversized_upstream_aborts_on_received_bytes(bounded upstream spend + no promotion),node_origin_oversized_blob_aborts_on_received_bytes_without_scoring,resolve_cache_default_blob_size_clamps_to_a_small_cache.cargo build,cargo clippy --workspace --all-targets,cargo fmt --checkclean;cargo nextestgreen: client-pull 226/226, node 1521/1521, common config 363/363, cli config_validate 27/27; anvil-e2e compile gate clean.🤖 Generated with Claude Code