feat(wallet): mainnet pruned and full on-device chain modes #125
11 changed files with 397 additions and 77 deletions
|
|
@ -724,6 +724,8 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
||||||
// an onion daemon outright while no `arti` is bundled.
|
// an onion daemon outright while no `arti` is bundled.
|
||||||
artiBin = expectedArtiPath(),
|
artiBin = expectedArtiPath(),
|
||||||
walletFilename = WalletChildBinaries.WALLET_FILENAME,
|
walletFilename = WalletChildBinaries.WALLET_FILENAME,
|
||||||
|
mainnet = false,
|
||||||
|
prune = false,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -752,6 +754,8 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
||||||
walletRpcBin = bins.walletRpc.orEmpty(),
|
walletRpcBin = bins.walletRpc.orEmpty(),
|
||||||
artiBin = expectedArtiPath(),
|
artiBin = expectedArtiPath(),
|
||||||
walletFilename = WalletChildBinaries.WALLET_FILENAME,
|
walletFilename = WalletChildBinaries.WALLET_FILENAME,
|
||||||
|
mainnet = false,
|
||||||
|
prune = false,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -767,12 +771,14 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
||||||
* is what launches the node *and* the wallet child (one call in the core).
|
* is what launches the node *and* the wallet child (one call in the core).
|
||||||
*
|
*
|
||||||
* `monerodDatadir` is left empty on purpose: the SDK resolves that to
|
* `monerodDatadir` is left empty on purpose: the SDK resolves that to
|
||||||
* `$ONIONWIRE_HOME/chain`, the same per-identity directory a spawned `monerod`
|
* `$ONIONWIRE_HOME/chain/{testnet,mainnet-pruned,mainnet-full}` from
|
||||||
* would use, so Kotlin never invents an absolute path. `monero-wallet-rpc` is
|
* [mainnet] and [prune], so Kotlin never invents an absolute path.
|
||||||
* still required — Cuprate has no wallet layer, so the subprocess stays, and the
|
|
||||||
* core rejects a config without it.
|
|
||||||
*/
|
*/
|
||||||
suspend fun setInProcessCuprate(bins: WalletChildBinaryPaths): Result<Unit> =
|
suspend fun setInProcessCuprate(
|
||||||
|
bins: WalletChildBinaryPaths,
|
||||||
|
mainnet: Boolean,
|
||||||
|
prune: Boolean,
|
||||||
|
): Result<Unit> =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
runCatching {
|
runCatching {
|
||||||
requireWire().setChainSource(
|
requireWire().setChainSource(
|
||||||
|
|
@ -787,6 +793,8 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
||||||
// clearnet, so the core never spawns the SOCKS child.
|
// clearnet, so the core never spawns the SOCKS child.
|
||||||
artiBin = expectedArtiPath(),
|
artiBin = expectedArtiPath(),
|
||||||
walletFilename = WalletChildBinaries.WALLET_FILENAME,
|
walletFilename = WalletChildBinaries.WALLET_FILENAME,
|
||||||
|
mainnet = mainnet,
|
||||||
|
prune = prune,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -318,9 +318,8 @@ const val STARTING_CHILD_NOTICE: String =
|
||||||
*/
|
*/
|
||||||
const val CUPRATE_PREPRODUCTION_WARNING: String =
|
const val CUPRATE_PREPRODUCTION_WARNING: String =
|
||||||
"On-device node is Cuprate, which is pre-production: its own user book says do NOT use " +
|
"On-device node is Cuprate, which is pre-production: its own user book says do NOT use " +
|
||||||
"cuprated for any serious purposes, it runs testnet only here (mainnet is unvalidated), " +
|
"cuprated for any serious purposes, mainnet is unvalidated, and its monerod RPC parity " +
|
||||||
"and its monerod RPC parity is incomplete (Cuprate issue #278). Try the in-process " +
|
"is incomplete (Cuprate issue #278). Try the in-process path; do not hold funds on it."
|
||||||
"path; do not hold funds on it."
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This build was compiled without the `cuprate-daemon` feature, so the stored
|
* This build was compiled without the `cuprate-daemon` feature, so the stored
|
||||||
|
|
@ -342,18 +341,36 @@ const val CUPRATE_NOT_IN_BUILD_NOTICE: String =
|
||||||
* measured honestly is the free space on the filesystem the fjall store grows
|
* measured honestly is the free space on the filesystem the fjall store grows
|
||||||
* into, and the device can be told when that is not enough.
|
* into, and the device can be told when that is not enough.
|
||||||
*/
|
*/
|
||||||
const val CHAIN_FREE_SPACE_FLOOR_BYTES: Long = 3L * 1024 * 1024 * 1024
|
const val CHAIN_TESTNET_FLOOR_BYTES: Long = 3L * 1024 * 1024 * 1024
|
||||||
|
const val CHAIN_MAINNET_PRUNED_FLOOR_BYTES: Long = 64L * 1024 * 1024 * 1024
|
||||||
|
const val CHAIN_MAINNET_FULL_FLOOR_BYTES: Long = 280L * 1024 * 1024 * 1024
|
||||||
|
|
||||||
|
/** Testnet floor, kept so existing tests still name one constant. */
|
||||||
|
const val CHAIN_FREE_SPACE_FLOOR_BYTES: Long = CHAIN_TESTNET_FLOOR_BYTES
|
||||||
|
|
||||||
|
fun chainStorageFloorBytes(mainnet: Boolean, prune: Boolean): Long = when {
|
||||||
|
!mainnet -> CHAIN_TESTNET_FLOOR_BYTES
|
||||||
|
prune -> CHAIN_MAINNET_PRUNED_FLOOR_BYTES
|
||||||
|
else -> CHAIN_MAINNET_FULL_FLOOR_BYTES
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What the chain store costs, in the user's terms: the free space this device
|
* What the chain store costs, in the user's terms: the free space this device
|
||||||
* actually has, and what the node does *not* tell us.
|
* actually has, and what the node does *not* tell us.
|
||||||
*/
|
*/
|
||||||
fun chainStorageLine(freeBytes: Long?): String = when {
|
fun chainStorageLine(freeBytes: Long?, mainnet: Boolean = false, prune: Boolean = false): String {
|
||||||
freeBytes == null ->
|
val kind = when {
|
||||||
"chain store: free space on this device could not be read."
|
!mainnet -> "a synced testnet store"
|
||||||
else ->
|
prune -> "a pruned mainnet store (tens of GiB)"
|
||||||
"chain store: ${formatBytes(freeBytes)} free on this device — a synced testnet store " +
|
else -> "a full mainnet store (hundreds of GiB)"
|
||||||
"grows into it. The node reports no size estimate of its own."
|
}
|
||||||
|
return when {
|
||||||
|
freeBytes == null ->
|
||||||
|
"chain store: free space on this device could not be read."
|
||||||
|
else ->
|
||||||
|
"chain store: ${formatBytes(freeBytes)} free on this device — $kind " +
|
||||||
|
"grows into it. The node reports no size estimate of its own."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -361,13 +378,20 @@ fun chainStorageLine(freeBytes: Long?): String = when {
|
||||||
* may. Fail-closed on an unreadable filesystem: an unknown free space is not
|
* may. Fail-closed on an unreadable filesystem: an unknown free space is not
|
||||||
* reported as enough.
|
* reported as enough.
|
||||||
*/
|
*/
|
||||||
fun chainStorageBlockedReason(freeBytes: Long?): String? = when {
|
fun chainStorageBlockedReason(
|
||||||
freeBytes == null ->
|
freeBytes: Long?,
|
||||||
"Free space on the chain store's filesystem could not be read, so it is not known to fit."
|
mainnet: Boolean = false,
|
||||||
freeBytes < CHAIN_FREE_SPACE_FLOOR_BYTES ->
|
prune: Boolean = false,
|
||||||
"Not enough space for the chain store: ${formatBytes(freeBytes)} free, and the " +
|
): String? {
|
||||||
"on-device node needs at least ${formatBytes(CHAIN_FREE_SPACE_FLOOR_BYTES)}."
|
val floor = chainStorageFloorBytes(mainnet, prune)
|
||||||
else -> null
|
return when {
|
||||||
|
freeBytes == null ->
|
||||||
|
"Free space on the chain store's filesystem could not be read, so it is not known to fit."
|
||||||
|
freeBytes < floor ->
|
||||||
|
"Not enough space for the chain store: ${formatBytes(freeBytes)} free, and the " +
|
||||||
|
"on-device node needs at least ${formatBytes(floor)}."
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -253,10 +253,10 @@ fun WalletScreen(
|
||||||
.onFailure { daemonError = it.message ?: it.toString() }
|
.onFailure { daemonError = it.message ?: it.toString() }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onInProcessNode = {
|
onInProcessNode = { mainnet, prune ->
|
||||||
daemonError = null
|
daemonError = null
|
||||||
scope.launch {
|
scope.launch {
|
||||||
vm.setInProcessCuprate(bins)
|
vm.setInProcessCuprate(bins, mainnet, prune)
|
||||||
.onFailure { daemonError = it.message ?: it.toString() }
|
.onFailure { daemonError = it.message ?: it.toString() }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -617,7 +617,7 @@ private fun WalletChildCard(
|
||||||
onDaemonText: (String) -> Unit,
|
onDaemonText: (String) -> Unit,
|
||||||
onSaveDaemon: () -> Unit,
|
onSaveDaemon: () -> Unit,
|
||||||
onReceiveOnly: () -> Unit,
|
onReceiveOnly: () -> Unit,
|
||||||
onInProcessNode: () -> Unit,
|
onInProcessNode: (mainnet: Boolean, prune: Boolean) -> Unit,
|
||||||
starting: Boolean = false,
|
starting: Boolean = false,
|
||||||
onStart: () -> Unit,
|
onStart: () -> Unit,
|
||||||
onStop: () -> Unit,
|
onStop: () -> Unit,
|
||||||
|
|
@ -630,7 +630,15 @@ private fun WalletChildCard(
|
||||||
// poller, or the user would press Start having seen neither.
|
// poller, or the user would press Start having seen neither.
|
||||||
val inProcess = input?.chainInProcess == true || chain?.kind == ChainChoice.IN_PROCESS_CUPRATE
|
val inProcess = input?.chainInProcess == true || chain?.kind == ChainChoice.IN_PROCESS_CUPRATE
|
||||||
val startWhy = startBlockedReason(bins, input, onionDaemon, starting)
|
val startWhy = startBlockedReason(bins, input, onionDaemon, starting)
|
||||||
?: if (inProcess) chainStorageBlockedReason(nodeFreeBytes) else null
|
?: if (inProcess) {
|
||||||
|
chainStorageBlockedReason(
|
||||||
|
nodeFreeBytes,
|
||||||
|
mainnet = chain?.mainnet == true,
|
||||||
|
prune = chain?.prune == true,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
val stopWhy = stopBlockedReason(input)
|
val stopWhy = stopBlockedReason(input)
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
|
|
@ -731,11 +739,25 @@ private fun WalletChildCard(
|
||||||
// reads before Start.
|
// reads before Start.
|
||||||
Spacer(Modifier.height(8.dp))
|
Spacer(Modifier.height(8.dp))
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
onClick = onInProcessNode,
|
onClick = { onInProcessNode(true, true) },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.testTag("wallet-chain-mainnet-pruned"),
|
||||||
|
) { Text("Mainnet pruned") }
|
||||||
|
Spacer(Modifier.height(4.dp))
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = { onInProcessNode(true, false) },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.testTag("wallet-chain-mainnet-full"),
|
||||||
|
) { Text("Mainnet full") }
|
||||||
|
Spacer(Modifier.height(4.dp))
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = { onInProcessNode(false, false) },
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.testTag("wallet-chain-in-process"),
|
.testTag("wallet-chain-in-process"),
|
||||||
) { Text("On-device node (Cuprate)") }
|
) { Text("Testnet (experimental)") }
|
||||||
|
|
||||||
if (inProcess) {
|
if (inProcess) {
|
||||||
Spacer(Modifier.height(8.dp))
|
Spacer(Modifier.height(8.dp))
|
||||||
|
|
@ -749,7 +771,11 @@ private fun WalletChildCard(
|
||||||
)
|
)
|
||||||
Spacer(Modifier.height(4.dp))
|
Spacer(Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
chainStorageLine(nodeFreeBytes),
|
chainStorageLine(
|
||||||
|
nodeFreeBytes,
|
||||||
|
mainnet = chain?.mainnet == true,
|
||||||
|
prune = chain?.prune == true,
|
||||||
|
),
|
||||||
style = MaterialTheme.typography.labelSmall,
|
style = MaterialTheme.typography.labelSmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|
|
||||||
|
|
@ -338,7 +338,7 @@ class WalletChildStatusTextTest {
|
||||||
assertTrue("it names the software", warning.contains("Cuprate"))
|
assertTrue("it names the software", warning.contains("Cuprate"))
|
||||||
assertTrue("it quotes the user book", warning.contains("do NOT use cuprated"))
|
assertTrue("it quotes the user book", warning.contains("do NOT use cuprated"))
|
||||||
assertTrue("it names the parity gap", warning.contains("Cuprate issue #278"))
|
assertTrue("it names the parity gap", warning.contains("Cuprate issue #278"))
|
||||||
assertTrue("it says testnet", warning.contains("testnet"))
|
assertTrue("it says mainnet is unvalidated", warning.contains("mainnet is unvalidated"))
|
||||||
assertTrue("it is a sentence, not a glyph", warning.trim().endsWith("."))
|
assertTrue("it is a sentence, not a glyph", warning.trim().endsWith("."))
|
||||||
assertTrue("it is long enough to be a sentence", warning.length > 80)
|
assertTrue("it is long enough to be a sentence", warning.length > 80)
|
||||||
}
|
}
|
||||||
|
|
@ -364,6 +364,33 @@ class WalletChildStatusTextTest {
|
||||||
assertNull(chainStorageBlockedReason(64L * 1024 * 1024 * 1024))
|
assertNull(chainStorageBlockedReason(64L * 1024 * 1024 * 1024))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun mainnet_pruned_needs_more_than_testnet() {
|
||||||
|
val forty = 40L * 1024 * 1024 * 1024
|
||||||
|
assertNull(chainStorageBlockedReason(forty, mainnet = false, prune = false))
|
||||||
|
val why = chainStorageBlockedReason(forty, mainnet = true, prune = true)
|
||||||
|
assertNotNull(why)
|
||||||
|
assertTrue(why!!, why.contains("64.0 GiB"))
|
||||||
|
assertNull(
|
||||||
|
chainStorageBlockedReason(
|
||||||
|
CHAIN_MAINNET_PRUNED_FLOOR_BYTES,
|
||||||
|
mainnet = true,
|
||||||
|
prune = true,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun mainnet_full_needs_more_than_pruned() {
|
||||||
|
val why = chainStorageBlockedReason(
|
||||||
|
CHAIN_MAINNET_PRUNED_FLOOR_BYTES,
|
||||||
|
mainnet = true,
|
||||||
|
prune = false,
|
||||||
|
)
|
||||||
|
assertNotNull(why)
|
||||||
|
assertTrue(why!!, why.contains("280.0 GiB"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun the_storage_line_reports_the_measured_number() {
|
fun the_storage_line_reports_the_measured_number() {
|
||||||
val line = chainStorageLine(41L * 1024 * 1024 * 1024)
|
val line = chainStorageLine(41L * 1024 * 1024 * 1024)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ use onionwire::node::{FlushOutcome as CoreFlushOutcome, Node};
|
||||||
use onionwire::outbox::{DEFAULT_MAX_ATTEMPTS, OutboxEntry, OutboxStatus};
|
use onionwire::outbox::{DEFAULT_MAX_ATTEMPTS, OutboxEntry, OutboxStatus};
|
||||||
use onionwire::pay;
|
use onionwire::pay;
|
||||||
use onionwire::qr;
|
use onionwire::qr;
|
||||||
use onionwire::wallet::ChainSource;
|
use onionwire::wallet::{ChainNetwork, ChainSource};
|
||||||
use onionwire::wallet_child::{ChildConfig, WalletChildState};
|
use onionwire::wallet_child::{ChildConfig, WalletChildState};
|
||||||
|
|
||||||
uniffi::setup_scaffolding!();
|
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
|
/// 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
|
/// caller never has to invent an absolute path. Every other kind uses exactly
|
||||||
/// what it was given (or the core's own default), unchanged.
|
/// 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 {
|
fn child_config(cfg: ChainConfig, home: &Path) -> ChildConfig {
|
||||||
let source = match cfg.kind {
|
let source = match cfg.kind {
|
||||||
ChainChoice::None => ChainSource::None,
|
ChainChoice::None => ChainSource::None,
|
||||||
ChainChoice::Local => ChainSource::Local {
|
ChainChoice::Local => ChainSource::Local {
|
||||||
monerod_bin: PathBuf::from(cfg.monerod_bin),
|
monerod_bin: PathBuf::from(cfg.monerod_bin),
|
||||||
datadir: PathBuf::from(cfg.monerod_datadir),
|
datadir: PathBuf::from(cfg.monerod_datadir),
|
||||||
|
prune: cfg.prune,
|
||||||
},
|
},
|
||||||
ChainChoice::InProcessCuprate => ChainSource::InProcessCuprate {
|
ChainChoice::InProcessCuprate => {
|
||||||
datadir: if cfg.monerod_datadir.trim().is_empty() {
|
let network = if cfg.mainnet {
|
||||||
home.join("chain")
|
ChainNetwork::Mainnet
|
||||||
} else {
|
} 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 {
|
ChainChoice::Remote => ChainSource::Remote {
|
||||||
host: cfg.host,
|
host: cfg.host,
|
||||||
port: cfg.port,
|
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 {
|
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 => (
|
ChainSource::None => (
|
||||||
ChainChoice::None,
|
ChainChoice::None,
|
||||||
String::new(),
|
String::new(),
|
||||||
0,
|
0,
|
||||||
String::new(),
|
String::new(),
|
||||||
String::new(),
|
String::new(),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
),
|
),
|
||||||
ChainSource::Local {
|
ChainSource::Local {
|
||||||
monerod_bin,
|
monerod_bin,
|
||||||
datadir,
|
datadir,
|
||||||
|
prune,
|
||||||
} => (
|
} => (
|
||||||
ChainChoice::Local,
|
ChainChoice::Local,
|
||||||
String::new(),
|
String::new(),
|
||||||
0,
|
0,
|
||||||
monerod_bin.display().to_string(),
|
monerod_bin.display().to_string(),
|
||||||
datadir.display().to_string(),
|
datadir.display().to_string(),
|
||||||
|
true,
|
||||||
|
*prune,
|
||||||
),
|
),
|
||||||
ChainSource::InProcessCuprate { datadir } => (
|
ChainSource::InProcessCuprate {
|
||||||
|
datadir,
|
||||||
|
network,
|
||||||
|
prune,
|
||||||
|
} => (
|
||||||
ChainChoice::InProcessCuprate,
|
ChainChoice::InProcessCuprate,
|
||||||
String::new(),
|
String::new(),
|
||||||
0,
|
0,
|
||||||
String::new(),
|
String::new(),
|
||||||
datadir.display().to_string(),
|
datadir.display().to_string(),
|
||||||
|
matches!(network, ChainNetwork::Mainnet),
|
||||||
|
*prune,
|
||||||
),
|
),
|
||||||
ChainSource::Remote { host, port } => (
|
ChainSource::Remote { host, port } => (
|
||||||
ChainChoice::Remote,
|
ChainChoice::Remote,
|
||||||
|
|
@ -802,6 +832,8 @@ fn chain_config(cfg: &ChildConfig) -> ChainConfig {
|
||||||
*port,
|
*port,
|
||||||
String::new(),
|
String::new(),
|
||||||
String::new(),
|
String::new(),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
ChainConfig {
|
ChainConfig {
|
||||||
|
|
@ -813,6 +845,8 @@ fn chain_config(cfg: &ChildConfig) -> ChainConfig {
|
||||||
wallet_rpc_bin: cfg.wallet_rpc_bin.display().to_string(),
|
wallet_rpc_bin: cfg.wallet_rpc_bin.display().to_string(),
|
||||||
arti_bin: cfg.arti_bin.display().to_string(),
|
arti_bin: cfg.arti_bin.display().to_string(),
|
||||||
wallet_filename: cfg.wallet_filename.clone(),
|
wallet_filename: cfg.wallet_filename.clone(),
|
||||||
|
mainnet,
|
||||||
|
prune,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -997,6 +1031,13 @@ pub struct ChainConfig {
|
||||||
pub arti_bin: String,
|
pub arti_bin: String,
|
||||||
/// Wallet file name inside `$ONIONWIRE_HOME/wallet`.
|
/// Wallet file name inside `$ONIONWIRE_HOME/wallet`.
|
||||||
pub wallet_filename: String,
|
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.
|
/// One snapshot of the app-owned wallet child.
|
||||||
|
|
@ -1713,6 +1754,8 @@ mod tests {
|
||||||
wallet_rpc_bin: "/data/app/nativeLibraryDir/libmonerowalletrpc.so".to_string(),
|
wallet_rpc_bin: "/data/app/nativeLibraryDir/libmonerowalletrpc.so".to_string(),
|
||||||
arti_bin: "/data/app/nativeLibraryDir/libarti.so".to_string(),
|
arti_bin: "/data/app/nativeLibraryDir/libarti.so".to_string(),
|
||||||
wallet_filename: "wallet".to_string(),
|
wallet_filename: "wallet".to_string(),
|
||||||
|
mainnet: false,
|
||||||
|
prune: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1726,10 +1769,49 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
child.source,
|
child.source,
|
||||||
ChainSource::InProcessCuprate {
|
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]
|
#[test]
|
||||||
|
|
@ -1739,7 +1821,9 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
child.source,
|
child.source,
|
||||||
ChainSource::InProcessCuprate {
|
ChainSource::InProcessCuprate {
|
||||||
datadir: PathBuf::from(given)
|
datadir: PathBuf::from(given),
|
||||||
|
network: ChainNetwork::Testnet,
|
||||||
|
prune: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -1776,7 +1860,7 @@ mod tests {
|
||||||
ChainChoice::InProcessCuprate => {
|
ChainChoice::InProcessCuprate => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
back.monerod_datadir,
|
back.monerod_datadir,
|
||||||
sdk_home().join("chain").display().to_string()
|
sdk_home().join("chain").join("testnet").display().to_string()
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
back.monerod_bin.is_empty(),
|
back.monerod_bin.is_empty(),
|
||||||
|
|
@ -1815,7 +1899,9 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn node_state_names_the_apps_own_chain_for_the_in_process_source() {
|
fn node_state_names_the_apps_own_chain_for_the_in_process_source() {
|
||||||
let source = ChainSource::InProcessCuprate {
|
let source = ChainSource::InProcessCuprate {
|
||||||
datadir: sdk_home().join("chain"),
|
datadir: sdk_home().join("chain").join("testnet"),
|
||||||
|
network: ChainNetwork::Testnet,
|
||||||
|
prune: false,
|
||||||
};
|
};
|
||||||
let cases = [
|
let cases = [
|
||||||
(WalletChildState::Off, "off"),
|
(WalletChildState::Off, "off"),
|
||||||
|
|
@ -1844,6 +1930,7 @@ mod tests {
|
||||||
ChainSource::Local {
|
ChainSource::Local {
|
||||||
monerod_bin: PathBuf::from("monerod"),
|
monerod_bin: PathBuf::from("monerod"),
|
||||||
datadir: PathBuf::from("/chain"),
|
datadir: PathBuf::from("/chain"),
|
||||||
|
prune: false,
|
||||||
},
|
},
|
||||||
ChainSource::Remote {
|
ChainSource::Remote {
|
||||||
host: "peer.onion".to_string(),
|
host: "peer.onion".to_string(),
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,8 @@ mod imp {
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
|
|
||||||
|
use cuprated::config::{resolve_max_memory, Config};
|
||||||
use cuprated::Node;
|
use cuprated::Node;
|
||||||
use cuprated::config::{Config, resolve_max_memory};
|
|
||||||
|
|
||||||
/// The network this daemon runs. Testnet, deliberately — see the module
|
/// The network this daemon runs. Testnet, deliberately — see the module
|
||||||
/// docs. Cuprate spells this `Testnet`.
|
/// docs. Cuprate spells this `Testnet`.
|
||||||
|
|
@ -107,8 +107,13 @@ mod imp {
|
||||||
/// Blocking this thread for the duration of the launch is the same thing
|
/// 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
|
/// the app already does for a `.onion` chain source's SOCKS readiness
|
||||||
/// wait.
|
/// wait.
|
||||||
pub fn launch(datadir: &Path, port: u16) -> Result<Self, String> {
|
pub fn launch(
|
||||||
let text = config_toml(datadir, port);
|
datadir: &Path,
|
||||||
|
port: u16,
|
||||||
|
network: &str,
|
||||||
|
prune: bool,
|
||||||
|
) -> Result<Self, String> {
|
||||||
|
let text = config_toml(datadir, port, network, prune);
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
std::thread::Builder::new()
|
std::thread::Builder::new()
|
||||||
.name("onionwire-cuprate".into())
|
.name("onionwire-cuprate".into())
|
||||||
|
|
@ -193,10 +198,10 @@ mod imp {
|
||||||
/// default silently standing in for the setting that was meant.
|
/// default silently standing in for the setting that was meant.
|
||||||
///
|
///
|
||||||
/// No data directory is created here — the caller owns the 0700 wallet dir.
|
/// 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();
|
let datadir = datadir.display();
|
||||||
format!(
|
format!(
|
||||||
r#"network = "{NETWORK}"
|
r#"network = "{network}"
|
||||||
offline = false
|
offline = false
|
||||||
fast_sync = true
|
fast_sync = true
|
||||||
target_max_memory = {TARGET_MAX_MEMORY}
|
target_max_memory = {TARGET_MAX_MEMORY}
|
||||||
|
|
@ -209,6 +214,9 @@ cache_directory = "{datadir}/cache"
|
||||||
[storage]
|
[storage]
|
||||||
reader_threads = {READER_THREADS}
|
reader_threads = {READER_THREADS}
|
||||||
|
|
||||||
|
[storage.blockchain]
|
||||||
|
prune = {prune}
|
||||||
|
|
||||||
# The unrestricted listener: this is the one the wallet child dials, and the one
|
# 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
|
# with real numbers. The restricted listener is off — its metrics are
|
||||||
# placeholders, and nothing in this app reads them.
|
# 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.
|
/// between revisions is a hard error, not a silently ignored setting.
|
||||||
#[test]
|
#[test]
|
||||||
fn the_config_parses_into_this_revision() {
|
fn the_config_parses_into_this_revision() {
|
||||||
let mut config: Config =
|
let mut config: Config = toml::from_str(&config_toml(
|
||||||
toml::from_str(&config_toml(Path::new("/tmp/onionwire-chain"), 18081))
|
Path::new("/tmp/onionwire-chain"),
|
||||||
.expect("the config must parse against the pinned cuprated revision");
|
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");
|
resolve_max_memory(&mut config).expect("target_max_memory is set, so nothing to probe");
|
||||||
assert_eq!(format!("{:?}", config.network), NETWORK);
|
assert_eq!(format!("{:?}", config.network), NETWORK);
|
||||||
// The fjall store is Cuprate's, under the datadir it was given —
|
// The fjall store is Cuprate's, under the datadir it was given —
|
||||||
|
|
@ -278,7 +290,12 @@ mod imp {
|
||||||
|
|
||||||
impl CuprateNode {
|
impl CuprateNode {
|
||||||
/// Always fails: this build has no in-process daemon.
|
/// 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())
|
Err(super::NO_FEATURE_MSG.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -295,4 +312,4 @@ mod imp {
|
||||||
pub use imp::CuprateNode;
|
pub use imp::CuprateNode;
|
||||||
|
|
||||||
#[cfg(feature = "cuprate-daemon")]
|
#[cfg(feature = "cuprate-daemon")]
|
||||||
pub use imp::{NETWORK, config_toml};
|
pub use imp::{config_toml, NETWORK};
|
||||||
|
|
|
||||||
30
src/node.rs
30
src/node.rs
|
|
@ -29,7 +29,7 @@ use crate::ratelimit::TokenBucket;
|
||||||
use crate::sanitize;
|
use crate::sanitize;
|
||||||
use crate::session::{self, Keys};
|
use crate::session::{self, Keys};
|
||||||
use crate::store::{Friend, FriendProfile, Message, Payment, PaymentWrite, Store};
|
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};
|
use crate::wallet_child::{ChildConfig, WalletChild, WalletChildState, WalletChildStatus};
|
||||||
|
|
||||||
pub struct RotateResult {
|
pub struct RotateResult {
|
||||||
|
|
@ -567,6 +567,10 @@ impl Node {
|
||||||
|
|
||||||
// ----- the app-owned wallet child (`src/wallet_child.rs`) ----------------
|
// ----- 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
|
/// The child settings this node would spawn with: the stored record, or the
|
||||||
/// defaults (receive-only, binaries by name) when nothing was ever set.
|
/// defaults (receive-only, binaries by name) when nothing was ever set.
|
||||||
pub fn wallet_child_config(&self) -> ChildConfig {
|
pub fn wallet_child_config(&self) -> ChildConfig {
|
||||||
|
|
@ -593,6 +597,30 @@ impl Node {
|
||||||
Ok(())
|
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.
|
/// 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
|
/// Idempotent: a live wallet child is reported, not respawned. Spawning is
|
||||||
|
|
|
||||||
19
src/tui.rs
19
src/tui.rs
|
|
@ -18,7 +18,7 @@ use crate::outbox::DEFAULT_MAX_ATTEMPTS;
|
||||||
use crate::qr::{self, QrPayload};
|
use crate::qr::{self, QrPayload};
|
||||||
use crate::sanitize;
|
use crate::sanitize;
|
||||||
use crate::store::{Friend, FriendProfile, Message, OutboxEntry, OutboxStatus, Payment};
|
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_ACCENT: Color = Color::Rgb(232, 165, 75);
|
||||||
const C_TEXT: Color = Color::Rgb(196, 214, 176);
|
const C_TEXT: Color = Color::Rgb(196, 214, 176);
|
||||||
|
|
@ -1669,6 +1669,9 @@ impl App {
|
||||||
KeyCode::Char('s') => self.wallet_child_start(),
|
KeyCode::Char('s') => self.wallet_child_start(),
|
||||||
KeyCode::Char('x') => self.wallet_child_stop(),
|
KeyCode::Char('x') => self.wallet_child_stop(),
|
||||||
KeyCode::Char('p') => self.wallet_child_probe(),
|
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') => {
|
KeyCode::Char('c') => {
|
||||||
self.screen = Screen::WalletSetup(WalletSetup::CreateWarn {
|
self.screen = Screen::WalletSetup(WalletSetup::CreateWarn {
|
||||||
typed: String::new(),
|
typed: String::new(),
|
||||||
|
|
@ -2142,6 +2145,16 @@ impl App {
|
||||||
self.status_note = Some(self.wallet_child_note());
|
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.
|
/// The child status line, or the copy that names what is missing.
|
||||||
fn wallet_child_note(&mut self) -> String {
|
fn wallet_child_note(&mut self) -> String {
|
||||||
let line = self.rt.block_on(self.node.wallet_child_refresh()).line();
|
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",
|
BackupKind::Restore => "type RESTORE Esc cancel ? help",
|
||||||
},
|
},
|
||||||
Screen::Passphrase { .. } => "Enter submit 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::CreateWarn { .. }) => "type SPEND Esc cancel ? help",
|
||||||
Screen::WalletSetup(WalletSetup::CreatePass { .. } | WalletSetup::ImportPass { .. }) => {
|
Screen::WalletSetup(WalletSetup::CreatePass { .. } | WalletSetup::ImportPass { .. }) => {
|
||||||
"Enter submit Esc cancel ? help"
|
"Enter submit Esc cancel ? help"
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,31 @@ impl std::fmt::Display for Error {
|
||||||
|
|
||||||
impl std::error::Error 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
|
/// 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.
|
/// is ever implied — every `Remote` is constructed from explicit user input.
|
||||||
///
|
///
|
||||||
|
|
@ -34,17 +59,21 @@ pub enum ChainSource {
|
||||||
monerod_bin: PathBuf,
|
monerod_bin: PathBuf,
|
||||||
/// Data directory for the local daemon.
|
/// Data directory for the local daemon.
|
||||||
datadir: PathBuf,
|
datadir: PathBuf,
|
||||||
|
/// `monerod --prune-blockchain`. Full node when false.
|
||||||
|
prune: bool,
|
||||||
},
|
},
|
||||||
/// A chain daemon **inside this process** (Cuprate), with its chain in
|
/// A chain daemon **inside this process** (Cuprate), with its chain in
|
||||||
/// `datadir`. Nothing is spawned; the wallet child still dials loopback
|
/// `datadir`. Nothing is spawned; the wallet child still dials loopback
|
||||||
/// RPC, so this is a [`ChainSource::Local`] with a different owner.
|
/// 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
|
/// Cuprate is still pre-production: mainnet RPC parity is unvalidated.
|
||||||
/// the in-process daemon is **testnet-only** in this build (Cuprate is
|
/// The UI must say so. `network`/`prune` are the user's choice; old
|
||||||
/// pre-production and its mainnet RPC parity is unvalidated).
|
/// stored records without those keys are testnet, unpruned.
|
||||||
InProcessCuprate {
|
InProcessCuprate {
|
||||||
/// Data directory for the daemon's chain database.
|
/// Data directory for the daemon's chain database.
|
||||||
datadir: PathBuf,
|
datadir: PathBuf,
|
||||||
|
network: ChainNetwork,
|
||||||
|
prune: bool,
|
||||||
},
|
},
|
||||||
/// A daemon address the user supplied. Trust follows the address.
|
/// A daemon address the user supplied. Trust follows the address.
|
||||||
Remote {
|
Remote {
|
||||||
|
|
@ -71,8 +100,22 @@ impl ChainSource {
|
||||||
pub fn label(&self) -> String {
|
pub fn label(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
ChainSource::None => "receive-only".to_string(),
|
ChainSource::None => "receive-only".to_string(),
|
||||||
ChainSource::Local { .. } => "local node".to_string(),
|
ChainSource::Local { prune: true, .. } => "local pruned node".to_string(),
|
||||||
ChainSource::InProcessCuprate { .. } => "in-process 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) => {
|
ChainSource::Remote { host, .. } if is_onion_host(host) => {
|
||||||
"remote onion daemon".to_string()
|
"remote onion daemon".to_string()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ use zeroize::Zeroizing;
|
||||||
|
|
||||||
use crate::cuprate::CuprateNode;
|
use crate::cuprate::CuprateNode;
|
||||||
use crate::store::Store;
|
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
|
/// `monerod` RPC port for a local chain source. Unrestricted RPC default; the
|
||||||
/// wallet child is the only thing that dials it.
|
/// 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.
|
/// for a remote source (their disk, not ours) and for receive-only.
|
||||||
pub fn chain_datadir(source: &ChainSource) -> Option<&Path> {
|
pub fn chain_datadir(source: &ChainSource) -> Option<&Path> {
|
||||||
match source {
|
match source {
|
||||||
ChainSource::Local { datadir, .. } | ChainSource::InProcessCuprate { datadir } => {
|
ChainSource::Local { datadir, .. } | ChainSource::InProcessCuprate { datadir, .. } => {
|
||||||
Some(datadir)
|
Some(datadir)
|
||||||
}
|
}
|
||||||
ChainSource::None | ChainSource::Remote { .. } => None,
|
ChainSource::None | ChainSource::Remote { .. } => None,
|
||||||
|
|
@ -377,8 +377,8 @@ impl WalletChild {
|
||||||
|
|
||||||
/// The exact argv used to spawn `monerod`. Single source of truth: `start`
|
/// The exact argv used to spawn `monerod`. Single source of truth: `start`
|
||||||
/// spawns this and the tests assert on it.
|
/// spawns this and the tests assert on it.
|
||||||
pub fn monerod_argv(bin: &Path, datadir: &Path, rpc_port: u16) -> Vec<String> {
|
pub fn monerod_argv(bin: &Path, datadir: &Path, rpc_port: u16, prune: bool) -> Vec<String> {
|
||||||
vec![
|
let mut argv = vec![
|
||||||
bin.display().to_string(),
|
bin.display().to_string(),
|
||||||
"--non-interactive".into(),
|
"--non-interactive".into(),
|
||||||
"--data-dir".into(),
|
"--data-dir".into(),
|
||||||
|
|
@ -387,7 +387,11 @@ impl WalletChild {
|
||||||
"127.0.0.1".into(),
|
"127.0.0.1".into(),
|
||||||
"--rpc-bind-port".into(),
|
"--rpc-bind-port".into(),
|
||||||
rpc_port.to_string(),
|
rpc_port.to_string(),
|
||||||
]
|
];
|
||||||
|
if prune {
|
||||||
|
argv.push("--prune-blockchain".into());
|
||||||
|
}
|
||||||
|
argv
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The exact argv used to spawn `monero-wallet-rpc`. Digest login is
|
/// The exact argv used to spawn `monero-wallet-rpc`. Digest login is
|
||||||
|
|
@ -487,9 +491,11 @@ impl WalletChild {
|
||||||
ChainSource::Local {
|
ChainSource::Local {
|
||||||
monerod_bin,
|
monerod_bin,
|
||||||
datadir,
|
datadir,
|
||||||
|
prune,
|
||||||
} => {
|
} => {
|
||||||
ensure_parent(datadir)?;
|
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 child = spawn(&argv, "monerod")?;
|
||||||
let mut guard = self
|
let mut guard = self
|
||||||
.monerod
|
.monerod
|
||||||
|
|
@ -497,7 +503,11 @@ impl WalletChild {
|
||||||
.map_err(|e| ChildError(format!("monerod lock: {e}")))?;
|
.map_err(|e| ChildError(format!("monerod lock: {e}")))?;
|
||||||
*guard = Some(child);
|
*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 { .. } => {}
|
ChainSource::None | ChainSource::Remote { .. } => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -584,15 +594,25 @@ impl WalletChild {
|
||||||
/// node answers), so this works from the TUI's blocking thread *and* from an
|
/// 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
|
/// SDK async context. It is the same shape as the SOCKS readiness wait
|
||||||
/// above: no daemon, no wallet child.
|
/// 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
|
// Feature first: in a build without it, a datadir complaint would be a
|
||||||
// misleading answer to "why is there no daemon".
|
// misleading answer to "why is there no daemon".
|
||||||
if !crate::cuprate::available() {
|
if !crate::cuprate::available() {
|
||||||
return Err(ChildError(crate::cuprate::NO_FEATURE_MSG.into()));
|
return Err(ChildError(crate::cuprate::NO_FEATURE_MSG.into()));
|
||||||
}
|
}
|
||||||
create_dir_700(datadir).map_err(|e| ChildError(format!("chain datadir: {e}")))?;
|
create_dir_700(datadir).map_err(|e| ChildError(format!("chain datadir: {e}")))?;
|
||||||
let node = CuprateNode::launch(datadir, DEFAULT_MONEROD_RPC_PORT)
|
let node = CuprateNode::launch(
|
||||||
.map_err(|e| ChildError(format!("in-process daemon: {e}")))?;
|
datadir,
|
||||||
|
DEFAULT_MONEROD_RPC_PORT,
|
||||||
|
network.cuprate_toml(),
|
||||||
|
prune,
|
||||||
|
)
|
||||||
|
.map_err(|e| ChildError(format!("in-process daemon: {e}")))?;
|
||||||
let mut guard = self
|
let mut guard = self
|
||||||
.cuprate
|
.cuprate
|
||||||
.lock()
|
.lock()
|
||||||
|
|
@ -729,6 +749,7 @@ impl ChildConfig {
|
||||||
ChainSource::Local {
|
ChainSource::Local {
|
||||||
monerod_bin,
|
monerod_bin,
|
||||||
datadir,
|
datadir,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
if monerod_bin.as_os_str().is_empty() {
|
if monerod_bin.as_os_str().is_empty() {
|
||||||
return Err(ChildError("monerod path required for a local node".into()));
|
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() {
|
if datadir.as_os_str().is_empty() {
|
||||||
return Err(ChildError(
|
return Err(ChildError(
|
||||||
"chain data dir required for an in-process daemon".into(),
|
"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 {
|
ChainSource::Local {
|
||||||
monerod_bin,
|
monerod_bin,
|
||||||
datadir,
|
datadir,
|
||||||
|
prune,
|
||||||
} => serde_json::json!({
|
} => serde_json::json!({
|
||||||
"kind": "local",
|
"kind": "local",
|
||||||
"monerod_bin": monerod_bin.display().to_string(),
|
"monerod_bin": monerod_bin.display().to_string(),
|
||||||
"datadir": datadir.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",
|
"kind": "cuprate",
|
||||||
"datadir": datadir.display().to_string(),
|
"datadir": datadir.display().to_string(),
|
||||||
|
"network": network.dir_name(),
|
||||||
|
"prune": prune,
|
||||||
}),
|
}),
|
||||||
ChainSource::Remote { host, port } => serde_json::json!({
|
ChainSource::Remote { host, port } => serde_json::json!({
|
||||||
"kind": "remote",
|
"kind": "remote",
|
||||||
|
|
@ -989,6 +1018,7 @@ fn source_from_json(value: &serde_json::Value) -> Result<ChainSource> {
|
||||||
Ok(ChainSource::Local {
|
Ok(ChainSource::Local {
|
||||||
monerod_bin: PathBuf::from(monerod_bin),
|
monerod_bin: PathBuf::from(monerod_bin),
|
||||||
datadir: PathBuf::from(datadir),
|
datadir: PathBuf::from(datadir),
|
||||||
|
prune: value.get("prune").and_then(|v| v.as_bool()).unwrap_or(false),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
"cuprate" => {
|
"cuprate" => {
|
||||||
|
|
@ -999,8 +1029,15 @@ fn source_from_json(value: &serde_json::Value) -> Result<ChainSource> {
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
ChildError("stored in-process chain source has no data dir".into())
|
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 {
|
Ok(ChainSource::InProcessCuprate {
|
||||||
datadir: PathBuf::from(datadir),
|
datadir: PathBuf::from(datadir),
|
||||||
|
network,
|
||||||
|
prune,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
"remote" => {
|
"remote" => {
|
||||||
|
|
@ -1144,6 +1181,7 @@ mod tests {
|
||||||
ChainSource::Local {
|
ChainSource::Local {
|
||||||
monerod_bin: monerod,
|
monerod_bin: monerod,
|
||||||
datadir: dir.join("monerod-data"),
|
datadir: dir.join("monerod-data"),
|
||||||
|
prune: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1589,6 +1627,7 @@ mod tests {
|
||||||
&PathBuf::from("/usr/bin/monerod"),
|
&PathBuf::from("/usr/bin/monerod"),
|
||||||
&datadir,
|
&datadir,
|
||||||
DEFAULT_MONEROD_RPC_PORT,
|
DEFAULT_MONEROD_RPC_PORT,
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
let pairs: Vec<(&str, &str)> = argv
|
let pairs: Vec<(&str, &str)> = argv
|
||||||
.windows(2)
|
.windows(2)
|
||||||
|
|
@ -1748,6 +1787,8 @@ mod tests {
|
||||||
fn in_process_source(dir: &Path) -> ChainSource {
|
fn in_process_source(dir: &Path) -> ChainSource {
|
||||||
ChainSource::InProcessCuprate {
|
ChainSource::InProcessCuprate {
|
||||||
datadir: dir.join("chain"),
|
datadir: dir.join("chain"),
|
||||||
|
network: ChainNetwork::Testnet,
|
||||||
|
prune: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1855,6 +1896,8 @@ mod tests {
|
||||||
let empty = ChildConfig {
|
let empty = ChildConfig {
|
||||||
source: ChainSource::InProcessCuprate {
|
source: ChainSource::InProcessCuprate {
|
||||||
datadir: PathBuf::new(),
|
datadir: PathBuf::new(),
|
||||||
|
network: ChainNetwork::Testnet,
|
||||||
|
prune: false,
|
||||||
},
|
},
|
||||||
..ChildConfig::default()
|
..ChildConfig::default()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1138,9 +1138,10 @@ fn chain_source_labels_name_what_the_child_dials() {
|
||||||
ChainSource::Local {
|
ChainSource::Local {
|
||||||
monerod_bin: PathBuf::from("/usr/bin/monerod"),
|
monerod_bin: PathBuf::from("/usr/bin/monerod"),
|
||||||
datadir: PathBuf::from("/var/lib/onionwire"),
|
datadir: PathBuf::from("/var/lib/onionwire"),
|
||||||
|
prune: false,
|
||||||
}
|
}
|
||||||
.label(),
|
.label(),
|
||||||
"local node"
|
"local full node"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ChainSource::Remote {
|
ChainSource::Remote {
|
||||||
|
|
@ -1226,6 +1227,7 @@ fn child_settings_round_trip_sealed_and_keep_the_creds() {
|
||||||
local.source = ChainSource::Local {
|
local.source = ChainSource::Local {
|
||||||
monerod_bin: PathBuf::new(),
|
monerod_bin: PathBuf::new(),
|
||||||
datadir: PathBuf::from("/var/lib/onionwire"),
|
datadir: PathBuf::from("/var/lib/onionwire"),
|
||||||
|
prune: false,
|
||||||
};
|
};
|
||||||
let err = local.validate().expect_err("a local node needs monerod");
|
let err = local.validate().expect_err("a local node needs monerod");
|
||||||
assert!(err.to_string().contains("monerod path required"), "{err}");
|
assert!(err.to_string().contains("monerod path required"), "{err}");
|
||||||
|
|
@ -1265,7 +1267,7 @@ async fn an_in_process_cuprate_node_answers_the_typed_daemon_client() {
|
||||||
let addr = format!("127.0.0.1:{port}");
|
let addr = format!("127.0.0.1:{port}");
|
||||||
let budget = std::time::Duration::from_secs(5);
|
let budget = std::time::Duration::from_secs(5);
|
||||||
|
|
||||||
let mut node = onionwire::cuprate::CuprateNode::launch(&datadir, port)
|
let mut node = onionwire::cuprate::CuprateNode::launch(&datadir, port, "Testnet", false)
|
||||||
.expect("launch the in-process testnet daemon");
|
.expect("launch the in-process testnet daemon");
|
||||||
|
|
||||||
// `launch` returns with the services started; the RPC listener can still be
|
// `launch` returns with the services started; the RPC listener can still be
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue