In 060695c22ae7b2b0f2a1dd1417ed1b9d5a5ab542 “test: Failed load after migrate should restore backup”
Adding a review note because it took me some time to understand why this error pops up only after migration is complete and not during the process as this particular error comes from inside CWallet::AttachChain
that is a part of CWallet::Create
. The reason I found is that all the CWallet::Create
calls inside the migration process pass an empty context that doesn’t contain the chain
due to which the chain doesn’t need to be attached. Only while loading the wallet after migration, the proper wallet context is passed that triggers this error.
https://github.com/bitcoin/bitcoin/blob/9f713b83dcf7480e6c4447f0f263bef096d55cc7/src/wallet/wallet.cpp#L4206-L4210
I verified that the migration-before-loading was triggered/completed by using the below patch in the migrate_and_get_rpc
function. The below patch can be added separately as well (not necessary in this PR) because all the tests pass.
0diff --git a/test/functional/wallet_migration.py b/test/functional/wallet_migration.py
1index a1b319b90b..890478da26 100755
2--- a/test/functional/wallet_migration.py
3+++ b/test/functional/wallet_migration.py
4@@ -125,7 +125,7 @@ class WalletMigrationTest(BitcoinTestFramework):
5 if w["name"] == wallet_name:
6 assert_equal(w["warnings"], ["This wallet is a legacy wallet and will need to be migrated with migratewallet before it can be loaded"])
7 # Migrate, checking that rescan does not occur
8- with self.master_node.assert_debug_log(expected_msgs=[], unexpected_msgs=["Rescanning"]):
9+ with self.master_node.assert_debug_log(expected_msgs=["Migrating wallet storage database from BerkeleyDB to SQLite."], unexpected_msgs=["Rescanning"]):
10 migrate_info = self.master_node.migratewallet(wallet_name=wallet_name, **kwargs)
11 # Update wallet name in case the initial wallet was completely migrated to a watch-only wallet
12 # (in which case the wallet name would be suffixed by the 'watchonly' term)