wallet: land the wallet-child stack on main + expose start/stop/status through UniFFI (issue #107) #108

Merged
sirius merged 6 commits from wt/t_8a8ff353 into main 2026-09-18 13:45:17 +00:00
Owner

Origin

Forgejo issue sirius/onionwire#107. This is the parent/prerequisite card: land the wallet-child stack on main and expose its lifecycle through the UniFFI facade so the Android wallet screen can start the child.

What this PR is

  1. The unmerged stack, rebased onto main. origin/feat/wallet-child-rpc (wallet child lifecycle + user-chosen ChainSource, then stored wallet config + WalletStatus snapshot + pay/tip readiness guard) rebased onto main at 462b576. Conflicts were resolved by re-applying intent on main's shape:
    • src/store.rs: both sides appended tests to mod at_rest; both were kept. Git's conflict chunking also swallowed one closing brace shared by the two sides (the file did not compile after a naive marker deletion), which is fixed in the same commit.
    • src/node.rs tip(): main's newer body wins (tip row, memo, tip_chat_line, sign_receipt) and the branch's readiness guard is applied on top of it (wallet_snapshot() + wallet::NOT_CONFIGURED_MSG).
    • src/node.rs had no test module on the branch and one on main: main's test module is kept.
    • scripts/publish-release.sh is identical to main (no reintroduced conflict markers): git grep -n -E '^(<<<<<<<|>>>>>>>)' <head> is empty and bash -n scripts/publish-release.sh is clean.
  2. The child is wired into the production path (it was dead code).
  3. UniFFI surface for start/stop/status + the chain source.

UniFFI method names (the Android contract, verbatim)

start_wallet_child() -> WalletChildStatus            (async)
stop_wallet_child()  -> ()                           (sync, WResult)
wallet_status()      -> WalletChildStatus            (sync)
set_chain_source(config: ChainConfig) -> ()          (sync, WResult)
chain_source()       -> ChainConfig                  (sync)

Records: WalletChildStatus - state, running, configured, chain_source, last_error and ChainConfig - kind (ChainChoice: None/Local/Remote), monerod_bin, monerod_datadir, host, port, wallet_rpc_bin, arti_bin, wallet_filename.

state is a lowercase label: off / connecting / syncing / ready / exited. chain_source is the label: receive-only / local node / remote onion daemon / remote daemon. It is derived from the real process plus the last probe — never from env-var presence — and a child that has died is reported exited, never ready.

One-line note for the Android card: call set_chain_source with absolute wallet_rpc_bin / arti_bin paths from nativeLibraryDir, then start_wallet_child(), then poll wallet_status(). A .onion daemon also needs arti_bin; the SOCKS child is spawned by the core.

2. Node / TUI wiring

  • Node::start_wallet_child / stop_wallet_child / wallet_child_status / wallet_child_refresh / wallet_child_config / set_wallet_child_config.
  • The start path uses WalletChild::start(&store) -> WalletClient::into_wallet(), so the existing payment spines (pay_invoice, tip, ingest_receipt) talk to the app-owned child. No payment-frame shape changed and the receipt-verification conjunctive match is untouched.
  • with_wallet_rpc_bin / with_arti_bin are honoured on the start path (the configured absolute path is what gets spawned) — pinned by a test that asserts the spawned process's own $0 and argv.
  • Node::shutdown now stops the wallet child. Without it, an app exit orphaned the spawn-capable monero-wallet-rpc (and monerod), which is what docs/WALLET.md already claimed stop() did on shutdown.
  • TUI: the F6 wallet screen gains s (start), x (stop), p (probe) and a child status row (rendered only when a chain source is configured, so an unconfigured install renders exactly as before). The /pay and /tip key handlers now run Node::wallet_readiness before sending, which is what that guard was written for and until now nothing called.
  • start is idempotent (a live child is reported, not respawned); a spawn failure is an error and leaves no half-started child.

3. Settings persistence

ChildConfig - source, wallet_rpc_bin, arti_bin, wallet_filename is stored in the same sealed wallet_child record as the generated RPC creds. The record write is now a read-modify-write (wallet_child::merge_record), so first-start credential generation cannot clobber a saved config and a later save cannot clobber the creds. Validation happens before anything is written.

4. Docs

docs/WALLET.md is reconciled with main and corrected where the inherited text described things that do not ship here:

  • the "F7 config screen" section (endpoint entry, test connection, save) belongs to feat/wallet-create-import; this stack ships the stored config API, not that screen, and now says so;
  • Local mode is not wired yet is replaced by the shipped lifecycle, the five states, and the exact API names for desktop and Android;
  • the readiness-guard paragraph now matches the real call sites (send_pay / send_tip).
  • The not-configured copy still names F7 because it is the wallet-UI branch's string, asserted by that branch's tests; changing it here would only create a conflict for the follow-up landing. Flagged as a follow-up below.

docs/THREAT_MODEL.md's additive SOCKS/chain-source wording is unchanged from the branch and was checked against src/wallet_child.rs. docs/PROTOCOL.md is untouched (no payment-frame change).

Known follow-up (not this PR)

The F7 wallet-config screen, the chain-source picker and the wallet/chain TUI redesign live on origin/feat/wallet-create-import (which also carries an in-process Cuprate chain daemon behind a feature flag). This PR lands the child + SDK contract that #107 needs; landing that UI branch is a separate card, and its tui.rs / tests/tui_spec.rs / tests/tui_frames.rs work is outside this card's file whitelist.

Evidence (on this head)

  • cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings -> exit 0
  • cargo test --locked --target x86_64-unknown-linux-gnu -> exit 0, aggregate over every target: 341 passed; 0 failed; 0 ignored (50 in the lib target, the rest across the integration targets; the Tor-dependent ones report ignored/0-test when the network is not available, exactly as on main).
  • cargo test --locked --lib -> test result: ok. 50 passed; 0 failed; 0 ignored
  • cd crates/onionwire-sdk && cargo test --locked && cargo clippy --locked --all-targets -- -D warnings -> exit 0 (27 unit tests). The SDK has its own lockfile; no root dependency was added, so it did not need regenerating.
  • No conflict markers: git grep -n -E '^(<<<<<<<|>>>>>>>)' HEAD is empty; bash -n scripts/publish-release.sh is clean; git diff origin/main HEAD -- scripts/publish-release.sh is empty.
  • New tests: start_wallet_child_honours_the_configured_binary, a_died_child_reports_exited_and_never_ready, chain_source_persists_and_keeps_the_sealed_creds, a_rejected_chain_source_is_not_persisted, a_missing_binary_fails_the_start_and_leaves_no_child, a_receive_only_node_reports_off_and_refuses_to_start_a_child, shutdown_stops_the_wallet_child, chain_source_labels_name_what_the_child_dials, child_settings_round_trip_sealed_and_keep_the_creds.
  • mock_wallet in src/node.rs's tests had to learn get_info: Wallet::transfer probes the chain tip before spending, and the old single-answer mock made every outbound-tip test fail as "not synced". That is a test-harness fix, not a behaviour change.
## Origin Forgejo issue sirius/onionwire#107. This is the parent/prerequisite card: land the wallet-child stack on `main` and expose its lifecycle through the UniFFI facade so the Android wallet screen can start the child. ## What this PR is 1. **The unmerged stack, rebased onto `main`.** `origin/feat/wallet-child-rpc` (wallet child lifecycle + user-chosen ChainSource, then stored wallet config + WalletStatus snapshot + pay/tip readiness guard) rebased onto `main` at 462b576. Conflicts were resolved by re-applying intent on main's shape: - `src/store.rs`: both sides appended tests to `mod at_rest`; **both** were kept. Git's conflict chunking also swallowed one closing brace shared by the two sides (the file did not compile after a naive marker deletion), which is fixed in the same commit. - `src/node.rs` `tip()`: main's newer body wins (tip row, memo, `tip_chat_line`, `sign_receipt`) and the branch's readiness guard is applied on top of it (`wallet_snapshot()` + `wallet::NOT_CONFIGURED_MSG`). - `src/node.rs` had no test module on the branch and one on `main`: main's test module is kept. - `scripts/publish-release.sh` is **identical to `main`** (no reintroduced conflict markers): `git grep -n -E '^(<<<<<<<|>>>>>>>)' <head>` is empty and `bash -n scripts/publish-release.sh` is clean. 2. **The child is wired into the production path** (it was dead code). 3. **UniFFI surface** for start/stop/status + the chain source. ## UniFFI method names (the Android contract, verbatim) start_wallet_child() -> WalletChildStatus (async) stop_wallet_child() -> () (sync, WResult) wallet_status() -> WalletChildStatus (sync) set_chain_source(config: ChainConfig) -> () (sync, WResult) chain_source() -> ChainConfig (sync) Records: `WalletChildStatus - state, running, configured, chain_source, last_error` and `ChainConfig - kind (ChainChoice: None/Local/Remote), monerod_bin, monerod_datadir, host, port, wallet_rpc_bin, arti_bin, wallet_filename`. `state` is a lowercase label: `off` / `connecting` / `syncing` / `ready` / `exited`. `chain_source` is the label: `receive-only` / `local node` / `remote onion daemon` / `remote daemon`. It is derived from the real process plus the last probe — never from env-var presence — and a child that has died is reported `exited`, never `ready`. **One-line note for the Android card:** call `set_chain_source` with absolute `wallet_rpc_bin` / `arti_bin` paths from `nativeLibraryDir`, then `start_wallet_child()`, then poll `wallet_status()`. A `.onion` daemon also needs `arti_bin`; the SOCKS child is spawned by the core. ## 2. Node / TUI wiring - `Node::start_wallet_child` / `stop_wallet_child` / `wallet_child_status` / `wallet_child_refresh` / `wallet_child_config` / `set_wallet_child_config`. - The start path uses `WalletChild::start(&store)` -> `WalletClient::into_wallet()`, so the existing payment spines (`pay_invoice`, `tip`, `ingest_receipt`) talk to the app-owned child. No payment-frame shape changed and the receipt-verification conjunctive match is untouched. - `with_wallet_rpc_bin` / `with_arti_bin` are honoured on the start path (the configured absolute path is what gets spawned) — pinned by a test that asserts the spawned process's own `$0` and argv. - `Node::shutdown` now stops the wallet child. Without it, an app exit orphaned the spawn-capable `monero-wallet-rpc` (and `monerod`), which is what `docs/WALLET.md` already claimed `stop()` did on shutdown. - TUI: the F6 wallet screen gains `s` (start), `x` (stop), `p` (probe) and a child status row (rendered only when a chain source is configured, so an unconfigured install renders exactly as before). The `/pay` and `/tip` key handlers now run `Node::wallet_readiness` before sending, which is what that guard was written for and until now nothing called. - `start` is idempotent (a live child is reported, not respawned); a spawn failure is an error and leaves no half-started child. ## 3. Settings persistence `ChildConfig - source, wallet_rpc_bin, arti_bin, wallet_filename` is stored in the same sealed `wallet_child` record as the generated RPC creds. The record write is now a read-modify-write (`wallet_child::merge_record`), so first-start credential generation cannot clobber a saved config and a later save cannot clobber the creds. Validation happens before anything is written. ## 4. Docs `docs/WALLET.md` is reconciled with `main` and corrected where the inherited text described things that do not ship here: - the "F7 config screen" section (endpoint entry, test connection, save) belongs to `feat/wallet-create-import`; this stack ships the stored config API, not that screen, and now says so; - `Local mode is not wired yet` is replaced by the shipped lifecycle, the five states, and the exact API names for desktop and Android; - the readiness-guard paragraph now matches the real call sites (`send_pay` / `send_tip`). - The not-configured copy still names F7 because it is the wallet-UI branch's string, asserted by that branch's tests; changing it here would only create a conflict for the follow-up landing. Flagged as a follow-up below. `docs/THREAT_MODEL.md`'s additive SOCKS/chain-source wording is unchanged from the branch and was checked against `src/wallet_child.rs`. `docs/PROTOCOL.md` is untouched (no payment-frame change). ## Known follow-up (not this PR) The F7 wallet-config screen, the chain-source picker and the wallet/chain TUI redesign live on `origin/feat/wallet-create-import` (which also carries an in-process Cuprate chain daemon behind a feature flag). This PR lands the child + SDK contract that #107 needs; landing that UI branch is a separate card, and its `tui.rs` / `tests/tui_spec.rs` / `tests/tui_frames.rs` work is outside this card's file whitelist. ## Evidence (on this head) - `cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings` -> exit 0 - `cargo test --locked --target x86_64-unknown-linux-gnu` -> exit 0, aggregate over every target: **341 passed; 0 failed; 0 ignored** (50 in the lib target, the rest across the integration targets; the Tor-dependent ones report `ignored`/0-test when the network is not available, exactly as on `main`). - `cargo test --locked --lib` -> `test result: ok. 50 passed; 0 failed; 0 ignored` - `cd crates/onionwire-sdk && cargo test --locked && cargo clippy --locked --all-targets -- -D warnings` -> exit 0 (27 unit tests). The SDK has its own lockfile; no root dependency was added, so it did not need regenerating. - No conflict markers: `git grep -n -E '^(<<<<<<<|>>>>>>>)' HEAD` is empty; `bash -n scripts/publish-release.sh` is clean; `git diff origin/main HEAD -- scripts/publish-release.sh` is empty. - New tests: `start_wallet_child_honours_the_configured_binary`, `a_died_child_reports_exited_and_never_ready`, `chain_source_persists_and_keeps_the_sealed_creds`, `a_rejected_chain_source_is_not_persisted`, `a_missing_binary_fails_the_start_and_leaves_no_child`, `a_receive_only_node_reports_off_and_refuses_to_start_a_child`, `shutdown_stops_the_wallet_child`, `chain_source_labels_name_what_the_child_dials`, `child_settings_round_trip_sealed_and_keep_the_creds`. - `mock_wallet` in `src/node.rs`'s tests had to learn `get_info`: `Wallet::transfer` probes the chain tip before spending, and the old single-answer mock made every outbound-tip test fail as "not synced". That is a test-harness fix, not a behaviour change.
The app now owns monero-wallet-rpc (and monerod when the chain source is
local) instead of requiring the user to start them and export
ONIONWIRE_WALLET_RPC.

- ChainSource enum: None / Local { monerod_bin, datadir } / Remote { host,
  port }. No default remote node; Remote is only constructed from explicit
  user input. A .onion Remote is refused without a SOCKS proxy (separate
  card).
- WalletChild in src/wallet_child.rs spawns monero-wallet-rpc with
  --rpc-bind-ip 127.0.0.1, a random free loopback port, generated
  --rpc-login, and --wallet-dir /wallet; monerod too for a
  local source. --trusted-daemon is never passed.
- Generated RPC creds are sealed in the encrypted SQLCipher store
  (wallet_child table, AEAD on top of whole-db encryption), never a
  plaintext file. The Wallet client is built from the generated loopback
  URL, not from_env.
- Readiness predicate: chain_ready() requires synchronized==true, height>0,
  height>=target_height; can_spend() and can_verify_receipts() gate on it.
  Unsynced -> receipts stay verified=0, spend refused with a clear message.
- Backend-aware timeouts: local management calls keep 5s; chain-dependent
  calls (get_info, get_transfers, transfer) get 60s (CHAIN_RPC_TIMEOUT),
  because a first sync or a remote daemon outlasts 5s and a 5s cap there
  is what left receipts permanently unverified.
- node.rs ingest_receipt gates on can_verify_receipts() instead of
  configured() alone.
- docs/WALLET.md rewritten for the child lifecycle + chain source.

Base: feat/wallet-create-import (PR #66). Do not rebase onto main.

Co-Authored-By: Hermes Agent <agent@local>
The only input path for the wallet was env. Add the same three remote-mode
fields as stored config so the F7 screen can set them and headless runs read
one source of truth:

- `wallet_config` table in the encrypted store (one row; the login is sealed
  with the store data key under `onionwire/wallet-config/v1`, on top of
  SQLCipher). Empty URL clears it. `Store::load_wallet_config` /
  `save_wallet_config`.
- `WalletConfig { rpc_url, rpc_login: Zeroizing<String>, no_spend }` with a
  redacting `Debug`; `Wallet::from_config`, and `Wallet::for_boot` which
  prefers stored config, falls back to env, and refuses to dial a bad stored
  endpoint. Node::start* now reads the store before constructing the wallet.
- `WalletStatus { configured, connected, last_error, balance_line,
  receive_address }`: `connected` only ever comes from a probe
  (`Wallet::status`, get_address + get_balance); config alone leaves it false.
  `Node::wallet_status` is the cheap draw-path read, `wallet_refresh` the
  probe that folds into it.
- One-shot `Wallet::ping(rpc_url, rpc_login) -> PingResult { ok, status,
  error }` for the Test-connection button: same loopback/digest rules, errors
  redacted and capped.
- `readiness(configured, connected, no_spend, is_tip) -> Readiness` plus
  `Node::wallet_readiness` (async, block_on-friendly): not configured →
  NOT_CONFIGURED_MSG; /tip on a no-spend wallet → VIEW_ONLY_MSG before any
  dial; configured but not connected → NOT_CONNECTED_MSG; else ready.
- `Node::wallet_save_config` persists, validates first, then re-reads so the
  live wallet and snapshot follow a Save without a restart.
- `Node::wallet` is now a Mutex<Wallet> (cloned out before each await) so the
  wallet can be re-pointed mid-session.

Local-mode fields stay reserved: the child lifecycle is t_69ce8e46 and is not
wired here. docs/WALLET.md documents the stored config, boot precedence and
the exact guard copy.

Tests: 38 in tests/wallet.rs including exact-refusal-copy, boot precedence,
sealed-on-disk login, ping sanitization and connected-only-after-probe.
The module was dead code: nothing started the child, so the payment spines
could only ever see an env-configured monero-wallet-rpc. Now:

- Node::start_wallet_child / stop_wallet_child / wallet_child_status /
  wallet_child_refresh / wallet_child_config / set_wallet_child_config. The
  start path honours the configured absolute binary path, points the node's
  wallet at the child, and shutdown() stops the child rather than orphaning
  a spend-capable RPC behind a loopback socket.
- The status is derived from the real process (try_wait) and the last probe:
  off / connecting / syncing / ready / exited, plus the chain-source label.
  A dead child is never reported ready.
- ChildConfig (source, wallet_rpc_bin, arti_bin, wallet_filename) persists in
  the sealed wallet_child record next to the generated creds; the record is a
  read-modify-write so first-start creds never clobber a saved config.
- TUI: F6 gains s (start) / x (stop) / p (probe) and a child status row, and
  the /pay and /tip key handlers now call the core readiness guard before
  sending.
ChainConfig / ChainChoice / WalletChildStatus records and
set_chain_source(config) / chain_source() / start_wallet_child() /
stop_wallet_child() / wallet_status(). Android passes absolute binary paths
from nativeLibraryDir; the core never resolves a binary the caller named.
docs(wallet): describe the child lifecycle that ships here
All checks were successful
ci / test (pull_request) Successful in 5m31s
ci / sdk (pull_request) Successful in 1m22s
android-ci / android (pull_request) Successful in 8m52s
ci / fuzz (pull_request) Successful in 4m37s
c5af978d14
The inherited section described an F7 config screen with endpoint entry and
test-connection that is not in this stack (it lives on
feat/wallet-create-import), and called local mode 'not wired yet'. Both are
now wrong: the child is wired, and the stored wallet config is a core API
without a screen. Say which is which.
sirius merged commit 143bf6e0d0 into main 2026-09-18 13:45:17 +00:00
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!108
No description provided.