wallet: a connect refusal while coming up is not a status error
This commit is contained in:
parent
081bdfac3e
commit
4136f36dd4
2 changed files with 85 additions and 10 deletions
71
src/node.rs
71
src/node.rs
|
|
@ -1014,7 +1014,8 @@ impl Node {
|
||||||
self.child_height.store(height, Ordering::Relaxed);
|
self.child_height.store(height, Ordering::Relaxed);
|
||||||
self.child_target.store(target_height, Ordering::Relaxed);
|
self.child_target.store(target_height, Ordering::Relaxed);
|
||||||
if let Ok(mut slot) = self.child_error.lock() {
|
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()
|
self.wallet_child_status()
|
||||||
}
|
}
|
||||||
|
|
@ -2316,6 +2317,32 @@ pub fn ingest_chat_frame(
|
||||||
Ok(line.to_vec())
|
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(
|
fn spawn_rend(
|
||||||
node: Arc<Node>,
|
node: Arc<Node>,
|
||||||
rend: impl futures::Stream<Item = tor_hsservice::RendRequest> + Send + 'static,
|
rend: impl futures::Stream<Item = tor_hsservice::RendRequest> + Send + 'static,
|
||||||
|
|
@ -4137,6 +4164,48 @@ pub(crate) mod tests {
|
||||||
.unwrap_or_default()
|
.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
|
/// 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
|
/// 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
|
/// read with `-13 No wallet file` while the file sat on disk. The second
|
||||||
|
|
|
||||||
|
|
@ -19,18 +19,24 @@ impl std::fmt::Display for Error {
|
||||||
|
|
||||||
impl std::error::Error for Error {}
|
impl std::error::Error for Error {}
|
||||||
|
|
||||||
impl Error {
|
/// Is this failure "the wallet RPC is not answering yet"? That is the one class
|
||||||
/// Is this failure "the wallet RPC is not answering yet"? That is the one
|
/// a retry can fix — a freshly spawned `monero-wallet-rpc` binds its port a
|
||||||
/// class a retry can fix — a freshly spawned `monero-wallet-rpc` binds its
|
/// moment after `spawn` returns. Everything else (a refused passphrase, a
|
||||||
/// port a moment after `spawn` returns. Everything else (a refused
|
/// protocol error) is the RPC's own answer and retrying it would only repeat it.
|
||||||
/// 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.
|
/// Deliberately *not* the timeout: a hung child is not a start in progress.
|
||||||
pub fn is_unreachable(&self) -> bool {
|
///
|
||||||
let msg = self.0.as_str();
|
/// 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:")
|
msg.starts_with("wallet connect:") || msg.starts_with("wallet write:")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Error {
|
||||||
|
/// [`error_is_unreachable`], on this error's own message.
|
||||||
|
pub fn is_unreachable(&self) -> bool {
|
||||||
|
error_is_unreachable(self.0.as_str())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Which Monero network an on-device daemon follows.
|
/// Which Monero network an on-device daemon follows.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue