wallet: wait for listeners before treating connect refusal as an error #155

Merged
sirius merged 5 commits from onionwire/t_c8fe0549-onionwire-wallet-start-waits-for-the-dae into main 2026-09-24 00:44:44 +00:00
Owner

Implements Task 1, 2, 3, 4 and 7 of /home/lancelot/.hermes/plans/2026-09-23_193050-stabilize-cuprate-wallet-startup.md (Rust half + one doc sentence). Task 5/6 (Android Kotlin) are a separate apk-dev card; Task 8's end-to-end verification is the follow-up verification card.

What changed

Start waits for the listeners.

  • monero-wallet-rpc is not spawned until 127.0.0.1:18081 accepts a TCP connection (5s budget, DAEMON_LISTENER_TIMEOUT). Only the sources that bind that port are waited on — ChainSource::Local and ChainSource::InProcessCuprate; a remote or receive-only source has no loopback daemon to dial.
  • The child is not handed back until its own --rpc-bind-port accepts (5s, WALLET_RPC_LISTENER_TIMEOUT), so start_wallet_child_with cannot publish a client whose port is still closed.
  • Both gates reuse one poll loop (WalletChild::poll_loopback) that the SOCKS path already had; socks_listener_ready keeps its existing error text byte-for-byte. The new gate's message names the port and what did not accept (chain daemon RPC on 127.0.0.1:18081 did not accept ... — not continuing startup against a closed port).
  • Nothing else moved: the creds() call is still the only Store mutex in start_children and still runs after the daemon is up, and WalletChildStatus::line() and the SOCKS error string are untouched.
  • open_wallet_blocking's 10s retry is untouched. TCP accept is not "HTTP is serving open_wallet".

A connect refusal while the child is coming up is not a status error.

  • wallet::error_is_unreachable(msg) is now the one rule (the old Error::is_unreachable was inlined and could drift from the row's copy).
  • node::probe_error(connected, probed, previous) stores the probe's error only when it is the RPC's own answer. wallet connect: / wallet write: while the row is not connected leaves the row's previous real error in place instead of flashing the string and clearing it on the next tick.
  • Deliberately still stored: timeouts, -13, No wallet file, a refused passphrase, and the same connect text once the child has been answering (so a child that accepted once and then died still shows), because the filter is keyed on the probe result, not on the string alone.

Scope note: the lib test harness had to learn to present the port

src/node.rs and src/wallet_child.rs's test modules are inside the card's allow-list, and they needed changes — a sh fake cannot bind a port. Without them 13 start-path tests failed at the new gate, which is exactly what the gate should do to a fake.

  • New #[cfg(test)] wallet_child::test_support::PublishedPortHold: watches a fake child's argv log and holds the --rpc-bind-port it publishes, releasing it when the gate's own probe connects (so a dial after the gate still sees the child's real state, never a stand-in). A rewrite of the log is a new publication, so a restart whose argv is identical is held again.
  • Tests whose own mock answers the RPC changed shape: the node publishes the child only after the gate has seen the accept, so the pid is no longer available to the test during that window. They now read the port from <argv.log>.<pid> on disk (wait_for_restarted_rpc_port, pid-shaped names only — a child killed between its shared write and its own leaves a .writing temp that still names the old port) and bind their mock before the gate's probe. a_restart_is_not_given_the_stopped_childs_port's stale-shared-log premise is asserted at the moment it is true, with a fake that lands its own log first and the shared path 2s later.
  • No production behaviour is behind a test-only flag; the gates run in every test that starts a child.

Not done here

  • The Android display/reload fix is a separate card (Task 5/6).
  • No release, no tag, nothing pushed to main.
  • Mainnet Cuprate is still unvalidated, and chain P2P is still clearnet.

Evidence

cargo test --locked --target x86_64-unknown-linux-gnu --lib -- --test-threads=8

test result: ok. 95 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 12.84s

Named tests:

test wallet_child::tests::loopback_listener_ready_accepts_a_live_listener_and_times_out_without_one ... ok
test wallet_child::tests::socks_listener_ready_accepts_a_live_listener_and_times_out_without_one ... ok
test node::tests::an_unreachable_probe_is_not_a_status_error ... ok
test wallet_child::tests::a_status_line_keeps_the_error_after_the_sync_segment ... ok

cargo check --locked --target x86_64-unknown-linux-gnu — exit 0.
cargo clippy --locked --target x86_64-unknown-linux-gnu --all-targets -- -D warnings — clean.
rustfmt --edition 2024 --check on src/wallet.rs (0 diffs) and src/node.rs (3 diffs, all inherited at HEAD: lines 31/647/723).
git diff --stat origin/main..HEAD: docs/WALLET.md, src/node.rs, src/wallet.rs, src/wallet_child.rs — the four allowed files only.

Implements Task 1, 2, 3, 4 and 7 of `/home/lancelot/.hermes/plans/2026-09-23_193050-stabilize-cuprate-wallet-startup.md` (Rust half + one doc sentence). Task 5/6 (Android Kotlin) are a separate `apk-dev` card; Task 8's end-to-end verification is the follow-up verification card. ## What changed **Start waits for the listeners.** - `monero-wallet-rpc` is not spawned until `127.0.0.1:18081` accepts a TCP connection (5s budget, `DAEMON_LISTENER_TIMEOUT`). Only the sources that bind that port are waited on — `ChainSource::Local` and `ChainSource::InProcessCuprate`; a remote or receive-only source has no loopback daemon to dial. - The child is not handed back until its own `--rpc-bind-port` accepts (5s, `WALLET_RPC_LISTENER_TIMEOUT`), so `start_wallet_child_with` cannot publish a client whose port is still closed. - Both gates reuse one poll loop (`WalletChild::poll_loopback`) that the SOCKS path already had; `socks_listener_ready` keeps its existing error text byte-for-byte. The new gate's message names the port and what did not accept (`chain daemon RPC on 127.0.0.1:18081 did not accept ... — not continuing startup against a closed port`). - Nothing else moved: the `creds()` call is still the only `Store` mutex in `start_children` and still runs after the daemon is up, and `WalletChildStatus::line()` and the SOCKS error string are untouched. - `open_wallet_blocking`'s 10s retry is untouched. TCP accept is not "HTTP is serving `open_wallet`". **A connect refusal while the child is coming up is not a status error.** - `wallet::error_is_unreachable(msg)` is now the one rule (the old `Error::is_unreachable` was inlined and could drift from the row's copy). - `node::probe_error(connected, probed, previous)` stores the probe's error only when it is the RPC's own answer. `wallet connect:` / `wallet write:` while the row is not connected leaves the row's previous real error in place instead of flashing the string and clearing it on the next tick. - Deliberately still stored: timeouts, `-13`, `No wallet file`, a refused passphrase, and the same connect text once the child has been answering (so a child that accepted once and then died still shows), because the filter is keyed on the probe result, not on the string alone. ## Scope note: the lib test harness had to learn to present the port `src/node.rs` and `src/wallet_child.rs`'s test modules are inside the card's allow-list, and they needed changes — a `sh` fake cannot bind a port. Without them 13 start-path tests failed at the new gate, which is exactly what the gate should do to a fake. - New `#[cfg(test)] wallet_child::test_support::PublishedPortHold`: watches a fake child's argv log and holds the `--rpc-bind-port` it publishes, releasing it when the gate's own probe connects (so a dial after the gate still sees the child's real state, never a stand-in). A rewrite of the log is a new publication, so a restart whose argv is identical is held again. - Tests whose own mock answers the RPC changed shape: the node publishes the child only after the gate has seen the accept, so the pid is no longer available to the test during that window. They now read the port from `<argv.log>.<pid>` on disk (`wait_for_restarted_rpc_port`, pid-shaped names only — a child killed between its shared write and its own leaves a `.writing` temp that still names the old port) and bind their mock *before* the gate's probe. `a_restart_is_not_given_the_stopped_childs_port`'s stale-shared-log premise is asserted at the moment it is true, with a fake that lands its own log first and the shared path 2s later. - No production behaviour is behind a test-only flag; the gates run in every test that starts a child. ## Not done here - The Android display/reload fix is a separate card (Task 5/6). - No release, no tag, nothing pushed to `main`. - Mainnet Cuprate is still unvalidated, and chain P2P is still clearnet. ## Evidence `cargo test --locked --target x86_64-unknown-linux-gnu --lib -- --test-threads=8` test result: ok. 95 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 12.84s Named tests: test wallet_child::tests::loopback_listener_ready_accepts_a_live_listener_and_times_out_without_one ... ok test wallet_child::tests::socks_listener_ready_accepts_a_live_listener_and_times_out_without_one ... ok test node::tests::an_unreachable_probe_is_not_a_status_error ... ok test wallet_child::tests::a_status_line_keeps_the_error_after_the_sync_segment ... ok `cargo check --locked --target x86_64-unknown-linux-gnu` — exit 0. `cargo clippy --locked --target x86_64-unknown-linux-gnu --all-targets -- -D warnings` — clean. `rustfmt --edition 2024 --check` on `src/wallet.rs` (0 diffs) and `src/node.rs` (3 diffs, all inherited at HEAD: lines 31/647/723). `git diff --stat origin/main..HEAD`: `docs/WALLET.md`, `src/node.rs`, `src/wallet.rs`, `src/wallet_child.rs` — the four allowed files only.
sirius force-pushed onionwire/t_c8fe0549-onionwire-wallet-start-waits-for-the-dae from e683d092e2
Some checks failed
ci / test (pull_request) Successful in 6m6s
ci / sdk (pull_request) Successful in 1m27s
android-ci / android (pull_request) Has been cancelled
ci / fuzz (pull_request) Has been cancelled
to 2f3d5d69c3
Some checks failed
android-ci / android (pull_request) Has been cancelled
ci / test (pull_request) Successful in 8m43s
ci / sdk (pull_request) Successful in 1m16s
ci / fuzz (pull_request) Successful in 5m21s
2026-09-24 00:36:26 +00:00
Compare
sirius merged commit 6d815b0fe8 into main 2026-09-24 00:44:44 +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!155
No description provided.