monerod: spawn a pruned local monerod as the chain source #91

Closed
sirius wants to merge 2 commits from wt/t_4789c42f into main
Owner

docs/WALLET.md Chain source listed "spawn a local monerod (pruned on-device)" as an option with nothing implementing it. This adds src/monerod.rs and the opt-in node wiring.

What lands

  • src/monerod.rs (new, std only, no new dependency)
    • Monerod::spawn(home) finds monerod on PATH, creates $ONIONWIRE_HOME/monero/ at 0700, spawns the child, and waits for the RPC port (5s, monerod::READY_TIMEOUT). A binary that is missing or a port that never answers is a typed Err — the caller falls back to "no local chain".
    • argv: --data-dir $ONIONWIRE_HOME/monero --non-interactive --prune-blockchain --rpc-bind-ip 127.0.0.1 --rpc-bind-port 18089 --log-file .../monerod.log.
    • rpc_addr() is 127.0.0.1:18089; that is what the wallet child is told with --daemon-address.
    • stop(self) SIGTERMs, then SIGKILLs after 10s, and reaps. std has no signal API and the crate takes no libc, so SIGTERM goes through kill(1) with a SIGKILL fallback if that fails.
    • wait_for_ready(addr, timeout) polls TcpStream::connect_timeout; a listening port is ready enough, and the wallet child reports its own sync progress. No HTTP client added.
  • src/node.rs wiring, opt-in behind ONIONWIRE_MONEROD=1: start_monerod spawns on a blocking task during start_with_passphrase (never fatal — it logs and the node starts), shutdown() takes the daemon out of the mutex and stops it off the reactor, and monerod_rpc_addr() reports the address.
  • docs/WALLET.md: env table row plus an "Option 1 in practice" subsection under Chain source (the existing "user supplies a daemon" text is untouched).

Locks held

Loopback-only RPC; no --trusted-daemon; no --restricted-rpc; no SOCKS, no C-tor, no UDP; no clearnet daemon default; data dir under $ONIONWIRE_HOME at 0700, never /tmp; pruned is the on-device target. p2p keeps monerod's own defaults (the docs say plainly that a pruned local node still dials peers to sync — "local daemon" is about whose node sees your addresses, not about going offline). docs/THREAT_MODEL.md needed no change; the chain-source section already describes the spawned local daemon and stays consistent.

Tests (7, src/monerod.rs in-module)

argv is pruned + loopback and carries none of trusted-daemon / socks / proxy / udp / --bind-ip 0.0.0.0; PATH lookup requires an executable file; an empty search path and a missing binary each return a clear Err while leaving a 0700 data dir; the default addr is 127.0.0.1:18089; wait_for_ready times out against a bound-then-dropped port; and a fake daemon script spawns, reports its addr, then dies on stop() — asserted by its pid no longer existing.

TDD order was RED first: the tests were committed to the file before the implementation, and cargo test --lib monerod failed with 13 unresolved-item errors naming Monerod, rpc_addr, wait_for_ready, args and find_in; then the implementation made it green.

Verification

cargo check  --locked --target x86_64-unknown-linux-gnu     ok
cargo clippy --locked --all-targets -- -D warnings           ok (0 warnings)
cargo test   --locked --target x86_64-unknown-linux-gnu monerod
    7 passed; 0 failed
cargo test   --locked --lib                                  27 passed; 0 failed  (21 before the rebase; main's node.rs tests account for the rest)
rustfmt --edition 2024 --check src/monerod.rs                clean
rustfmt --edition 2024 --check src/node.rs                    7 hunks, all 7 inherited (origin/main gives the same 7)
cd crates/onionwire-sdk && cargo check --locked               ok

No Rust files outside the allowed scope were touched; src/wallet.rs, Cargo.toml, src/tui.rs and src/hs.rs are untouched. crates/onionwire-sdk is a separate workspace and no public signature changed (one added pub fn plus a new pub mod), so its lockfile is unaffected.

Rebase onto main

origin/main moved past this branch's base (cf77116), and the only conflict was in src/node.rs, where this branch adds start_monerod/env_flag at the same spot main (#88) inserted bootstrap_ratchet and friends. Resolved by keeping both blocks; nothing was dropped. One more line was needed that main introduced in the meantime: the Node literal inside node.rs's #[cfg(test)] mod tests now needs monerod: Mutex::new(None), or the test build fails with E0063 missing field monerod. That is the same class of change the store card hit when a field is added to a struct — one line in an in-repo test helper, inside an allowed file. All commands above were re-run on the rebased tree.

Review round 1 rework (head 4ff95ce)

Two corrections from the round-1 review, both in the pushed head:

  1. spawn_without_monerod_on_path_is_a_clear_error no longer passes Some(OsStr::new("")). split_paths("") is one empty element, so the old setup probed ./monerod in the test cwd; it now uses an empty temp dir. RED was reproduced first by planting an executable ./monerod in the crate root (old test fails there, new test passes with the same file still present).
  2. docs/WALLET.md no longer claims the wallet child is pointed at the local RPC. Nothing does that: --daemon-address appears in src/ only in comments and Node::monerod_rpc_addr() has no caller. The doc now tells the operator to point their own wallet child at 127.0.0.1:18089 and says the address is only exposed programmatically. The same overclaim in the monerod_rpc_addr doc comment in src/node.rs is fixed too.

Plus the non-blocking note: a one-line module-doc caveat that the port-liveness readiness check cannot tell whose port it is.

Re-verified at 4ff95ce: cargo check --locked --target x86_64-unknown-linux-gnu ok, cargo clippy --locked --all-targets -- -D warnings exit 0, cargo test --locked --target x86_64-unknown-linux-gnu --lib monerod 7 passed / 0 failed, cargo test --locked --lib 27 passed / 0 failed, rustfmt --edition 2024 --check src/monerod.rs clean, src/node.rs hunk count 7 = the 7 inherited from cf77116.

`docs/WALLET.md` Chain source listed "spawn a local `monerod` (pruned on-device)" as an option with nothing implementing it. This adds `src/monerod.rs` and the opt-in node wiring. ## What lands - **src/monerod.rs** (new, std only, no new dependency) - `Monerod::spawn(home)` finds `monerod` on `PATH`, creates `$ONIONWIRE_HOME/monero/` at 0700, spawns the child, and waits for the RPC port (5s, `monerod::READY_TIMEOUT`). A binary that is missing or a port that never answers is a typed `Err` — the caller falls back to "no local chain". - argv: `--data-dir $ONIONWIRE_HOME/monero --non-interactive --prune-blockchain --rpc-bind-ip 127.0.0.1 --rpc-bind-port 18089 --log-file .../monerod.log`. - `rpc_addr()` is `127.0.0.1:18089`; that is what the wallet child is told with `--daemon-address`. - `stop(self)` SIGTERMs, then SIGKILLs after 10s, and reaps. std has no signal API and the crate takes no `libc`, so SIGTERM goes through `kill(1)` with a SIGKILL fallback if that fails. - `wait_for_ready(addr, timeout)` polls `TcpStream::connect_timeout`; a listening port is ready enough, and the wallet child reports its own sync progress. No HTTP client added. - **src/node.rs** wiring, opt-in behind `ONIONWIRE_MONEROD=1`: `start_monerod` spawns on a blocking task during `start_with_passphrase` (never fatal — it logs and the node starts), `shutdown()` takes the daemon out of the mutex and stops it off the reactor, and `monerod_rpc_addr()` reports the address. - **docs/WALLET.md**: env table row plus an "Option 1 in practice" subsection under Chain source (the existing "user supplies a daemon" text is untouched). ## Locks held Loopback-only RPC; no `--trusted-daemon`; no `--restricted-rpc`; no SOCKS, no C-tor, no UDP; no clearnet daemon default; data dir under `$ONIONWIRE_HOME` at 0700, never `/tmp`; pruned is the on-device target. p2p keeps monerod's own defaults (the docs say plainly that a pruned local node still dials peers to sync — "local daemon" is about whose node sees your addresses, not about going offline). `docs/THREAT_MODEL.md` needed no change; the chain-source section already describes the spawned local daemon and stays consistent. ## Tests (7, `src/monerod.rs` in-module) argv is pruned + loopback and carries none of `trusted-daemon` / `socks` / `proxy` / `udp` / `--bind-ip 0.0.0.0`; PATH lookup requires an executable file; an empty search path and a missing binary each return a clear `Err` while leaving a 0700 data dir; the default addr is `127.0.0.1:18089`; `wait_for_ready` times out against a bound-then-dropped port; and a fake daemon script spawns, reports its addr, then dies on `stop()` — asserted by its pid no longer existing. TDD order was RED first: the tests were committed to the file before the implementation, and `cargo test --lib monerod` failed with 13 unresolved-item errors naming `Monerod`, `rpc_addr`, `wait_for_ready`, `args` and `find_in`; then the implementation made it green. ## Verification ``` cargo check --locked --target x86_64-unknown-linux-gnu ok cargo clippy --locked --all-targets -- -D warnings ok (0 warnings) cargo test --locked --target x86_64-unknown-linux-gnu monerod 7 passed; 0 failed cargo test --locked --lib 27 passed; 0 failed (21 before the rebase; main's node.rs tests account for the rest) rustfmt --edition 2024 --check src/monerod.rs clean rustfmt --edition 2024 --check src/node.rs 7 hunks, all 7 inherited (origin/main gives the same 7) cd crates/onionwire-sdk && cargo check --locked ok ``` No Rust files outside the allowed scope were touched; `src/wallet.rs`, `Cargo.toml`, `src/tui.rs` and `src/hs.rs` are untouched. `crates/onionwire-sdk` is a separate workspace and no public signature changed (one added `pub fn` plus a new `pub mod`), so its lockfile is unaffected. ## Rebase onto main `origin/main` moved past this branch's base (`cf77116`), and the only conflict was in `src/node.rs`, where this branch adds `start_monerod`/`env_flag` at the same spot main (#88) inserted `bootstrap_ratchet` and friends. Resolved by keeping both blocks; nothing was dropped. One more line was needed that main introduced in the meantime: the `Node` literal inside node.rs's `#[cfg(test)] mod tests` now needs `monerod: Mutex::new(None)`, or the test build fails with `E0063 missing field monerod`. That is the same class of change the store card hit when a field is added to a struct — one line in an in-repo test helper, inside an allowed file. All commands above were re-run on the rebased tree. ## Review round 1 rework (head 4ff95ce) Two corrections from the round-1 review, both in the pushed head: 1. `spawn_without_monerod_on_path_is_a_clear_error` no longer passes `Some(OsStr::new(""))`. `split_paths("")` is one empty element, so the old setup probed `./monerod` in the test cwd; it now uses an empty temp dir. RED was reproduced first by planting an executable `./monerod` in the crate root (old test fails there, new test passes with the same file still present). 2. `docs/WALLET.md` no longer claims the wallet child is pointed at the local RPC. Nothing does that: `--daemon-address` appears in `src/` only in comments and `Node::monerod_rpc_addr()` has no caller. The doc now tells the operator to point their own wallet child at `127.0.0.1:18089` and says the address is only exposed programmatically. The same overclaim in the `monerod_rpc_addr` doc comment in `src/node.rs` is fixed too. Plus the non-blocking note: a one-line module-doc caveat that the port-liveness readiness check cannot tell whose port it is. Re-verified at 4ff95ce: `cargo check --locked --target x86_64-unknown-linux-gnu` ok, `cargo clippy --locked --all-targets -- -D warnings` exit 0, `cargo test --locked --target x86_64-unknown-linux-gnu --lib monerod` 7 passed / 0 failed, `cargo test --locked --lib` 27 passed / 0 failed, `rustfmt --edition 2024 --check src/monerod.rs` clean, `src/node.rs` hunk count 7 = the 7 inherited from `cf77116`.
monerod: spawn a pruned local monerod as the chain source
All checks were successful
ci / test (pull_request) Successful in 4m29s
ci / sdk (pull_request) Successful in 1m18s
android-ci / android (pull_request) Successful in 10m6s
cdaf403e94
docs/WALLET.md §Chain source offered "spawn a local monerod (pruned
on-device)" but nothing implemented it. Add src/monerod.rs: find monerod
on PATH, mkdir $ONIONWIRE_HOME/monero at 0700, spawn it with
--prune-blockchain --non-interactive and its RPC bound to 127.0.0.1:18089,
poll the port for readiness, and stop it with SIGTERM (SIGKILL after 10s).

