Skip to main content

Module store

Module store 

Source
Expand description

Durable storage for pointer records, with merge-on-put.

The chunk store answers “already have it” and stops, which is right for an immutable record and wrong for a mutable one — it would silently drop every update. It also requires BLAKE3(content) == address, which no pointer can satisfy. So pointers get their own store rather than an exemption carved into that one.

§The shape of a write

A put is three steps, because the caller’s gates sit between them:

  1. inspect parses and compares against what is held: the arrival is either unchanged, stale, or a candidate that would win.
  2. verify checks the candidate’s signature — after the caller’s admission gates, and before it verifies payment.
  3. commit writes it, and settles the disk charge taken for it.

Those three are internal to the crate; PointerStore::put_bytes is the same sequence in one call, for callers with nothing to do in between.

Nothing cheap happens after something expensive: a resubmission of what is held is refused before any signature check, so repeatedly submitting one paid state buys no ML-DSA verifications. Step 2 runs outside any store lock, so a flood of unpaid candidates cannot block every other address behind one verification, and step 3 re-checks under the lock, because the world may have moved while payment was being verified.

§Atomicity

The commit — compare, write, re-index — runs inside a single blocking task holding a synchronous lock. Splitting it across an await would let a cancelled caller release the lock while its write was still in flight, leaving the index describing a record the disk no longer holds. Because the whole transaction lives in one task, dropping the caller’s future cannot tear it.

On disk each record is one file named by its hex address, under {root}/pointers/<shard>/, where the shard is the address’s last byte in hex: 256 directories, as the chunk store keeps, so no directory grows with the whole store. The last byte rather than the first because a node holds addresses near its own identity, and their leading bytes cluster. Writes go to a uniquely named temporary file in the shard and are renamed into place, so a crash leaves either the old record or the new one, never a torn one. A lock file under {root}/pointers/ keeps two processes from keeping two indexes over one set of files.

Structs§

PointerStore
A store of pointer records.
PointerStoreStats
What the store has done since it was opened, for telemetry.

Enums§

PutOutcome
What a put did.

Constants§

SUPERSEDED_RETENTION
How long a replaced record is kept after an update, in memory.