Skip to content

refactor(storage): reduce the storage contract to revisioned records - #39

Merged
brandonweeks merged 5 commits into
mainfrom
storage-revisions
Jul 18, 2026
Merged

brandonweeks merged 5 commits into
mainfrom
storage-revisions

Conversation

@brandonweeks

Copy link
Copy Markdown
Owner

Storage backends now implement typed reads and writes with optimistic revisions and three sentinels: ErrNotFound, ErrConflict on a stale revision, and ErrExists on a duplicate create. The reservation, lease, and status-transition machine moves into the CA as a read-classify-write loop that retries from a fresh read on conflict, so backends never classify ACME state. storage/storagetest provides a conformance suite for backend authors, and NewMemoryStorage is a reference backend that passes it.

Orders store ids and compose urls on read. On top of the contract change, handlers now authorize certificate fetches through the issuing order, enforce order and authorization expiry, and serve the account orders URL and order list required by RFC 8555 §7.1.2.

Storage backends now implement typed reads and writes with optimistic
revisions and three sentinels: ErrNotFound, ErrConflict on a stale
revision, and ErrExists on a duplicate create. The reservation, lease,
and status-transition machine moves into the CA as a read-classify-write
loop that retries from a fresh read on conflict, so every lost race is
judged against the exact record the winning write replaced and backends
never classify ACME state.

Records round-trip by encoding rather than struct identity: a read
returns a record that marshals to the document that was written. Leases
and nonce expiry are judged with the CA host clock, so backends need no
clock; the CreateNonce ttl is a hint that only licenses storage-level
cleanup.

The badger backend keeps its key schema, wraps records in an envelope
carrying an explicit revision counter, and drops all reservation logic.
storage/storagetest provides a conformance suite for backend authors, and
NewMemoryStorage is a reference backend that passes it.
A certificate is served only when the order it names references it back,
so one left behind by a failed or superseded finalize belongs to no one.
The account-wide order scan it replaces was the last caller of
GetOrdersByAccount, which leaves the Storage contract.
RFC 8555 Section 7.1.2 requires the account object to name an orders
URL, and a client may refuse an account without one. Compose the URL on
read like the other wire fields rather than persisting and back-filling
it, and back it with an account orders endpoint: CreateOrder names each
new order on its account, and the list is composed from those IDs, so
Storage still needs no lookup beyond GetAccountByKey.
@brandonweeks
brandonweeks merged commit 9bbb50c into main Jul 18, 2026
6 checks passed
@brandonweeks
brandonweeks deleted the storage-revisions branch July 18, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant