diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -226,6 +226,7 @@ } std::vector getDestValues(const std::string &prefix) override { + LOCK(m_wallet.cs_wallet); return m_wallet.GetDestValues(prefix); } void lockCoin(const COutPoint &output) override { diff --git a/src/qt/test/addressbooktests.cpp b/src/qt/test/addressbooktests.cpp --- a/src/qt/test/addressbooktests.cpp +++ b/src/qt/test/addressbooktests.cpp @@ -100,6 +100,7 @@ } auto check_addbook_size = [&wallet](int expected_size) { + LOCK(wallet->cs_wallet); QCOMPARE(static_cast(wallet->mapAddressBook.size()), expected_size); }; diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -54,9 +54,11 @@ return ret.str(); } -bool GetWalletAddressesForKey(const Config &config, CWallet *const pwallet, - const CKeyID &keyid, std::string &strAddr, - std::string &strLabel) { +static bool GetWalletAddressesForKey(const Config &config, + CWallet *const pwallet, + const CKeyID &keyid, std::string &strAddr, + std::string &strLabel) + EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { bool fLabelFound = false; CKey key; pwallet->GetKey(keyid, key); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1525,7 +1525,8 @@ CWallet *const pwallet, const CWalletTx &wtx, int nMinDepth, bool fLong, UniValue &ret, const isminefilter &filter_ismine, - const std::string *filter_label) { + const std::string *filter_label) + EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { Amount nFee; std::list listReceived; std::list listSent; diff --git a/src/wallet/test/walletdb_tests.cpp b/src/wallet/test/walletdb_tests.cpp --- a/src/wallet/test/walletdb_tests.cpp +++ b/src/wallet/test/walletdb_tests.cpp @@ -38,6 +38,7 @@ BOOST_CHECK(batch.WriteName(dst2, "name2")); { auto w = LoadWallet(batch); + LOCK(w->cs_wallet); BOOST_CHECK_EQUAL(1, w->mapAddressBook.count(dst1)); BOOST_CHECK_EQUAL("name1", w->mapAddressBook[dst1].name); BOOST_CHECK_EQUAL("name2", w->mapAddressBook[dst2].name); @@ -47,6 +48,7 @@ { auto w = LoadWallet(batch); + LOCK(w->cs_wallet); BOOST_CHECK_EQUAL(0, w->mapAddressBook.count(dst1)); BOOST_CHECK_EQUAL(1, w->mapAddressBook.count(dst2)); } @@ -62,6 +64,7 @@ BOOST_CHECK(batch.WritePurpose(dst2, "purpose2")); { auto w = LoadWallet(batch); + LOCK(w->cs_wallet); BOOST_CHECK_EQUAL(1, w->mapAddressBook.count(dst1)); BOOST_CHECK_EQUAL("purpose1", w->mapAddressBook[dst1].purpose); BOOST_CHECK_EQUAL("purpose2", w->mapAddressBook[dst2].purpose); @@ -71,6 +74,7 @@ { auto w = LoadWallet(batch); + LOCK(w->cs_wallet); BOOST_CHECK_EQUAL(0, w->mapAddressBook.count(dst1)); BOOST_CHECK_EQUAL(1, w->mapAddressBook.count(dst2)); } @@ -88,6 +92,7 @@ BOOST_CHECK(batch.WriteDestData(dst2, "key2", "value4")); { auto w = LoadWallet(batch); + LOCK(w->cs_wallet); std::string val; BOOST_CHECK(w->GetDestData(dst1, "key1", &val)); BOOST_CHECK_EQUAL("value1", val); @@ -103,6 +108,7 @@ { auto w = LoadWallet(batch); + LOCK(w->cs_wallet); std::string dummy; BOOST_CHECK(w->GetDestData(dst1, "key1", &dummy)); BOOST_CHECK(!w->GetDestData(dst1, "key2", &dummy)); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -872,7 +872,8 @@ int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0; uint64_t nAccountingEntryNumber = 0; - std::map mapAddressBook; + std::map + mapAddressBook GUARDED_BY(cs_wallet); std::set setLockedCoins GUARDED_BY(cs_wallet); @@ -1011,18 +1012,23 @@ //! Adds a destination data tuple to the store, and saves it to disk bool AddDestData(const CTxDestination &dest, const std::string &key, - const std::string &value); + const std::string &value) + EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); //! Erases a destination data tuple in the store and on disk - bool EraseDestData(const CTxDestination &dest, const std::string &key); + bool EraseDestData(const CTxDestination &dest, const std::string &key) + EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); //! Adds a destination data tuple to the store, without saving it to disk void LoadDestData(const CTxDestination &dest, const std::string &key, - const std::string &value); + const std::string &value) + EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); //! Look up a destination data tuple in the store, return true if found //! false otherwise bool GetDestData(const CTxDestination &dest, const std::string &key, - std::string *value) const; + std::string *value) const + EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); //! Get all destination values matching a prefix. - std::vector GetDestValues(const std::string &prefix) const; + std::vector GetDestValues(const std::string &prefix) const + EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); //! Adds a watch-only address to the store, and saves it to disk. bool AddWatchOnly(const CScript &dest, int64_t nCreateTime) @@ -1243,7 +1249,8 @@ bool DelAddressBook(const CTxDestination &address); - const std::string &GetLabelName(const CScript &scriptPubKey) const; + const std::string &GetLabelName(const CScript &scriptPubKey) const + EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void GetScriptForMining(std::shared_ptr &script); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3555,7 +3555,6 @@ const std::string &strPurpose) { bool fUpdated = false; { - // mapAddressBook LOCK(cs_wallet); std::map::iterator mi = mapAddressBook.find(address); @@ -3579,7 +3578,6 @@ bool CWallet::DelAddressBook(const CTxDestination &address) { { - // mapAddressBook LOCK(cs_wallet); // Delete destdata tuples associated with address. @@ -4336,7 +4334,6 @@ std::vector CWallet::GetDestValues(const std::string &prefix) const { - LOCK(cs_wallet); std::vector values; for (const auto &address : mapAddressBook) { for (const auto &data : address.second.destdata) { diff --git a/src/wallet/wallettool.cpp b/src/wallet/wallettool.cpp --- a/src/wallet/wallettool.cpp +++ b/src/wallet/wallettool.cpp @@ -106,7 +106,6 @@ } static void WalletShowInfo(CWallet *wallet_instance) { - // lock required because of some AssertLockHeld() LOCK(wallet_instance->cs_wallet); tfm::format(std::cout, "Wallet info\n===========\n");