Repository navigation
feat(gateway): cache what pulls deliver, and one cache store for node and gateway - #2908
Conversation
decdn gateway keeps a decdn-cache CacheEngine under <data-dir>/cache (--cache-mb, default 10240; 0 turns it off) with the node's eviction loop on it. Every pull streams into it through CacheStores, a StreamStore over admit_bao_stream_until. A request whose bytes the cache holds, whole or its one Range, is served from it with no pull and no allowance charge, and counts in decdn_gateway_cache_hits_total. The CLI may now link iroh-blobs (decdn-cache without its s3 feature); the client SDK and sponsord still may not. contiguous_byte_ranges ends an open span at the blob's size, which the cache's bitfield needs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pointer journey runs its gateway with --cache-mb 0, since it counts a repeat request against the namespace allowance. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…apability A spent allowance or a page no capability covers now answers from the cache when it holds every byte of the response, since a hit costs nothing. Manifests the cache holds whole are read from it with no pull, and a site's index.html checks the cache as entries do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ange IngestStore, StreamStore, BaoRangeReader, StashedFault, IngestEnd, IngestFuture, SourceFuture, HashMismatch and ProvenSize move from decdn-client to decdn-bao-range, beside RangedStore. decdn-client re-exports each at its old path. decdn_cache::CacheStore implements the contract once and replaces the node's NodeAdmitStore and the gateway's own store; the gateway keeps only its StreamStores opener. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…in use An entry whose declared size passes --max-blob-mb answers 413 before any pull, as a raw blob does. CacheEngine::hold_in_use returns an InUse guard that keeps a hash out of capacity eviction; a CacheStore holds its entry while it lives, and a gateway cache hit holds it while it reads and counts as a use for LRU. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 10 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟡 Changes recommended
A misleading comment remains in crates/node/Cargo.toml referencing the removed NodeAdmitStore module instead of the current decdn_cache::CacheStore usage, so the change needs an update to prevent future dependency confusion.
1 open issue
What changed in this PR
Implements persistent gateway caching backed by decdn-cache::CacheEngine, serves repeat requests as cache hits without pulls/allowance charges, and unifies node + gateway pull-ingest storage via a single CacheStore contract moved into decdn-bao-range.
Changes:
- Add on-disk gateway cache (
<data-dir>/cache) with--cache-mbsizing/disable, eviction-loop lifecycle, cache-hit serving, and cache-hit metrics/status/dashboard wiring. - Move pull-side ingest/store contract types from
decdn-clienttodecdn-bao-range(withdecdn-clientre-exports) and implement once asdecdn_cache::CacheStore. - Fix
contiguous_byte_rangesso open-ended spans correctly extend to blob end; update dependency-edge checks and documentation accordingly.
| File | Description |
|---|---|
| docker/README.decdn.md | Updates Docker documentation to describe gateway cache behavior/configuration and related operational notes. |
| crates/node/src/node_origin/store_fault_tests.rs | Adds/updates node origin tests validating fault handling when using the new cache-backed store path. |
| crates/node/src/node_origin/pull_leg.rs | Refactors the node pull leg to ingest into the unified CacheStore and adjust associated pull-leg wiring. |
| crates/node/src/node_origin/mod.rs | Updates node origin module structure/exports to align with CacheStore usage and related helpers/tests. |
| crates/node/src/node_origin/backend_source/tests.rs | Adjusts backend source tests to operate with the new cache-backed ingest/store contract. |
| crates/node/src/node_origin/backend_source.rs | Updates backend source implementation and docs to use the unified CacheStore-based ingest path. |
| crates/node/src/node_origin/admit_store/tests.rs | Removes or updates obsolete tests tied to the prior admit-store implementation superseded by CacheStore. |
| crates/node/src/node_origin/admit_store.rs | Removes the legacy admit-store implementation now replaced by decdn_cache::CacheStore. |
| crates/node/Cargo.toml | Updates node crate dependencies/features to support the new cache store and feature gating (including S3 where needed). |
| crates/e2e/tests/gateway_public.rs | Adds/updates gateway public e2e coverage to verify cache-hit behavior on repeat requests and ranges. |
| crates/e2e/tests/gateway_pointer.rs | Adjusts pointer e2e coverage to keep accounting stable by controlling cache configuration during runs. |
| crates/common/src/cli/gateway/tests.rs | Adds tests for gateway CLI flag parsing/behavior around cache sizing and disabling. |
| crates/common/src/cli/gateway.rs | Introduces gateway CLI options for cache sizing/disable and documents their semantics in help text. |
| crates/client/tests/snapshots/public_api__public_api.snap | Updates the client public API snapshot to reflect moved/re-exported ingest contract and size-proof types. |
| crates/client/src/streamer.rs | Adapts streamer plumbing to use the ingest/store contract types now hosted in decdn-bao-range. |
| crates/client/src/source.rs | Refactors client source code to use/re-export the relocated ingest contract and related futures/types. |
| crates/client/src/sink.rs | Updates client sink code to reference the relocated fault/type definitions via decdn-bao-range re-exports. |
| crates/client/src/lib.rs | Adjusts client crate exports and size-proof verification usage to the new ProvenSize API location/constructor. |
| crates/client/src/driver/tests.rs | Adds regression tests covering contiguous range construction when the final span has an open end. |
| crates/client/src/driver.rs | Fixes contiguous_byte_ranges so an open-ended span correctly terminates at the blob’s total size. |
| crates/client/Cargo.toml | Updates client crate features/dev-deps to align tests and helpers with the moved decdn-bao-range modules. |
| crates/cli/src/commands/gateway/worker.rs | Threads cache-backed store plumbing into the gateway worker so streamed pulls can fill the gateway cache. |
| crates/cli/src/commands/gateway/tests.rs | Adds gateway command tests validating cache-hit behavior, allowance/capability bypass on hits, and size-cap handling. |
| crates/cli/src/commands/gateway/status/tests.rs | Updates status endpoint tests/fixtures to include cache-hit counters in the reported status model. |
| crates/cli/src/commands/gateway/metrics/tests.rs | Adds metrics tests to validate cache-hit series exposure and expected counter behavior. |
| crates/cli/src/commands/gateway/metrics.rs | Implements cache-hit counter reporting for metrics and status integration. |
| crates/cli/src/commands/gateway.rs | Implements the gateway cache lifecycle and cache-hit serving path, including hit accounting and cache-backed reads. |
| crates/cli/src/commands/fetch/cache_store/tests.rs | Adds tests ensuring streamed fetches can fill and then read back data via cache-backed stream stores. |
| crates/cli/src/commands/fetch/cache_store.rs | Introduces cache-backed StreamStore adapters (CacheStores) for gateway/cache-integrated streaming fetches. |
| crates/cli/src/commands/fetch.rs | Extends fetch command logic to optionally stream through cache-backed stores rather than scratch-only storage. |
| crates/cli/README.md | Updates CLI documentation around dependency constraints and cache-related behavior/footprint. |
| crates/cli/dashboard/src/view.test.ts | Updates dashboard view tests to reflect the new cache-hit counter in status/metrics data. |
| crates/cli/dashboard/src/fixtures/status-public.json | Refreshes dashboard fixtures to include cache-hit counters in the public status shape. |
| crates/cli/dashboard/src/fixtures/status-pool-error.json | Refreshes dashboard fixtures to include cache-hit counters in the pool-error status shape. |
| crates/cli/dashboard/src/fixtures/status-loopback.json | Refreshes dashboard fixtures to include cache-hit counters in the loopback status shape. |
| crates/cli/dashboard/src/contract.test.ts | Updates dashboard contract tests to require/validate the presence of the cache-hit counter field. |
| crates/cli/dashboard/src/components/StatTiles.tsx | Adds a dashboard stat tile for cache hits and integrates it into the existing tile layout. |
| crates/cli/dashboard/src/components/StatTiles.test.ts | Adds/updates component tests to validate rendering and labeling of the new cache hits stat tile. |
| crates/cli/dashboard/src/api.ts | Extends dashboard API typings/models to include the new cache-hit counter in counters payloads. |
| crates/cli/Cargo.toml | Updates CLI crate dependencies/features to include cache support while preserving dependency/feature constraints. |
| crates/cache/src/ranged_store.rs | Updates ranged store docs/implementation references to the new shared cache-store ingest contract location. |
| crates/cache/src/lib.rs | Exports cache-store modules/types needed by node/gateway, including the unified CacheStore and in-use guard types. |
| crates/cache/src/engine.rs | Adds/extends in-use tracking to prevent eviction/release while entries are actively read or being filled. |
| crates/cache/src/cache_store/tests.rs | Adds comprehensive tests for CacheStore ingest semantics, faults, progress, and eviction pinning behavior. |
| crates/cache/src/cache_store.rs | Implements the unified CacheStore over CacheEngine to satisfy the moved decdn-bao-range ingest contract. |
| crates/bao-range/src/size_proof.rs | Moves/defines ProvenSize in decdn-bao-range with verified construction semantics. |
| crates/bao-range/src/lib.rs | Exposes the ingest module and re-exports moved contract types so downstream crates can depend on stable paths. |
| crates/bao-range/src/ingest.rs | Introduces the pull-side ingest/store contract types and related futures/errors in their new crate home. |
| crates/bao-range/Cargo.toml | Adds required dependencies/features for the new ingest contract module and its async IO needs. |
| CLAUDE.md | Updates repository guidance/docs to reflect the new cache/store architecture and dependency constraints. |
| Cargo.toml | Adjusts workspace dependency feature defaults to keep decdn-cache store-only by default and control feature propagation. |
| Cargo.lock | Updates lockfile to reflect new/shifted dependencies introduced by the cache/store contract refactor. |
| adr/appendix-gateway.md | Updates gateway ADR appendix with detailed cache behavior, hit semantics, and operational notes. |
| adr/appendix-binaries.md | Updates binary/dependency footprint documentation to reflect the new cache linkage and constraints. |
| adr/038-bao-verified-range-streaming.md | Updates the ADR to align terminology and module boundaries with the refactored ingest/store contract layout. |
| .github/scripts/tests/test_check_crate_edges.py | Updates crate-edge enforcement tests to match revised dependency allowances and exceptions. |
| .github/scripts/check_crate_edges.py | Updates the dependency-edge checking script to support new cache-related dependency rules and documented exceptions. |
Review effort: Balanced
| # `NodeAdmitStore` (`src/node_origin/admit_store.rs`, #1621) implements | ||
| # `decdn_bao_range::RangedStore` directly (delegating to `NodeRangedStore`), so |
There was a problem hiding this comment.
Rewrote both crates/node/Cargo.toml comments to say what the node names from decdn-bao-range and bao-tree today (the pull-side contract CacheStore implements, and the encoder types), and fixed the same stale mention in crates/cache/src/ranged_store/tests.rs.
🤖 Addressed by Claude Code
…he hit The loopback refusal is how a page learns to register a capability, and both SDK contract suites pin it. A spent public allowance still serves a hit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

The last step of #2881's plan for the gateway.
decdn gatewaykeeps what it pulls in adecdn-cacheCacheEngineand serves repeat requests from it, and the node and the gateway share one cache-backed store. It builds on #2884, #2886, #2887 and #2903, all merged. It combines #2905, #2906 and #2907, which are closed in favor of this PR, plus their follow-ups.What changes
Gateway cache
<data-dir>/cacheholds the cache.--cache-mb(default 10240) sets its size, and--cache-mb 0turns it off. The node's eviction loop runs on it, with the node's default marks and free-disk margin. On exit the gateway stops the loop, waits for it to end, then shuts the cache down.Streamerover theCacheStoresopener.decdn getkeeps its scratch directory.Range. A hit is served from the cache with the same headers a pull gets. It starts no pull, spends no capability and charges no allowance, so it is served even when the allowance is spent. A loopback page that no capability covers still gets its 402, even for a hit: that refusal is how a page learns to register a capability, and both SDK contract suites rely on it. Blobs, bundle entries and a site'sindex.htmlcan all hit. A blob the cache holds whole answersHEADwith its length.InUsebelow.decdn_gateway_cache_hits_total, also in/_statusand on the dashboard.--max-blob-mbanswers 413 before any pull, as a raw blob already did.One cache store, with the pull-side contract in
decdn-bao-rangeIngestStore,StreamStore,BaoRangeReader,StashedFault,IngestEnd,IngestFuture,SourceFuture,HashMismatchandProvenSizemove fromdecdn-clienttodecdn-bao-range, besideRangedStore.decdn-clientre-exports each one at its old path, so thepublic_apisnapshot changes only in paths.ProvenSize::verifyis the only way to make aProvenSize.decdn-bao-rangegainsanyhow,iroh-ioandtokio; none of them is the blob store.decdn_cache::CacheStoreimplements the contract once, overadmit_bao_stream_until. It replaces the node'sNodeAdmitStoreand the gateway's own copy. Two parts are optional:with_session(proof-node capture for a serving leg) andon_admitted(the node's bytes-received count).CacheEngine::hold_in_usereturns anInUseguard. While any guard on a hash lives, eviction skips the hash and refuses to release it. ACacheStoreholds its entry for its lifetime, so GC never sweeps an entry under a fill. Such a sweep silently loses the fill's later writes (client: re-evaluate running decdn-client on the iroh-blobs store (0.104.1) #2881, upstream FsStore: deleting a loaded partial entry leaves its .bitfield file behind n0-computer/iroh-blobs#350).Fix in
decdn-clientcontiguous_byte_rangesends a span that has no end at the blob's size. Before, it dropped that span. The cache's bitfield gives the last span an open end, so a stream reading the cache stopped one span short.Dependency check and docs
iroh-blobsthroughdecdn-cachewithout itss3feature. The client SDK and sponsord still may not, and nothing may link the AWS SDK. The workspace takesdecdn-cachewithout default features, and the node turnss3back on.CLAUDE.md,adr/appendix-gateway.md § Cache,adr/appendix-binaries.md, ADR 038, the Docker README, and the gateway module doc.Tests
decdn-cachestore tests cover:HashMismatch;CacheStore.Rangeis served with no pull and no allowance charge;Streamerover the cache reads back a 1.5 MB blob.driver: an open span runs to the blob's end.anvil-e2e: a new journey checks that a repeatGETand aRangecome from the cache, with no node bytes and no allowance charge. The existing journeys run with--cache-mb 0, so their accounting is unchanged.cargo clippy --workspace --all-targets --all-featureswith warnings denied,cargo doc,check_crate_edges.pyand its pytest suite,cargo fmt --check, and the dashboard's tests, typecheck and lint.Not covered
A blob released before a request arrives, and not yet swept by GC, still reads as present, and a hit on it can lose its bytes mid-read. The hold stops new releases; it does not re-protect a blob already released. The window lasts at most one GC interval (300 s by default).
🤖 Generated with Claude Code