Repository navigation
wallet: fix migration with watch-only transactions - #36825
psychemist wants to merge 2 commits into
Conversation
Aborting a RemoveTxs() transaction invokes an empty std::function, which throws `std::bad_function_call`. Implement a no-op abort callback since memory changes are deferred until after database commit. Extend RemoveTxs coverage to verify rollback restores the database record and leaves wallet memory unchanged.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
7410d01 to
6ed5058
Compare
|
force-pushed to amend last commit message and add issue author as co-author. no code changes |
|
the return value of |
|
tACK 6ed5058 |
|
tACK 6ed5058 |
|
@Eunovo pushed a commit adding the changes you suggested and updated the PR description to reflect this change |
Removing transactions updates `mapWallet` only after database commit is successful. Requiring an empty map beforehand causes migration of legacy wallets containing only watch-only transactions to fail. Move final address book and transaction map emptiness checks for legacy wallets with no spendable material to `DoMigration()`, after `RunWithinTxn()` commits the migration database transaction and the commit callback registered by `RemoveTxs()` updates memory. Add regression coverage to verify the successfully migrated wallet retains the original balance and transaction after unloading and reloading without rescanning. Co-authored-by: David Gumberg <[email protected]>
0fd1311 to
b1a356d
Compare
|
🐙 This pull request conflicts with the target branch and needs rebase. |
|
tACK b1a356d, wallet migrates with transaction and balance and all wallet tests pass. we forced a failure after the database save the original wallet was restored unchanged. on v31.1 / v30.2 without this fix, the wallet gets stuck half-migrated need to restore the backup by hand. and it needs a rebase onto #34193, will retest after. Used AI! |

Fixes #36483
As described in the linked issue, migration to descriptor wallets currently fails for legacy wallets that contain no spendable keys and are tracking watch-only transactions.
When a database transaction containing
RemoveTxs()is aborted, the database rolls back and the registeredon_abortcallback is invoked. The current listener contains an emptystd::functionso calling it throwsstd::bad_function_calland masks the actual migration error.The first commit changes the callback to a no-op function since no memory cleanup happens on abort. It also adds a unit test to confirm that abort restores the database record and leaves wallet memory unchanged.
After this commit, the functional test supplied by the issue's author changes from
bad_function_calltoError: Not all transaction records were migrated (-4), exposing the migration error previously masked by the abort callback exception.During wallet migration,
RemoveTxs()defers deletion of transactions from the original wallet's in-memorymapWalletuntil after the database commit. The current check that requires an empty map before the database commit causes migration to fail.The second commit moves the check for an empty
mapWalletto afterRunWithinTxn()commits the database transaction and runs the commit callback, when transactions marked for removal have been deleted.A new functional test is added to cover migration of a blank wallet with watch-only transactions. It checks that the destination watch-only wallet retains both transactions and balance, including after unloading and reloading the wallet, without rescanning the blockchain.