fix(store): checkpoint the WAL on the store's own keyed connection #54

Merged
sirius merged 2 commits from feat/store-checkpoint-wal into main 2026-09-12 22:10:11 +00:00
Owner

Why

Node::shutdown() / Node::flush() promise a WAL checkpoint, but on the SQLCipher store (PR #43) that checkpoint ran through a short-lived second connection with no key, so it degenerated to:

wal: store is SQLCipher-encrypted — skipped (file is not a database)

Nothing was lost (sqlite folds the WAL in when the last connection closes), but the explicit truncation never happened on a real store.

What

  1. src/store.rs — new Store::checkpoint_wal() runs PRAGMA wal_checkpoint(TRUNCATE) on the connection Store owns (the keyed one). wipe_messages reuses it instead of its inline copy.
  2. src/node.rs — Node::checkpoint() locks the node's Arc<Mutex<Store>> and calls it. The second-connection helper and its "encrypted store is skipped" doc caveat are deleted. Node::shutdown() / Node::flush() public signatures unchanged.
  3. Tests — the offline test that built a plaintext db moves with the code into src/store.rs::at_rest::checkpoint_wal_truncates_an_encrypted_store_wal: it writes 64 rows through Store::open_at_with_passphrase, then asserts onionwire.db-wal is 0 bytes after checkpoint_wal(). The live test (tests/tor_lifecycle.rs, ignored) now also asserts the WAL is non-empty before flush() and 0 bytes after, on a bootstrapped node. The node.rs::lifecycle_tests module goes away: with the helper gone nothing in it runs without a live node, and "no store at all" is no longer a state a Node can be in (start always opens/creates the store).

RED first, on the current implementation, against a real encrypted store:

thread 'node::lifecycle_tests::checkpoint_wal_truncates_a_live_wal' panicked at src/node.rs:1154:30:
checkpoint: "store is SQLCipher-encrypted — skipped (file is not a database)"

Evidence

  • cargo test --locked — 28 suites, 216 passed, 0 failed, 4 ignored. (216 not 217: two offline tests in node.rs were deleted, one store-level test added; store::at_rest::checkpoint_wal_truncates_an_encrypted_store_wal ... ok.)
  • cargo clippy --locked --all-targets -- -D warnings — exit 0.
  • Live Tor, real Arti descriptor upload: cargo test --locked --test tor_lifecycle -- --ignored --nocapture → test shutdown_stops_the_node_and_later_calls_are_typed_errors ... ok (1 passed, 135.9s), including the new WAL assertions.

Stacking

Based on feat/tor-lifecycle @ 48c06df (PR #49) — the second-connection helper this card deletes only exists there, not on main, so a main-based branch could not deliver item 2 of the card. Retarget this PR to main once #49 lands; the diff is then exactly the 3 files above.

Wire frames / protocol untouched, no docs/PROTOCOL.md change.

## Why `Node::shutdown()` / `Node::flush()` promise a WAL checkpoint, but on the SQLCipher store (PR #43) that checkpoint ran through a short-lived **second** connection with no key, so it degenerated to: ``` wal: store is SQLCipher-encrypted — skipped (file is not a database) ``` Nothing was lost (sqlite folds the WAL in when the last connection closes), but the explicit truncation never happened on a real store. ## What 1. `src/store.rs` — new `Store::checkpoint_wal()` runs `PRAGMA wal_checkpoint(TRUNCATE)` on the connection `Store` owns (the keyed one). `wipe_messages` reuses it instead of its inline copy. 2. `src/node.rs` — `Node::checkpoint()` locks the node's `Arc<Mutex<Store>>` and calls it. The second-connection helper and its "encrypted store is skipped" doc caveat are deleted. `Node::shutdown()` / `Node::flush()` public signatures unchanged. 3. Tests — the offline test that built a *plaintext* db moves with the code into `src/store.rs::at_rest::checkpoint_wal_truncates_an_encrypted_store_wal`: it writes 64 rows through `Store::open_at_with_passphrase`, then asserts `onionwire.db-wal` is 0 bytes after `checkpoint_wal()`. The live test (`tests/tor_lifecycle.rs`, ignored) now also asserts the WAL is non-empty before `flush()` and 0 bytes after, on a bootstrapped node. The `node.rs::lifecycle_tests` module goes away: with the helper gone nothing in it runs without a live node, and "no store at all" is no longer a state a `Node` can be in (`start` always opens/creates the store). RED first, on the current implementation, against a real encrypted store: ``` thread 'node::lifecycle_tests::checkpoint_wal_truncates_a_live_wal' panicked at src/node.rs:1154:30: checkpoint: "store is SQLCipher-encrypted — skipped (file is not a database)" ``` ## Evidence * `cargo test --locked` — 28 suites, 216 passed, 0 failed, 4 ignored. (216 not 217: two offline tests in `node.rs` were deleted, one store-level test added; `store::at_rest::checkpoint_wal_truncates_an_encrypted_store_wal ... ok`.) * `cargo clippy --locked --all-targets -- -D warnings` — exit 0. * Live Tor, real Arti descriptor upload: `cargo test --locked --test tor_lifecycle -- --ignored --nocapture` → `test shutdown_stops_the_node_and_later_calls_are_typed_errors ... ok` (1 passed, 135.9s), including the new WAL assertions. ## Stacking Based on `feat/tor-lifecycle` @ 48c06df (PR #49) — the second-connection helper this card deletes only exists there, not on `main`, so a `main`-based branch could not deliver item 2 of the card. Retarget this PR to `main` once #49 lands; the diff is then exactly the 3 files above. Wire frames / protocol untouched, no `docs/PROTOCOL.md` change.
fix(store): checkpoint the WAL on the store's own keyed connection
All checks were successful
ci / test (pull_request) Successful in 4m23s
2c3d9fd176
The WAL checkpoint that `Node::shutdown`/`flush` promise ran through a
short-lived second connection that no longer works: since the SQLCipher
store every db is encrypted and its key lives inside `Store`, so an
unkeyed second connection reads the file as noise and the checkpoint
degenerated to "store is SQLCipher-encrypted — skipped (file is not a
database)".

`Store::checkpoint_wal()` now runs `PRAGMA wal_checkpoint(TRUNCATE)` on
the connection `Store` owns, and `wipe_messages` reuses it instead of its
inline copy. The node-side helper and its doc caveat are gone; the
offline test moves with the code into `store.rs` and runs against a real
encrypted store (it failed on the old implementation with exactly the
SQLITE_NOTADB skip above). The live shutdown test now checks the WAL is
0 bytes after `flush` on a bootstrapped node.

Public signatures of `Node::shutdown`/`flush` are unchanged.
sirius changed target branch from feat/tor-lifecycle to main 2026-09-12 21:18:25 +00:00
Merge branch 'main' into feat/store-checkpoint-wal
All checks were successful
ci / test (pull_request) Successful in 4m18s
111e90ce0a
sirius merged commit 175cb58aba into main 2026-09-12 22:10:11 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!54
No description provided.