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 4ad2347358
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

View file

@ -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())
}
}