wallet: typed chain-daemon client for the Cuprate parity gaps
The chain probe was a hand-rolled brace-scanner in `src/node.rs`. Cuprate
breaks three of its assumptions, all measured in Spike A
(`docs/cuprate-launch-spike.md` §Parity gaps, evidence in that spike's
`rpc-evidence/`):
1. **A height above the tip is a bare HTTP 500 with an empty body.** monerod
answers a JSON-RPC error object instead (`TOO_BIG_HEIGHT`, code -2). The
client now parses the HTTP status once, de-chunks `Transfer-Encoding:
chunked` bodies (axum/hyper; the old brace-scan is not a parse once a blob
spans more than one chunk), and maps both spellings of the height failure to
one typed `WalletError::DaemonHeightOutOfRange`. `get_height` and `get_block`
are height-addressed: their 5xx is the height error. `get_info` is not: its
5xx is `WalletError::DaemonHttpStatus`.
2. **`get_info` metrics are not measurements.** Cuprate reports zero peers while
it downloads blocks, its restricted server answers a placeholder
`database_size` (exactly 5 GiB) and an empty `version`, and `free_space` is
`u64::MAX` on both servers. `DaemonInfo` carries height and target only, so
there is no field for a placeholder to reach the UI. The wallet screen's sync
line is now built from block-height movement between two probes: "connected
to P2P" needs the height to have moved, "no new blocks" is what a stalled
daemon gets, and Cuprate's at-rest `synchronized = true` with
`target_height = 0` reads as unknown instead of `1160/0`.
3. **`get_height` is a URI endpoint**: `{"method":"get_height"}` over
`/json_rpc` is rejected with 422, so the client uses `GET /get_height`, which
both daemons answer. The wallet-child routing rule is pinned too: it dials
the daemon's *unrestricted* listener (monerod's `--rpc-bind-port`, and
whatever port an in-process Cuprate binds for `[rpc.unrestricted]`), never the
restricted one — a restricted listener answers, so a mix-up shows up as a
wrong number rather than as an error.
Scope deviations, stated plainly:
- the card names `src/wallet.rs` + the TUI bindings. The probe itself lived in
`src/node.rs`; it now delegates (net -100 lines there), and the routing
constant/test live in `src/wallet_child.rs`. Tests are in `tests/wallet.rs`,
`tests/tui_spec.rs` and `src/wallet_child.rs`'s test module.
- `daemon_get_block()` is **not called by anything yet**: it is the entry point
the wallet's own block scan (Phase 2) needs, and the out-of-range answer it has
to survive is item 1, so the mapping lives with the client.
- the card's item 3 gives the unrestricted port as 18089 and the restricted one
as 28089. In monerod's numbering 18089 *is* the restricted port; the app's
local source already dials the unrestricted 18081. The rule is what is pinned,
not those numbers.
- `docs/cuprate-launch-spike.md` merged to `main` after this branch's base
commit, so it is not in this tree and its Recommendation bullets are not
updated here.
- based on `feat/wallet-create-import` (the wallet line, unmerged): the daemon
client has no home on `main`. Retarget to `main` when that line lands.
Proof: `cargo test --locked` 306 passed / 0 failed, `cargo clippy --locked
--all-targets -- -D warnings` clean, `rustfmt --edition 2024 --check` adds no
hunk to any file (the inherited hunks in `src/node.rs`/`src/tui.rs`/
`tests/tui_spec.rs` are unchanged in count or region).
This commit is contained in:
parent
750ea92663
commit
e6b5024ad3
7 changed files with 850 additions and 1334 deletions
90
src/tui.rs
90
src/tui.rs
|
|
@ -1132,6 +1132,10 @@ struct App {
|
|||
who_open: bool,
|
||||
chat_scroll: u16,
|
||||
job_rx: Option<mpsc::Receiver<String>>,
|
||||
/// The height the wallet screen saw last time it probed the daemon, so
|
||||
/// connectivity can be read from movement instead of from `get_info`'s peer
|
||||
/// counts (Cuprate reports zero peers while it is downloading blocks).
|
||||
chain_last_height: std::cell::Cell<Option<u64>>,
|
||||
}
|
||||
|
||||
enum Screen {
|
||||
|
|
@ -1517,13 +1521,72 @@ pub fn wallet_view(
|
|||
}
|
||||
}
|
||||
|
||||
/// The sync line: what the daemon's own numbers say, and nothing else.
|
||||
///
|
||||
/// Connectivity is inferred from **block-height movement** between two probes.
|
||||
/// It is never inferred from `get_info` peer counts (Cuprate answers
|
||||
/// `outgoing_connections_count = 0` while it is downloading blocks) and never
|
||||
/// from `database_size`/`free_space`/`version` (its restricted server answers a
|
||||
/// 5 GiB placeholder, `u64::MAX` and an empty string).
|
||||
///
|
||||
/// `previous_height` is the height of the previous probe on this screen, or
|
||||
/// `None` when there is no earlier sample to compare with.
|
||||
pub fn sync_line(sync: &DaemonSync, previous_height: Option<u64>) -> String {
|
||||
if !sync.reachable {
|
||||
return format!(
|
||||
"sync: unknown — {}",
|
||||
sync.note.as_deref().unwrap_or("no daemon")
|
||||
);
|
||||
}
|
||||
if sync.target_height == 0 {
|
||||
// No target is not "caught up": Cuprate says `synchronized = true` with
|
||||
// `target_height = 0` while it has no peers to sync from. Showing
|
||||
// `1160/0` would dress that up as progress.
|
||||
return format!(
|
||||
"sync: unknown — daemon reports no chain target (height {})",
|
||||
sync.height
|
||||
);
|
||||
}
|
||||
if sync.height >= sync.target_height {
|
||||
return format!("sync: synced — height {}", sync.height);
|
||||
}
|
||||
match previous_height {
|
||||
Some(previous) if previous < sync.height => format!(
|
||||
"sync: connected to P2P — syncing {}/{}",
|
||||
sync.height, sync.target_height
|
||||
),
|
||||
Some(_) => format!(
|
||||
"sync: no new blocks — {}/{} (daemon answering, no progress)",
|
||||
sync.height, sync.target_height
|
||||
),
|
||||
None => format!("sync: syncing — {}/{}", sync.height, sync.target_height),
|
||||
}
|
||||
}
|
||||
|
||||
/// Pure builder for the chain block: every honest-status rule lives here.
|
||||
///
|
||||
/// The no-history form: callers that have no earlier probe to compare with (the
|
||||
/// frame tests, the first draw) get the same lines they always did.
|
||||
pub fn chain_view(
|
||||
source: &ChainSource,
|
||||
child: WalletChildState,
|
||||
sync: &DaemonSync,
|
||||
free_gb: Option<u64>,
|
||||
readiness: WalletReadiness,
|
||||
) -> ChainView {
|
||||
chain_view_with_progress(source, child, sync, free_gb, readiness, None)
|
||||
}
|
||||
|
||||
/// [`chain_view`] with the previous probe's height, which is what the live
|
||||
/// screen passes: it is the only input that can tell "syncing" apart from
|
||||
/// "connected but stalled".
|
||||
pub fn chain_view_with_progress(
|
||||
source: &ChainSource,
|
||||
child: WalletChildState,
|
||||
sync: &DaemonSync,
|
||||
free_gb: Option<u64>,
|
||||
readiness: WalletReadiness,
|
||||
previous_height: Option<u64>,
|
||||
) -> ChainView {
|
||||
let source_line = match source {
|
||||
ChainSource::None => "chain: receive-only — no daemon, no chain traffic".to_string(),
|
||||
|
|
@ -1543,18 +1606,7 @@ pub fn chain_view(
|
|||
WalletChildState::Running => "daemon: running (child owned by this app)",
|
||||
}
|
||||
.to_string();
|
||||
let sync_line = if sync.reachable {
|
||||
if sync.synced() {
|
||||
format!("sync: synced — height {}", sync.height)
|
||||
} else {
|
||||
format!("sync: syncing — {}/{}", sync.height, sync.target_height)
|
||||
}
|
||||
} else {
|
||||
format!(
|
||||
"sync: unknown — {}",
|
||||
sync.note.as_deref().unwrap_or("no daemon")
|
||||
)
|
||||
};
|
||||
let sync_text = sync_line(sync, previous_height);
|
||||
let storage_line = match (source, free_gb) {
|
||||
(ChainSource::Local { .. }, Some(gb)) => format!(
|
||||
"storage: {gb} GB free here — pruned mainnet wants ~50-60 GB, a full node ~200 GB"
|
||||
|
|
@ -1568,7 +1620,7 @@ pub fn chain_view(
|
|||
ChainView {
|
||||
source_line: truncate_chars(&source_line, WALLET_LINE_MAX),
|
||||
child_line: truncate_chars(&child_line, WALLET_LINE_MAX),
|
||||
sync_line: truncate_chars(&sync_line, WALLET_LINE_MAX),
|
||||
sync_line: truncate_chars(&sync_text, WALLET_LINE_MAX),
|
||||
storage_line: truncate_chars(&storage_line, WALLET_LINE_MAX),
|
||||
status_line: readiness.line().to_string(),
|
||||
ready: readiness.ready(),
|
||||
|
|
@ -1637,6 +1689,7 @@ impl App {
|
|||
who_open: false,
|
||||
chat_scroll: 0,
|
||||
job_rx: None,
|
||||
chain_last_height: std::cell::Cell::new(None),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -2199,12 +2252,21 @@ impl App {
|
|||
let sync = self
|
||||
.rt
|
||||
.block_on(self.node.wallet_chain_sync(CHAIN_SYNC_BUDGET));
|
||||
let chain = chain_view(
|
||||
// The only thing that can distinguish "connected and syncing" from
|
||||
// "answering but stalled" is whether the height moved since last draw.
|
||||
let previous_height = self.chain_last_height.get();
|
||||
self.chain_last_height.set(if sync.reachable {
|
||||
Some(sync.height)
|
||||
} else {
|
||||
None
|
||||
});
|
||||
let chain = chain_view_with_progress(
|
||||
&source,
|
||||
child,
|
||||
&sync,
|
||||
self.node.wallet_chain_free_gb(),
|
||||
readiness,
|
||||
previous_height,
|
||||
);
|
||||
let receive_addr = self
|
||||
.rt
|
||||
|
|
|
|||
Loading…
Reference in a new issue