Merge bitcoin/bitcoin#29375: wallet: remove unused 'accept_no_keys' arg from decryption process

2bb25ce502 wallet: remove unused 'accept_no_keys' arg from decryption process (furszy)

Pull request description:

  Found it while reviewing other PR. Couldn't contain myself from cleaning it up.

  The wallet decryption process (`CheckDecryptionKey()` and `Unlock()`)
  contains an arg 'accept_no_keys,' introduced in #13926, that has
  never been used.
  Additionally, this also removes the unimplemented `SplitWalletPath`
  function.

ACKs for top commit:
  delta1:
    ACK 2bb25ce502
  epiccurious:
    utACK 2bb25ce502.
  achow101:
    ACK 2bb25ce502
  theStack:
    Code-review ACK 2bb25ce502

Tree-SHA512: e0537c994be19ca0032551d8a64cf1755c8997e04d21ee0522b31de26ad90b9eb02a8b415448257b60bced484b9d2a23b37586e12dc5ff6e35bdd8ff2165c6bf
This commit is contained in:
Ava Chow 2024-02-06 12:53:19 -05:00
commit 03d95cc630
No known key found for this signature in database
GPG key ID: 17565732E08E5E41
5 changed files with 13 additions and 14 deletions

View file

@ -20,7 +20,6 @@ class ArgsManager;
struct bilingual_str; struct bilingual_str;
namespace wallet { namespace wallet {
void SplitWalletPath(const fs::path& wallet_path, fs::path& env_directory, std::string& database_filename);
class DatabaseCursor class DatabaseCursor
{ {

View file

@ -225,7 +225,7 @@ isminetype LegacyScriptPubKeyMan::IsMine(const CScript& script) const
assert(false); assert(false);
} }
bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys) bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key)
{ {
{ {
LOCK(cs_KeyStore); LOCK(cs_KeyStore);
@ -258,7 +258,7 @@ bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key
LogPrintf("The wallet is probably corrupted: Some keys decrypt but not all.\n"); LogPrintf("The wallet is probably corrupted: Some keys decrypt but not all.\n");
throw std::runtime_error("Error unlocking wallet: some keys decrypt but not all. Your wallet file may be corrupt."); throw std::runtime_error("Error unlocking wallet: some keys decrypt but not all. Your wallet file may be corrupt.");
} }
if (keyFail || (!keyPass && !accept_no_keys)) if (keyFail || !keyPass)
return false; return false;
fDecryptionThoroughlyChecked = true; fDecryptionThoroughlyChecked = true;
} }
@ -2049,7 +2049,7 @@ isminetype DescriptorScriptPubKeyMan::IsMine(const CScript& script) const
return ISMINE_NO; return ISMINE_NO;
} }
bool DescriptorScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys) bool DescriptorScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key)
{ {
LOCK(cs_desc_man); LOCK(cs_desc_man);
if (!m_map_keys.empty()) { if (!m_map_keys.empty()) {
@ -2074,7 +2074,7 @@ bool DescriptorScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master
LogPrintf("The wallet is probably corrupted: Some keys decrypt but not all.\n"); LogPrintf("The wallet is probably corrupted: Some keys decrypt but not all.\n");
throw std::runtime_error("Error unlocking wallet: some keys decrypt but not all. Your wallet file may be corrupt."); throw std::runtime_error("Error unlocking wallet: some keys decrypt but not all. Your wallet file may be corrupt.");
} }
if (keyFail || (!keyPass && !accept_no_keys)) { if (keyFail || !keyPass) {
return false; return false;
} }
m_decryption_thoroughly_checked = true; m_decryption_thoroughly_checked = true;

View file

@ -179,7 +179,7 @@ public:
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; } virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }
//! Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the keys handled by it. //! Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the keys handled by it.
virtual bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) { return false; } virtual bool CheckDecryptionKey(const CKeyingMaterial& master_key) { return false; }
virtual bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) { return false; } virtual bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) { return false; }
virtual util::Result<CTxDestination> GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) { return util::Error{Untranslated("Not supported")}; } virtual util::Result<CTxDestination> GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) { return util::Error{Untranslated("Not supported")}; }
@ -379,7 +379,7 @@ public:
util::Result<CTxDestination> GetNewDestination(const OutputType type) override; util::Result<CTxDestination> GetNewDestination(const OutputType type) override;
isminetype IsMine(const CScript& script) const override; isminetype IsMine(const CScript& script) const override;
bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override; bool CheckDecryptionKey(const CKeyingMaterial& master_key) override;
bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) override; bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) override;
util::Result<CTxDestination> GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) override; util::Result<CTxDestination> GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) override;
@ -610,7 +610,7 @@ public:
util::Result<CTxDestination> GetNewDestination(const OutputType type) override; util::Result<CTxDestination> GetNewDestination(const OutputType type) override;
isminetype IsMine(const CScript& script) const override; isminetype IsMine(const CScript& script) const override;
bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override; bool CheckDecryptionKey(const CKeyingMaterial& master_key) override;
bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) override; bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) override;
util::Result<CTxDestination> GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) override; util::Result<CTxDestination> GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) override;