Locks held: loopback-only RPC, no --trusted-daemon, no SOCKS, no C-tor,
no clearnet default, no UDP, no new dependency (std only — SIGTERM goes
through kill(1) because the crate takes no libc). A missing binary or a
port that never answers is an Err the node logs and shrugs off: no local
chain is the honest state, not a crash.

Node wires it opt-in via ONIONWIRE_MONEROD=1: start_monerod spawns on a
blocking task during start_with_passphrase, shutdown() takes the daemon
and stops it off the reactor, and monerod_rpc_addr() reports where the
wallet child should point --daemon-address.

Tests (7, in-module): argv is pruned/loopback and carries no forbidden
flag; PATH lookup needs an executable; empty PATH and a missing binary
both Err with a clear message (and the data dir is 0700); default addr is
127.0.0.1:18089; wait_for_ready times out against a dead port; a fake
daemon spawns, reports its addr, and stops via SIGTERM (its pid is gone).
sirius force-pushed wt/t_4789c42f from cdaf403e94
All checks were successful
ci / test (pull_request) Successful in 4m29s
ci / sdk (pull_request) Successful in 1m18s
android-ci / android (pull_request) Successful in 10m6s
to c45b008e97
All checks were successful
ci / test (pull_request) Successful in 5m6s
ci / sdk (pull_request) Successful in 1m18s
android-ci / android (pull_request) Successful in 8m32s
2026-09-17 00:58:48 +00:00
Compare
monerod: fix the PATH-empty test and the wallet-child doc overclaim
All checks were successful
ci / test (pull_request) Successful in 4m56s
ci / sdk (pull_request) Successful in 1m9s
android-ci / android (pull_request) Successful in 8m35s
4ff95ce271
Review round 1 (artifact lens) on PR #91 found two defects.

