tui: F7 can save and start an app-owned chain source #170

Merged
sirius merged 4 commits from onionwire/t_fcd38efc-onionwire-tui-f7-can-save-and-start-an-a into main 2026-09-28 05:09:45 +00:00
Owner

The defect, reproduced on a fresh install

WalletSetupConfigState::save() ran the wallet-config write first and returned early on its error, so F7 with chain = in-process Cuprate, network = testnet and an empty url row wrote nothing: not saved · wallet RPC endpoint required. Typing a URL then demanded a login, and the only way to save was to invent an endpoint (http://127.0.0.1:28083/json_rpc plus u:p) that the app-owned child never dials.

That refusal belongs to Wallet::from_config and it is about an externally run monero-wallet-rpc. An app-owned chain source (local monerod, in-process Cuprate) spawns its own child, which generates its own creds and picks its own port, and Node::start_wallet_child_with replaces the stored client after the spawn — so on that path the url/login rows describe an endpoint the app never dials.

Which save outcomes are allowed now

  • Both halves written — saved · not dialled yet — ctrl-s starts it, ctrl-t tests the endpoint (unchanged).
  • One half refused — not saved · wallet config: WHY · chain source: WHY, one line shape either way round, and the half that wrote says so. Both halves are attempted on every save, so a wallet-RPC refusal can no longer silently drop a chain source the user just picked.
  • App-owned source with an empty url (ChainSource::Local, ChainSource::InProcessCuprate) — the endpoint question is not asked; the chain source is written and the save reports saved. Nothing is written to the wallet config on that path, and the stored one is left as it was.
  • A typed endpoint with no login — still refused. Wallet::from_config / Node::wallet_save_config are untouched: a stored rpc_url without credentials is a broken config and the SDK/UniFFI path depends on that check. What changed is what the screen demands, not what the validator accepts.
  • A refused chain-source row (empty datadir, unparsable daemon) — writes nothing for the chain, and now reports the wallet half's outcome on the same line instead of dropping it.

The chain row in a build without cuprate-daemon

WalletSetupConfigState::chain_display() mirrors prune_display() / network_display(): for the in-process pick it appends crate::cuprate::NO_FEATURE_MSG — this build has no in-process chain daemon — rebuild with --features cuprate-daemon — clamped to the frame width by the existing fit_cells path. The pick stays in the picker: builds with the feature exist, and a stored in-process source must still be readable.

Start-failure contract chosen: all or nothing

A start that fails part way stops whatever that call spawned — the in-process daemon, a spawned monerod, the SOCKS child, the wallet RPC — before the error is handed back. Why that is right for an in-process daemon too:

  • The caller receives the error, not the client. Node::start_wallet_child_with returns Err and drops the WalletChild, so a daemon left running has no owner and no handle; nothing in the app could stop or reuse it.
  • An owner that did keep the child (a unit test, or a future caller) would then hold 18081 and get wallet child already running from the retry, so keeping it buys nothing and can wedge the next ctrl-s.
  • What a retry actually reuses is the chain datadir on disk — CuprateNode's own Drop also shuts the daemon down cleanly, so nothing is silently leaked.
  • The same contract is already asserted one level up by node::tests::a_missing_binary_fails_the_start_and_leaves_no_child, which is deliberate and was left untouched.

src/wallet_child.rs already behaved that way, so this change states the contract where the stop happens and makes both tests express it. The red test was red because its fake monero-wallet-rpc never binds the port its own readiness gate probes: start() returned that error, the test discarded it with let _ =, and then asserted the daemon had survived a failed start. It now holds the published port the way the module's other start tests do (test_support::PublishedPortHold) and expects the start to succeed; every assertion it had is kept. The failure path gets its own test instead (a_start_that_fails_after_the_daemon_came_up_leaves_nothing_running).

Scope and siblings

  • Touched: src/tui.rs, src/wallet_child.rs, docs/TUI.md, docs/WALLET.md (tests live in src/). No forbidden file was modified.
  • Sibling card t_35a220dd owns monero-wallet-rpc path resolution (a binary resolved beside the app rather than a bare name on PATH) plus src/node.rs. Nothing here touches that; the end-to-end run below relied on monero-wallet-rpc being on PATH on this host. That card also edits docs/WALLET.md, so a small conflict there is expected when it lands.

Evidence

$ cargo check --locked --target x86_64-unknown-linux-gnu
CHECK=0
$ cargo clippy --locked --target x86_64-unknown-linux-gnu --all-targets -- -D warnings
CLIPPYNOFEAT=0
$ cargo clippy --locked --target x86_64-unknown-linux-gnu --all-targets --features cuprate-daemon -- -D warnings
CLIPPYFEAT=0

$ cargo test --locked --target x86_64-unknown-linux-gnu --lib -- --test-threads=8
test result: ok. 138 passed; 0 failed; 0 ignored

$ cargo test --locked --target x86_64-unknown-linux-gnu --features cuprate-daemon --lib -- --test-threads=1
test wallet_child::tests::in_process_source_launches_a_daemon_and_stop_shuts_it_down ... ok
test wallet_child::tests::a_start_that_fails_after_the_daemon_came_up_leaves_nothing_running ... ok
test node::tests::a_missing_binary_fails_the_start_and_leaves_no_child ... ok
test tui::wallet_setup_config_tests::an_app_owned_source_saves_without_a_typed_wallet_rpc ... ok
test tui::wallet_setup_config_tests::a_wallet_rpc_refusal_does_not_cancel_the_chain_source_write ... ok
test tui::wallet_setup_config_tests::a_typed_endpoint_without_a_login_is_still_refused ... ok
test tui::wallet_setup_config_tests::a_build_with_the_daemon_does_not_disown_the_in_process_choice ... ok
test result: ok. 144 passed; 0 failed; 0 ignored

# the without-the-feature run covers the other new one:
test tui::wallet_setup_config_tests::a_build_without_the_daemon_says_so_on_the_chain_row ... ok

End to end, real TUI, fresh ONIONWIRE_HOME, --features cuprate-daemon

F7 → chain = in-process (3 spaces), network = testnet, url and login left empty, Ctrl-S:

│  url        (none)
│  login      (none) · type user:pass
│> chain      in-process node · cuprate in this app  (space changes)
│  network    testnet  (space changes)
│NODE ──────
│node  child  connecting · in-process testnet · sync 1/0 · No wallet file
│last      saved · not dialled yet — ctrl-s starts it, ctrl-t tests the endpoint

$ ss -ltn | grep 18081
LISTEN 0      128        127.0.0.1:18081      0.0.0.0:*

Ctrl-X → node child off · in-process testnet, and ss -ltn | grep 18081 returns nothing.

Not exercised

mainnet (the in-process daemon is testnet-only in this tree), a real .onion chain daemon, Android, a funded wallet, a --release build, and any wallet file actually created in the child (the run reached No wallet file, which is the expected state on a home with no wallet yet).

## The defect, reproduced on a fresh install `WalletSetupConfigState::save()` ran the wallet-config write first and returned early on its error, so F7 with `chain` = in-process Cuprate, `network` = testnet and an empty `url` row wrote **nothing**: `not saved · wallet RPC endpoint required`. Typing a URL then demanded a login, and the only way to save was to invent an endpoint (`http://127.0.0.1:28083/json_rpc` plus `u:p`) that the app-owned child never dials. That refusal belongs to `Wallet::from_config` and it is about an **externally run** `monero-wallet-rpc`. An app-owned chain source (local `monerod`, in-process Cuprate) spawns its own child, which generates its own creds and picks its own port, and `Node::start_wallet_child_with` replaces the stored client after the spawn — so on that path the `url`/`login` rows describe an endpoint the app never dials. ## Which save outcomes are allowed now - **Both halves written** — `saved · not dialled yet — ctrl-s starts it, ctrl-t tests the endpoint` (unchanged). - **One half refused** — `not saved · wallet config: WHY · chain source: WHY`, one line shape either way round, and the half that wrote says so. Both halves are attempted on every save, so a wallet-RPC refusal can no longer silently drop a chain source the user just picked. - **App-owned source with an empty `url`** (`ChainSource::Local`, `ChainSource::InProcessCuprate`) — the endpoint question is not asked; the chain source is written and the save reports `saved`. Nothing is written to the wallet config on that path, and the stored one is left as it was. - **A typed endpoint with no login** — still refused. `Wallet::from_config` / `Node::wallet_save_config` are untouched: a stored `rpc_url` without credentials is a broken config and the SDK/UniFFI path depends on that check. What changed is what the *screen* demands, not what the validator accepts. - **A refused chain-source row** (empty datadir, unparsable `daemon`) — writes nothing for the chain, and now reports the wallet half's outcome on the same line instead of dropping it. ## The chain row in a build without `cuprate-daemon` `WalletSetupConfigState::chain_display()` mirrors `prune_display()` / `network_display()`: for the in-process pick it appends `crate::cuprate::NO_FEATURE_MSG` — `this build has no in-process chain daemon — rebuild with --features cuprate-daemon` — clamped to the frame width by the existing `fit_cells` path. The pick stays in the picker: builds with the feature exist, and a stored in-process source must still be readable. ## Start-failure contract chosen: all or nothing A start that fails part way stops whatever that call spawned — the in-process daemon, a spawned `monerod`, the SOCKS child, the wallet RPC — before the error is handed back. Why that is right for an in-process daemon too: - The caller receives the **error**, not the client. `Node::start_wallet_child_with` returns `Err` and drops the `WalletChild`, so a daemon left running has no owner and no handle; nothing in the app could stop or reuse it. - An owner that *did* keep the child (a unit test, or a future caller) would then hold `18081` and get `wallet child already running` from the retry, so keeping it buys nothing and can wedge the next `ctrl-s`. - What a retry actually reuses is the chain **datadir** on disk — `CuprateNode`'s own `Drop` also shuts the daemon down cleanly, so nothing is silently leaked. - The same contract is already asserted one level up by `node::tests::a_missing_binary_fails_the_start_and_leaves_no_child`, which is deliberate and was left untouched. `src/wallet_child.rs` already behaved that way, so this change states the contract where the stop happens and makes both tests express it. The red test was red because its fake `monero-wallet-rpc` never binds the port its own readiness gate probes: `start()` returned that error, the test discarded it with `let _ =`, and then asserted the daemon had survived a failed start. It now holds the published port the way the module's other start tests do (`test_support::PublishedPortHold`) and expects the start to succeed; every assertion it had is kept. The failure path gets its own test instead (`a_start_that_fails_after_the_daemon_came_up_leaves_nothing_running`). ## Scope and siblings - Touched: `src/tui.rs`, `src/wallet_child.rs`, `docs/TUI.md`, `docs/WALLET.md` (tests live in `src/`). No forbidden file was modified. - Sibling card `t_35a220dd` owns `monero-wallet-rpc` **path resolution** (a binary resolved beside the app rather than a bare name on `PATH`) plus `src/node.rs`. Nothing here touches that; the end-to-end run below relied on `monero-wallet-rpc` being on `PATH` on this host. That card also edits `docs/WALLET.md`, so a small conflict there is expected when it lands. ## Evidence ``` $ cargo check --locked --target x86_64-unknown-linux-gnu CHECK=0 $ cargo clippy --locked --target x86_64-unknown-linux-gnu --all-targets -- -D warnings CLIPPYNOFEAT=0 $ cargo clippy --locked --target x86_64-unknown-linux-gnu --all-targets --features cuprate-daemon -- -D warnings CLIPPYFEAT=0 $ cargo test --locked --target x86_64-unknown-linux-gnu --lib -- --test-threads=8 test result: ok. 138 passed; 0 failed; 0 ignored $ cargo test --locked --target x86_64-unknown-linux-gnu --features cuprate-daemon --lib -- --test-threads=1 test wallet_child::tests::in_process_source_launches_a_daemon_and_stop_shuts_it_down ... ok test wallet_child::tests::a_start_that_fails_after_the_daemon_came_up_leaves_nothing_running ... ok test node::tests::a_missing_binary_fails_the_start_and_leaves_no_child ... ok test tui::wallet_setup_config_tests::an_app_owned_source_saves_without_a_typed_wallet_rpc ... ok test tui::wallet_setup_config_tests::a_wallet_rpc_refusal_does_not_cancel_the_chain_source_write ... ok test tui::wallet_setup_config_tests::a_typed_endpoint_without_a_login_is_still_refused ... ok test tui::wallet_setup_config_tests::a_build_with_the_daemon_does_not_disown_the_in_process_choice ... ok test result: ok. 144 passed; 0 failed; 0 ignored # the without-the-feature run covers the other new one: test tui::wallet_setup_config_tests::a_build_without_the_daemon_says_so_on_the_chain_row ... ok ``` ### End to end, real TUI, fresh `ONIONWIRE_HOME`, `--features cuprate-daemon` F7 → `chain` = in-process (3 spaces), `network` = testnet, `url` and `login` left empty, `Ctrl-S`: ``` │ url (none) │ login (none) · type user:pass │> chain in-process node · cuprate in this app (space changes) │ network testnet (space changes) │NODE ────── │node child connecting · in-process testnet · sync 1/0 · No wallet file │last saved · not dialled yet — ctrl-s starts it, ctrl-t tests the endpoint $ ss -ltn | grep 18081 LISTEN 0 128 127.0.0.1:18081 0.0.0.0:* ``` `Ctrl-X` → `node child off · in-process testnet`, and `ss -ltn | grep 18081` returns nothing. ## Not exercised mainnet (the in-process daemon is testnet-only in this tree), a real `.onion` chain daemon, Android, a funded wallet, a `--release` build, and any wallet file actually created in the child (the run reached `No wallet file`, which is the expected state on a home with no wallet yet).
A save on F7 ran the wallet-config write first and returned early on its
error, so an empty 'url' row failed the whole save: 'wallet RPC endpoint
required'. That refusal belongs to Wallet::from_config and it is about an
externally run monero-wallet-rpc; an app-owned chain source (local monerod,
in-process Cuprate) spawns its own child with generated creds and a port it
picked, and Node::start_wallet_child_with replaces the stored client after
the spawn, so the url/login rows describe no endpoint the app dials.

- an empty endpoint on an app-owned source no longer vetoes the chain-source
  write; the validator itself is untouched, and a *typed* endpoint with no
  login is still refused
- both halves of a save are attempted and reported on one line shape, so a
  wallet-config refusal cannot silently drop a chain source the user picked
cuprate::available() was never consulted in the TUI, so the 'chain' row
offered 'in-process node · cuprate in this app' in a build whose only possible
answer is cuprate::NO_FEATURE_MSG. The row now carries that wording where the
choice is made, the same way prune_display()/network_display() carry theirs.
The choice stays in the picker: builds with the feature exist, and a stored
in-process source must still be readable.
Settle the contract the red feature-gated test was fighting, and make the code
and both tests express it: a start that fails after the chain daemon came up is
all or nothing, the same contract
node::tests::a_missing_binary_fails_the_start_and_leaves_no_child asserts one
level up. A daemon left running behind an error has no owner (the caller gets
the error back, not the client), no handle to stop it, and holds 18081 against
the next start; what a retry reuses is the chain datadir on disk, never a
process that outlived its owner. start_with_creds already behaved that way, so
this states the contract where the stop happens rather than changing it.

in_process_source_launches_a_daemon_and_stop_shuts_it_down was red because its
fake monero-wallet-rpc never binds the port its own readiness gate probes:
start() returns that error, the test discarded it with `let _ =`, and it then
asserted the daemon had survived a failed start. It now holds the published
port the way the module's other start tests do
(test_support::PublishedPortHold) and expects the start to succeed, with every
assertion it had kept. The failure path gets its own test instead, which pins
the tear-down: neither child running, the daemon's port closed, the chain
datadir kept.
docs: the F7 save gate and the app-owned chain source
All checks were successful
ci / test (pull_request) Successful in 6m49s
ci / sdk (pull_request) Successful in 1m25s
1e3eceabcb
TUI.md: the `last` line's shape when one half of a save is refused, why an
app-owned source saves with an empty `url` while a typed endpoint with no login
is still refused, and the wording the `chain` row carries in a build without
`cuprate-daemon`.

WALLET.md: the same gate from the node's side, and the start contract — a start
that fails part way stops what it spawned and leaves the chain datadir as the
thing a retry reuses.
sirius merged commit c550a197ac into main 2026-09-28 05:09:45 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!170
No description provided.