From a466c43764bab3b77ad17a073ace265db359e161 Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 8 Oct 2026 10:59:45 -0400 Subject: [PATCH] tui: the Cuprate start path answers get_info, and the Linux TUI includes it Node::start_wallet_child is the call the TUI makes. The test stores an in-process testnet source, starts the child, and checks the typed daemon client's get_info. It does not bootstrap Tor. cuprate-daemon is now in the Linux TUI default, so a release build of the onionwire bin links the daemon with no extra feature flag. A build with --no-default-features still refuses with NO_FEATURE_MSG. cuprated keeps default-features = false so Cuprate's arti feature cannot pull arti-client 0.44 next to OnionWire's 0.46. Cargo.lock is unchanged: cuprated was already an optional dependency. --- Cargo.toml | 9 ++- docs/THREAT_MODEL.md | 5 +- docs/WALLET.md | 12 ++- src/cuprate.rs | 3 +- src/node.rs | 186 +++++++++++++++++++++++++++++++++++++++++++ src/wallet_child.rs | 14 ++++ 6 files changed, 218 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4bd00bc..d9bcf62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,13 +17,14 @@ repository = "https://github.com/sirius0xdev/onionwire" # every build by rusqlite's `bundled-sqlcipher-vendored-openssl`, vendored and # static: that is the SQLCipher layer, not Arti's TLS.) [features] -default = ["rustls"] +default = ["rustls", "cuprate-daemon"] native-tls = ["arti-client/native-tls"] rustls = ["arti-client/rustls"] # In-process Monero chain daemon (Cuprate) as the local chain source, instead of -# spawning `monerod`. 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 this pins a git revision and pulls a large tree (RandomX, +# spawning `monerod`. ON in the Linux TUI/release binary (this default). A build +# with `--no-default-features` does not include it. `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 this pins a git revision and pulls a large tree (RandomX, # fjall, axum/hyper, rayon). See `docs/WALLET.md`, "The in-process chain daemon". # # Cuprate's own `arti` feature stays OFF (and is off in its default feature set, diff --git a/docs/THREAT_MODEL.md b/docs/THREAT_MODEL.md index 8075e96..dadf0cf 100644 --- a/docs/THREAT_MODEL.md +++ b/docs/THREAT_MODEL.md @@ -219,8 +219,9 @@ 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. **An in-process daemon** (Cuprate, behind the `cuprate-daemon` feature, off by - default). P2P, consensus and RandomX run in the OnionWire process; nothing is +2. **An in-process daemon** (Cuprate, behind the `cuprate-daemon` feature, on in + the Linux TUI/release binary; a `--no-default-features` build does not + include it). 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. diff --git a/docs/WALLET.md b/docs/WALLET.md index fe11888..71d4564 100644 --- a/docs/WALLET.md +++ b/docs/WALLET.md @@ -158,12 +158,16 @@ Settings live in the sealed `wallet_child` record (`ChildConfig`: `source`, ### The in-process chain daemon (`cuprate-daemon`) ``` -cargo build --release --features cuprate-daemon +cargo build --release --bin onionwire ``` -- **Off by default.** `cuprated` is pre-1.0, not on crates.io (placeholder - crates), git-pinned, behind the feature. Without the feature, a stored - in-process source can still be read back, but start fails with +That is the Linux TUI/release build. It includes the in-process daemon. +`--features cuprate-daemon` still selects it; that flag is no longer required +for the TUI. A build with `--no-default-features` does not include the daemon. + +- **On in the Linux TUI default.** `cuprated` is pre-1.0, not on crates.io + (placeholder crates), git-pinned. Without the feature, a stored in-process + source can still be read back, but start fails with `this build has no in-process chain daemon — rebuild with --features cuprate-daemon`. - **Pre-production.** Cuprate's own user book says do not use `cuprated` for serious purposes. RPC parity is incomplete (`docs/cuprate-launch-spike.md`). diff --git a/src/cuprate.rs b/src/cuprate.rs index 5ef6922..a13ea92 100644 --- a/src/cuprate.rs +++ b/src/cuprate.rs @@ -11,7 +11,8 @@ //! Locked facts this module encodes: //! //! * `cuprated` is a **git** dependency pinned to a revision, behind the -//! `cuprate-daemon` feature, off by default. Cuprate is pre-1.0 and is not +//! `cuprate-daemon` feature, which the Linux TUI default includes. A +//! `--no-default-features` build does not. Cuprate is pre-1.0 and is not //! published to crates.io (every Cuprate crate there is a `0.0.0-placeholder` //! name reservation), so a pinned revision is the only honest way to depend on //! it. diff --git a/src/node.rs b/src/node.rs index ed4d666..fd52ab1 100644 --- a/src/node.rs +++ b/src/node.rs @@ -3364,12 +3364,55 @@ pub(crate) mod tests { node.stop_wallet_child().expect("stop"); } + /// Holds [`crate::wallet_child::test_support::unrestricted_port_lock`] on a + /// thread of its own. The guard is not `Send`, and this test awaits, so the + /// async fn must not hold it (`clippy::await_holding_lock`). + #[cfg(feature = "cuprate-daemon")] + struct UnrestrictedPortHold { + tx: Option>, + handle: Option>, + } + + #[cfg(feature = "cuprate-daemon")] + impl UnrestrictedPortHold { + fn new() -> Self { + let (ready_tx, ready_rx) = std::sync::mpsc::channel(); + let (tx, rx) = std::sync::mpsc::channel(); + let handle = std::thread::spawn(move || { + let _guard = crate::wallet_child::test_support::unrestricted_port_lock(); + let _ = ready_tx.send(()); + let _ = rx.recv(); + }); + ready_rx + .recv() + .expect("the port lock thread must answer before the test binds"); + Self { + tx: Some(tx), + handle: Some(handle), + } + } + } + + #[cfg(feature = "cuprate-daemon")] + impl Drop for UnrestrictedPortHold { + fn drop(&mut self) { + drop(self.tx.take()); + if let Some(handle) = self.handle.take() { + let _ = handle.join(); + } + } + } + /// The case the user hit: the wallet RPC is refused (`os error 111`) while /// the chain source is this box's own daemon. The status still shows the /// chain's height and target — asked of the daemon directly — and the state /// stays `connecting`, because the *wallet* is what did not answer. #[tokio::test] async fn a_refused_wallet_rpc_falls_back_to_the_local_daemons_own_height() { + // The in-process launch tests bind this same port. Hold it for the + // whole test so a default build (feature on) does not race them. + #[cfg(feature = "cuprate-daemon")] + let _port = UnrestrictedPortHold::new(); let dir = tempfile::tempdir().unwrap(); let home = dir.path().join("child"); let Some(()) = mock_daemon_on_default_port(1160, 3_090_939).await else { @@ -3458,6 +3501,149 @@ pub(crate) mod tests { assert!(err.contains("no chain source configured"), "{err}"); } + /// The call the TUI makes. A direct `CuprateNode::launch` does not prove + /// `start_wallet_child` pointed the wallet child at that node. + /// + /// Testnet, no peers: RPC answers at genesis. Not a sync. + #[cfg(feature = "cuprate-daemon")] + #[test] + fn start_wallet_child_in_process_cuprate_answers_get_info() { + let _port = crate::wallet_child::test_support::unrestricted_port_lock(); + let rt = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("runtime"); + rt.block_on(start_wallet_child_in_process_cuprate_answers_get_info_inner()); + } + + #[cfg(feature = "cuprate-daemon")] + async fn start_wallet_child_in_process_cuprate_answers_get_info_inner() { + let dir = tempfile::tempdir().unwrap(); + let home = dir.path().join("child"); + let node = offline_node(&home, Arc::new(NoDial)); + let log = dir.path().join("wallet-rpc.argv"); + let bin = fake_child_bin( + &dir.path().join("fake-bins"), + "monero-wallet-rpc", + &log, + "sleep 60", + ); + node.set_in_process_cuprate(ChainNetwork::Testnet, false) + .expect("store an in-process testnet source"); + let mut cfg = node.wallet_child_config(); + let ChainSource::InProcessCuprate { + datadir, + network, + prune, + } = &cfg.source + else { + panic!("stored source is not in-process: {:?}", cfg.source); + }; + assert_eq!(*network, ChainNetwork::Testnet); + assert!(!prune); + assert!( + datadir.starts_with(&home), + "datadir must live under the wallet home: {}", + datadir.display() + ); + let datadir = datadir.clone(); + cfg.wallet_rpc_bin = bin; + node.set_wallet_child_config(&cfg) + .expect("point the child at the fake wallet rpc"); + assert!( + WalletChild::chain_copy(&node.wallet_child_config().source) + .contains(crate::cuprate::TESTNET_ONLY), + "an in-process status line must keep the testnet caveat" + ); + + let _hold = PublishedPortHold::watching(std::slice::from_ref(&log)); + node.start_wallet_child() + .expect("the TUI start path launches the in-process daemon"); + + let addr = format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}"); + let mut argv = String::new(); + for _ in 0..200 { + argv = std::fs::read_to_string(&log).unwrap_or_default(); + if argv.contains("--daemon-address") { + break; + } + tokio::time::sleep(Duration::from_millis(10)).await; + } + let lines: Vec<&str> = argv.lines().collect(); + assert!( + lines + .windows(2) + .any(|w| w == ["--daemon-address", addr.as_str()]), + "the wallet child must be pointed at the in-process RPC, got {argv}" + ); + + let budget = Duration::from_secs(5); + let mut info = None; + for _ in 0..40 { + if let Ok(got) = wallet::daemon_get_info(&addr, budget).await { + info = Some(got); + break; + } + tokio::time::sleep(Duration::from_millis(250)).await; + } + let info = info.expect("the unrestricted RPC the child points at never answered get_info"); + assert!(info.height >= 1, "genesis is height 1: {info:?}"); + assert_eq!( + info.target_height, 0, + "a testnet node with no peers reports no target: {info:?}" + ); + assert!( + datadir.join("testnet").join("fjall").is_dir(), + "the chain store must live under the wallet home: {}", + datadir.display() + ); + + node.stop_wallet_child().expect("stop"); + let mut closed = false; + for _ in 0..40 { + if tokio::net::TcpStream::connect(&addr).await.is_err() { + closed = true; + break; + } + tokio::time::sleep(Duration::from_millis(250)).await; + } + assert!( + closed, + "the unrestricted RPC was still accepting after stop_wallet_child" + ); + } + + /// Same call, feature off: the refusal names the feature and spawns nothing. + #[cfg(not(feature = "cuprate-daemon"))] + #[tokio::test] + async fn start_wallet_child_without_the_feature_returns_no_feature_msg() { + let dir = tempfile::tempdir().unwrap(); + let home = dir.path().join("child"); + let node = offline_node(&home, Arc::new(NoDial)); + let log = dir.path().join("wallet-rpc.argv"); + let bin = fake_child_bin( + &dir.path().join("fake-bins"), + "monero-wallet-rpc", + &log, + "sleep 30", + ); + node.set_in_process_cuprate(ChainNetwork::Testnet, false) + .expect("store an in-process source"); + let mut cfg = node.wallet_child_config(); + cfg.wallet_rpc_bin = bin; + node.set_wallet_child_config(&cfg).expect("set bin"); + + let err = node + .start_wallet_child() + .expect_err("a build without the feature must not start a daemon"); + assert!(err.contains(crate::cuprate::NO_FEATURE_MSG), "{err}"); + assert!( + !log.exists(), + "the wallet RPC must not be spawned against a daemon that never started" + ); + assert!(!node.wallet_child_status().running, "{err}"); + } + /// The start path honours `with_wallet_rpc_bin` — the configured absolute /// path is what gets spawned, not a name off `PATH` — and the status tracks /// the real process. diff --git a/src/wallet_child.rs b/src/wallet_child.rs index d61dab8..d10746d 100644 --- a/src/wallet_child.rs +++ b/src/wallet_child.rs @@ -2150,6 +2150,7 @@ mod tests { #[cfg(feature = "cuprate-daemon")] #[test] fn in_process_source_launches_a_daemon_and_stop_shuts_it_down() { + let _port = super::test_support::unrestricted_port_lock(); let dir = tmp_dir("cuprate-on"); let store = open_store(&dir); let rpc_log = dir.join("wallet-rpc.argv"); @@ -2204,6 +2205,7 @@ mod tests { #[cfg(feature = "cuprate-daemon")] #[test] fn a_start_that_fails_after_the_daemon_came_up_leaves_nothing_running() { + let _port = super::test_support::unrestricted_port_lock(); let dir = tmp_dir("cuprate-late-failure"); let store = open_store(&dir); let rpc_log = dir.join("wallet-rpc.argv"); @@ -2370,6 +2372,18 @@ pub(crate) mod test_support { use std::sync::atomic::{AtomicBool, Ordering}; use std::time::{Duration, SystemTime}; + /// Every in-process launch binds [`DEFAULT_MONEROD_RPC_PORT`]. `cargo test` + /// runs those tests in parallel, so they take this for the whole launch + /// and the stop that follows. + /// + /// ponytail: one process-wide lock. A free port per launch would also have + /// to move the wallet child's `--daemon-address`, which is the constant. + #[cfg(feature = "cuprate-daemon")] + pub(crate) fn unrestricted_port_lock() -> std::sync::MutexGuard<'static, ()> { + static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); + LOCK.lock().unwrap_or_else(|e| e.into_inner()) + } + /// Holds every `--rpc-bind-port` a watched argv log publishes, for as long /// as this value lives. ///