Repository navigation
Description
Problem
A node has three cache-miss ingest paths, and only one is a problem:
| Path | Memory today |
|---|---|
| Origin backend (s3/http/fs) | O(chunk) — streams into the store |
| Serve/window pull-through (the #915 "tee") | O(chunk) — streams into the store |
Cache-miss warm/buyer leg (stream_fetch_shared) |
O(blob) — buffers the whole blob |
The warm/buyer leg is the lone buffered outlier. #1600 halved its peak (~2× → ~1× in RAM) but it still holds the whole blob. max_blob_size_mb (1 GiB default) exists largely to bound that RAM — so a node with 2 GB RAM and 2 TB disk cannot warm a blob bigger than its memory, even though its disk could hold it many times over. The buffering buys nothing: BLAKE3/bao verifies every 16 KiB chunk group against the root as it lands (ADR 038), so integrity is already incremental — holding the whole blob adds only cost.
A CDN that advertises large-file delivery should not cap a blob at memory size.
Intent
Treat "fetch from a peer" and "fetch from my own backend" as the same operation with a swapped source. Introduce a BlobSource seam with two impls:
- BackendSource — the operator's own s3/http/fs backend: unpaid, plaintext, trusted-because-it-is-your-config (today's
Origintrait). - PeerSource — another node over paid
cdn/client/v1, bao-verified against a known root. feat(node): reactive mid-pull deposit top-up on the node-to-node buyer leg (#1530) #1600's reactive top-up / resume-at-paid-frontier moves inside it.
Both write through the shared range-aware admit path (the cache-API foundation issue), so every source streams to disk at O(chunk-group) memory. The warm/buyer leg's in-memory buffer then disappears.
With memory off the table, remove max_blob_size_mb entirely and make admission a disk decision: the ceiling is cache_size_mb (the disk knob we already have), and warm-concurrency reserves the blob's actual size — a peer signs total_bytes up front, so admission is a precise pre-check, not a worst-case cap. Capacity eviction reuses the foundation's logical + lease-protected eviction path.
Vocabulary
This de-overloads "origin". The OriginAssignment network role (a node authorized to serve a namespace, ADR 002) stays "origin". The ingest trait — today named Origin but actually a backend adapter — becomes BlobSource.
End state
A node serves or warms any blob its cache budget can hold, from any source, at O(chunk-group) memory. Genuinely larger files arrive as application-layer manifests of many blobs (ADR 002), unchanged. Includes updating ADR 003 §Two-tier deposit and the max_blob_size_mb config docs.
Depends on
The range-aware cache API foundation (the shared admit path). This work layers on top of it.
Out of scope
- No bao-direct store import (kept as a future optimization; we unify at the plaintext seam so backend and peer share one code path).
- No change to serve/export, DHT routing, or the namespace/origin-role model.
- No new large-file manifest format.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
alpergundogdu commentedon Aug 5, 2026
Depends on #1607 (the shared range-aware
admitpath). This work layers on top of it.alpergundogdu commentedon Aug 5, 2026
Land
PeerSourceinclient-pull, notnode, so the CLI legs collapse onto it tooOne scope note before this is picked up. As written this is
feat(node)andPeerSourcereads asNodeOriginDeps-bound. But the paid resume / reactive-top-up loop that moves insidePeerSourceis the same loop the CLI hand-rolls in two more places:crates/cli/src/commands/fetch.rs(fetch_blob_streaming, feat(contracts): on-chain enumeration views to eliminate event-log replay #1497)crates/cli/src/commands/bundle_pull.rs(Reactive mid-fetch top-up fordecdn bundle pull#1599 — still buffered, no top-up)clidepends onclient-pull, not onnode. So ifPeerSourceis built in thenodecrate, those two legs still can't call it and keep their own copies of the loop — #1599 stays a third hand-written copy even after this lands.Ask: put
PeerSource(or the paid-pull driver it wraps —open_progressive_pull+content_paid_frontier+genuine_exhaustion+ the top-up/settle-wait/reseed arms) inclient-pull, the one crate bothnodeandclialready depend on. Keep the node-specific bits (NodeOriginDeps, metrics,deps.buyer.top_up_channel) behind a smallFundertrait the node implements, soclient-pullstays chain-handle-agnostic.Then the source/sink split is clean and shared across both binaries:
client-pull):BackendSource(unpaid) |PeerSource(paid, owns reactive top-up).admit(node warm/serve, refactor(cache): unify blob ingest behind a range-aware cache API with retained partials #1607), a file writer (decdn fetch), file × N (bundle pull).admit-to-cache is one sink, not the spine — a serve-miss fans out to cache and the client stream.Net: reactive top-up becomes a property of
PeerSource, and all three paid consumers get it by depending onPeerSource+ choosing a sink — instead of the two hand-parallel loops we have now (fetch.rs+node_origin/resume.rs) becoming three. Origin serve stays onBackendSourceand correctly has no top-up (no channel to top up).Doesn't change this issue's intent or the #1607 → #1608 sequencing — just fixes the crate the seam lands in so #1599 closes as a call-site rather than a third copy.
alpergundogdu commentedon Aug 5, 2026
Context: this is the
Sourceaxis (node side) of the range-minimized pull (#1621).BlobSource/PeerSourcefill the gaps the driver (A) computes viamissing_ranges, writing through #1607'sadmit. The lean CLI precursor — routingbundle pullthroughfetch's streaming top-up loop (no new driver) — merged as #1612; the fullBlobSourceseam +max_blob_size_mbremoval is still this issue. Depends on #1607.feat(client-pull,cli): range-minimized decdn fetch via gap-driven dri…
alpergundogdu commentedon Aug 13, 2026
Closing — split. The core intent (unify miss sources behind one
BlobSourcewriting through the sharedadmitpath) is done:BackendSource(own-origin, Flow A #1655) andPeerSource(paid peer, inclient-pull) both ingest throughNodeRangedStore/admit_bao_streamat O(chunk-group) memory. The warm/buyer in-memory buffer is gone.The one remaining deliverable — remove
max_blob_size_mband make admission a disk decision — is now the whole of a simpler focused issue: #1678. (Re-anchored: after the payment-pool rewrite #1667 the ADR edit targets the refundable-floorMpolicy, not the retired two-tier deposit.) Tracking there.