Skip to content

Commit db0f254

Browse files
committed
Reserve keypool, check std::set entries exist before erasing
- reserve key for tx calls erase without checking if it was found
1 parent f20c752 commit db0f254

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/wallet/wallet.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4667,11 +4667,9 @@ void CWallet::UpdateKeyPoolsFromTransactions(const std::string& strOpType, const
46674667
std::vector<unsigned char> key1 = vvchOpParameters[1];
46684668

46694669
if (strOpType == "bdap_new_account") {
4670-
//reservedEd25519PubKeys.push_back(key1);
46714670
ReserveEdKeyForTransactions(key1);
46724671
}
46734672
else if (strOpType == "bdap_new_link_request" || strOpType == "bdap_new_link_accept") {
4674-
//reservedEd25519PubKeys.push_back(key0);
46754673
ReserveEdKeyForTransactions(key0);
46764674
fNeedToUpdateLinks = true;
46774675
}
@@ -4774,10 +4772,11 @@ void CWallet::ReserveEdKeyForTransactions(const std::vector<unsigned char>& pubK
47744772
}
47754773

47764774
if (EraseIndex) {
4777-
std::set<int64_t>::iterator eraseIndexEd = setInternalEdKeyPool.find(IndexToErase);
4778-
std::set<int64_t>::iterator eraseIndex = setInternalKeyPool.find(IndexToErase);
4779-
4775+
std::set<int64_t>::iterator eraseIndexEd = setInternalEdKeyPool.find(IndexToErase);
4776+
std::set<int64_t>::iterator eraseIndex = setInternalKeyPool.find(IndexToErase);
4777+
if (eraseIndexEd != setInternalEdKeyPool.end())
47804778
setInternalEdKeyPool.erase(eraseIndexEd);
4779+
if (eraseIndex != setInternalKeyPool.end())
47814780
setInternalKeyPool.erase(eraseIndex);
47824781
}
47834782

@@ -4790,7 +4789,7 @@ void CWallet::KeepKey(int64_t nIndex)
47904789
CWalletDB walletdb(strWalletFile);
47914790
walletdb.ErasePool(nIndex);
47924791
nKeysLeftSinceAutoBackup = nWalletBackups ? nKeysLeftSinceAutoBackup - 1 : 0;
4793-
}
4792+
}
47944793
LogPrintf("keypool keep %d\n", nIndex);
47954794
}
47964795

0 commit comments

Comments
 (0)