tui: the Cuprate start path answers get_info, and the Linux TUI includes it #177

Merged
sirius merged 2 commits from onionwire/t_6f94e378-onionwire-tui-cuprate-start-path-must-la into main 2026-10-08 21:24:24 +00:00
9 changed files with 228 additions and 16 deletions

View file

@ -116,6 +116,8 @@ jobs:
-w /src \ -w /src \
"$RUST_IMAGE" \ "$RUST_IMAGE" \
sh -euxc 'mkdir -p /src /target/tmp && tar xzf - -C /src && cd /src \ sh -euxc 'mkdir -p /src /target/tmp && tar xzf - -C /src && cd /src \
&& apt-get update \
&& apt-get install -y --no-install-recommends cmake build-essential \
&& rustup component add clippy \ && rustup component add clippy \
&& cargo test --locked \ && cargo test --locked \
&& cargo clippy --locked --all-targets -- -D warnings' && cargo clippy --locked --all-targets -- -D warnings'
@ -131,8 +133,11 @@ jobs:
# `v*.*.*` — while both the root suites and local `cargo test` stay green. # `v*.*.*` — while both the root suites and local `cargo test` stay green.
# Build it here. # Build it here.
# #
# The root `test` job no longer installs `pkg-config`/`libssl-dev` — the root # The root `test` job installs `cmake` and `build-essential` (g++, make) because
# crate defaults to Arti's rustls backend, so TLS needs no system OpenSSL. # the default feature set includes `cuprate-daemon`. RandomX's build script
# calls cmake; without it the job dies with "is cmake not installed?" (os error 2).
# It still does not install `pkg-config`/`libssl-dev` — the root crate defaults
# to Arti's rustls backend, so TLS needs no system OpenSSL.
# The `rusqlite` `bundled-sqlcipher-vendored-openssl` feature that both jobs # The `rusqlite` `bundled-sqlcipher-vendored-openssl` feature that both jobs
# use compiles OpenSSL from source, which needs `perl` and `make` (present in # use compiles OpenSSL from source, which needs `perl` and `make` (present in
# the `rust:*-bookworm` image), not the `-dev` headers. This job keeps the # the `rust:*-bookworm` image), not the `-dev` headers. This job keeps the

View file

@ -79,7 +79,7 @@ jobs:
"$RUST_IMAGE" \ "$RUST_IMAGE" \
sh -euxc 'mkdir -p /src /target/tmp && tar xzf - -C /src && cd /src \ sh -euxc 'mkdir -p /src /target/tmp && tar xzf - -C /src && cd /src \
&& apt-get update \ && apt-get update \
&& apt-get install -y --no-install-recommends pkg-config libssl-dev \ && apt-get install -y --no-install-recommends pkg-config libssl-dev cmake build-essential \
&& rustup toolchain install nightly --profile minimal \ && rustup toolchain install nightly --profile minimal \
&& rustup default nightly \ && rustup default nightly \
&& cargo install cargo-fuzz --locked \ && cargo install cargo-fuzz --locked \

View file

@ -218,7 +218,7 @@ jobs:
"$RUST_IMAGE" \ "$RUST_IMAGE" \
sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \ sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \
&& apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true update \ && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true update \
&& apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true install -y --no-install-recommends pkg-config libssl-dev \ && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true install -y --no-install-recommends pkg-config libssl-dev cmake build-essential \
&& cargo build --release --locked \ && cargo build --release --locked \
&& strip /target/release/onionwire \ && strip /target/release/onionwire \
&& ls -l /target/release/onionwire' && ls -l /target/release/onionwire'
@ -301,7 +301,7 @@ jobs:
"$RUST_IMAGE" \ "$RUST_IMAGE" \
sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \ sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \
&& apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true update \ && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true update \
&& apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true install -y --no-install-recommends pkg-config libssl-dev \ && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true install -y --no-install-recommends pkg-config libssl-dev cmake build-essential \
&& cargo build --release --locked \ && cargo build --release --locked \
&& strip /target/release/onionwire \ && strip /target/release/onionwire \
&& ls -l /target/release/onionwire' && ls -l /target/release/onionwire'

View file

