Repository navigation
fix(node,client)!: max_blob_size caps bytes held per blob, not offsets served - #2464
Conversation
…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]>
Code coverage overviewLanguages: Rust, Solidity Rust / code-coverage/cargo-llvm-cov
View coverage of the 10 most impacted files.
Solidity / code-coverage/forge
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
There was a problem hiding this comment.
🔵 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 withBlobTooLargebefore opening a leg that could only land past the cap; the resume-offset guard and the early acquire size-gate are removed in favor ofclaim_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 tagsFillError::held_bytes_cap, delivers what landed, then sends a mid-streamDeclined(ServeStop::BlobTooLarge) counted on the newdecdn_serve_stream_midstream_blob_too_large_total, never onserve_stream_node_fault_total. - Docs + metrics: ADR 005 §
max_blob_sizeenforcement 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]>
Gas snapshotNo gas changes vs base. |
Closes #2463
Summary
Testnet nodes (sin1, ash1, lon1) raised
DecdnServeNodeFaulton 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 withBlobTooLarge(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_bytesclaim 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 withBlobTooLargebefore it opens a leg, so nothing past the cap is pulled or paid.first_legand the node'sPrimeLeg::predicted_legcut 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.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.FillError::held_bytes_cap. The serve leg delivers what landed, then sends a mid-streamStreamError::Declinedand ends asServeStop::BlobTooLarge. That end is counted on the newdecdn_serve_stream_midstream_blob_too_large_total, never onserve_stream_node_fault_total. Requesters fail over: a partial holder gets a pull-through bar, other holders are declined for the fetch.max_blob_sizeenforcement and the observability appendix are updated.Review follow-up (779ba7c)
(0, cap)against a signed size of zero and failedrange alignment; it now skips a zero size (client_delivers_empty_blob_under_a_held_cap).acquirenow 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.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).--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.--all-targets --all-features -D warnings,cargo docwith warnings denied, andnextestfor node/cache/client/cli/common: 4364/4364.Tests
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).gap_scoped_leg_*and the oversized-upstream retry, which is now refused before commit.source_setheld-cap bar logic is unchanged. A partial holder'sDeclinedstill 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 docwith 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_spanruns with cap 0 and is a settle-log race; the other isproof_wait::stream_frames_count_*.cargo test --no-run -p decdn-e2e --features anvil-e2e: compiles.nextestlocally because the disk is full. CI covers it.🤖 Generated with Claude Code