fix(store): checkpoint the WAL on the store's own keyed connection
All checks were successful
ci / test (pull_request) Successful in 4m23s

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.
This commit is contained in:
t 2026-09-12 15:56:33 -04:00
commit 2c3d9fd176
No known key found for this signature in database
3 changed files with 77 additions and 99 deletions

View file

@ -10,7 +10,7 @@
//!
//! The offline half of this contract — the Arti-status projection, the WAL
//! checkpoint, and the SDK's typed error after shutdown — runs in the normal
//! suite (`tests/hs.rs`, `src/node.rs`, `crates/onionwire-sdk/src/lib.rs`).
//! suite (`tests/hs.rs`, `src/store.rs`, `crates/onionwire-sdk/src/lib.rs`).
use onionwire::node::{FlushOutcome, Node};
use onionwire::hs::TorState;
@ -52,10 +52,25 @@ async fn shutdown_stops_the_node_and_later_calls_are_typed_errors() {
"start returned Ok but tor_state() is {started_state:?}"
);
// Rows written by `start` (self row, current onion) are still in the WAL at
// this point: no checkpoint has run, and the connection that wrote them is
// still open.
let wal = home.join("onionwire.db-wal");
let before = std::fs::metadata(&wal).map(|m| m.len()).unwrap_or(0);
assert!(
before > 0,
"expected pending WAL frames before flush, got {before}"
);
// A flush with nothing queued is a no-op that reports it, not an error.
let drained: FlushOutcome = node.flush().await.expect("flush on a live node");
assert_eq!(drained.remaining, 0, "empty outbox: {drained:?}");
// `flush` promises a truncated WAL, and on an encrypted store that only
// works through the store's own keyed connection.
let left = std::fs::metadata(&wal).map(|m| m.len()).unwrap_or(0);
assert_eq!(left, 0, "flush left {left} bytes of WAL to replay");
node.shutdown().await.expect("shutdown");
assert_eq!(