wallet: show the chain daemon's sync height and target on the child status
The user watching an in-process Cuprate node on Android saw only a phase word (connecting, with 'wallet connect: Connection refused (os error 111)') and asked to see height vs tip. - WalletChildStatus gains height / target_height, and line() appends 'sync h/t' when a probe read either number. No percentage is invented when the daemon reports no target (h/0 is honest), and an off/exited child reports 0/0. - Node::wallet_child_refresh fills them: one wallet-RPC get_info now answers both the readiness gate and the numbers (Wallet::chain_info, with chain_ready built on the same parse), and when the wallet RPC is down while the chain source is local/in-process, the loopback daemon is asked directly (ChildConfig::daemon_probe_addr). A refused daemon stays 0/0 — unknown, not caught up. Only refresh dials; the draw path reads two atomics. - UniFFI WalletChildStatus carries the same two u64 fields so Android can show them; SDK test covers the round trip. Tests: cargo test --locked --target x86_64-unknown-linux-gnu (all green), clippy -D warnings clean; crates/onionwire-sdk cargo test --locked + clippy clean (separate workspace).
This commit is contained in:
parent
bc74b4f4af
commit
0a91744924
5 changed files with 468 additions and 17 deletions
|
|
@ -727,6 +727,21 @@ impl ChildConfig {
|
|||
pub fn source_label(&self) -> String {
|
||||
self.source.label()
|
||||
}
|
||||
|
||||
/// Where a status refresh may ask the chain daemon itself for
|
||||
/// height/target, when the wallet RPC is not answering. Only a daemon this
|
||||
/// box owns: a `monerod`/Cuprate the child spawned binds loopback, and
|
||||
/// asking it is a plain local socket. A remote daemon is the wallet child's
|
||||
/// to dial (over SOCKS, if it is an onion) — a status refresh does not open
|
||||
/// a second path to it.
|
||||
pub fn daemon_probe_addr(&self) -> Option<String> {
|
||||
match self.source {
|
||||
ChainSource::Local { .. } | ChainSource::InProcessCuprate { .. } => {
|
||||
Some(format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}"))
|
||||
}
|
||||
ChainSource::None | ChainSource::Remote { .. } => None,
|
||||
}
|
||||
}
|
||||
/// Reject a configuration that could only fail later (empty binary path,
|
||||
/// empty host, port 0) *before* it is persisted or spawned.
|
||||
pub fn validate(&self) -> Result<()> {
|
||||
|
|
@ -888,6 +903,12 @@ pub struct WalletChildStatus {
|
|||
/// The chain-source label: `receive-only` / `local node` /
|
||||
/// `remote onion daemon` / `remote daemon`.
|
||||
pub chain_source: String,
|
||||
/// Blocks the chain daemon currently has. `0` means unknown (not started, or
|
||||
/// the last probe failed). This is daemon height, never wallet-rpc scan height.
|
||||
pub height: u64,
|
||||
/// Blocks the daemon is syncing towards. `0` means the daemon reported none
|
||||
/// (not the same as caught up — see `wallet::chain_ready`).
|
||||
pub target_height: u64,
|
||||
/// The last failure, display-ready. Never carries the generated login.
|
||||
pub last_error: Option<String>,
|
||||
}
|
||||
|
|
@ -900,6 +921,13 @@ impl WalletChildStatus {
|
|||
return String::new();
|
||||
}
|
||||
let mut line = format!("child {} · {}", self.state.as_str(), self.chain_source);
|
||||
// A probe that read nothing says nothing: the line is unchanged until a
|
||||
// daemon (or the wallet's daemon) actually reported numbers. No
|
||||
// percentage is derived — `target_height == 0` is "the daemon told us
|
||||
// nothing", not "caught up".
|
||||
if self.height > 0 || self.target_height > 0 {
|
||||
line.push_str(&format!(" · sync {}/{}", self.height, self.target_height));
|
||||
}
|
||||
if let Some(err) = &self.last_error {
|
||||
line.push_str(" · ");
|
||||
line.push_str(err);
|
||||
|
|
@ -1965,6 +1993,102 @@ mod tests {
|
|||
assert!(closed, "the daemon's RPC listener outlived stop()");
|
||||
}
|
||||
|
||||
fn probe_status(state: WalletChildState, height: u64, target_height: u64) -> WalletChildStatus {
|
||||
WalletChildStatus {
|
||||
state,
|
||||
running: true,
|
||||
configured: true,
|
||||
chain_source: "in-process node".to_string(),
|
||||
height,
|
||||
target_height,
|
||||
last_error: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// No probe numbers, no `sync` segment: a snapshot that never read a height
|
||||
/// renders exactly the line it rendered before this existed.
|
||||
#[test]
|
||||
fn a_status_line_without_probe_numbers_carries_no_sync_segment() {
|
||||
let line = probe_status(WalletChildState::Connecting, 0, 0).line();
|
||||
assert_eq!(line, "child connecting · in-process node");
|
||||
assert!(!line.contains("sync"), "{line}");
|
||||
}
|
||||
|
||||
/// The numbers the user asked for: the daemon's own height over the tip it
|
||||
/// is syncing towards, on the same one-liner the wallet screen already shows.
|
||||
#[test]
|
||||
fn a_status_line_shows_the_daemons_height_and_target() {
|
||||
let line = probe_status(WalletChildState::Connecting, 1160, 3_090_939).line();
|
||||
assert!(line.contains("sync 1160/3090939"), "{line}");
|
||||
assert!(!line.contains('%'), "{line}");
|
||||
}
|
||||
|
||||
/// A daemon that reports no target is not a caught-up chain: the height is
|
||||
/// still shown — over `0` — and no percentage is invented for it.
|
||||
#[test]
|
||||
fn a_missing_target_still_shows_the_height_and_no_percent() {
|
||||
let line = probe_status(WalletChildState::Syncing, 4549, 0).line();
|
||||
assert!(line.contains("sync 4549/0"), "{line}");
|
||||
assert!(!line.contains('%'), "{line}");
|
||||
}
|
||||
|
||||
/// The failure text stays last: a probe number never displaces the error a
|
||||
/// reader is looking for.
|
||||
#[test]
|
||||
fn a_status_line_keeps_the_error_after_the_sync_segment() {
|
||||
let mut status = probe_status(WalletChildState::Connecting, 1160, 3_090_939);
|
||||
status.last_error = Some("wallet connect: Connection refused (os error 111)".into());
|
||||
let line = status.line();
|
||||
assert!(line.contains("sync 1160/3090939"), "{line}");
|
||||
assert!(
|
||||
line.ends_with("· wallet connect: Connection refused (os error 111)"),
|
||||
"{line}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Only a daemon this box owns is asked directly. A remote daemon is the
|
||||
/// wallet child's to dial — a status refresh must not open a second path to
|
||||
/// it, and receive-only has nothing to ask at all.
|
||||
#[test]
|
||||
fn only_a_loopback_source_gets_a_daemon_probe_address() {
|
||||
let loopback = format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}");
|
||||
for source in [
|
||||
ChainSource::Local {
|
||||
monerod_bin: PathBuf::from("monerod"),
|
||||
datadir: PathBuf::from("/chain"),
|
||||
prune: false,
|
||||
},
|
||||
ChainSource::InProcessCuprate {
|
||||
datadir: PathBuf::from("/chain"),
|
||||
network: ChainNetwork::Mainnet,
|
||||
prune: true,
|
||||
},
|
||||
] {
|
||||
let cfg = ChildConfig {
|
||||
source: source.clone(),
|
||||
..ChildConfig::default()
|
||||
};
|
||||
assert_eq!(cfg.daemon_probe_addr().as_deref(), Some(loopback.as_str()));
|
||||
}
|
||||
for source in [
|
||||
ChainSource::None,
|
||||
ChainSource::Remote {
|
||||
host: "peer.onion".to_string(),
|
||||
port: 18081,
|
||||
},
|
||||
ChainSource::Remote {
|
||||
host: "203.0.113.7".to_string(),
|
||||
port: 18081,
|
||||
},
|
||||
] {
|
||||
let cfg = ChildConfig {
|
||||
source,
|
||||
..ChildConfig::default()
|
||||
};
|
||||
assert_eq!(cfg.daemon_probe_addr(), None);
|
||||
}
|
||||
}
|
||||
|
||||
/// Poll a loopback address until it accepts, inside a budget.
|
||||
#[cfg(feature = "cuprate-daemon")]
|
||||
fn waits_for_tcp(addr: &str, budget: Duration) -> bool {
|
||||
|
|
|
|||
Loading…
Reference in a new issue