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

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.
This commit is contained in:
rust-dev 2026-09-17 13:17:32 -04:00
commit 35a19bc37c
No known key found for this signature in database
12 changed files with 3785 additions and 53 deletions

View file

@ -1425,31 +1425,41 @@ pub const PRUNED_NOTE: &str = "pruned nodes are not archives: a deep seed restor
pub const ONION_NO_SOCKS_MSG: &str =
"a remote .onion daemon needs a local SOCKS listener.\nthis build does not have one yet — pick a local monerod,\nor a clearnet/loopback daemon you run yourself.";
/// The three choices the picker offers, in order. A public node is never one of
/// The four choices the picker offers, in order. A public node is never one of
/// them and a remote daemon is never preselected.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChainChoice {
ReceiveOnly,
LocalMonerod,
InProcessCuprate,
RemoteDaemon,
}
impl ChainChoice {
pub const ALL: [ChainChoice; 3] = [Self::ReceiveOnly, Self::LocalMonerod, Self::RemoteDaemon];
pub const ALL: [ChainChoice; 4] = [
Self::ReceiveOnly,
Self::LocalMonerod,
Self::InProcessCuprate,
Self::RemoteDaemon,
];
pub fn label(self) -> &'static str {
match self {
Self::ReceiveOnly => "receive-only (no daemon)",
Self::LocalMonerod => "spawn a local monerod",
Self::InProcessCuprate => "run an in-process daemon",
Self::RemoteDaemon => "enter a daemon address",
}
}
/// One line under the label, so the choice is not a mystery.
/// One line under the label, so the choice is not a mystery. The in-process
/// row carries [`crate::cuprate::TESTNET_ONLY`]'s fact: it is not a daemon
/// the user can treat as a mainnet node yet.
pub fn detail(self) -> &'static str {
match self {
Self::ReceiveOnly => "chain traffic stays off this device entirely",
Self::LocalMonerod => "the app owns monerod; chain stays on this device",
Self::InProcessCuprate => "Cuprate in this app: testnet only, no binary",
Self::RemoteDaemon => "someone else's daemon: they see your addresses",
}
}
@ -1460,6 +1470,7 @@ impl ChainChoice {
match source {
ChainSource::None => Self::ReceiveOnly,
ChainSource::Local { .. } => Self::LocalMonerod,
ChainSource::InProcessCuprate { .. } => Self::InProcessCuprate,
ChainSource::Remote { .. } => Self::RemoteDaemon,
}
}
@ -1598,6 +1609,13 @@ pub fn chain_view_with_progress(
monerod_bin.display(),
datadir.display()
),
ChainSource::InProcessCuprate { datadir } => format!(
// The caveat is not decoration: this daemon runs testnet, and a
// user who reads it as a mainnet node would be misled.
"chain: in-process daemon — {}; chain in {}",
crate::cuprate::TESTNET_ONLY,
datadir.display()
),
ChainSource::Remote { host, port } => format!("chain: remote daemon {host}:{port}"),
};
let child_line = match child {
@ -1608,10 +1626,14 @@ pub fn chain_view_with_progress(
.to_string();
let sync_text = sync_line(sync, previous_height);
let storage_line = match (source, free_gb) {
(ChainSource::Local { .. }, Some(gb)) => format!(
// Both local sources put the chain on this device's disk; only the
// *owner* of the daemon differs.
(ChainSource::Local { .. } | ChainSource::InProcessCuprate { .. }, Some(gb)) => format!(
"storage: {gb} GB free here — pruned mainnet wants ~50-60 GB, a full node ~200 GB"
),
(ChainSource::Local { .. }, None) => "storage: could not read free space".to_string(),
(ChainSource::Local { .. } | ChainSource::InProcessCuprate { .. }, None) => {
"storage: could not read free space".to_string()
}
(ChainSource::Remote { .. }, _) => {
"storage: on the daemon operator's disk, not yours".to_string()
}
@ -1715,6 +1737,13 @@ impl App {
continue;
}
if let Some(exit) = self.handle_key(key)? {
// The children this app owns are not detached. Without this,
// `monero-wallet-rpc` (and a spawned `monerod`) would outlive the
// app as orphans, and an in-process Cuprate node would never get
// its shutdown asked for.
if let Err(e) = self.node.wallet_child_stop() {
eprintln!("wallet child on exit: {e}");
}
return Ok(exit);
}
}
@ -2315,7 +2344,7 @@ impl App {
}
let result = match self.node.wallet_child_state() {
WalletChildState::Running => self.node.wallet_child_stop(),
_ => self.node.wallet_child_start(),
_ => self.node.wallet_child_start(&self.rt),
};
self.status_note = Some(match result {
Ok(()) => match self.node.wallet_child_state() {
@ -2386,6 +2415,16 @@ impl App {
let source = self.node.default_local_chain_source();
self.apply_chain_source(source, None);
}
ChainChoice::InProcessCuprate => {
let source = self.node.default_in_process_chain_source();
// The saved note says the caveat again: the picker's row is
// gone once this screen closes.
let note = format!(
"chain source saved — in-process daemon, {}",
crate::cuprate::TESTNET_ONLY
);
self.apply_chain_source(source, Some(note));
}
}
return Ok(());
}