Skip to content

fix(node,client-pull): enforce max_blob_size on received bytes, not the peer claim (#1895) - #1899

Merged
alpergundogdu merged 3 commits into
mainfrom
claude/serene-booth-dd0293
Sep 1, 2026
Merged

alpergundogdu merged 3 commits into
mainfrom
claude/serene-booth-dd0293

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #1895.

Problem

On a node-to-node cache-miss pull, a relaying node refused with BlobTooLarge 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 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_bytes ceiling is enforced on real, BLAKE3-verified received bytes instead.

  • Removed the four up-front claim gates — window.rs peer + own-origin serve legs, and client-pull fetch_inner_once + open_progressive_pull.
  • Buffered path (receive_and_pay): aborts 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 can't 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 — 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-spend release_unspent sites are unchanged).
  • Renamed BlobTooLargeClaim{claimed} → BlobTooLarge{received, ceiling} and PullVerdict::OversizeClaim → Oversize (still terminal in retry, bumps node_pull_too_large, not scored against the provider). ProbeResponse.total_bytes stays a pure advisory cost-hint.

⚠️ Semantics change

This changes the documented meaning of max_blob_size_mb from 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_bytes is authoritative for the bao tree (decode_verified_range / BaoTree::new), the cdn/client/v1 wire 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.
  • Unset max_blob_size_mb → min(50 GB, cache_size_mb) (new DEFAULT_MAX_BLOB_SIZE_MB), clamped so the max_blob ≤ cache_size invariant holds on smaller caches.
  • No disk-aware sizing, no startup disk check — deferred to a future decdn node doctor (cache eviction fires at 90% of the config number, not real free space, so a doctor comparing cache_size_mb vs. free space at cache_dir is the right home for that).
  • A single blob > 50 GB is now rejected by default (fine for sharded manifests; operators raise the knob or set 0 for unlimited).

Out of scope (follow-ups, not built)

  • Negative cache for over-ceiling hashes.
  • ADR 005 update for the new max_blob_size_mb meaning.
  • decdn node doctor config/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 --check clean; cargo nextest green: 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

alpergundogdu and others added 2 commits September 1, 2026 17:06
…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]>
Copilot AI lite review requested due to automatic review settings September 1, 2026 16:09

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.

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 BlobTooLargeClaim to BlobTooLarge and update retry/scoring/metrics behavior accordingly.
  • Adjust cache defaults so an unset max_blob_size_mb resolves 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, BlobTooLarge is constructed with ceiling: max_received_wire, but max_received_wire is a wire-byte bound derived from max_blob_size_bytes. This makes the error/log report the wrong ceiling (and in different units than other BlobTooLarge constructions 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.

Comment thread crates/client-pull/src/lib.rs Resolved
@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.66% (was 82.64%, ▲ +0.02%) — 71261/86209 lines

File Coverage Lines Δ
crates/cli/src/commands/config.rs 87.08% 795/913 ● 0.00%
crates/cli/src/commands/fetch.rs 32.60% 522/1601 ▲ +0.04%
crates/client-pull/src/driver.rs 91.45% 866/947 ▲ +0.10%
crates/client-pull/src/lib.rs 89.66% 1743/1944 ▼ 0.24%
crates/client-pull/src/retry.rs 100.00% 56/56 ● 0.00%
crates/client-pull/src/source.rs 92.94% 316/340 ▲ +0.11%
crates/common/src/config/mod.rs 97.10% 6996/7205 ● 0.00%
crates/e2e/src/client.rs 0.00% 0/454 ● 0.00%
crates/node/src/handlers/client/window.rs 75.06% 295/393 ▲ +0.25%
crates/node/src/node_origin/mod.rs 92.78% 976/1052 ▼ 0.01%
crates/node/src/node_origin/pull_leg.rs 87.07% 586/673 ▲ +1.46%
History
Commit Total Δ vs base
bf1432d 82.67% ▲ +0.03%
b8aa85f (HEAD) 82.66% ▲ +0.02%

…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]>
@alpergundogdu
alpergundogdu merged commit adab034 into main Sep 1, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/serene-booth-dd0293 branch September 1, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node-to-node size-claim gate lets a holder centralize traffic (refuse-on-claim → refuse-on-received-bytes)

2 participants