From 685cf34cb9d4505c0ff2980e515bfa7dbc8d3e81 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 3 Jul 2024 15:32:11 +0700 Subject: [PATCH 1/2] fix: unlock descriptor wallet for mixing-only --- src/wallet/scriptpubkeyman.cpp | 8 ++++---- src/wallet/scriptpubkeyman.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index b3840905ea42b..678022e1f22e7 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -331,7 +331,7 @@ void LegacyScriptPubKeyMan::MarkUnusedAddresses(WalletBatch &batch, const CScrip void LegacyScriptPubKeyMan::UpgradeKeyMetadata() { LOCK(cs_KeyStore); // mapKeyMetadata - if (m_storage.IsLocked() || m_storage.IsWalletFlagSet(WALLET_FLAG_KEY_ORIGIN_METADATA) || !IsHDEnabled()) { + if (m_storage.IsLocked(false) || m_storage.IsWalletFlagSet(WALLET_FLAG_KEY_ORIGIN_METADATA) || !IsHDEnabled()) { return; } @@ -1901,7 +1901,7 @@ void DescriptorScriptPubKeyMan::ReturnDestination(int64_t index, bool internal, std::map DescriptorScriptPubKeyMan::GetKeys() const { AssertLockHeld(cs_desc_man); - if (m_storage.HasEncryptionKeys() && !m_storage.IsLocked()) { + if (m_storage.HasEncryptionKeys() && !m_storage.IsLocked(true)) { KeyMap keys; for (auto key_pair : m_map_crypted_keys) { const CPubKey& pubkey = key_pair.second.first; @@ -2014,7 +2014,7 @@ bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const } if (m_storage.HasEncryptionKeys()) { - if (m_storage.IsLocked()) { + if (m_storage.IsLocked(true)) { return false; } @@ -2423,7 +2423,7 @@ bool DescriptorScriptPubKeyMan::GetDescriptorString(std::string& out) const void DescriptorScriptPubKeyMan::UpgradeDescriptorCache() { LOCK(cs_desc_man); - if (m_storage.IsLocked() || m_storage.IsWalletFlagSet(WALLET_FLAG_LAST_HARDENED_XPUB_CACHED)) { + if (m_storage.IsLocked(false) || m_storage.IsWalletFlagSet(WALLET_FLAG_LAST_HARDENED_XPUB_CACHED)) { return; } diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index 7188ce9d1da4b..9c639b73ebfb7 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -40,7 +40,7 @@ class WalletStorage virtual void SetMinVersion(enum WalletFeature, WalletBatch* = nullptr) = 0; virtual const CKeyingMaterial& GetEncryptionKey() const = 0; virtual bool HasEncryptionKeys() const = 0; - virtual bool IsLocked(bool fForMixing = false) const = 0; + virtual bool IsLocked(bool fForMixing) const = 0; // for LegacyScriptPubKeyMan::TopUpInner needs: virtual void UpdateProgress(const std::string&, int) = 0; From c94490839912e21965a01655fa24f837f037b4f6 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 3 Jul 2024 15:32:27 +0700 Subject: [PATCH 2/2] refactor: simplify implementation of function CWallet::IsLocked --- src/wallet/wallet.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 4bd880888c982..29d6104270a67 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -5459,21 +5459,11 @@ bool CWallet::IsLocked(bool fForMixing) const { if (!IsCrypted()) return false; - bool result; - { - LOCK(cs_wallet); - result = vMasterKey.empty(); - } - // fForMixing fOnlyMixingAllowed return - // --------------------------------------- - // true true result - // true false result - // false true true - // false false result if(!fForMixing && fOnlyMixingAllowed) return true; - return result; + LOCK(cs_wallet); + return vMasterKey.empty(); } bool CWallet::Lock(bool fAllowMixing)