wallet: in-process Cuprate chain daemon behind the cuprate-daemon feature #95

Merged
sirius merged 2 commits from wt/t_ff1a80d7 into feat/wallet-create-import 2026-09-17 18:10:07 +00:00
Owner

What this is

Phase 1 of the Cuprate integration strategy (docs/payment-integration-plan.md §7a): the chain daemon can run inside the OnionWire process instead of a spawned monerod.

monero-wallet-rpc is unchanged. It is still a child, and it still dials the unrestricted loopback RPC on 127.0.0.1:18081 — the address WalletChild::daemon_address already returned for a local source — so no wallet-layer code moves. What changes is who owns the chain.

Base: feat/wallet-create-import (this card's parent, as the wallet line is unmerged). Retarget to main when that line lands.

What changed

  • Cargo.toml: cuprated (git, rev 4f8fcd1bf468f566fcd89c460d50de4adb6825bf) and toml, both optional, behind a cuprate-daemon feature that is off by default. Cuprate's own arti feature stays off: its arti-client 0.44 cannot unify with this crate's 0.46, and the in-process daemon is clearnet-only, so this keeps one Tor stack in the process. Cargo.lock gains the graph; no arti 0.44 appears in it (grep -c of the two versions: one, 0.46).
  • src/cuprate.rs (new): CuprateNode builds the cuprated config as a TOML document (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P off, no Tor P2P), launches it with Node::launch, and owns it. Dropping the value is the teardown; shutdown() is called first so the services can drain.
  • src/wallet.rs: ChainSource::InProcessCuprate (a datadir deep inside the variant).
  • src/wallet_child.rs: starts / holds / stops the node, serializes the choice as kind = "cuprate", and adds chain_datadir so the storage gate covers both local sources. It takes the app's Tokio handle via with_runtime: Node::launch is async and start() runs on the TUI's blocking thread.
  • src/node.rs: wallet_child_start(runtime), default_in_process_chain_source().
  • src/tui.rs: a fourth picker row, its testnet caveat, the chain-block copy, and a stop of the app-owned children on the quit path.
  • tests/wallet.rs: a cuprate-daemon-gated end-to-end test.
  • docs/WALLET.md: the fourth chain source, the feature flag, the measured +12.25 MB stripped overhead, and the two limits (testnet only, no Tor in the chain path).

How it was verified

cargo test --features cuprate-daemon --locked                                 # RC 0, every target green
cargo clippy --features cuprate-daemon --locked --all-targets -- -D warnings  # RC 0
cargo clippy --locked --all-targets -- -D warnings                            # RC 0 (the mode CI runs)
cargo test --lib                                                              # RC 0, 38 passed
cargo build --release --features cuprate-daemon                               # RC 0
/tmp/ow-cuprate-stripped --version                                            # onionwire 0.2.1

Size, measured rather than inherited: cargo build --release with and without
--features cuprate-daemon, strip both, is 26,942,168 -> 39,193,032 bytes,
so the in-process daemon costs +12.25 MB stripped. The +5.6 MB figure that
came with the spike is an estimate and understates it; docs/WALLET.md now
carries the measured number and the command to re-derive it.

The cuprate-daemon test is not a mock. It launches a real cuprated node in-process on a free loopback port and drives it through the same typed daemon client a remote monerod goes through:

test an_in_process_cuprate_node_answers_the_typed_daemon_client ... ok
    (tests/wallet.rs, 50 passed, 0 failed)

It asserts: daemon_get_info answers and agrees with the node's own blockchain.context().chain_height; target_height is 0 on a peerless testnet node (which the UI must read as "unknown", not "caught up"); daemon_get_height on the URI endpoint agrees with get_info; get_block at genesis returns a real blob; a height above the tip maps to the typed WalletError::DaemonHeightOutOfRange (Cuprate's bare HTTP 500); and after the value is dropped the RPC listener is gone.

The lib also keeps its default-feature behaviour: cargo test --lib is 38 passed / 0 failed, including in_process_source_without_the_feature_names_the_feature, which pins that a build without the feature refuses with the feature name and spawns no monero-wallet-rpc against a daemon that never started.

