feat(wallet): mainnet pruned and full on-device chain modes
All checks were successful
ci / test (pull_request) Successful in 5m45s
ci / sdk (pull_request) Successful in 1m34s
ci / fuzz (pull_request) Successful in 4m51s
android-ci / android (pull_request) Successful in 13m2s

Cuprate in-process and TUI keys 1/2/3 pick mainnet pruned, mainnet
full, or experimental testnet. Datadirs are split so a prune store
cannot mix with a full one. Android storage floors scale with the
choice. Cuprate remains pre-production; mainnet is unvalidated.
This commit is contained in:
agent 2026-09-19 12:54:35 -04:00
commit 5080652e3b
No known key found for this signature in database
11 changed files with 397 additions and 77 deletions

View file

@ -60,8 +60,8 @@ mod imp {
use std::path::Path;
use std::sync::mpsc;
use cuprated::config::{resolve_max_memory, Config};
use cuprated::Node;
use cuprated::config::{Config, resolve_max_memory};
/// The network this daemon runs. Testnet, deliberately — see the module
/// docs. Cuprate spells this `Testnet`.
@ -107,8 +107,13 @@ mod imp {
/// Blocking this thread for the duration of the launch is the same thing
/// the app already does for a `.onion` chain source's SOCKS readiness
/// wait.
pub fn launch(datadir: &Path, port: u16) -> Result<Self, String> {
let text = config_toml(datadir, port);
pub fn launch(
datadir: &Path,
port: u16,
network: &str,
prune: bool,
) -> Result<Self, String> {
let text = config_toml(datadir, port, network, prune);
let (tx, rx) = mpsc::channel();
std::thread::Builder::new()
.name("onionwire-cuprate".into())
@ -193,10 +198,10 @@ mod imp {
/// default silently standing in for the setting that was meant.
///
/// No data directory is created here — the caller owns the 0700 wallet dir.
pub fn config_toml(datadir: &Path, port: u16) -> String {
pub fn config_toml(datadir: &Path, port: u16, network: &str, prune: bool) -> String {
let datadir = datadir.display();
format!(
r#"network = "{NETWORK}"
r#"network = "{network}"
offline = false
fast_sync = true
target_max_memory = {TARGET_MAX_MEMORY}
@ -209,6 +214,9 @@ cache_directory = "{datadir}/cache"
[storage]
reader_threads = {READER_THREADS}
[storage.blockchain]
prune = {prune}
# The unrestricted listener: this is the one the wallet child dials, and the one
# with real numbers. The restricted listener is off — its metrics are
# placeholders, and nothing in this app reads them.
@ -247,9 +255,13 @@ mode = "Auto"
/// between revisions is a hard error, not a silently ignored setting.
#[test]
fn the_config_parses_into_this_revision() {
let mut config: Config =
toml::from_str(&config_toml(Path::new("/tmp/onionwire-chain"), 18081))
.expect("the config must parse against the pinned cuprated revision");
let mut config: Config = toml::from_str(&config_toml(
Path::new("/tmp/onionwire-chain"),
18081,
"Testnet",
false,
))
.expect("the config must parse against the pinned cuprated revision");
resolve_max_memory(&mut config).expect("target_max_memory is set, so nothing to probe");
assert_eq!(format!("{:?}", config.network), NETWORK);
// The fjall store is Cuprate's, under the datadir it was given —
@ -278,7 +290,12 @@ mod imp {
impl CuprateNode {
/// Always fails: this build has no in-process daemon.
pub fn launch(_datadir: &Path, _port: u16) -> Result<Self, String> {
pub fn launch(
_datadir: &Path,
_port: u16,
_network: &str,
_prune: bool,
) -> Result<Self, String> {
Err(super::NO_FEATURE_MSG.into())
}
@ -295,4 +312,4 @@ mod imp {
pub use imp::CuprateNode;
#[cfg(feature = "cuprate-daemon")]
pub use imp::{NETWORK, config_toml};
pub use imp::{config_toml, NETWORK};

View file

@ -29,7 +29,7 @@ use crate::ratelimit::TokenBucket;
use crate::sanitize;
use crate::session::{self, Keys};
use crate::store::{Friend, FriendProfile, Message, Payment, PaymentWrite, Store};
use crate::wallet::{self, Readiness, Wallet, WalletConfig, WalletStatus};
use crate::wallet::{self, ChainNetwork, ChainSource, Readiness, Wallet, WalletConfig, WalletStatus};
use crate::wallet_child::{ChildConfig, WalletChild, WalletChildState, WalletChildStatus};
pub struct RotateResult {
@ -567,6 +567,10 @@ impl Node {
// ----- the app-owned wallet child (`src/wallet_child.rs`) ----------------
pub fn home(&self) -> &Path {
&self.home
}
/// The child settings this node would spawn with: the stored record, or the
/// defaults (receive-only, binaries by name) when nothing was ever set.
pub fn wallet_child_config(&self) -> ChildConfig {
@ -593,6 +597,30 @@ impl Node {
Ok(())
}
/// Store an in-process Cuprate source. Datadirs are split so a pruned
/// mainnet store cannot mix with a full one (Cuprate cannot un-prune).
pub fn set_in_process_cuprate(
&self,
network: ChainNetwork,
prune: bool,
) -> Result<(), String> {
let mut cfg = self.wallet_child_config();
if cfg.wallet_rpc_bin.as_os_str().is_empty() {
cfg.wallet_rpc_bin = PathBuf::from("monero-wallet-rpc");
}
let name = match (network, prune) {
(ChainNetwork::Mainnet, true) => "mainnet-pruned",
(ChainNetwork::Mainnet, false) => "mainnet-full",
(ChainNetwork::Testnet, _) => "testnet",
};
cfg.source = ChainSource::InProcessCuprate {
datadir: self.home.join("chain").join(name),
network,
prune: matches!(network, ChainNetwork::Mainnet) && prune,
};
self.set_wallet_child_config(&cfg)
}
/// Start the app-owned wallet child and point this node's wallet at it.
///
/// Idempotent: a live wallet child is reported, not respawned. Spawning is

View file

@ -18,7 +18,7 @@ use crate::outbox::DEFAULT_MAX_ATTEMPTS;
use crate::qr::{self, QrPayload};
use crate::sanitize;
use crate::store::{Friend, FriendProfile, Message, OutboxEntry, OutboxStatus, Payment};
use crate::wallet::{self, ChainSource};
use crate::wallet::{self, ChainNetwork, ChainSource};
const C_ACCENT: Color = Color::Rgb(232, 165, 75);
const C_TEXT: Color = Color::Rgb(196, 214, 176);
@ -1669,6 +1669,9 @@ impl App {
KeyCode::Char('s') => self.wallet_child_start(),
KeyCode::Char('x') => self.wallet_child_stop(),
KeyCode::Char('p') => self.wallet_child_probe(),
KeyCode::Char('1') => self.set_cuprate_chain(ChainNetwork::Mainnet, true),
KeyCode::Char('2') => self.set_cuprate_chain(ChainNetwork::Mainnet, false),
KeyCode::Char('3') => self.set_cuprate_chain(ChainNetwork::Testnet, false),
KeyCode::Char('c') => {
self.screen = Screen::WalletSetup(WalletSetup::CreateWarn {
typed: String::new(),
@ -2142,6 +2145,16 @@ impl App {
self.status_note = Some(self.wallet_child_note());
}
fn set_cuprate_chain(&mut self, network: ChainNetwork, prune: bool) {
self.status_note = Some(match self.node.set_in_process_cuprate(network, prune) {
Ok(()) => format!(
"chain source: {}",
self.node.wallet_child_config().source.label()
),
Err(e) => format!("chain source: {e}"),
});
}
/// The child status line, or the copy that names what is missing.
fn wallet_child_note(&mut self) -> String {
let line = self.rt.block_on(self.node.wallet_child_refresh()).line();
@ -3179,7 +3192,9 @@ match screen {
BackupKind::Restore => "type RESTORE Esc cancel ? help",
},
Screen::Passphrase { .. } => "Enter submit Esc cancel ? help",
Screen::Wallet { .. } => "c create i import r qr s/x child Esc back ? help",
Screen::Wallet { .. } => {
"c create i import r qr s/x child 1 pruned 2 full 3 testnet Esc back ? help"
}
Screen::WalletSetup(WalletSetup::CreateWarn { .. }) => "type SPEND Esc cancel ? help",
Screen::WalletSetup(WalletSetup::CreatePass { .. } | WalletSetup::ImportPass { .. }) => {
"Enter submit Esc cancel ? help"

View file

@ -19,6 +19,31 @@ impl std::fmt::Display for Error {
impl std::error::Error for Error {}
/// Which Monero network an on-device daemon follows.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChainNetwork {
Mainnet,
Testnet,
}
impl ChainNetwork {
/// Cuprate TOML `network = "..."` spelling (`Mainnet` / `Testnet`).
pub fn cuprate_toml(self) -> &'static str {
match self {
Self::Mainnet => "Mainnet",
Self::Testnet => "Testnet",
}
}
/// Directory segment so mainnet and testnet stores never share a fjall dir.
pub fn dir_name(self) -> &'static str {
match self {
Self::Mainnet => "mainnet",
Self::Testnet => "testnet",
}
}
}
/// The user's choice of where the Monero daemon lives. No default remote node
/// is ever implied — every `Remote` is constructed from explicit user input.
///
@ -34,17 +59,21 @@ pub enum ChainSource {
monerod_bin: PathBuf,
/// Data directory for the local daemon.
datadir: PathBuf,
/// `monerod --prune-blockchain`. Full node when false.
prune: bool,
},
/// A chain daemon **inside this process** (Cuprate), with its chain in
/// `datadir`. Nothing is spawned; the wallet child still dials loopback
/// RPC, so this is a [`ChainSource::Local`] with a different owner.
///
/// Two consequences the UI has to state: the chain is on this device, and
/// the in-process daemon is **testnet-only** in this build (Cuprate is
/// pre-production and its mainnet RPC parity is unvalidated).
/// Cuprate is still pre-production: mainnet RPC parity is unvalidated.
/// The UI must say so. `network`/`prune` are the user's choice; old
/// stored records without those keys are testnet, unpruned.
InProcessCuprate {
/// Data directory for the daemon's chain database.
datadir: PathBuf,
network: ChainNetwork,
prune: bool,
},
/// A daemon address the user supplied. Trust follows the address.
Remote {
@ -71,8 +100,22 @@ impl ChainSource {
pub fn label(&self) -> String {
match self {
ChainSource::None => "receive-only".to_string(),
ChainSource::Local { .. } => "local node".to_string(),
ChainSource::InProcessCuprate { .. } => "in-process node".to_string(),
ChainSource::Local { prune: true, .. } => "local pruned node".to_string(),
ChainSource::Local { prune: false, .. } => "local full node".to_string(),
ChainSource::InProcessCuprate {
network: ChainNetwork::Mainnet,
prune: true,
..
} => "in-process mainnet pruned".to_string(),
ChainSource::InProcessCuprate {
network: ChainNetwork::Mainnet,
prune: false,
..
} => "in-process mainnet full".to_string(),
ChainSource::InProcessCuprate {
network: ChainNetwork::Testnet,
..
} => "in-process testnet".to_string(),
ChainSource::Remote { host, .. } if is_onion_host(host) => {
"remote onion daemon".to_string()
}

View file

@ -39,7 +39,7 @@ use zeroize::Zeroizing;
use crate::cuprate::CuprateNode;
use crate::store::Store;
use crate::wallet::{self, ChainSource, Wallet};
use crate::wallet::{self, ChainNetwork, ChainSource, Wallet};
/// `monerod` RPC port for a local chain source. Unrestricted RPC default; the
/// wallet child is the only thing that dials it.
@ -355,7 +355,7 @@ impl WalletChild {
/// for a remote source (their disk, not ours) and for receive-only.
pub fn chain_datadir(source: &ChainSource) -> Option<&Path> {
match source {
ChainSource::Local { datadir, .. } | ChainSource::InProcessCuprate { datadir } => {
ChainSource::Local { datadir, .. } | ChainSource::InProcessCuprate { datadir, .. } => {
Some(datadir)
}
ChainSource::None | ChainSource::Remote { .. } => None,
@ -377,8 +377,8 @@ impl WalletChild {
/// The exact argv used to spawn `monerod`. Single source of truth: `start`
/// spawns this and the tests assert on it.
pub fn monerod_argv(bin: &Path, datadir: &Path, rpc_port: u16) -> Vec<String> {
vec![
pub fn monerod_argv(bin: &Path, datadir: &Path, rpc_port: u16, prune: bool) -> Vec<String> {
let mut argv = vec![
bin.display().to_string(),
"--non-interactive".into(),
"--data-dir".into(),
@ -387,7 +387,11 @@ impl WalletChild {
"127.0.0.1".into(),
"--rpc-bind-port".into(),
rpc_port.to_string(),
]
];
if prune {
argv.push("--prune-blockchain".into());
}
argv
}
/// The exact argv used to spawn `monero-wallet-rpc`. Digest login is
@ -487,9 +491,11 @@ impl WalletChild {
ChainSource::Local {
monerod_bin,
datadir,
prune,
} => {
ensure_parent(datadir)?;
let argv = Self::monerod_argv(monerod_bin, datadir, DEFAULT_MONEROD_RPC_PORT);
let argv =
Self::monerod_argv(monerod_bin, datadir, DEFAULT_MONEROD_RPC_PORT, *prune);
let child = spawn(&argv, "monerod")?;
let mut guard = self
.monerod
@ -497,7 +503,11 @@ impl WalletChild {
.map_err(|e| ChildError(format!("monerod lock: {e}")))?;
*guard = Some(child);
}
ChainSource::InProcessCuprate { datadir } => self.start_in_process_daemon(datadir)?,
ChainSource::InProcessCuprate {
datadir,
network,
prune,
} => self.start_in_process_daemon(datadir, *network, *prune)?,
ChainSource::None | ChainSource::Remote { .. } => {}
}
@ -584,15 +594,25 @@ impl WalletChild {
/// node answers), so this works from the TUI's blocking thread *and* from an
/// SDK async context. It is the same shape as the SOCKS readiness wait
/// above: no daemon, no wallet child.
fn start_in_process_daemon(&self, datadir: &Path) -> Result<()> {
fn start_in_process_daemon(
&self,
datadir: &Path,
network: ChainNetwork,
prune: bool,
) -> Result<()> {
// Feature first: in a build without it, a datadir complaint would be a
// misleading answer to "why is there no daemon".
if !crate::cuprate::available() {
return Err(ChildError(crate::cuprate::NO_FEATURE_MSG.into()));
}
create_dir_700(datadir).map_err(|e| ChildError(format!("chain datadir: {e}")))?;
let node = CuprateNode::launch(datadir, DEFAULT_MONEROD_RPC_PORT)
.map_err(|e| ChildError(format!("in-process daemon: {e}")))?;
let node = CuprateNode::launch(
datadir,
DEFAULT_MONEROD_RPC_PORT,
network.cuprate_toml(),
prune,
)
.map_err(|e| ChildError(format!("in-process daemon: {e}")))?;
let mut guard = self
.cuprate
.lock()
@ -729,6 +749,7 @@ impl ChildConfig {
ChainSource::Local {
monerod_bin,
datadir,
..
} => {
if monerod_bin.as_os_str().is_empty() {
return Err(ChildError("monerod path required for a local node".into()));
@ -739,7 +760,7 @@ impl ChildConfig {
));
}
}
ChainSource::InProcessCuprate { datadir } => {
ChainSource::InProcessCuprate { datadir, .. } => {
if datadir.as_os_str().is_empty() {
return Err(ChildError(
"chain data dir required for an in-process daemon".into(),
@ -949,14 +970,22 @@ fn source_to_json(source: &ChainSource) -> serde_json::Value {
ChainSource::Local {
monerod_bin,
datadir,
prune,
} => serde_json::json!({
"kind": "local",
"monerod_bin": monerod_bin.display().to_string(),
"datadir": datadir.display().to_string(),
"prune": prune,
}),
ChainSource::InProcessCuprate { datadir } => serde_json::json!({
ChainSource::InProcessCuprate {
datadir,
network,
prune,
} => serde_json::json!({
"kind": "cuprate",
"datadir": datadir.display().to_string(),
"network": network.dir_name(),
"prune": prune,
}),
ChainSource::Remote { host, port } => serde_json::json!({
"kind": "remote",
@ -989,6 +1018,7 @@ fn source_from_json(value: &serde_json::Value) -> Result<ChainSource> {
Ok(ChainSource::Local {
monerod_bin: PathBuf::from(monerod_bin),
datadir: PathBuf::from(datadir),
prune: value.get("prune").and_then(|v| v.as_bool()).unwrap_or(false),
})
}
"cuprate" => {
@ -999,8 +1029,15 @@ fn source_from_json(value: &serde_json::Value) -> Result<ChainSource> {
.ok_or_else(|| {
ChildError("stored in-process chain source has no data dir".into())
})?;
let network = match value.get("network").and_then(|v| v.as_str()) {
Some("mainnet") => ChainNetwork::Mainnet,
_ => ChainNetwork::Testnet,
};
let prune = value.get("prune").and_then(|v| v.as_bool()).unwrap_or(false);
Ok(ChainSource::InProcessCuprate {
datadir: PathBuf::from(datadir),
network,
prune,
})
}
"remote" => {
@ -1144,6 +1181,7 @@ mod tests {
ChainSource::Local {
monerod_bin: monerod,
datadir: dir.join("monerod-data"),
prune: false,
}
}
@ -1589,6 +1627,7 @@ mod tests {
&PathBuf::from("/usr/bin/monerod"),
&datadir,
DEFAULT_MONEROD_RPC_PORT,
false,
);
let pairs: Vec<(&str, &str)> = argv
.windows(2)
@ -1748,6 +1787,8 @@ mod tests {
fn in_process_source(dir: &Path) -> ChainSource {
ChainSource::InProcessCuprate {
datadir: dir.join("chain"),
network: ChainNetwork::Testnet,
prune: false,
}
}
@ -1855,6 +1896,8 @@ mod tests {
let empty = ChildConfig {
source: ChainSource::InProcessCuprate {
datadir: PathBuf::new(),
network: ChainNetwork::Testnet,
prune: false,
},
..ChildConfig::default()
};