Skip to content

cache: drop double BLAKE3 hash once iroh-blobs exposes verified-insert #233

Closed

Description

@thiras

Summary

CacheEngine::pull_through currently pays BLAKE3 twice on the happy path of a cache miss:

  1. Explicit Hash::new(&bytes) for content-address verification before insertion.
  2. Implicit rehash inside iroh_blobs::store::fs::FsStore::blobs().add_bytes(...), which always hashes what it's storing.

For small blobs this is negligible. For larger blobs — the default max_blob_size_mb is 1 GB and the design tolerates objects up to ~10 GB — it is not. BLAKE3 is fast but not free, and the cost is 100% of the origin-miss hot path.

Why not merge the two today

The verify-then-insert order is correctness-load-bearing: dropping the pre-check and trusting iroh-blobs to notice a mismatch would mean unverified bytes transiently enter the store. The workaround is an iroh-blobs API that accepts an expected hash and refuses the insert atomically if the computed hash disagrees.

Action

When iroh-blobs exposes such an API (or an equivalent "insert-with-expected-hash" call), replace the explicit Hash::new(&bytes) + add_bytes pair in crates/cache/src/engine.rs pull_through with the single verified-insert call. Keep the post-receive size cap and the HashMismatch error surface.

Tracking

Referenced by the TODO(#233): comment at crates/cache/src/engine.rs:1005. When picking this up, also update that comment to cite this issue number.

Acceptance

  • Single BLAKE3 pass per pull-through miss.
  • hash_mismatch_is_rejected_and_not_cached still passes unchanged.
  • No change to CacheError::HashMismatch variant shape.

🤖 Generated with Claude Code

Activity

  1. added
    kind:feature
    on Apr 14, 2026
  2. added
    status:blocked
    on Apr 14, 2026
  3. added 3 commits that reference this issue on May 10, 2026
    2464211
    f8f859b
    ed4d321
  4. added 3 commits that reference this issue on May 10, 2026
    55cb245
    012549e
    11cd4e5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:featurestatus:blocked

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions