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

chadtmiller.com/knotless

git that lives in your Atmosphere account

knotless.dev
1 collaborator

knotless 0.17.0 Latest 2 packages, 1 image

1
10

knotless-serve: repositories are read by the atproto crate's readers

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/knotless:serve/archive-stream

knotless-serve now reads accounts' repositories through the atproto crate's readers instead of its own copy in archive.rs. The crate is the same code grain and group-host use. One change in behaviour: a CAR whose tree isn't the one its keys make is now refused, as STAR-lite already was.

Claude Opus 5.5 · high

What changes

crates/knotless-serve/src/archive.rs reads through atproto 0.2.1. STAR-lite goes through star_lite::Reader, fed the body a piece at a time. A CAR goes through car::read, Commit::from_bytes and mst::Tree::read. The file's own STAR-lite reader, MST walk, root builder, ciborium encoding and varint go: 215 lines in, 563 out. What stays is knotless's part: asking the mirror first, the 256 MiB bound, and keeping the collections asked for.

What is refused changes in three ways:

  • A CAR's tree must be the one its keys make. Before, the CAR path walked whatever tree the blocks held; the STAR-lite path already checked the root.
  • Commits must be version 3.
  • Every commit, tree node and CAR header must be canonical DRISL, with map keys in order, where ciborium took any order.

Records' JSON is still read by knotless::drisl::record.

docs/design/serve.md says so.

Why

grain and knotless each kept a copy of the same STAR-lite reader, CAR walk and root builder, and they had drifted on decoding strictness. The readers now live once in the crate, released as 0.2.1 from at://did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.pull/3n2sill5plitd, with the commit check in 0.2.2 (at://did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.pull/3n2skohreiylq), and grain moved to them in its own pull. This one moves knotless.

How it was checked

  • cargo test -p knotless-serve --lib archive:: passes locally, 5 tests:
    • Repos built with the crate open to their records.
    • Each refusal: another account, another key, a commit changed after signing, a flipped block, a cut-short CAR, a missing record, a missing commit, a CAR with no root.
    • The @atproto/repo fixture reads the same as STAR-lite and as a CAR, fed 1, 7 and all bytes at a time. The STAR-lite refusals check the crate's messages.
  • clippy and the rest of the tests are left to the checks. Clippy here picks up Homebrew's older toolchain.

Shortcomings

  • A repository whose commit isn't version 3, or whose commit, tree node or CAR header isn't canonical DRISL, now fails its backfill and is logged account not backfilled. The reference PDS writes neither.
  • A CAR's commit is now checked by atproto::Commit::verified (0.2.2), as grain, group-host and the STAR-lite reader check one, so a commit whose rev is not a TID is refused here too.
Approved

This moves archive.rs onto atproto 0.2.1's star_lite::Reader, car::read, Commit::from_bytes and mst::Tree::read. It drops the file's own STAR-lite, MST and varint code, and the diff matches the body.

  • Reading: read buffers the first bytes to look for the STAR-lite magic. It then feeds chunks to the reader, or collects the rest of the body for a CAR. The 256 MiB bound is still counted per chunk in Body::chunk. The commit's DID and signature are still checked for the CAR path. kept and the collection filter are unchanged.
  • Tests: they now cover each refusal and feed the fixture 1, 7 and all bytes at a time. That covers chunk boundaries.
  • Docs: docs/design/serve.md is updated. No changeset is needed, because only knotless-serve changed.
  • Cargo.toml and ciborium: the stream feature on reqwest is dev-only, for the test helper. ciborium and sha2 are still used elsewhere in the crate, so the unused-dependency lint won't fire.
  • Checks: check, test, docs and e2e were still running or queued when I read them. The test check holds the 100% coverage gate, so it's worth watching.
  • Behaviour change: the stricter refusals (non-v3 commits and non-canonical DRISL now fail the backfill) are the intended change and the body states them. I'm not asking for anything on them.
Approved

Since my approval at ce11543, the pull bumps atproto to 0.2.2 and has the CAR path call Commit::verified(commit, did, key). That replaces the DID and signature checks archive.rs did itself. This also removes one of the shortcomings the body lists, the duplicated commit check. The tests now expect the crate's messages ("a commit for another account", "a commit the account's key did not sign"), and the change is small and consistent. The check, e2e, docs and test checks were still running or queued when I read them. The test check holds the coverage gate, so watch it. The body's shortcomings note still says archive.rs checks the commit itself, which is now out of date. That is only wording, and I'm not asking for a change.

Merged as 2981930