Accounting reasoning: a write that is retried after a lost answer must happen once, and a call that dies between its journal lines must never be replayed as if whole. The journal feature `call_transactions` frames a call's lines with `call.begun` and `call.closed`; the lines between count only when the closing line says `ok`. Every replay (open, the viewer, verify, rebuild, the projection's catch-up) goes through one gate (`CallGate`), so no state is built from half a call and a replay of any prefix ending inside a call equals the replay of the prefix before it. A call that never closed is closed `unfinished` at the next open; a call that fails after writing lines is closed `failed`, its SQLite changes (one transaction per call) rolled back and the live ledger rebuilt without them. The closing line keeps the answer given, so a repeat of a request key returns it; the key table is rebuilt from the journal alone. The envelope is untouched. Lines outside a frame apply as ever, so every journal written before the feature replays as it was. Books get a unique id (`books_id`) at creation, and older books at the format upgrade, in the `journal.format_set` that declares the feature. The frame lines never move the audit's figure head. The upgrade's declaration now also carries the id, so the three tests that pinned its exact payload compare it without the id. No figure and no golden moved. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
63 lines
2.1 KiB
Rust
63 lines
2.1 KiB
Rust
//! `ledger-store`: durable persistence for the books.
|
|
//!
|
|
//! Three pieces, one job — keep the books safe:
|
|
//!
|
|
//! * [`journal`] — the source of truth. An append-only, hash-chained JSONL
|
|
//! journal. Every state change is an immutable fact, fsync'd on append.
|
|
//! * [`blob`] — the bytes. Content-addressed (SHA-256), immutable,
|
|
//! deduplicated receipt and document storage.
|
|
//! * [`Store`] — the SQLite projection plus the write path. SQLite is the
|
|
//! query engine and is disposable by design: [`Store::rebuild`] drops it
|
|
//! and replays the journal. [`Store::verify`] replays the journal into a
|
|
//! fresh engine and diffs its reports against both the live ledger and
|
|
//! the projection.
|
|
//!
|
|
//! The write path is singular: **validate → journal → mutate → apply**.
|
|
//! Journal first means a failed write leaves nothing behind; a failed
|
|
//! SQLite apply leaves the journal ahead, and the next open heals it via
|
|
//! `last_applied_seq`. There is exactly one writer: `Store` is `!Sync` by
|
|
//! construction (it owns a `rusqlite::Connection`).
|
|
|
|
pub mod access;
|
|
pub mod auth;
|
|
pub mod backup;
|
|
pub mod blob;
|
|
pub mod cancel;
|
|
pub mod chain;
|
|
pub mod describe;
|
|
pub mod error;
|
|
pub mod exports;
|
|
pub mod form1099;
|
|
pub mod format;
|
|
pub mod git_locks;
|
|
pub mod journal;
|
|
pub mod lock;
|
|
pub mod meta;
|
|
pub mod ops;
|
|
pub mod passphrase;
|
|
pub mod reconcilable;
|
|
#[cfg(test)]
|
|
mod refuse;
|
|
pub mod root;
|
|
pub mod saving;
|
|
pub mod schema;
|
|
pub mod snapshot;
|
|
pub mod store;
|
|
pub mod uploads;
|
|
#[cfg(windows)]
|
|
pub mod winsec;
|
|
|
|
pub use blob::BlobStore;
|
|
pub use error::StoreError;
|
|
pub use format::{FormatUpgrade, JournalFormat, SUPPORTED_JOURNAL_FORMAT};
|
|
pub use journal::{GENESIS_PREV, JournalLine, JournalWriter};
|
|
pub use snapshot::{DiskCheck, Snapshot};
|
|
pub use store::audit;
|
|
pub use store::calls;
|
|
pub use store::{
|
|
Attachment, BillPreview, DepreciationRun, DisposalPreview, EntryRow, EventRow, Extraction,
|
|
ExtractionStatus, InvoicePreview, JOURNAL_FILE, LEGACY_DB_FILE, LOCK_FILE, MAX_RECURRING_RUN,
|
|
PayrollLineInput, PreviewPosting, Reconciliation, Statement, Store, Subject, VerifyReport,
|
|
WriteOffEvidence, database_in_use, db_file, db_file_for, is_database_file,
|
|
};
|