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

@ -34,7 +34,7 @@ use onionwire::node::{FlushOutcome as CoreFlushOutcome, Node};
use onionwire::outbox::{DEFAULT_MAX_ATTEMPTS, OutboxEntry, OutboxStatus};
use onionwire::pay;
use onionwire::qr;
use onionwire::wallet::ChainSource;
use onionwire::wallet::{ChainNetwork, ChainSource};
use onionwire::wallet_child::{ChildConfig, WalletChildState};
uniffi::setup_scaffolding!();
@ -742,20 +742,40 @@ fn from_core_flush(o: CoreFlushOutcome) -> FlushOutcome {
/// per-identity directory the core documents for a local chain — so a Kotlin
/// caller never has to invent an absolute path. Every other kind uses exactly
/// what it was given (or the core's own default), unchanged.
fn cuprate_chain_dir(home: &Path, mainnet: bool, prune: bool) -> PathBuf {
let name = match (mainnet, prune) {
(true, true) => "mainnet-pruned",
(true, false) => "mainnet-full",
(false, _) => "testnet",
};
home.join("chain").join(name)
}
fn child_config(cfg: ChainConfig, home: &Path) -> ChildConfig {
let source = match cfg.kind {
ChainChoice::None => ChainSource::None,
ChainChoice::Local => ChainSource::Local {
monerod_bin: PathBuf::from(cfg.monerod_bin),
datadir: PathBuf::from(cfg.monerod_datadir),
prune: cfg.prune,
},
ChainChoice::InProcessCuprate => ChainSource::InProcessCuprate {
datadir: if cfg.monerod_datadir.trim().is_empty() {
home.join("chain")
ChainChoice::InProcessCuprate => {
let network = if cfg.mainnet {
ChainNetwork::Mainnet
} else {
PathBuf::from(cfg.monerod_datadir)
},
},
ChainNetwork::Testnet
};
let prune = cfg.mainnet && cfg.prune;
ChainSource::InProcessCuprate {
datadir: if cfg.monerod_datadir.trim().is_empty() {
cuprate_chain_dir(home, cfg.mainnet, prune)
} else {
PathBuf::from(cfg.monerod_datadir)
},
network,
prune,
}
}
ChainChoice::Remote => ChainSource::Remote {
host: cfg.host,
port: cfg.port,
@ -769,32 +789,42 @@ fn child_config(cfg: ChainConfig, home: &Path) -> ChildConfig {
}
}
/// And back, for the Kotlin prefill.
fn chain_config(cfg: &ChildConfig) -> ChainConfig {
let (kind, host, port, monerod_bin, monerod_datadir) = match &cfg.source {
let (kind, host, port, monerod_bin, monerod_datadir, mainnet, prune) = match &cfg.source {
ChainSource::None => (
ChainChoice::None,
String::new(),
0,
String::new(),
String::new(),
false,
false,
),
ChainSource::Local {
monerod_bin,
datadir,
prune,
} => (
ChainChoice::Local,
String::new(),
0,
monerod_bin.display().to_string(),
datadir.display().to_string(),
true,
*prune,
),
ChainSource::InProcessCuprate { datadir } => (
ChainSource::InProcessCuprate {
datadir,
network,
prune,
} => (
ChainChoice::InProcessCuprate,
String::new(),
0,
String::new(),
datadir.display().to_string(),
matches!(network, ChainNetwork::Mainnet),
*prune,
),
ChainSource::Remote { host, port } => (
ChainChoice::Remote,
@ -802,6 +832,8 @@ fn chain_config(cfg: &ChildConfig) -> ChainConfig {
*port,
String::new(),
String::new(),
false,
false,
),
};
ChainConfig {
@ -813,6 +845,8 @@ fn chain_config(cfg: &ChildConfig) -> ChainConfig {
wallet_rpc_bin: cfg.wallet_rpc_bin.display().to_string(),
arti_bin: cfg.arti_bin.display().to_string(),
wallet_filename: cfg.wallet_filename.clone(),
mainnet,
prune,
}
}
@ -997,6 +1031,13 @@ pub struct ChainConfig {
pub arti_bin: String,
/// Wallet file name inside `$ONIONWIRE_HOME/wallet`.
pub wallet_filename: String,
/// Cuprate / local `monerod`: mainnet when true, testnet when false.
/// Ignored for Remote and None. Old records without the field stay testnet.
pub mainnet: bool,
/// Cuprate / local `monerod`: prune the chain. Ignored for Remote and None.
/// Once a Cuprate store is pruned it cannot be un-pruned — we keep pruned
/// and full in separate datadirs.
pub prune: bool,
}
/// One snapshot of the app-owned wallet child.
@ -1713,6 +1754,8 @@ mod tests {
wallet_rpc_bin: "/data/app/nativeLibraryDir/libmonerowalletrpc.so".to_string(),
arti_bin: "/data/app/nativeLibraryDir/libarti.so".to_string(),
wallet_filename: "wallet".to_string(),
mainnet: false,
prune: false,
}
}
@ -1726,10 +1769,49 @@ mod tests {
assert_eq!(
child.source,
ChainSource::InProcessCuprate {
datadir: sdk_home().join("chain")
datadir: sdk_home().join("chain").join("testnet"),
network: ChainNetwork::Testnet,
prune: false,
}
);
assert_eq!(child.source_label(), "in-process node");
assert_eq!(child.source_label(), "in-process testnet");
}
#[test]
fn child_config_mainnet_pruned_uses_its_own_datadir() {
let mut req = request(ChainChoice::InProcessCuprate, "");
req.mainnet = true;
req.prune = true;
let child = child_config(req, &sdk_home());
assert_eq!(
child.source,
ChainSource::InProcessCuprate {
datadir: sdk_home().join("chain").join("mainnet-pruned"),
network: ChainNetwork::Mainnet,
prune: true,
}
);
assert_eq!(child.source_label(), "in-process mainnet pruned");
let back = chain_config(&child);
assert!(back.mainnet);
assert!(back.prune);
}
#[test]
fn child_config_mainnet_full_uses_its_own_datadir() {
let mut req = request(ChainChoice::InProcessCuprate, "");
req.mainnet = true;
req.prune = false;
let child = child_config(req, &sdk_home());
assert_eq!(
child.source,
ChainSource::InProcessCuprate {
datadir: sdk_home().join("chain").join("mainnet-full"),
network: ChainNetwork::Mainnet,
prune: false,
}
);
assert_eq!(child.source_label(), "in-process mainnet full");
}
#[test]
@ -1739,7 +1821,9 @@ mod tests {
assert_eq!(
child.source,
ChainSource::InProcessCuprate {
datadir: PathBuf::from(given)
datadir: PathBuf::from(given),
network: ChainNetwork::Testnet,
prune: false,
}
);
}
@ -1776,7 +1860,7 @@ mod tests {
ChainChoice::InProcessCuprate => {
assert_eq!(
back.monerod_datadir,
sdk_home().join("chain").display().to_string()
sdk_home().join("chain").join("testnet").display().to_string()
);
assert!(
back.monerod_bin.is_empty(),
@ -1815,7 +1899,9 @@ mod tests {
#[test]
fn node_state_names_the_apps_own_chain_for_the_in_process_source() {
let source = ChainSource::InProcessCuprate {
datadir: sdk_home().join("chain"),
datadir: sdk_home().join("chain").join("testnet"),
network: ChainNetwork::Testnet,
prune: false,
};
let cases = [
(WalletChildState::Off, "off"),
@ -1844,6 +1930,7 @@ mod tests {
ChainSource::Local {
monerod_bin: PathBuf::from("monerod"),
datadir: PathBuf::from("/chain"),
prune: false,
},
ChainSource::Remote {
host: "peer.onion".to_string(),