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

@ -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()
};