android: Start wallet no longer looks like a no-op while Cuprate launches
Tapping Start held the SQLCipher mutex for the whole in-process Node::launch and blocked the UniFFI tokio worker, so wallet_status stayed off with no error. Drop the store lock until creds are needed, spawn_blocking the sync start, and show that Start is in flight. The APK still runs Cuprate testnet only; this does not add mainnet or prune.
This commit is contained in:
parent
2df10124ef
commit
0acf89a0b4
7 changed files with 103 additions and 34 deletions
10
src/node.rs
10
src/node.rs
|
|
@ -617,10 +617,12 @@ impl Node {
|
|||
cfg.build(self.home.join("wallet"))
|
||||
.map_err(|e| e.to_string())?,
|
||||
);
|
||||
let client = {
|
||||
let store = self.store.lock().map_err(|e| e.to_string())?;
|
||||
child.start(&store).map_err(|e| e.to_string())?
|
||||
};
|
||||
// Do not hold SQLCipher across Cuprate/`monerod` launch: `wallet_status`
|
||||
// also locks the store, and a blocked poller is how Android Start looks
|
||||
// like it did nothing.
|
||||
let client = child
|
||||
.start_unlocking_store(&self.store)
|
||||
.map_err(|e| e.to_string())?;
|
||||
let Some(client) = client else {
|
||||
return Err("chain source is receive-only — nothing to start".into());
|
||||
};
|
||||
|
|
|
|||
|
|
@ -435,13 +435,36 @@ impl WalletChild {
|
|||
/// what gates every spawn: the SOCKS child, like the wallet child, is only
|
||||
/// reachable through an unlocked store.
|
||||
pub fn start(&self, store: &Store) -> Result<Option<WalletClient>> {
|
||||
self.start_with_creds(|| self.creds(store))
|
||||
}
|
||||
|
||||
/// Same as [`WalletChild::start`], but the store mutex is taken only for
|
||||
/// the generated RPC creds — not across chain-daemon launch.
|
||||
///
|
||||
/// Cuprate's `Node::launch` (and a slow `monerod`) can run for a long time.
|
||||
/// Holding SQLCipher for that whole window freezes every `wallet_status`
|
||||
/// poll, which on Android makes **Start** look like a no-op: the button
|
||||
/// fires, status stays `off`, no error.
|
||||
pub fn start_unlocking_store(&self, store: &Mutex<Store>) -> Result<Option<WalletClient>> {
|
||||
self.start_with_creds(|| {
|
||||
let guard = store
|
||||
.lock()
|
||||
.map_err(|e| ChildError(format!("store lock: {e}")))?;
|
||||
self.creds(&guard)
|
||||
})
|
||||
}
|
||||
|
||||
fn start_with_creds(
|
||||
&self,
|
||||
creds: impl FnOnce() -> Result<(String, Zeroizing<String>)>,
|
||||
) -> Result<Option<WalletClient>> {
|
||||
if !self.is_enabled() {
|
||||
return Ok(None);
|
||||
}
|
||||
if self.running() {
|
||||
return Err(ChildError("wallet child already running".into()));
|
||||
}
|
||||
match self.start_children(store) {
|
||||
match self.start_children(creds) {
|
||||
Ok(client) => Ok(client),
|
||||
Err(e) => {
|
||||
// A failure after the SOCKS child came up must not leave the
|
||||
|
|
@ -452,7 +475,10 @@ impl WalletChild {
|
|||
}
|
||||
}
|
||||
|
||||
fn start_children(&self, store: &Store) -> Result<Option<WalletClient>> {
|
||||
fn start_children(
|
||||
&self,
|
||||
creds: impl FnOnce() -> Result<(String, Zeroizing<String>)>,
|
||||
) -> Result<Option<WalletClient>> {
|
||||
// Local chain source: own the daemon first, so the wallet child has
|
||||
// something to dial. Either a spawned `monerod` or the in-process
|
||||
// Cuprate node — both bind `DEFAULT_MONEROD_RPC_PORT` on loopback, so
|
||||
|
|
@ -485,7 +511,10 @@ impl WalletChild {
|
|||
_ => None,
|
||||
};
|
||||
|
||||
let (user, pass) = self.creds(store)?;
|
||||
// Creds are the only store read. Callers that pass
|
||||
// `start_unlocking_store` take the mutex here, after the chain daemon
|
||||
// is already up, so a long Cuprate launch does not freeze SQLCipher.
|
||||
let (user, pass) = creds()?;
|
||||
let port = Self::pick_port()?;
|
||||
let login = format!("{user}:{}", pass.as_str());
|
||||
let daemon = Self::daemon_address(&self.source);
|
||||
|
|
@ -1135,6 +1164,14 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn start_unlocking_store_is_the_same_as_start_for_receive_only() {
|
||||
let dir = tmp_dir("none-unlock");
|
||||
let store = std::sync::Mutex::new(open_store(&dir));
|
||||
let child = WalletChild::new(ChainSource::None, dir.join("wallet"), None).unwrap();
|
||||
assert!(child.start_unlocking_store(&store).unwrap().is_none());
|
||||
}
|
||||
|
||||
/// A live listener for the readiness gate to dial. `arti proxy -p <port>`
|
||||
/// binds localhost only, so 127.0.0.1 is exactly what the gate probes.
|
||||
fn held_loopback_port() -> (std::net::TcpListener, u16) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue