Skip to content

fix(node,client)!: max_blob_size caps bytes held per blob, not offsets served - #2464

Merged
thiras merged 2 commits into
mainfrom
claude/max-blob-held-bytes
Oct 16, 2026
Merged

thiras merged 2 commits into
mainfrom
claude/max-blob-held-bytes

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2463

Summary

Testnet nodes (sin1, ash1, lon1) raised DecdnServeNodeFault on reads of a 30.59 GB blob that crossed 16 GiB. The cause: max_blob_size (16384 MiB there) was enforced as a byte-offset ceiling. A pull-through for any range past 16 GiB aborted with BlobTooLarge (sometimes after paying upstream), and the serve counted it as a node fault.

The cap now bounds how many bytes of one blob are held, not which offsets are served. Ranges past the cap offset are served while the bytes held for that blob fit. #1895 still holds: the peer's unverified total_bytes claim drives no refusal.

Changes

  • drive / fill_gap: meters the content the store holds. Each leg is cut to the room left under the cap (re-billed present bytes don't count). When a missing byte could only land past the cap, the drive ends with BlobTooLarge before it opens a leg, so nothing past the cap is pulled or paid. first_leg and the node's PrimeLeg::predicted_leg cut the same way.
  • open_progressive_pull: the resume-offset guard is gone. One stream carries at most the cap's worth of content from its own offset (defense in depth, chunk-group granular).
  • acquire / Downloader: a size claim is clamped to furthest range start + cap, so an explicit range past the cap is planned. Fails only when bytes held pass the cap.
  • Node window path:
    • Before commit: refuses Declined (serve_stream_rejected_blob_too_large) only when the node already holds the cap's worth of the blob. It reads its own store, never the request offset or the claim.
    • Mid-stream: a fill that ends at the cap is tagged FillError::held_bytes_cap. The serve leg delivers what landed, then sends a mid-stream StreamError::Declined and ends as ServeStop::BlobTooLarge. That end is counted on the new decdn_serve_stream_midstream_blob_too_large_total, never on serve_stream_node_fault_total. Requesters fail over: a partial holder gets a pull-through bar, other holders are declined for the fetch.
  • ADR 005 §max_blob_size enforcement and the observability appendix are updated.

Review follow-up (779ba7c)

  • Empty blob under a cap: the per-stream bound sized (0, cap) against a signed size of zero and failed range alignment; it now skips a zero size (client_delivers_empty_blob_under_a_held_cap).
  • Concurrent legs: each leg's room counts only bytes already held, so two lanes could together pass the cap. acquire now runs work that could pass the cap on one stream (one lane, no extra streams); it narrows the fetch and never refuses on the claim. A resumed store whose proven size needs more than the cap ends before any leg opens.
  • Node bound: runs inside one assembly are sequential. Two concurrent pulls of one blob can still pass the cap by about one credit-window leg each, plus up to one chunk group of alignment slack; ADR 005 states this. So "nothing past the cap is paid" holds for a requester's fetch, and for a node up to that slack.
  • Sibling fills: a serve read of bytes no fill landed while the node holds the cap's worth ends as a mid-stream Declined, not a node fault, whichever fill ended. A store that fails to read bytes it holds stays a node fault (tagged only after a presence check).
  • The pre-commit gate logs a failed store read; ADR 005 scopes the size refusal and the probe rule to the own origin; ADR 039, config help, --max-blob-mb, CHANGELOG (node, client: a proxy over its max_blob_size fails an over-ceiling range as a bare early EOF instead of refusing BlobTooLarge, and the client retries the same proxy #2256 entry rewritten) and stale comments follow.
  • Verified: workspace clippy --all-targets --all-features -D warnings, cargo doc with warnings denied, and nextest for node/cache/client/cli/common: 4364/4364.

Tests

  • New: client driver (a_range_past_the_cap_offset_is_pulled_while_held_bytes_fit, a_pull_into_a_full_cap_ends_before_it_opens, a_gap_over_the_cap_pulls_up_to_the_cap_then_ends), acquire (a_range_past_the_cap_offset_is_fetched_while_held_bytes_fit, ranges_over_the_cap_end_the_item), node end-to-end (window_pull_through_past_the_cap_offset_is_served_while_held_bytes_fit, window_pull_through_over_the_held_cap_ends_declined_without_a_node_fault, window_pull_through_with_the_cap_already_held_is_refused_before_commit).
  • Updated: tests that pinned the offset semantics. That includes gap_scoped_leg_* and the oversized-upstream retry, which is now refused before commit.
  • The source_set held-cap bar logic is unchanged. A partial holder's Declined still means "won't pull through; serves its covered blocks", and only the docs were reworded.

Verification

  • cargo clippy --workspace --all-targets --all-features -D warnings: clean.
  • cargo doc with warnings denied: clean.
  • cargo nextest run -p decdn-node -p decdn-cache -p decdn-client -p decdn-cli --all-features: 3880/3880 pass. Two flakes passed on retry, and neither involves the cap: window_pull_through_bounded_unaligned_range_pulls_only_the_span runs with cap 0 and is a settle-log race; the other is proof_wait::stream_frames_count_*.
  • cargo test --no-run -p decdn-e2e --features anvil-e2e: compiles.
  • I did not run the whole-workspace nextest locally because the disk is full. CI covers it.

🤖 Generated with Claude Code

…s served

A node's `max_blob_size` cap was enforced as a byte-offset ceiling, so a
pull-through read of a large blob past the cap offset aborted with
`BlobTooLarge` (sometimes after paying upstream) and the serve counted it
on `decdn_serve_stream_node_fault_total`. Testnet nodes with a 16 GiB cap
faulted this way on reads past 16 GiB of a 30.59 GB blob.

The cap now bounds how many bytes of one blob a node or client holds:

- `drive` meters the bytes the store holds, cuts each leg to the room
  left under the cap, and ends with `BlobTooLarge` before it opens a leg
  that could only land bytes past it. `first_leg` and the node's primed
  leg prediction cut the same way.
- `open_progressive_pull` no longer refuses an offset past the cap; one
  stream carries at most the cap's worth of content from its own offset.
- `acquire` clamps a size claim to the furthest range start plus the cap,
  and fails only when the bytes held pass the cap.
- The window serve path refuses `Declined` before commit only when the
  node already holds the cap's worth of the blob. A fill that ends at the
  cap mid-stream stops the serve with a mid-stream `Declined` the
  requester fails over on, counted on the new
  `decdn_serve_stream_midstream_blob_too_large_total`, never as a node
  fault.

The peer's unverified `total_bytes` claim still drives no refusal (#1895).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 18:27
@github-code-quality

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

Copy link
Copy Markdown

Code coverage overview

Languages: Rust, Solidity

Rust / code-coverage/cargo-llvm-cov

main c0c2f8b claude/max-blob-held... 779ba7c +/-
75% 75% 0%
View coverage of the 10 most impacted files.
File main c0c2f8b claude/max-blob-held... 779ba7c +/-
crates/client/src/lib.rs 88% 88% 0%
crates/client/src/scheduler.rs 94% 94% 0%
crates/node/src...erve_encoder.rs 89% 89% 0%
crates/node/src...gin/pull_leg.rs 85% 85% 0%
crates/cache/src/engine.rs 91% 91% 0%
crates/client/s...c/downloader.rs 83% 83% 0%
crates/node/src...lient/window.rs 74% 74% 0%
crates/client/src/source.rs 93% 93% 0%
crates/client/src/driver.rs 95% 96% +1%
crates/cache/sr...fill_session.rs 95% 96% +1%

Solidity / code-coverage/forge

main c0c2f8b claude/max-blob-held... 779ba7c +/-
92% 92% 0%

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


Updated October 16, 2026 08:55 UTC

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.

🔵 Needs a closer look

It reworks security- and payment-sensitive enforcement semantics across the node serve path, client pull/scheduler/driver, cache, and ADR canon, so it warrants final human review despite no concrete defect being found.

0 open findings

What changed in this PR

This PR fixes issue #2463: max_blob_size was enforced as a byte-offset ceiling, so a node holding only part of a >16 GiB blob raised DecdnServeNodeFault whenever a read crossed the configured offset — even though the node held only a few GB. The fix re-interprets max_blob_size as a cap on how many bytes of one blob a node holds, not which offsets it may serve. This preserves the #1895 invariant (never refuse on a peer's unverified total_bytes claim) and makes an oversized read fail over cleanly rather than counting as a node fault.

Changes:

  • Client pull path (driver, scheduler, lib, downloader, source): legs are cut to the room the store's BLAKE3-verified held bytes leave under the cap; the drive ends with BlobTooLarge before opening a leg that could only land past the cap; the resume-offset guard and the early acquire size-gate are removed in favor of claim_reach (furthest range start + cap). Each stream is still bounded to the cap's worth of content from its own offset (defense in depth).
  • Node serve path (window, serve_leg, serve_encoder, wire, outcome, pull_leg, node_origin): the open-time gate reads only the node's own store (refuse before commit only when it already holds the cap's worth); a mid-stream fill that ends at the cap tags FillError::held_bytes_cap, delivers what landed, then sends a mid-stream Declined (ServeStop::BlobTooLarge) counted on the new decdn_serve_stream_midstream_blob_too_large_total, never on serve_stream_node_fault_total.
  • Docs + metrics: ADR 005 §max_blob_size enforcement and the observability appendix are rewritten; a new mid-stream counter is added and wired through the metrics/outcome plumbing.
File Description
crates/​client/​src/​lib.rs Per-stream wire bound recomputed as cap's worth from the offset; resume guard removed; BlobTooLarge docs reworded.
crates/​client/​src/​driver.rs held_room, leg_range(max_len), and end-before-open BlobTooLarge metering of held bytes.
crates/​client/​src/​scheduler.rs claim_reach helper; acquire clamps to reach and ends on held>cap / bound>=reach.
crates/​client/​src/​downloader.rs Store sizing uses claim_reach; ranges/whole moved before store open.
crates/​client/​src/​source.rs BlobSource::max_blob_size_bytes doc; ScriptedSource::capped test double.
crates/​cache/​src/​fill_session.rs FillError carries held_bytes_cap; Unlanded wrapper; ended_at_held_bytes_cap chain walker.
crates/​cache/​src/​engine.rs PresentRanges::held_bytes().
crates/​node/​src/​handlers/​client/​{window,serve_leg,serve_encoder,wire,outcome,mod}.rs Own-store open-time gate, mid-stream Declined refusal path, ServeStop::BlobTooLarge.
crates/​node/​src/​node_origin/​{mod,pull_leg}.rs predicted_leg cut to cap's worth; held_bytes_cap classification; doc updates.
crates/​node/​src/​metrics.rs (+tests) New serve_stream_midstream_blob_too_large counter, registered and listed as an inbound-failure reason.
adr/​005-protocol.md, adr/​appendix-observability.md Canon updated to the held-bytes semantics + new metric row.
Test files (node/​tests/​*, client/​src/​**/​tests.rs) Updated offset-semantics tests and new held-cap coverage.

I reviewed the core metering (fill_gap end-before-open termination, re-bill loop, claim_reach bounds, held > cap vs >= cap boundaries), the cache FillError/io::Error source-chain detection, the metrics registration (auto-registered via MetricsGroup, no *_total_total), and the ADR anchors. The logic is internally consistent and the new tests exercise the key paths; I did not find a concrete defect to flag.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

- A requester with a cap opens the empty blob again: the per-stream bound
  sizes no range against a signed size of zero.
- acquire runs work that could pass the cap on one stream (one lane, no
  extra streams), so concurrent legs cannot each take the same room. A
  resumed store whose proven size needs more than the cap ends before any
  leg opens.
- A serve read of bytes no fill landed while the node holds the cap's worth
  of the blob ends as a mid-stream Declined, so a sibling fill that ended at
  the cap is no node fault. A store that fails to read bytes it holds stays
  a fault, never a cap refusal.
- The held-bytes gate logs a failed store read; the mid-stream cap stop logs
  at info with hash and cap.
- ADR 005 scopes the size refusal to the own origin and states the chunk
  group and concurrent-leg slack; ADR 039, config help, CHANGELOG and stale
  comments follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@thiras
thiras merged commit b715f67 into main Oct 16, 2026
31 checks passed
@thiras
thiras deleted the claude/max-blob-held-bytes branch October 16, 2026 08:57
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.

max_blob_size_mb caps the byte offset a node may serve, not the bytes it stores per blob

3 participants