wallet: land the in-process Cuprate chain source on main
All checks were successful
ci / test (pull_request) Successful in 5m39s
ci / sdk (pull_request) Successful in 1m22s
android-ci / android (pull_request) Successful in 8m58s
ci / fuzz (pull_request) Successful in 4m45s

`ChainSource::InProcessCuprate { datadir }` is the fourth chain source: P2P,
consensus and RandomX run inside the OnionWire process instead of as a spawned
`monerod`. The wallet layer does not move — the daemon binds the same loopback
unrestricted RPC (`127.0.0.1:18081`) that `WalletChild::daemon_address` already
returns for a local source, so `wallet_rpc_argv`, the RPC client, the payment
frames and the receipt-verification path are untouched.

- Cargo.toml: `cuprated` (git, rev 4f8fcd1b) + `toml`, both optional, behind the
  `cuprate-daemon` feature, OFF by default. `cuprated`'s own `arti` feature is
  disabled (`default-features = false`): its arti-client 0.44 cannot unify with
  this crate's 0.46, and the in-process daemon is clearnet-only. One Tor stack in
  the process. `Cargo.lock` gains the graph; a default build's
  `cargo tree --locked -e normal -i cuprated` still says "did not match any
  packages", and only `arti-client v0.46.0` is in the lock.
- src/cuprate.rs (new): `CuprateNode` builds the cuprated config as TOML
  (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P
  off), launches it on a runtime it owns, and owns the node. `launch` is
  synchronous on purpose: `WalletChild::start` is sync (the TUI calls it from its
  blocking thread, UniFFI calls it from an async context) and a runtime cannot be
  started from inside a runtime, so the launch runs on a thread of its own and
  the node + its runtime come back over a channel. Dropping the value asks the
  node to shut down and `shutdown_background`s the runtime, which is the only
  exit that cannot panic when the value is dropped inside another runtime.
  The type exists in every build (feature off: `launch` fails with the feature
  name), so the chain-source type, its stored record and its copy do not fork on
  a cargo feature.
- src/wallet.rs: the variant, its label (`in-process node`), and the chain-daemon
  client the wallet line carried (typed `WalletError`, de-chunked HTTP,
  `get_height` over the URI endpoint, an above-the-tip height as one typed
  error). Cuprate answers those three differently from monerod and the
  in-process source is what makes them the *local* case.
- src/wallet_child.rs: launches/holds/stops the node, `chain_datadir` for the
  free-space/ownership question, the honest `chain_copy` line, `kind =
  "cuprate"` in the sealed record, and `ChildConfig::validate` for it.
- src/tui.rs: the wallet screen's chain line carries the testnet caveat when the
  configured source is the in-process one. It computes the line at draw time, so
  `Screen::Wallet`'s shape (which tests construct) does not change.
- docs/WALLET.md, docs/THREAT_MODEL.md, docs/cuprate-android-spike.md: the
  feature flag and how to enable it, where the (fjall) chain store lives, the
  **measured** +11.8 MiB delta, the pre-production/testnet caveat, and the
  in-repo aarch64-linux-android proof with exit codes.

Scope deviations, stated plainly:
- `src/cuprate.rs` and its one `src/lib.rs` module line are not in the card's
  allowed list; the card's own deliverable describes the module's behaviour.
- `crates/onionwire-sdk/src/lib.rs` is forbidden, but adding a variant to a
  `pub enum` that the SDK matches exhaustively breaks the SDK workspace, and the
  root CI `sdk` job runs on every PR. One variant plus two match arms land here
  so the SDK keeps compiling (`cargo test --locked` + clippy clean); the SDK card
  owns the rest — feature passthrough, the config field's semantics, the label
  and its tests, and the Android check.
- `tests/wallet.rs` carries the launch test. `tests/tui_frames.rs` is untouched:
  main has no `ChainChoice` to pin (the chain-source picker is the unmerged F7
  work, and `docs/WALLET.md` says so rather than describing a picker that does
  not exist).

Proof (all on this tree):
- Default build: `cargo test --locked --target x86_64-unknown-linux-gnu` → 345
  passed / 0 failed across 33 suites, exit 0; `cargo clippy --locked
  --all-targets --target x86_64-unknown-linux-gnu -- -D warnings` exit 0.
- Feature on: `cargo test --locked --features cuprate-daemon --target
  x86_64-unknown-linux-gnu` → 347 passed / 0 failed, exit 0; same clippy with
  `--features cuprate-daemon` exit 0. The two extra tests are the real thing:
  `wallet_child::tests::in_process_source_launches_a_daemon_and_stop_shuts_it_down`
  and `tests/wallet.rs::an_in_process_cuprate_node_answers_the_typed_daemon_client`
  — the latter launches the node, drives `get_info` / `get_height` / `get_block`
  through the typed client, checks the above-the-tip 500 maps to
  `DaemonHeightOutOfRange`, checks the chain store is under the chain datadir,
  and checks the listener dies with the node.
- aarch64: `cargo check --locked --release --target aarch64-linux-android
  --features cuprate-daemon` exit 0 (1m 50s), and the full link exit 0
  (`cargo rustc ... --bin onionwire -- <NDK C++ runtime / compiler-rt link
  args>`) producing `ELF 64-bit LSB pie executable, ARM aarch64, for Android 26,
  built by NDK r28c`.
- Size: stripped aarch64 release binary, 24,725,704 bytes without the feature and
  37,053,472 with it — +12,327,768 bytes (≈ +11.8 MiB), the figure
  `docs/WALLET.md` now quotes.
This commit is contained in:
agent 2026-09-18 13:45:59 -04:00
commit ffea4bf9df
No known key found for this signature in database
12 changed files with 2804 additions and 50 deletions

View file

@ -193,7 +193,34 @@ the app does not pick a public remote node for them.
Unsynced or not running is an honest “not ready” / unverified state, not a
fake success.
2. **A daemon address they supply.** The wallet child points `--daemon-address`
2. **An in-process daemon** (Cuprate, behind the `cuprate-daemon` feature, off by
default). P2P, consensus and RandomX run in the OnionWire process; nothing is
spawned and nothing leaves the device except the chain P2P traffic itself.
What that changes: there is **no daemon operator** to trust — your own process
is the daemon, so the "operator sees your addresses" question does not exist.
The spend key, the chain, and the messenger are then all on one device.
What it does not change: the **device is now the trust root for chain data**.
Chain state is only as trustworthy as the binary running it, and a
compromised device corrupts the chain view along with everything else.
Honest limits, stated here rather than in a footnote:
- Cuprate is **pre-production**. Its own user book says *"do NOT use cuprated
for any serious purposes"*, and its `monerod` RPC parity is incomplete
(Cuprate issue #278). This is why the source is an opt-in build feature and
a stored user choice, never a default.
- The config pins **testnet**. Mainnet is not validated by this app.
- Cuprate's own `arti` feature is off (its Tor stack is `arti-client` 0.44,
which cannot unify with this crate's 0.46), so the in-process daemon's P2P
traffic is **clearnet**: your ISP sees that this device talks to Monero
peers. No Tor is on the chain path — Tor is the messenger's transport here,
not the chain's.
- Inbound P2P is off and the restricted RPC listener is disabled; the
unrestricted RPC binds loopback only, and it is the address the wallet
child dials. `--trusted-daemon` is still never passed.
- The chain database is a separate embedded store (fjall) under the chain
data directory, not the SQLCipher store the messenger writes — different
file, different exposure: it is not encrypted by that store's key.
3. **A daemon address they supply.** The wallet child points `--daemon-address`
at that host. Trust follows the address:
- **Loopback** — same privacy as (1); the user owns `monerod`.
- **`.onion`** — chain traffic over Tor through a localhost SOCKS5 listener

View file

@ -57,17 +57,23 @@ not something the app stores for you.
## Chain source
The wallet needs a daemon for scan, verify, and spend. You pick one; OnionWire
does not pick a public remote node for you. The three shapes are:
does not pick a public remote node for you. The four shapes are:
```
ChainSource::None receive-only; no child, no daemon
ChainSource::Local { monerod_bin, datadir } the app spawns monerod on this box
ChainSource::InProcessCuprate { datadir } the daemon is inside this app
ChainSource::Remote { host, port } a daemon address you typed
```
1. **Local `monerod`.** Chain traffic stays on the box. You accept disk, first
sync, and (on Android) the daemon not always running.
2. **A daemon address you supply** — becomes `--daemon-address` on the wallet
2. **An in-process daemon** ([Cuprate](https://github.com/Cuprate/cuprate)
running inside the OnionWire process). No `monerod` binary to install or
spawn, chain on this device, and the wallet child dials the same loopback
port. **Testnet only** in this build, and it needs the `cuprate-daemon`
feature — see *The in-process chain daemon* below.
3. **A daemon address you supply** — becomes `--daemon-address` on the wallet
child. Loopback if you already run `monerod`. `.onion` if you want chain
traffic over Tor (see *Chain traffic over Tor* below). Clearnet only if you
type it — your ISP sees Monero-node traffic; it is never a default.
@ -75,6 +81,70 @@ ChainSource::Remote { host, port } a daemon address you typed
The port is a convention, not a constant: restricted RPC on `18089` is common,
but you supply it.
### The in-process chain daemon (`cuprate-daemon`)
Cuprate's chain daemon — P2P, consensus, RandomX — can run **inside the
OnionWire process** instead of as a spawned `monerod`. The wallet layer does not
change: `monero-wallet-rpc` is still a child, and it still dials the unrestricted
loopback RPC, `127.0.0.1:18081`, the same address a spawned `monerod` gets.
```
cargo build --release --features cuprate-daemon
```
- **Off by default.** `cuprated` is pre-1.0 and is not published to crates.io
(every Cuprate crate there is a `0.0.0-placeholder` name reservation), so it is
a git dependency pinned to a revision, behind the `cuprate-daemon` feature. A
default build does not compile it: the graph is large (RandomX, fjall,
axum/hyper, rayon) and it is a *choice*, never compiled-in. Without the feature
a stored in-process chain source can still be read back — the chain-source type
and its record do not fork on a cargo feature — but starting it fails with
`this build has no in-process chain daemon — rebuild with --features
cuprate-daemon`.
- **+11.8 MiB (12,327,768 bytes)** on a stripped `aarch64-linux-android` release
binary, measured in this repo: 24,725,704 bytes without the feature and
37,053,472 with it (`cargo rustc --release --target aarch64-linux-android
[--features cuprate-daemon] --bin onionwire`, both linked with the NDK C++
runtime / compiler-rt link args, then `llvm-strip`). The `+5.6 MB` figure that
circulated with the spike was an estimate and understates it. A cold build
also compiles the Cuprate graph in addition to this crate's own, so first-build
time grows accordingly.
- **Testnet only.** Cuprate is **pre-production software**. Its own user book
says *"do NOT use cuprated for any serious purposes"*, and its `monerod` RPC
parity is incomplete (Cuprate issue #278; the four gaps measured in this repo
are in `docs/cuprate-launch-spike.md` §Parity gaps). The config pins
`network = "Testnet"`; pointing a mainnet wallet at it is not something this
build claims to do. The wallet screen's chain line says so next to the source
(`testnet only — mainnet is unvalidated`).
- **No Tor in the chain path.** Cuprate's own `arti` feature is *not* enabled:
its Tor stack is `arti-client` 0.44, which cannot unify with this crate's 0.46,
and running two Tor stacks in one process is not a trade this app makes.
OnionWire's Arti is the only Tor here, and it serves the messenger. The
in-process daemon's P2P traffic is therefore **clearnet**: your ISP can see
that this device talks to Monero testnet peers, exactly as a spawned `monerod`
would.
- **Inbound connections are off** and the restricted RPC listener is disabled:
this is a wallet's daemon, not a public node (the restricted listener only
answers placeholder metrics — see below).
- **It is not a child process.** There is no pid to watch or signal: the node is
a value the app owns, and dropping it shuts the daemon down. `stop` (TUI key
`x`, or the SDK's `stop_wallet_child`) asks it to shut down with the wallet
child, and it does not outlive the app.
- **The chain lives in `$ONIONWIRE_HOME/chain`** — the same per-identity
directory a spawned `monerod` would use, so the two local sources are
interchangeable on disk. It is created `0700`. The chain database itself is
**fjall**, a separate embedded store from OnionWire's SQLCipher file:
Cuprate puts it under the datadir it is given (`<datadir>/testnet/fjall`), so
it is never beside `onionwire.db`.
- **Selecting it.** The chain source is a stored setting (`ChildConfig`), and
this build has no on-screen chain-source picker on the desktop TUI — that is
true of the other three sources too; the picker is a separate, unmerged piece
of work. What selects this source today is a `ChainSource::InProcessCuprate`
record with a `datadir` written through `Node::set_wallet_child_config` (the
SDK's `ChainConfig` path), and the daemon then starts with the child when the
wallet is started. The SDK gains its own chain-choice variant in a follow-up
card; until then `kind = "cuprate"` is the record's spelling.
### Chain traffic over Tor (`.onion` daemons)
A `.onion` daemon cannot be dialled directly, and OnionWire does not fall back

View file

@ -142,10 +142,49 @@ The release demo binary is 51 MB unstripped.
- `RANDOMX_DIR` / `DARCH` in `randomx-rs`'s build script are not a cross-compile
hazard today only because `DARCH` is inert. If the fork ever honours it, a
`-march=native` Android build would be a silent host-arch miscompile.
- Dependency cost is worth restating for the Android AAR: the same Cargo graph builds
**two** `tor-*`/`arti-client` families (Cuprate's 0.44 and OnionWire's 0.46) plus
`axum`/`hyper`/`fjall` for `cuprated`. That is build time and binary size, not a
correctness problem, but it is real on a phone.
- Dependency cost is worth restating for the Android AAR: the `cuprated` graph adds
`axum`/`hyper`/`fjall`/RandomX on top of this crate's own. That is build time and
binary size, not a correctness problem, but it is real on a phone.
The **two `arti` families** the spike tree built were an artifact of the PoC
manifest enabling `cuprated`'s default `arti` feature: OnionWire pins
`default-features = false` for `cuprated`, so its arti-client 0.44 is **not** in
this crate's graph — one Tor stack per process (see `docs/WALLET.md`).
- Throwaway harness (not committed, per spike policy):
`/var/tmp/cuprate-android-poc/{check-acceptance.sh,check-cold.sh,build-android.sh,link-android.sh}`
and the logs next to them (`/var/tmp/cuprate-android-{checkcold,accept,ndk2,link6}.log`).
## Proven in-repo (2026-09-18, card `t_04975420`)
The spike above ran on a throwaway PoC tree. The same two commands were re-run in
this repository, against `cuprated` at the same pinned revision
(`4f8fcd1bf468f566fcd89c460d50de4adb6825bf`) and behind this crate's
`cuprate-daemon` feature, with the environment from *Recipe* above:
```
$ cargo check --locked --release --target aarch64-linux-android --features cuprate-daemon
Finished `release` profile [optimized] target(s) in 1m 50s
CHECK_EXIT=0
$ cargo rustc --locked --release --target aarch64-linux-android \
--features cuprate-daemon --bin onionwire -- <the link args above>
Finished `release` profile [optimized] target(s) in 2m 05s
LINK_EXIT=0
$ file <target>/aarch64-linux-android/release/onionwire
ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked,
interpreter /system/bin/linker64, for Android 26, built by NDK r28c (13676358),
not stripped
```
`cargo rustc` needs `--bin onionwire` (or `--lib`) because this crate has both
targets and rustc link args may only go to one of them — the PoC had a single bin,
so this is new to the real tree.
Sizes, same target and link args, `llvm-strip`ed:
| build | stripped |
|---|---|
| without the feature | 24,725,704 bytes |
| `--features cuprate-daemon` | 37,053,472 bytes |
That is a delta of **12,327,768 bytes (≈ +11.8 MiB)**, the number
`docs/WALLET.md` quotes.