View file

@ -555,7 +555,7 @@ void CWallet::UpgradeDescriptorCache()
SetWalletFlag(WALLET_FLAG_LAST_HARDENED_XPUB_CACHED); SetWalletFlag(WALLET_FLAG_LAST_HARDENED_XPUB_CACHED);
} }
bool CWallet::Unlock(const SecureString& strWalletPassphrase, bool accept_no_keys) bool CWallet::Unlock(const SecureString& strWalletPassphrase)
{ {
CCrypter crypter; CCrypter crypter;
CKeyingMaterial _vMasterKey; CKeyingMaterial _vMasterKey;
@ -568,7 +568,7 @@ bool CWallet::Unlock(const SecureString& strWalletPassphrase, bool accept_no_key
return false; return false;
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey)) if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
continue; // try another master key continue; // try another master key
if (Unlock(_vMasterKey, accept_no_keys)) { if (Unlock(_vMasterKey)) {
// Now that we've unlocked, upgrade the key metadata // Now that we've unlocked, upgrade the key metadata
UpgradeKeyMetadata(); UpgradeKeyMetadata();
// Now that we've unlocked, upgrade the descriptor cache // Now that we've unlocked, upgrade the descriptor cache
@ -3374,12 +3374,12 @@ bool CWallet::Lock()
return true; return true;
} }
bool CWallet::Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys) bool CWallet::Unlock(const CKeyingMaterial& vMasterKeyIn)
{ {
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
for (const auto& spk_man_pair : m_spk_managers) { for (const auto& spk_man_pair : m_spk_managers) {
if (!spk_man_pair.second->CheckDecryptionKey(vMasterKeyIn, accept_no_keys)) { if (!spk_man_pair.second->CheckDecryptionKey(vMasterKeyIn)) {
return false; return false;
} }
} }

View file

@ -302,7 +302,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
private: private:
CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet); CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet);
bool Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys = false); bool Unlock(const CKeyingMaterial& vMasterKeyIn);
std::atomic<bool> fAbortRescan{false}; std::atomic<bool> fAbortRescan{false};
std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
@ -578,7 +578,7 @@ public:
// Used to prevent deleting the passphrase from memory when it is still in use. // Used to prevent deleting the passphrase from memory when it is still in use.
RecursiveMutex m_relock_mutex; RecursiveMutex m_relock_mutex;
bool Unlock(const SecureString& strWalletPassphrase, bool accept_no_keys = false); bool Unlock(const SecureString& strWalletPassphrase);
bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
bool EncryptWallet(const SecureString& strWalletPassphrase); bool EncryptWallet(const SecureString& strWalletPassphrase);