Skip to content

object-storage

Build a content-addressable object store over grafos-store::MemObjectStore (hot, leased memory) wrapped by TieredObjectStore (spills to BlockObjectStore on durable storage). The key is the SHA-256 of the bytes; CRC32 is verified on every read.

Source

cookbook/object-storage/ in the source tree.

The recipe extracts the host-testable manifest builder: take input bytes, compute SHA-256 + CRC32, return { sha256, crc32, size_bytes }. In production the manifest is what MemObjectStore::put() returns; reads use it to verify integrity end-to-end.

pub fn compute(input: &[u8]) -> ObjectManifest {
ObjectManifest {
sha256: sha256_hex(input),
crc32: crc32(input),
size_bytes: input.len(),
}
}

What’s interesting

  1. Two-layer integrity. SHA-256 is the address; CRC32 is the on-read sanity check. CRC32 catches in-flight bit flips that the SHA-256 lookup wouldn’t catch by itself (you only know what you asked for, not what the storage returned).
  2. The CRC32 is the standard polynomial. 0xedb88320 matches what zip and gzip use; crc32(b"123456789") is 0xCBF43926. Test pins this.
  3. Production drop-in. Replace the inline sha256_hex stub with sha2::Sha256 (already a workspace dep) and use grafos-store::MemObjectStore::put(bytes) -> ObjectManifest. The wire format is the same.