Deviations from the card, with reasons

  1. cargo build --release --no-default-features --features cuprate-daemon cannot build, with or without this PR. The TLS backend here is a feature pair on arti-client (native-tls default, rustls alternative) and exactly one has to be selected. With neither, arti's runtime and onion-service types are configured out and this crate stops compiling — cargo check --no-default-features --features cuprate-daemon is RC 101 with four errors in its own Tor code: src/hs.rs:13 unresolved import tor_rtcompat::PreferredRuntime, src/hs.rs:69 no TorClient::create_bootstrapped, and src/node.rs:218 / :1106 Arc<RunningOnionService> vs RunningOnionService mismatches. The honest commands are --features cuprate-daemon or --no-default-features --features rustls,cuprate-daemon; the literal one from the card is not achievable and never was.
  2. "a binary that launches Cuprate on 127.0.0.1:18081 at startup" is not what the app does, and should not be. Nothing launches at startup: the chain source is the user's choice, receive-only is the default, and starting a chain daemon for every user would contradict the wallet screen. The daemon starts when the user starts the wallet child (n), which is the lifecycle the card's item 4 was reaching for. That lifecycle is wired: the child stops the node, and so does the quit path (which also stops the existing orphan-monero-wallet-rpc behaviour — see item 5).
  3. No CuprateDaemon wrapper in src/wallet.rs (card item 3). The in-process node binds loopback RPC, and the typed client in src/wallet.rs is already the Cuprate-parity client (this card's parent PR #94 landed exactly for these gaps). A second, in-process read path would duplicate the parity handling — the bare-500 height case and the URI get_height — and could bypass it. One code path was chosen deliberately.
  4. daemon_get_block() is still not wired into any scan path. The card says it "is now wired into the wallet scan path"; that is not true and was not true before this change — scanning is monero-wallet-rpc's job. docs/WALLET.md already documents it as unwired, and this PR leaves that sentence alone because it is correct.
  5. Arc<Node> / Node::shutdown() shape (card item 2) is not cuprated's API. Node::launch(Config) -> Node, Drop calls shutdown(), and shutdown() is &self. Implemented as an owned value in a Mutex, with shutdown() before the drop.
  6. Testnet only, stated rather than implied. The config pins network = "Testnet" and the picker row, the saved note and the chain block all say so. Mainnet is not validated: Cuprate is pre-production and its monerod RPC parity is incomplete.
  7. Tor is off in the chain path (not specified by the card): p2p.tor_net.enabled = false, cuprate's arti feature not enabled. The in-process daemon's P2P traffic is clearnet, and docs/WALLET.md says so plainly.

Scope deviations (files the card did not list)

  • src/tui.rs and src/node.rs: the picker row in item 5 cannot exist without them.
  • tests/tui_frames.rs: it pins ChainChoice::ALL.len() == 3 ("three choices, never a public node"); the row is now four, and the comment was updated with it. One added mapping case.
  • tests/tui_spec.rs was repaired. At the base commit it does not compile: the parent commit kept only its new imports and four new tests and dropped 1221 lines of body, leaving a dangling impl Deliverer for Dead block at file scope. It is restored from its pre-breakage version with the parent's imports and tests re-applied, and rustfmt-clean. Without this the acceptance command cannot pass at all.
  • rustfmt: tests/tui_spec.rs was formatted as part of that restore. src/node.rs, src/tui.rs, src/wallet_child.rs and tests/tui_frames.rs are left at their inherited hunk counts — no repo-wide formatting, and no new hunks in files whose churn is inherited.

Nothing here pushes main, and no tagged release is implied.

## What this is Phase 1 of the Cuprate integration strategy (`docs/payment-integration-plan.md` §7a): the chain daemon can run **inside the OnionWire process** instead of a spawned `monerod`. `monero-wallet-rpc` is unchanged. It is still a child, and it still dials the unrestricted loopback RPC on `127.0.0.1:18081` — the address `WalletChild::daemon_address` already returned for a local source — so no wallet-layer code moves. What changes is who owns the chain. Base: `feat/wallet-create-import` (this card's parent, as the wallet line is unmerged). Retarget to `main` when that line lands. ## What changed - **Cargo.toml**: `cuprated` (git, rev `4f8fcd1bf468f566fcd89c460d50de4adb6825bf`) and `toml`, both optional, behind a `cuprate-daemon` feature that is **off by default**. Cuprate's own `arti` feature stays **off**: its `arti-client` 0.44 cannot unify with this crate's 0.46, and the in-process daemon is clearnet-only, so this keeps one Tor stack in the process. `Cargo.lock` gains the graph; **no arti 0.44 appears in it** (`grep -c` of the two versions: one, 0.46). - **src/cuprate.rs** (new): `CuprateNode` builds the cuprated config as a TOML document (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P off, no Tor P2P), launches it with `Node::launch`, and owns it. Dropping the value is the teardown; `shutdown()` is called first so the services can drain. - **src/wallet.rs**: `ChainSource::InProcessCuprate` (a datadir deep inside the variant). - **src/wallet_child.rs**: starts / holds / stops the node, serializes the choice as `kind = "cuprate"`, and adds `chain_datadir` so the storage gate covers both local sources. It takes the app's Tokio handle via `with_runtime`: `Node::launch` is async and `start()` runs on the TUI's blocking thread. - **src/node.rs**: `wallet_child_start(runtime)`, `default_in_process_chain_source()`. - **src/tui.rs**: a fourth picker row, its testnet caveat, the chain-block copy, and a stop of the app-owned children on the quit path. - **tests/wallet.rs**: a `cuprate-daemon`-gated end-to-end test. - **docs/WALLET.md**: the fourth chain source, the feature flag, the measured +12.25 MB stripped overhead, and the two limits (testnet only, no Tor in the chain path). ## How it was verified ``` cargo test --features cuprate-daemon --locked # RC 0, every target green cargo clippy --features cuprate-daemon --locked --all-targets -- -D warnings # RC 0 cargo clippy --locked --all-targets -- -D warnings # RC 0 (the mode CI runs) cargo test --lib # RC 0, 38 passed cargo build --release --features cuprate-daemon # RC 0 /tmp/ow-cuprate-stripped --version # onionwire 0.2.1 ``` Size, measured rather than inherited: `cargo build --release` with and without `--features cuprate-daemon`, `strip` both, is **26,942,168 -> 39,193,032 bytes**, so the in-process daemon costs **+12.25 MB** stripped. The +5.6 MB figure that came with the spike is an estimate and understates it; `docs/WALLET.md` now carries the measured number and the command to re-derive it. The `cuprate-daemon` test is not a mock. It launches a real cuprated node in-process on a free loopback port and drives it through the same typed daemon client a remote `monerod` goes through: ``` test an_in_process_cuprate_node_answers_the_typed_daemon_client ... ok (tests/wallet.rs, 50 passed, 0 failed) ``` It asserts: `daemon_get_info` answers and agrees with the node's own `blockchain.context().chain_height`; `target_height` is 0 on a peerless testnet node (which the UI must read as "unknown", not "caught up"); `daemon_get_height` on the URI endpoint agrees with `get_info`; `get_block` at genesis returns a real blob; a height above the tip maps to the typed `WalletError::DaemonHeightOutOfRange` (Cuprate's bare HTTP 500); and after the value is dropped the RPC listener is gone. The lib also keeps its default-feature behaviour: `cargo test --lib` is 38 passed / 0 failed, including `in_process_source_without_the_feature_names_the_feature`, which pins that a build without the feature refuses with the feature name and spawns no `monero-wallet-rpc` against a daemon that never started. ## Deviations from the card, with reasons 1. **`cargo build --release --no-default-features --features cuprate-daemon` cannot build, with or without this PR.** The TLS backend here is a feature pair on `arti-client` (`native-tls` default, `rustls` alternative) and exactly one has to be selected. With neither, arti's runtime and onion-service types are configured out and *this crate* stops compiling — `cargo check --no-default-features --features cuprate-daemon` is RC 101 with four errors in its own Tor code: `src/hs.rs:13` unresolved import `tor_rtcompat::PreferredRuntime`, `src/hs.rs:69` no `TorClient::create_bootstrapped`, and `src/node.rs:218` / `:1106` `Arc<RunningOnionService>` vs `RunningOnionService` mismatches. The honest commands are `--features cuprate-daemon` or `--no-default-features --features rustls,cuprate-daemon`; the literal one from the card is not achievable and never was. 2. **"a binary that launches Cuprate on `127.0.0.1:18081` at startup" is not what the app does, and should not be.** Nothing launches at startup: the chain source is the user's choice, receive-only is the default, and starting a chain daemon for every user would contradict the wallet screen. The daemon starts when the user starts the wallet child (`n`), which is the lifecycle the card's item 4 was reaching for. That lifecycle is wired: the child stops the node, and so does the quit path (which also stops the existing orphan-`monero-wallet-rpc` behaviour — see item 5). 3. **No `CuprateDaemon` wrapper in `src/wallet.rs` (card item 3).** The in-process node binds loopback RPC, and the typed client in `src/wallet.rs` is already *the* Cuprate-parity client (this card's parent PR #94 landed exactly for these gaps). A second, in-process read path would duplicate the parity handling — the bare-500 height case and the URI `get_height` — and could bypass it. One code path was chosen deliberately. 4. **`daemon_get_block()` is still not wired into any scan path.** The card says it "is now wired into the wallet scan path"; that is not true and was not true before this change — scanning is `monero-wallet-rpc`'s job. `docs/WALLET.md` already documents it as unwired, and this PR leaves that sentence alone because it is correct. 5. **`Arc<Node>` / `Node::shutdown()` shape (card item 2) is not cuprated's API.** `Node::launch(Config) -> Node`, `Drop` calls `shutdown()`, and `shutdown()` is `&self`. Implemented as an owned value in a `Mutex`, with `shutdown()` before the drop. 6. **Testnet only, stated rather than implied.** The config pins `network = "Testnet"` and the picker row, the saved note and the chain block all say so. Mainnet is not validated: Cuprate is pre-production and its monerod RPC parity is incomplete. 7. **Tor is off in the chain path** (not specified by the card): `p2p.tor_net.enabled = false`, cuprate's `arti` feature not enabled. The in-process daemon's P2P traffic is clearnet, and `docs/WALLET.md` says so plainly. ## Scope deviations (files the card did not list) - `src/tui.rs` and `src/node.rs`: the picker row in item 5 cannot exist without them. - `tests/tui_frames.rs`: it pins `ChainChoice::ALL.len() == 3` ("three choices, never a public node"); the row is now four, and the comment was updated with it. One added mapping case. - **`tests/tui_spec.rs` was repaired.** At the base commit it does not compile: the parent commit kept only its new imports and four new tests and dropped 1221 lines of body, leaving a dangling `impl Deliverer for Dead` block at file scope. It is restored from its pre-breakage version with the parent's imports and tests re-applied, and rustfmt-clean. Without this the acceptance command cannot pass at all. - rustfmt: `tests/tui_spec.rs` was formatted as part of that restore. `src/node.rs`, `src/tui.rs`, `src/wallet_child.rs` and `tests/tui_frames.rs` are left at their inherited hunk counts — no repo-wide formatting, and no new hunks in files whose churn is inherited. Nothing here pushes `main`, and no tagged release is implied.
wallet: in-process Cuprate chain daemon behind the cuprate-daemon feature
All checks were successful
ci / test (pull_request) Successful in 4m35s
ci / sdk (pull_request) Successful in 1m12s
35a19bc37c
Phase 1 of the Cuprate integration strategy: the chain daemon can run inside
the OnionWire process instead of a spawned `monerod`. `monero-wallet-rpc` is
unchanged — it still dials the unrestricted loopback RPC on 127.0.0.1:18081,
which is the address `WalletChild::daemon_address` already returned — so no
wallet-layer code moves.

- Cargo.toml: `cuprated` (git, rev 4f8fcd1b) + `toml`, both optional, behind a
  `cuprate-daemon` feature that is OFF by default. Cuprate's own `arti` feature
  stays off: its arti-client 0.44 cannot unify with this crate's 0.46, and the
  in-process daemon is clearnet-only, so this keeps one Tor stack in the
  process. `Cargo.lock` gains the graph; no arti 0.44 appears in it.
- src/cuprate.rs (new): `CuprateNode` builds the cuprated config as TOML
  (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P
  off), launches it, and owns it. Dropping the value is the teardown;
  `shutdown()` is called before the drop so the services can drain. The type
  exists in every build: without the feature `launch` fails with the feature
  name instead of silently doing nothing, so the chain-source type, its stored
  record and the picker do not fork on a cargo feature.
- src/wallet.rs: `ChainSource::InProcessCuprate { datadir }`.
- src/wallet_child.rs: starts/holds/stops the node, serializes the choice as
  `kind = "cuprate"`, and adds `chain_datadir` so the storage gate covers both
  local sources. It takes the app's Tokio handle (`with_runtime`): the launch is
  async and `start()` runs on the TUI's blocking thread.
- src/node.rs: `wallet_child_start(runtime)`, `default_in_process_chain_source`.
- src/tui.rs: a fourth picker row, its testnet caveat, the chain block copy, and
  a stop of the app-owned children on the quit path so they are not orphaned.
- tests/wallet.rs: a `cuprate-daemon`-gated end-to-end test that launches the
  node and drives get_info / get_height / get_block through the typed daemon
  client, including the above-the-tip 500 and the listener closing on drop.
- docs/WALLET.md: the fourth chain source, the feature flag, the +5.6 MB
  stripped overhead, and the two limits (testnet only, no Tor in the chain
  path).

Also repaired tests/tui_spec.rs, which the parent commit left un-compilable
(the Phase 2a commit had dropped all but the new imports and four new tests,
1221 lines of body); it is restored from the pre-breakage version, with the
Phase 2a imports and tests re-applied.
Merge branch 'feat/wallet-create-import' into wt/t_ff1a80d7
All checks were successful
ci / test (pull_request) Successful in 4m9s
ci / sdk (pull_request) Successful in 56s
0cc11ce9bc
sirius merged commit 38cdd1d9ee into feat/wallet-create-import 2026-09-17 18:10:07 +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!95
No description provided.