From 3d985d4f43b5344f998bcf6db22d02782e647a2a Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Wed, 16 Feb 2022 22:31:20 -0500 Subject: [PATCH 1/2] wallet: Don't generate keys when privkeys disabled when upgrading When private keys are disabled, we should not be trying to generate new keys during upgradewallet. --- src/wallet/scriptpubkeyman.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 7218ed11dc..53f7b773b4 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -469,6 +469,12 @@ bool LegacyScriptPubKeyMan::CanGetAddresses(bool internal) const bool LegacyScriptPubKeyMan::Upgrade(int prev_version, int new_version, bilingual_str& error) { LOCK(cs_KeyStore); + + if (m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { + // Nothing to do here if private keys are not enabled + return true; + } + bool hd_upgrade = false; bool split_upgrade = false; if (IsFeatureSupported(new_version, FEATURE_HD) && !IsHDEnabled()) { From c7376cc8d728f3a7c40f79bd57e7cef685def723 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Wed, 16 Feb 2022 22:37:21 -0500 Subject: [PATCH 2/2] tests: Test upgrading wallet with privkeys disabled --- test/functional/wallet_upgradewallet.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/functional/wallet_upgradewallet.py b/test/functional/wallet_upgradewallet.py index 36e72f2dd9..c452e1eafd 100755 --- a/test/functional/wallet_upgradewallet.py +++ b/test/functional/wallet_upgradewallet.py @@ -345,5 +345,16 @@ class UpgradeWalletTest(BitcoinTestFramework): desc_wallet = self.nodes[0].get_wallet_rpc("desc_upgrade") self.test_upgradewallet(desc_wallet, previous_version=169900, expected_version=169900) + self.log.info("Checking that descriptor wallets without privkeys do nothing, successfully") + self.nodes[0].createwallet(wallet_name="desc_upgrade_nopriv", descriptors=True, disable_private_keys=True) + desc_wallet = self.nodes[0].get_wallet_rpc("desc_upgrade_nopriv") + self.test_upgradewallet(desc_wallet, previous_version=169900, expected_version=169900) + + if self.is_bdb_compiled(): + self.log.info("Upgrading a wallet with private keys disabled") + self.nodes[0].createwallet(wallet_name="privkeys_disabled_upgrade", disable_private_keys=True, descriptors=False) + disabled_wallet = self.nodes[0].get_wallet_rpc("privkeys_disabled_upgrade") + self.test_upgradewallet(disabled_wallet, previous_version=169900, expected_version=169900) + if __name__ == '__main__': UpgradeWalletTest().main()