mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-27 17:51:24 +02:00
Merge bitcoin/bitcoin#31451: wallet: migration, avoid loading legacy wallet after failure when BDB isn't compiled
589ed1a8ea
wallet: migration, avoid loading wallet after failure when it wasn't loaded before (furszy) Pull request description: Fixes #31447. During migration failure, only load wallet back into memory when the wallet was loaded prior to migration. This fixes the case where BDB is not supported, which implies that no legacy wallet can be loaded into memory due to the lack of db writing functionality. Link to error description https://github.com/bitcoin/bitcoin/issues/31447#issuecomment-2528757140. This PR also improves migration backup related comments to better document the current workflow. ACKs for top commit: achow101: ACK589ed1a8ea
rkrux: ACK589ed1a8ea
pablomartin4btc: tACK589ed1a8ea
Tree-SHA512: c7a489d2b253c574ee0287b691ebe29fe8d026f659f68a3f6108eca8b4e1e420c67ca7803c6bd70c1e1440791833fabca3afbcf8fe8524c6c9fc08de95b618d0
This commit is contained in:
@@ -896,9 +896,7 @@ class WalletMigrationTest(BitcoinTestFramework):
|
||||
shutil.copytree(self.old_node.wallets_path / "failed", self.master_node.wallets_path / "failed")
|
||||
assert_raises_rpc_error(-4, "Failed to create database", self.master_node.migratewallet, "failed")
|
||||
|
||||
assert "failed" in self.master_node.listwallets()
|
||||
assert "failed_watchonly" not in self.master_node.listwallets()
|
||||
assert "failed_solvables" not in self.master_node.listwallets()
|
||||
assert all(wallet not in self.master_node.listwallets() for wallet in ["failed", "failed_watchonly", "failed_solvables"])
|
||||
|
||||
assert not (self.master_node.wallets_path / "failed_watchonly").exists()
|
||||
# Since the file in failed_solvables is one that we put there, migration shouldn't touch it
|
||||
@@ -912,6 +910,22 @@ class WalletMigrationTest(BitcoinTestFramework):
|
||||
_, _, magic = struct.unpack("QII", data)
|
||||
assert_equal(magic, BTREE_MAGIC)
|
||||
|
||||
####################################################
|
||||
# Perform the same test with a loaded legacy wallet.
|
||||
# The wallet should remain loaded after the failure.
|
||||
#
|
||||
# This applies only when BDB is enabled, as the user
|
||||
# cannot interact with the legacy wallet database
|
||||
# without BDB support.
|
||||
if self.is_bdb_compiled() is not None:
|
||||
# Advance time to generate a different backup name
|
||||
self.master_node.setmocktime(self.master_node.getblockheader(self.master_node.getbestblockhash())['time'] + 100)
|
||||
assert "failed" not in self.master_node.listwallets()
|
||||
self.master_node.loadwallet("failed")
|
||||
assert_raises_rpc_error(-4, "Failed to create database", self.master_node.migratewallet, "failed")
|
||||
wallets = self.master_node.listwallets()
|
||||
assert "failed" in wallets and all(wallet not in wallets for wallet in ["failed_watchonly", "failed_solvables"])
|
||||
|
||||
def test_blank(self):
|
||||
self.log.info("Test that a blank wallet is migrated")
|
||||
wallet = self.create_legacy_wallet("blank", blank=True)
|
||||
|
Reference in New Issue
Block a user