monerod: spawn a pruned local monerod as the chain source
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

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).
This commit is contained in:
agent 2026-09-16 20:54:54 -04:00
commit c45b008e97
No known key found for this signature in database
4 changed files with 525 additions and 1 deletions

View file

@ -27,6 +27,7 @@ document explains why, and what breaks when you do.
| `ONIONWIRE_WALLET_RPC` | `http://[user:pass@]host[:port][/path]`. Unset → no wallet; chat still works and `/pay` falls back to the profile `xmr_addr`. |
| `ONIONWIRE_WALLET_RPC_LOGIN` | `user:pass` when you do not want the password in the URL. Ignored if the URL carries userinfo. |
| `ONIONWIRE_WALLET_NO_SPEND` | `1` / `true` / `yes` / `on` → view-only deployment: `/tip` is refused locally, before any RPC dial. `/pay` and receipt verification keep working. |
| `ONIONWIRE_MONEROD` | `1` / `true` / `yes` / `on` → OnionWire spawns a pruned local `monerod` as the chain source (option 1 below). Unset → no local chain; the wallet child uses whatever daemon you gave it. |
`README.md` carries the operator summary; this file is the long form.
@ -78,6 +79,31 @@ does not pick a public remote node for you.
Remote daemons are untrusted (`--trusted-daemon` off). Unsynced or unreachable
→ receipts stay unverified and spend is refused. That is the honest state.
### Option 1 in practice: the in-app spawn
Set `ONIONWIRE_MONEROD=1` and the app starts the daemon itself — you do not run
`monerod` by hand. It looks for `monerod` on `PATH`, keeps its chain data in
`$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.
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
talk to it. p2p is untouched (`monerod`'s own defaults, port 18081): a pruned
node still dials peers on the Monero network to sync, so "local daemon" means
you are not handing your addresses to someone else's node — it does not mean the
sync is offline.
On start the app waits up to 5s for the RPC port to answer. A missing binary or
a port that never comes up is **not** fatal: it is logged, no local chain is
assumed, and the wallet reports the unsynced state above. On shutdown the daemon
is SIGTERMed (SIGKILL after 10s). If you stop the app with SIGKILL, `monerod`
keeps running and keeps syncing; kill it yourself or leave it — the next start
reuses the same data dir.
## Create a view-only wallet
Either path produces a wallet file with the view key only. Keep the seed /