From 4ad234735884c6a295a4cc7658474aab88832e12 Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 23 Sep 2026 20:33:49 -0400 Subject: [PATCH] wallet: a connect refusal while coming up is not a status error --- src/node.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/wallet.rs | 24 ++++++++++------- 2 files changed, 85 insertions(+), 10 deletions(-) diff --git a/src/node.rs b/src/node.rs index 8213dce..a886545 100644 --- a/src/node.rs +++ b/src/node.rs @@ -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, + previous: Option, +) -> Option { + 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, rend: impl futures::Stream + 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 diff --git a/src/wallet.rs b/src/wallet.rs index 2c66f45..e40fca0 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -19,17 +19,23 @@ impl std::fmt::Display for Error { impl std::error::Error for Error {} +/// Is this failure "the wallet RPC is not answering yet"? That is the one class +/// a retry can fix — a freshly spawned `monero-wallet-rpc` binds its port a +/// moment after `spawn` returns. Everything else (a refused passphrase, a +/// protocol error) is the RPC's own answer and retrying it would only repeat it. +/// +/// Deliberately *not* the timeout: a hung child is not a start in progress. +/// +/// The free function is the rule itself: a status row keeps an already +/// formatted `String`, and it must apply exactly the same test to it. +pub fn error_is_unreachable(msg: &str) -> bool { + msg.starts_with("wallet connect:") || msg.starts_with("wallet write:") +} + impl Error { - /// Is this failure "the wallet RPC is not answering yet"? That is the one - /// class a retry can fix — a freshly spawned `monero-wallet-rpc` binds its - /// port a moment after `spawn` returns. Everything else (a refused - /// passphrase, a protocol error) is the RPC's own answer and retrying it - /// would only repeat it. - /// - /// Deliberately *not* the timeout: a hung child is not a start in progress. + /// [`error_is_unreachable`], on this error's own message. pub fn is_unreachable(&self) -> bool { - let msg = self.0.as_str(); - msg.starts_with("wallet connect:") || msg.starts_with("wallet write:") + error_is_unreachable(self.0.as_str()) } }