Skip to content

feat(client)!: keep each download in an iroh-blobs store - #2958

Merged
alpergundogdu merged 8 commits into
mainfrom
client-store-iroh-blobs
Nov 24, 2026
Merged

alpergundogdu merged 8 commits into
mainfrom
client-store-iroh-blobs

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Steps 3 and 4 of moving the client store onto iroh-blobs (#2881). Builds on #2945 (donors splice outside the store) and #2946 (iroh-blobs 0.105).

What changes

  • A single download keeps its state in an iroh-blobs file store beside its destination, <dest>.decdn. The store holds the verified bytes, their outboard and the present ranges, and a resumed download reads them back from it. The .partial data file, the .partial.ranges record and ranged_store.rs's own file I/O are gone.
  • A bundle pull keeps one store for all its entries, <out>/.decdn-partial/store. The puller opens it on first use and closes it in BundlePuller::finish: removed when every pull settled every entry (none failed, none cut short), kept for the next run otherwise. The manifest fetch keeps its own short-lived store beside its staging file, so --overwrite, which fetches the manifest every run, never leaves a record in the shared store.
  • Finish: once a blob is complete the store exports it (ExportMode::TryReference: a rename on the same file system). A single download then removes its store directory.
  • Lost exports: after an export the store's entry points at the exported file. If that file is gone and the blob is needed again, the entry reads complete but cannot be read, and iroh-blobs ignores a fresh import into it. The downloader detects this (StaleStoreEntry) and fails the entry; a bundle then removes its store at the end of the run, so the next run fetches the blob fresh. This needs a failed run plus a finished file deleted before the rerun, or an exported file that fails its hash.
  • Ingest: decodes and verifies as before, then writes each batch of verified items (64 KiB ramping to 4 MiB) as one import_bao and only then marks it present. present stays an in-memory read, so the streamer never asks the store for a byte it does not hold.
  • No GC: stores run without GC and are deleted whole, so partials need no tags and the GC lost-write hazard (upstream #350) cannot occur.
  • Completed-but-unsynced recovery (from the 0.105 repros): a partial entry whose size the store never validated leaves out its last chunk group at open, and finalize does the same for an entry that holds every range but reads partial. Fetching that one group records the blob complete.
  • Export hash kept: the downloader hashes the exported file. For a single download, one whose bytes changed on disk after they verified is removed and fetched once more from an empty store, sharing the first pass's SourceSet so lanes continue their voucher sequence.
  • Streamer: ScratchStores opens one store in its scratch directory on first use.
  • Removed API: Downloader::refetched_targets. Public API snapshot updated.
  • Dependencies: decdn-client links iroh-blobs (file store only; no aws-lc, AWS SDK or JSON-RPC server), and so do the CLI and the sponsord daemon. check_crate_edges.py and CLAUDE.md say so. sponsord-onramp still links none.

Behaviour to note

  • A clean filtered pull removes the bundle store. Half-finished bytes an earlier run left for entries this pull did not select go with it, and a later pull of those entries fetches them again.
  • One store per process per directory. iroh-blobs locks its database, so two decdn get processes pulling the same bundle into the same directory at once cannot share a store. That already collided on the staging files.
  • No fixed thread count. FsStore builds its own multi-thread runtime with tokio's default worker count, and Options has no setting for it. Needs a device check on mobile.
  • The client has its own iroh-blobs ingest. decdn-cache's ingest sits behind CacheEngine and the crate edges forbid client → cache, so the client's decode-then-import loop (about 100 lines) duplicates the cache's in shape.

Tests

  • Store unit tests run on ClientRangedStore::in_memory (iroh-blobs MemStore on the test's runtime), so paused-clock tests keep working.
  • New: lost-export detection, the bundle store's keep-or-remove rule, a caller's store kept after export and failing stale on a lost or drifted export, export-hash refetch, exported-dest skip, store removal on finish, file-store resume and export (tests/ranged_store_client.rs), conformance on both backends.
  • cargo nextest run -p decdn-client -p decdn-cli -p decdn-bao-range --all-features: 2549 passed.
  • e2e (anvil-e2e): every cli_bundle_pull_* journey and cli_fetch_resume pass.
  • Workspace clippy (--all-features), fmt, cargo doc with warnings denied, public API snapshot: clean.

🤖 Generated with Claude Code

alpergundogdu and others added 3 commits November 23, 2026 19:12
A download keeps its verified bytes, their outboard and the present
ranges in an iroh-blobs file store beside its destination,
`<dest>.decdn`. A resumed download reads them back from the store; the
`.partial` data file and its `.partial.ranges` record are gone. Once the
blob is complete the store exports it to the destination (moving the
data file where the file system allows) and the directory is removed.

- `ClientRangedStore` wraps one blob in an iroh-blobs `Store`. Its
  ingest decodes and verifies as before, then writes each batch of
  verified items (64 KiB ramping to 4 MiB) as one import before marking
  it present, so `present` stays an in-memory read and a reader never
  asks for a byte the store does not hold.
- The store runs with no GC and is removed whole. A partial entry whose
  size the store never validated leaves out its last chunk group at
  open, and `finalize` does the same for an entry that holds every range
  but reads partial: fetching that group records the blob complete
  (iroh-blobs 0.105 recovers a completed-but-unsynced blob that way).
- The downloader hashes the exported file. One whose bytes changed on
  disk after they verified is removed and fetched again from an empty
  store, sharing the pass's sources so its vouchers continue.
- A bundle entry keeps its own store at `.decdn-partial/<hex>.decdn`;
  the dedup assembly reads the store's ranges through it.
- `ScratchStores` opens one store in its scratch directory on first use.
- Tests: unit tests run on an in-memory store (`ClientRangedStore::
  in_memory`), which runs on the test's runtime, so paused-clock tests
  see its work; resume and export tests run on a file store.
- `Downloader::refetched_targets` goes: no finalize hash refetches
  from scratch anymore.
- `decdn-client` now links iroh-blobs (file store only, no aws-lc or
  JSON-RPC server), and so do the CLI and the sponsord daemon. The
  crate-edge table and CLAUDE.md say so.

#2881

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The whole-file hash after an export (and of a destination that already
exists) reads the file 16 MiB at a time and hashes each read with
`blake3::Hasher::update_rayon`. It read 8 KiB at a time on one thread.
No memory map: a file another process truncates under a map would
crash the process.

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

github-code-quality Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust, Solidity

Rust / code-coverage/cargo-llvm-cov

main 9d4495f client-store-iroh-bl... a665da6 +/-
78% 78% 0%
View coverage of the 10 most impacted files.
File main 9d4495f client-store-iroh-bl... a665da6 +/-
crates/client/src/streamer.rs 88% 86% -2%
crates/client/s...undle/engine.rs 61% 60% -1%
crates/client/src/bundle.rs 45% 44% -1%
crates/client/s...c/source_set.rs 93% 93% 0%
crates/cli/src/.../bundle_pull.rs 63% 63% 0%
crates/node/src...s/client/mod.rs 88% 88% 0%
crates/client/src/scheduler.rs 94% 94% 0%
crates/client/s...ranged_store.rs 89% 91% +2%
crates/client/s...c/downloader.rs 83% 85% +2%
crates/client/s...le/run_store.rs 0% 96% +96%

Solidity / code-coverage/forge

main 9d4495f client-store-iroh-bl... a665da6 +/-
93% 93% 0%

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


Updated November 24, 2026 14:59 UTC

alpergundogdu and others added 4 commits November 23, 2026 19:52
… store

iroh-blobs exports only to an absolute path, and a download's destination
can be relative to the working directory (a bundle pulled to its default
destination), so `finalize` resolves it first. Adds an export test for
blobs small enough that the file store keeps them in its database.

The crate-edge script's tests follow the rule it now enforces: the SDK
and the crates built on it may link the blob store, the onramp may not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…blobs

# Conflicts:
#	crates/client/src/bundle/engine/tests.rs
…blobs

# Conflicts:
#	crates/client/src/downloader.rs
#	crates/client/src/ranged_store.rs
#	crates/client/src/ranged_store/tests.rs
A bundle pull keeps every entry's verified bytes in one iroh-blobs store,
`<out>/.decdn-partial/store`, instead of one store per entry. The store
opens on first use and closes in `BundlePuller::finish`: it is removed
once no partial blob in it belongs to an entry the run did not settle,
and kept otherwise so the next run resumes from it.

An export leaves the store's entry pointing at the exported file. When
that file is gone and the blob must be fetched again, the entry is a lost
export: `StaleStoreEntry` fails the entry, and the store is removed at
the run's end so the next run fetches it fresh. The manifest fetch keeps
its own store beside its staging file, which goes with the export.

`BundlePuller::partial_downloads` lists what the store holds only part
of, which the CLI's leftover-partials warning reads.

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

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

The bundle store goes when every pull of the puller settled every entry,
and stays for the next run otherwise. Drop the per-hash settled set, the
store's partial-blob listing and BundlePuller::partial_downloads; the
CLI's leftover warning counts staging files only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alpergundogdu
alpergundogdu merged commit 430c406 into main Nov 24, 2026
38 checks passed
@alpergundogdu
alpergundogdu deleted the client-store-iroh-blobs branch November 24, 2026 15:05
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.

1 participant