mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
wallet: fix migration with watch-only transactions #36825
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36825
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-wallet-migration-watch_only"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, 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.
Earlier concerns remain unresolved; see the Run archive linked from the Review report.
🔵 Suggestion ·
DbTxnListenerrequires no-op callbacks for unused eventsNo current registrant omits a callback, but handling empty callbacks centrally would remove the explicit no-op requirement and the associated
std::bad_function_calltrap.Location:
src/wallet/wallet.cpp:2295(head).Review coverage was incomplete.
Reviewed:
b1a356dee965· Review report · Previous reportspermalink
the return value of
WriteFullTx()is currently ignored. a possible follow-up is to check the return value and add test coverage to verify that the original wallet is preserved when a destination write failsforce-pushed to amend last commit message and add issue author as co-author. no code changes
the return value of
WriteFullTx()is currently ignored. a possible follow-up is to check the return value and add test coverage to verify that the original wallet is preserved when a destination write failstACK
6ed50582c1I ran both tests, and they pass with the fix but fail without it.
nit: Use wallet: ... instead of fix(wallet): ... in commit messages.
nit: Change .on_abort= {} to .on_abort = [] {} to match scriptpubkeyman.cpp:1040.
tACK 6ed5058
Concept ACK https://github.com/bitcoin/bitcoin/pull/36825/commits/6ed50582c17d15aac0252338411c99eb8b6047fc
https://github.com/bitcoin/bitcoin/pull/36825/commits/6ed50582c17d15aac0252338411c99eb8b6047fc:
I think it makes sense to move the check to after the DB transaction is committed and the in-memory state is updated. It is safe to do this because a failure after the DB commit still restores the legacy wallet.
https://github.com/bitcoin/bitcoin/pull/36825/commits/6ed50582c17d15aac0252338411c99eb8b6047fc:
nit: Is this assertion necessary?
https://github.com/bitcoin/bitcoin/pull/36825/commits/6ed50582c17d15aac0252338411c99eb8b6047fc:
Why use 2 txs instead of 1? The test would be simpler and easier to read with one tx, since there would be no need for loops.
used 2 transactions to show multiple transactions survive migration. will simplify to eliminate looping
i used the assertion to highlight that the watch-only descriptor wallet does not have private keys enabled even though it is migrated from a legacy wallet that does
good catch. moving the check to after the database commits is a more obvious confirmation that all transactions have been removed. i tested this by moving the check to
DoMigration()afterRunWithinTxn()and the new migration test case still passesThe presence of spendable material in the legacy wallet is what matters in this test, and this assertion does not test that. I think that line can be removed, but it's up to you.
@Eunovo pushed a commit adding the changes you suggested and updated the PR description to reflect this change
p.s force-pushed to squash last two commits into one since they address the same problem
🐙 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!