ProtoRune.MST (proto_rune v0.5.1)

Copy Markdown

Traversal of the Merkle Search Tree inside a repository checkout.

A com.atproto.sync.getRepo CAR (see ProtoRune.Atproto.Sync.get_repo/2) contains the repository's MST as DAG-CBOR node blocks. Each node holds a nullable left subtree link l and an ordered list of entries e, where every entry maps a collection/rkey key to the CID of a record block:

%{
  "l" => left_cid | nil,
  "e" => [
    %{"p" => prefix_len, "k" => key_suffix, "v" => record_cid, "t" => subtree_cid | nil}
  ]
}

Keys are prefix-compressed: an entry's full key is the first p bytes of the previous key in traversal order concatenated with k. Traversal is depth-first in-order (left subtree, then each entry followed by its right subtree t), which yields entries in sorted key order.

The MST root CID is the data field of the commit block, itself found under the CAR header's root CID (see ProtoRune.CAR.read/1).

Trust model

This module performs no verification: no key hashing, no inclusion proofs, no diffing. The blocks are trusted as delivered by the source PDS, matching the trust model of ProtoRune.Atproto.Sync.

Summary

Types

A decoded block map as returned by ProtoRune.Atproto.Sync.parse_car/1.

Functions

Enumerates the MST entries reachable from the given root CID.

Enumerates the records of a checkout, keyed by collection/rkey.

Types

blocks()

@type blocks() :: %{required(ProtoRune.CID.t()) => term()}

A decoded block map as returned by ProtoRune.Atproto.Sync.parse_car/1.

Functions

entries(blocks, root_cid)

@spec entries(blocks(), ProtoRune.CID.t()) ::
  {:ok, [{String.t(), ProtoRune.CID.t()}]} | {:error, tuple()}

Enumerates the MST entries reachable from the given root CID.

root_cid is the CID from the commit block's data field. Returns {:ok, [{key, cid}]} with the full collection/rkey key strings in sorted order, or {:error, {:missing_block, cid}} when the checkout is malformed and a referenced node block is absent.

records(blocks, root_cid)

@spec records(blocks(), ProtoRune.CID.t()) ::
  {:ok, %{required(String.t()) => term()}} | {:error, tuple()}

Enumerates the records of a checkout, keyed by collection/rkey.

Resolves each entry CID from entries/2 against blocks, so MST node and commit blocks are not part of the result. Returns {:error, {:missing_block, cid}} when a referenced block is absent from the checkout.