wallet: a connect refusal while coming up is not a status error

This commit is contained in:
agent 2026-09-23 20:33:49 -04:00
commit 4136f36dd4
No known key found for this signature in database
2 changed files with 85 additions and 10 deletions

View file

@ -1014,7 +1014,8 @@ impl Node {
self.child_height.store(height, Ordering::Relaxed);
self.child_target.store(target_height, Ordering::Relaxed);
if let Ok(mut slot) = self.child_error.lock() {
*slot = if connected { None } else { error };
let previous = slot.clone();
*slot = probe_error(connected, error, previous);
}
self.wallet_child_status()
}
@ -2316,6 +2317,32 @@ pub fn ingest_chat_frame(
Ok(line.to_vec())
}
/// The error a wallet-child probe leaves on the status row.
///
/// `probed` is what the probe said (`None` when the RPC answered); `previous` is
/// what the row already held. A wallet RPC that refuses the connection because
/// it is still coming up is not an error to show — the row would flash
/// `wallet connect: Connection refused` and then clear itself on the next tick.
/// It is not silent either: whatever real error the row already held survives.
/// A timeout, `-13`, `No wallet file`, or a bad passphrase is the RPC's own
/// answer and is kept, as is the same connect text once the child is up and
/// answering (`connected`) and then stops.
pub(crate) fn probe_error(
connected: bool,
probed: Option<String>,
previous: Option<String>,
) -> Option<String> {
if connected {
return None;
}
match probed {
Some(err) if wallet::error_is_unreachable(&err) => {
previous.filter(|prev| !wallet::error_is_unreachable(prev))
}
other => other,
}
}
fn spawn_rend(
node: Arc<Node>,
rend: impl futures::Stream<Item = tor_hsservice::RendRequest> + Send + 'static,
@ -4137,6 +4164,48 @@ pub(crate) mod tests {
.unwrap_or_default()
}
/// A wallet RPC that is not answering *yet* is not a row error: it is the
/// child coming up, and the row would otherwise flash the string the user
/// saw. Everything else — a timeout, `-13`, a refused passphrase — is the
/// RPC's own answer and stays on the row.
#[test]
fn an_unreachable_probe_is_not_a_status_error() {
use crate::wallet::error_is_unreachable;
assert!(error_is_unreachable(
"wallet connect: Connection refused (os error 111)"
));
assert!(error_is_unreachable("wallet write: Connection reset"));
assert!(!error_is_unreachable("wallet RPC timed out"));
assert!(!error_is_unreachable("No wallet file"));
assert_eq!(
probe_error(
false,
Some("wallet connect: Connection refused (os error 111)".into()),
None
),
None,
"a connect refusal while coming up is not a row error"
);
assert_eq!(
probe_error(
false,
Some("wallet connect: Connection refused (os error 111)".into()),
Some("bad passphrase".into())
),
Some("bad passphrase".into()),
"a connect refusal must not replace a real error"
);
assert_eq!(
probe_error(false, Some("No wallet file".into()), None),
Some("No wallet file".into()),
"an RPC answer is still stored"
);
assert_eq!(
probe_error(true, Some("ignored".into()), Some("old".into())),
None
);
}
/// The bug this card exists for: `monero-wallet-rpc` keeps a wallet open
/// only for the life of its process, so a restarted child answered every
/// read with `-13 No wallet file` while the file sat on disk. The second