wallet: the file-name picker must consult the disk, not only the catalogue #151
Merged
sirius
merged 4 commits from 2026-09-23 00:46:48 +00:00
onionwire/t_81deabb5-wallet-the-file-name-picker-must-consult into onionwire/t_67879b98-wallet-actually-open-the-wallet-file-and 2026-09-23
2026-09-22
tests: take the restart's port from the child that dials it
`a_restart_opens_the_stored_wallet_file` failed on the Pi runner twice in a row — CI run 905 job 1373 and run 901 job 1365 — and passed 3/3 on a 16-core host: open the wallet with a passphrase: "wallet file onionwire-1 is not open — the wallet RPC never answered (wallet connect: Connection refused (os error 111))" The whole `WALLET_OPEN_WAIT` was burned on refusals, so the mock was bound on a port the restarted child never dialled. Production is not the suspect: `WalletChild::start_children` builds the child's argv and the `WalletClient` URL from the same `pick_port` value, and `start_wallet_child_with` installs that client in `self.wallet` before `open_child_wallet` dials it, so the client can never carry the previous child's port. The harness is the suspect. It learned the restarted child's port from the *shared* argv log — a file every child writes — and cleared that file first. A clear is not a synchronisation: on a loaded runner the killed child's write lands after it, so the poller read the port of a child that was already dead and bound the mock there. Reproduced deterministically with a stand-in whose exec is late; with the old read the new test fails with the CI message, byte for byte. Each fake child now writes `<log>.<pid>` as well, and the shared copy lands first, so a pid-named file implies the shared one is complete. A test that spans two children reads the pid-named file: only that child can write it, so the port belongs to the child that dials it. `WalletChild::wallet_rpc_pid` (test-only) supplies the pid. `open_wallet_blocking` already retries while the RPC is unreachable and gives up after a bounded wait with a typed `OpenFailure::NotAnswering`, so it cannot refuse forever against a merely slow child: no production change. new test: node::tests::a_restart_is_not_given_the_stopped_childs_port
tests: write the fake child's argv log with one mv, not append-per-line
The wallet-child tests learn a spawned stand-in's port by polling its argv
log, and `fake_bin`/`fake_child_bin` truncated the log and then appended
one line per argument -- so a poller could read a prefix. A truncated port
is a *valid* u16 ("427" out of "42765"), so `wait_for_child_rpc_port`
happily returned a port nothing was listening on and the restart's
`open_wallet` died with `Connection refused` after its 10s budget; the
same prefix read is what `loopback_and_clearnet_remotes_carry_no_proxy...`
printed with its `--daemon-address` value missing.
Both tests failed on the first CI run of this branch (ci / test) and are
green in isolation, which is the signature of this race rather than of a
code defect. The argv now lands in the log with a single `mv`, so a reader
sees either no log or the complete one.
Measured with a tight read loop (argv-race-probe.sh): the append version
was caught mid-write 1/300 reads, the mv version 0/300.
wallet: the file-name picker consults the disk, not only the catalogue
next_wallet_filename returned <default>-<n> for the first n the SQLCipher catalogue did not hold, and never looked at the wallet directory. monero writes two files per wallet (<name> and <name>.keys) and refuses a create that would collide with either, so a file whose catalogue row is gone - Store::delete_wallet keeps the file, and a create whose record_wallet failed leaves one - meant every attempt proposed the same taken name and the daemon answered -21 Cannot create wallet. Already exists. for ever. Add wallet_name_taken (src/wallet_child.rs): it lists the wallet dir and answers whether <name> or <name>.keys is already there. next_wallet_filename now needs the candidate free in both places, and Node::wallet_dir() is the single source of $ONIONWIRE_HOME/wallet, used by the child spawn too. Fail closed: an unreadable (or missing) wallet dir is an error, not a guess. Reads only - nothing here deletes a file the catalogue does not hold, which may be the only copy of a funded wallet.