2 suggestions
Optional improvements
[suggestion] · The migration fix is introduced and immediately replaced
6ed50582 introduces a pre-commit comparison that 0fd13118 replaces, requiring review of superseded logic and obscuring the net move of completeness checks outside the transaction.
Location: src/wallet/wallet.cpp:4067 at 6ed50582c17d (commit) (commit).
Details and suggested fix
6ed50582c17d15aac0252338411c99eb8b6047fc adds the pending_removals comparison and a functional regression test. Its direct successor, 0fd13118a48756dc02999931a5a6c4605a623b31, removes that comparison, moves the completeness checks after RunWithinTxn(), and simplifies the same test. The intermediate commit bundles the fix and test rather than providing a test-first step. Fold these two commits into one describing the post-commit design, and update the PR description, whose second-commit explanation still describes the removed comparison. Keep e518ef26f489741540c0a97bce9e0db687f400c1 separate: its RemoveTxs() abort callback fix and unit test stand alone for backports. This changes the review flow, not the final tree.
[suggestion] · Post-commit completeness failures lack recovery coverage
The migration tests cover success and destination-creation failures, but not cleanup after the relocated completeness checks reject a committed, descriptor-flagged local database.
Location: src/wallet/wallet.cpp:4202 (head).
Details and suggested fix
test_watchonly_txs_no_privkeys() checks only success, and the existing cleanup fixtures fail before ApplyMigrationData(). A blank legacy wallet with importaddress(A) followed by setlabel(external_B, "x") reaches the post-commit address-book failure: the pre-existing migration loop clones the SEND entry but leaves it locally. Add a functional case asserting the migration error, restoration of the original BDB wallet with assert_is_bdb(), removal of the created watch-only wallet and directory, and preservation of the backup.
No RPC-reachable trigger for a residual mapWallet entry was established because unclassified transactions fail earlier, so testing that guard needs a unit-level fixture. If SEND entries are changed to migrate successfully, use a unit-level fixture for the address-book guard too.
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
Migration recovery historically extends beyond the migration transaction: failure while reloading a migrated wallet is also treated as migration failure and enters backup-based cleanup.
Andrew Chow's 2023 change explicitly added failed-reload handling after migration completes. Its patch routes unsuccessful reloads into cleanup of created wallets. This establishes that committing migration data was not historically an irrevocable declaration of overall success.