Skip to content

Commit 4015db8

Browse files
committed
[Wallet] Fix empty unlockSaplingsKeys.
1 parent c2bc104 commit 4015db8

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/sapling/crypter_sapling.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ bool CCryptoKeyStore::EncryptSaplingKeys(CKeyingMaterial& vMasterKeyIn)
133133

134134
bool CCryptoKeyStore::UnlockSaplingKeys(const CKeyingMaterial& vMasterKeyIn, bool fDecryptionThoroughlyChecked)
135135
{
136+
if (mapCryptedSaplingSpendingKeys.empty()) {
137+
LogPrintf("%s: mapCryptedSaplingSpendingKeys empty. No need to unlock anything.\n");
138+
return true;
139+
}
140+
136141
bool keyFail = false;
137142
bool keyPass = false;
138143
CryptedSaplingSpendingKeyMap::const_iterator miSapling = mapCryptedSaplingSpendingKeys.begin();

src/wallet/wallet.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,21 @@ bool CWallet::Unlock(const CKeyingMaterial& vMasterKeyIn)
347347
break;
348348
}
349349

350-
// Sapling
351-
if (!UnlockSaplingKeys(vMasterKeyIn, fDecryptionThoroughlyChecked)) {
352-
return false; // only could get here if (keyFail || !keyPass).
353-
}
354-
355350
if (keyPass && keyFail) {
356-
LogPrintf("The wallet is probably corrupted: Some keys decrypt but not all.");
351+
LogPrintf("The wallet is probably corrupted: Some keys decrypt but not all.\n");
357352
throw std::runtime_error("Error unlocking wallet: some keys decrypt but not all. Your wallet file may be corrupt.");
358353
}
354+
359355
if (keyFail || !keyPass)
360356
return false;
357+
358+
// Sapling
359+
if (!UnlockSaplingKeys(vMasterKeyIn, fDecryptionThoroughlyChecked)) {
360+
// If Sapling key encryption fail, let's unencrypt the rest of the keys
361+
LogPrintf("Sapling wallet unlock keys failed\n");
362+
throw std::runtime_error("Error unlocking wallet: some Sapling keys decrypt but not all. Your wallet file may be corrupt.");
363+
}
364+
361365
vMasterKey = vMasterKeyIn;
362366
fDecryptionThoroughlyChecked = true;
363367

@@ -748,6 +752,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
748752
Unlock(strWalletPassphrase);
749753
// if we are using HD, replace the HD seed with a new one
750754
if (m_spk_man->IsHDEnabled()) {
755+
LogPrintf("pre unlock setupGeneration\n");
751756
if (!m_spk_man->SetupGeneration(false, true)) {
752757
return false;
753758
}

0 commit comments

Comments
 (0)