1. `spawn_without_monerod_on_path_is_a_clear_error` passed
   `Some(OsStr::new(""))` as the search path. `std::env::split_paths("")`
   yields ONE empty element, so `find_in` probed the relative path
   `monerod` in the test's cwd and passed only because the crate root
   happened to hold no such file. Point it at an empty temp dir instead,
   which is what the card's "test by pointing PATH empty" asked for.
   Verified RED first: with an executable `./monerod` planted in the
   crate root, the old test fails
   ("spawn monerod: No such file or directory") and the new one passes
   with that same file still present.

2. The docs claimed a wiring the code does not perform:
   "The wallet child is pointed at that RPC with --daemon-address
   127.0.0.1:18089". Nothing points anything — `--daemon-address` exists
   in `src/` only inside comments, and `Node::monerod_rpc_addr()` has no
   caller. docs/WALLET.md now tells the operator to point their own
   wallet child at the loopback RPC and says the address is only exposed
   programmatically. The same overclaim in the `monerod_rpc_addr` doc
   comment in src/node.rs is corrected too.

Also one module-doc line for the non-blocking note: a port-liveness
check cannot tell whose port it is, so a pre-existing listener on 18089
yields Ok for a child that failed to bind.
sirius closed this pull request 2026-09-17 02:46:43 +00:00
sirius deleted branch wt/t_4789c42f 2026-09-17 05:04:04 +00:00
All checks were successful
ci / test (pull_request) Successful in 4m56s
ci / sdk (pull_request) Successful in 1m9s
android-ci / android (pull_request) Successful in 8m35s

Pull request closed

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!91
No description provided.