From 4ff95ce271b353b3576a5756c5add5a370ae9536 Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 16 Sep 2026 21:30:05 -0400 Subject: [PATCH] monerod: fix the PATH-empty test and the wallet-child doc overclaim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- docs/WALLET.md | 9 ++++++--- src/monerod.rs | 12 +++++++++--- src/node.rs | 5 +++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/WALLET.md b/docs/WALLET.md index eb3afd2..9b7f303 100644 --- a/docs/WALLET.md +++ b/docs/WALLET.md @@ -86,9 +86,12 @@ Set `ONIONWIRE_MONEROD=1` and the app starts the daemon itself — you do not ru `$ONIONWIRE_HOME/monero/` (mode 0700, never `/tmp` and never a shared location), and starts it with `--prune-blockchain --non-interactive`, its RPC bound to loopback only (`--rpc-bind-ip 127.0.0.1 --rpc-bind-port 18089`), logging to -`$ONIONWIRE_HOME/monero/monerod.log`. The wallet child is pointed at that RPC -with `--daemon-address 127.0.0.1:18089`; which process runs the wallet RPC (and -how it is started) is separate from this and unchanged. +`$ONIONWIRE_HOME/monero/monerod.log`. Point your wallet child at that RPC +yourself — `--daemon-address 127.0.0.1:18089`, exactly like the daemon address in +option 2 above. OnionWire does not configure the wallet child for you; the +address is only *exposed* to callers as `Node::monerod_rpc_addr()`, so a wallet +child left on its previous `--daemon-address` keeps using that one. Which process +runs the wallet RPC (and how it is started) is separate from this and unchanged. Zero trust is not optional here either: the spawn never passes `--trusted-daemon`, and the daemon's RPC is loopback so only this machine can diff --git a/src/monerod.rs b/src/monerod.rs index a6be2c3..803d18f 100644 --- a/src/monerod.rs +++ b/src/monerod.rs @@ -58,7 +58,10 @@ pub fn rpc_addr(port: u16) -> SocketAddr { /// /// A listening port is "ready enough": `monerod` binds RPC before it serves /// blocks, and the wallet child reports its own sync progress from there. We do -/// not speak HTTP ourselves. +/// not speak HTTP ourselves. Corollary: a port check cannot tell *whose* port it +/// is — if something already listens on `addr` (an operator's own `monerod`), +/// this returns `Ok` even though our child may have failed to bind. The +/// effective state is still "a local chain on loopback `addr`". pub fn wait_for_ready(addr: SocketAddr, timeout: Duration) -> Result<(), String> { let started = Instant::now(); loop { @@ -234,7 +237,6 @@ fn sigterm(pid: u32) -> bool { #[cfg(test)] mod tests { - use std::ffi::OsStr; use std::net::TcpListener; use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; @@ -326,7 +328,11 @@ mod tests { #[test] fn spawn_without_monerod_on_path_is_a_clear_error() { let dir = tempfile::tempdir().expect("tempdir"); - let empty = OsStr::new(""); + // The search path must be empty of `monerod`. `Some(OsStr::new(""))` is + // NOT that: `split_paths("")` yields one empty element, which `Path::join` + // resolves to `./monerod` in the test's cwd (so a `monerod` sitting in the + // crate root would be found). Point at an empty directory instead. + let empty = dir.path().as_os_str(); let err = match Monerod::spawn_with_path(dir.path(), Some(empty)) { Ok(_) => panic!("no monerod on PATH"), Err(e) => e, diff --git a/src/node.rs b/src/node.rs index b2ff2b9..c9e0392 100644 --- a/src/node.rs +++ b/src/node.rs @@ -278,8 +278,9 @@ impl Node { } /// Where the spawned local chain source listens, if this node started one - /// (`ONIONWIRE_MONEROD=1`). This is what the wallet child is pointed at - /// with `--daemon-address`; `None` means no local chain. + /// (`ONIONWIRE_MONEROD=1`). Exposed so a caller can point the wallet child + /// here with `--daemon-address`; the node does not wire that up itself. + /// `None` means no local chain. pub fn monerod_rpc_addr(&self) -> Option { self.monerod .lock()