From 25f5611d1a3f447a5a9f7aad86509f3f743545b7 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 29 Jul 2021 04:19:14 +0300 Subject: [PATCH] More of 11634: wallet: Add missing cs_wallet/cs_KeyStore locks to wallet --- src/wallet/test/coinjoin_tests.cpp | 5 +++-- src/wallet/wallet.cpp | 7 +++++++ src/wallet/wallet.h | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/wallet/test/coinjoin_tests.cpp b/src/wallet/test/coinjoin_tests.cpp index 803d12a3d4..de50738279 100644 --- a/src/wallet/test/coinjoin_tests.cpp +++ b/src/wallet/test/coinjoin_tests.cpp @@ -58,11 +58,12 @@ public: CWalletTx& AddTxToChain(uint256 nTxHash) { - auto it = wallet->mapWallet.find(nTxHash); - assert(it != wallet->mapWallet.end()); + std::map::iterator it; CMutableTransaction blocktx; { LOCK(wallet->cs_wallet); + it = wallet->mapWallet.find(nTxHash); + assert(it != wallet->mapWallet.end()); blocktx = CMutableTransaction(*it->second.tx); } CreateAndProcessBlock({blocktx}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9b4fa368a0..414bf690f5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1043,6 +1043,8 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun bool CWallet::GetLabelDestination(CTxDestination &dest, const std::string& label, bool bForceNew) { + AssertLockHeld(cs_wallet); + WalletBatch batch(*database); CAccount account; @@ -2474,6 +2476,8 @@ CAmount CWalletTx::GetAnonymizedCredit(const CCoinControl* coinControl) const if (!pwallet) return 0; + AssertLockHeld(pwallet->cs_wallet); + // Exclude coinbase and conflicted txes if (IsCoinBase() || GetDepthInMainChain() < 0) return 0; @@ -2514,6 +2518,8 @@ CAmount CWalletTx::GetDenominatedCredit(bool unconfirmed, bool fUseCache) const if (pwallet == nullptr) return 0; + AssertLockHeld(pwallet->cs_wallet); + // Must wait until coinbase is safely deep enough in the chain before valuing it if (IsCoinBase() && GetBlocksToMaturity() > 0) return 0; @@ -3725,6 +3731,7 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CTransac } auto calculateFee = [&](CAmount& nFee) -> bool { + AssertLockHeld(cs_wallet); nBytes = CalculateMaximumSignedTxSize(txNew, this, coin_control.fAllowWatchOnly); if (nBytes < 0) { strFailReason = _("Signing transaction failed"); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 6d775d02fe..1553fa9f4b 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -785,7 +785,7 @@ private: /* HD derive new child key (on internal or external chain) */ void DeriveNewChildKey(WalletBatch &batch, const CKeyMetadata& metadata, CKey& secretRet, uint32_t nAccountIndex, bool fInternal /*= false*/) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); - std::set setInternalKeyPool; + std::set setInternalKeyPool GUARDED_BY(cs_wallet); std::set setExternalKeyPool GUARDED_BY(cs_wallet); int64_t m_max_keypool_index GUARDED_BY(cs_wallet) = 0; std::map m_pool_key_to_index;