OXYGENHUB

The ledger: SQLite, frozen envelope with hash chain, proofs and HLC, signed checkpoints, verify issue #3 closed: completed andymccall opened this · 1 comment

andymccall

The core of Spectra: an append-only ledger in SQLite, tamper-evident the way Oxygen's history is, with everything else a projection of it (spec §9, §9.5).

  • spectra-core::store: opens <data>/spectra.db (WAL, synchronous=NORMAL, foreign keys), applies sqlx migrations, refuses a database from a newer version.
  • Append in one transaction: gap-free seq, ULID id, at_ms, hlc (a hybrid logical clock with the five-minute drift bound, oxygen spec §6.4), prev (the previous event's hash), hash (deterministic CBOR through oxy-core, hashed as BLAKE3("spectra1 event " || len || 0 || body), oxygen spec §5.1 and §5.2) and auth (key, method, assurance, proof). Projections update in the same transaction; events are published on the bus after commit.
  • Checkpoints: ledger.checkpoint { seq, hash, hlc, count } signed by the instance identity every 256 events, every ten minutes while writing, and at shutdown.
  • spectra admin verify: recomputes every hash and prev, verifies every proof against the identities and delegations in the ledger at that event's hlc, verifies every checkpoint; reports breaks, unproven events, since-revoked delegates; exit 1 on any.
  • The envelope (seq, id, at_ms, hlc, prev, hash, auth, kind, actor, session, project, subject, payload, trace) is frozen from this release. A test asserts the field set so it cannot drift, and a test edits a row in SQLite and shows verify catching it.
  • spectra admin rebuild and admin check. A projection-equality harness (append a random mix, rebuild, compare every table) that every later scenario test uses.

Depends on oxy-core (pinned as a subrepo under deps/, as oxygenhub pins its dependencies) for identities, signatures, encoding and hashing. Never reimplement those.

Done when the harness passes over 10,000 random events, appending stays under 10 ms with fsync, and an edited row is caught. After issue #1.

andymccall set labels feature ·

andymccall set milestone Sprint 1 ·

andymccall edited ·

andymccall referenced by change 36537112fcac on main ·

andymccall

Done: the ledger in crates/spectra-core. Events are deterministic CBOR through oxy-core, hashed as BLAKE3("spectra1 event " || len || 0 || body) and chained by prev; the envelope with its hybrid logical clock is frozen (a test asserts the field set). The instance key signs a checkpoint every 256 events (exactly, even mid-batch), every ten minutes while writing, and on demand, through oxy-core's challenge signing with a spectra1 checkpoint prefix. spectra admin verify [--json] catches an edited row, an edit with its hash recomputed, a removed row, and a checkpoint signed by another key; admin check and rebuild hold projections to the ledger over 10,000 random events. Measured in release: 0.15 ms a single append (target 10 ms). Also: make check and the pipeline now test and lint Spectra's own packages only, as --workspace was running oxy-core's 379 tests.

andymccall closed ·