~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Records are served with their proof by com.atproto.sync.getRecord

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:sync/get-record

What changes

The host answers com.atproto.sync.getRecord (did, collection, rkey) as a PDS does: an application/vnd.ipld.car rooted at the group's current signed commit, holding that commit, the tree's nodes covering the key (its path and its neighbours', the MST's covering proof, as the reference PDS sends), and the record's block when it is there. A record not there gets the same nodes, proving it absent. A repo not here is RepoNotFound, a group switched off RepoDeactivated, a missing parameter InvalidRequest, as getRepo answers. It spends from the same sync-repo limit as getRepo.

Why

Apps read a record an account just wrote with getRecord; grain-serve's refreshRecords failed on a group with "its PDS answered 501 Not Implemented", so what a group wrote through an app showed only once the relays brought it. The proof is built from the tree the host already builds for getRepo and the firehose's commits (Tree::covering_proof), so no new primitive was needed.

How it was checked

proves_a_record_or_its_absence_from_the_signed_commit in tests/repos.rs, over a tree of 200 records and several layers: the commit verifies against the group's signing key (Commit::verified), the record's CID is reached down the path from the commit's MST root, as grain reads a proof, and matches repo.getRecord's; keys before, between and after the records are proved absent; an unknown repo, a missing parameter and a deactivated group are refused by name.

Shortcomings

The host still routes no com.atproto.sync.getBlocks or com.atproto.sync.getRepoStatus (nor the deprecated getCheckout and getHead), which the reference PDS serves.

Approved

This adds com.atproto.sync.getRecord. It returns a CAR rooted at the signed head commit. The CAR holds the tree's covering proof, plus the record block when the record exists. It reuses Tree::covering_proof, which the firehose already uses. Errors go through did_of, so unknown repos give RepoNotFound and deactivated groups give RepoDeactivated, as getRepo does. The route shares the sync-repo limit. The change file, api.md and limits.md all changed with it. The test checks the commit signature, walks the proof down to the record, and checks absence for keys before, between and after the records. I read the diff and did not run it.

I found nothing that must change. Two minor notes:

  • record_proof reads head, the paths and the record in separate store calls. A write between them could mix commits. Only a fresh read would pay for that, so it's fine unless the store reads aren't in one transaction.
  • The new limits.md sentence runs long on one line, which is cosmetic.
Merged as bcd068a