@ -17,13 +17,14 @@ repository = "https://github.com/sirius0xdev/onionwire"
# every build by rusqlite's `bundled-sqlcipher-vendored-openssl`, vendored and # every build by rusqlite's `bundled-sqlcipher-vendored-openssl`, vendored and
# static: that is the SQLCipher layer, not Arti's TLS.) # static: that is the SQLCipher layer, not Arti's TLS.)
[features] [features]
default = ["rustls"] default = ["rustls", "cuprate-daemon"]
native-tls = ["arti-client/native-tls"] native-tls = ["arti-client/native-tls"]
rustls = ["arti-client/rustls"] rustls = ["arti-client/rustls"]
# In-process Monero chain daemon (Cuprate) as the local chain source, instead of # 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 # spawning `monerod`. ON in the Linux TUI/release binary (this default). A build
# to crates.io (every Cuprate crate there is a `0.0.0-placeholder` name # with `--no-default-features` does not include it. `cuprated` is pre-1.0 and is
# reservation), so this pins a git revision and pulls a large tree (RandomX, # 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". # 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, # Cuprate's own `arti` feature stays OFF (and is off in its default feature set,

View file

@ -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 Unsynced or not running is an honest “not ready” / unverified state, not a
fake success. fake success.
2. **An in-process daemon** (Cuprate, behind the `cuprate-daemon` feature, off by 2. **An in-process daemon** (Cuprate, behind the `cuprate-daemon` feature, on in
default). P2P, consensus and RandomX run in the OnionWire process; nothing is 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. 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 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. is the daemon, so the "operator sees your addresses" question does not exist.

View file

@ -158,12 +158,16 @@ Settings live in the sealed `wallet_child` record (`ChildConfig`: `source`,
### The in-process chain daemon (`cuprate-daemon`) ### 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 That is the Linux TUI/release build. It includes the in-process daemon.
crates), git-pinned, behind the feature. Without the feature, a stored `--features cuprate-daemon` still selects it; that flag is no longer required
in-process source can still be read back, but start fails with 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`. `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 - **Pre-production.** Cuprate's own user book says do not use `cuprated` for
serious purposes. RPC parity is incomplete (`docs/cuprate-launch-spike.md`). serious purposes. RPC parity is incomplete (`docs/cuprate-launch-spike.md`).

View file

@ -11,7 +11,8 @@
//! Locked facts this module encodes: //! Locked facts this module encodes:
//! //!
//! * `cuprated` is a **git** dependency pinned to a revision, behind the //! * `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` //! 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 //! name reservation), so a pinned revision is the only honest way to depend on
//! it. //! it.

View file

@ -3364,12 +3364,55 @@ pub(crate) mod tests {
node.stop_wallet_child().expect("stop"); 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<std::sync::mpsc::Sender<()>>,
handle: Option<std::thread::JoinHandle<()>>,
}
#[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 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 /// 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 /// chain's height and target — asked of the daemon directly — and the state
/// stays `connecting`, because the *wallet* is what did not answer. /// stays `connecting`, because the *wallet* is what did not answer.
#[tokio::test] #[tokio::test]
async fn a_refused_wallet_rpc_falls_back_to_the_local_daemons_own_height() { 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 dir = tempfile::tempdir().unwrap();
let home = dir.path().join("child"); let home = dir.path().join("child");
let Some(()) = mock_daemon_on_default_port(1160, 3_090_939).await else { 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}"); 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 /// 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 /// path is what gets spawned, not a name off `PATH` — and the status tracks
/// the real process. /// the real process.

View file

@ -2150,6 +2150,7 @@ mod tests {
#[cfg(feature = "cuprate-daemon")] #[cfg(feature = "cuprate-daemon")]
#[test] #[test]
fn in_process_source_launches_a_daemon_and_stop_shuts_it_down() { 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 dir = tmp_dir("cuprate-on");
let store = open_store(&dir); let store = open_store(&dir);
let rpc_log = dir.join("wallet-rpc.argv"); let rpc_log = dir.join("wallet-rpc.argv");
@ -2204,6 +2205,7 @@ mod tests {
#[cfg(feature = "cuprate-daemon")] #[cfg(feature = "cuprate-daemon")]
#[test] #[test]
fn a_start_that_fails_after_the_daemon_came_up_leaves_nothing_running() { 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 dir = tmp_dir("cuprate-late-failure");
let store = open_store(&dir); let store = open_store(&dir);
let rpc_log = dir.join("wallet-rpc.argv"); 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::sync::atomic::{AtomicBool, Ordering};
use std::time::{Duration, SystemTime}; 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 /// Holds every `--rpc-bind-port` a watched argv log publishes, for as long
/// as this value lives. /// as this value lives.
/// ///