Skip to content

Commit 0206956

Browse files
author
MarcoFalke
committed
Merge #15365: wallet: Add lock annotation for mapAddressBook
faa4647 wallet: Add lock annotation for mapAddressBook (MarcoFalke) Pull request description: This adds lock annotations for `mapAddressBook` and also moves one lock from inside `GetDestValues` to the caller to be in line with the other methods (`eraseDestData`, `addDestData`, ...) Tree-SHA512: cef9397523e2f5717d4a9a6b2da1fe07042484a51b3c067ae64425768637f334350a2c3db4ab7e00af99b2a587f6b656b68ee1195f6a3db6d47298d0b2b6174a
2 parents 30495d1 + faa4647 commit 0206956

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

src/interfaces/wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class WalletImpl : public Wallet
212212
}
213213
std::vector<std::string> getDestValues(const std::string& prefix) override
214214
{
215+
LOCK(m_wallet.cs_wallet);
215216
return m_wallet.GetDestValues(prefix);
216217
}
217218
void lockCoin(const COutPoint& output) override

src/qt/test/addressbooktests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ void TestAddAddressesToSendBook()
9595
}
9696

9797
auto check_addbook_size = [&wallet](int expected_size) {
98+
LOCK(wallet->cs_wallet);
9899
QCOMPARE(static_cast<int>(wallet->mapAddressBook.size()), expected_size);
99100
};
100101

src/wallet/rpcdump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static std::string DecodeDumpString(const std::string &str) {
6767
return ret.str();
6868
}
6969

70-
static bool GetWalletAddressesForKey(CWallet * const pwallet, const CKeyID &keyid, std::string &strAddr, std::string &strLabel)
70+
static bool GetWalletAddressesForKey(CWallet* const pwallet, const CKeyID& keyid, std::string& strAddr, std::string& strLabel) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
7171
{
7272
bool fLabelFound = false;
7373
CKey key;

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
13091309
* @param filter_ismine The "is mine" filter flags.
13101310
* @param filter_label Optional label string to filter incoming transactions.
13111311
*/
1312-
static void ListTransactions(interfaces::Chain::Lock& locked_chain, CWallet* const pwallet, const CWalletTx& wtx, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter_ismine, const std::string* filter_label)
1312+
static void ListTransactions(interfaces::Chain::Lock& locked_chain, CWallet* const pwallet, const CWalletTx& wtx, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter_ismine, const std::string* filter_label) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
13131313
{
13141314
CAmount nFee;
13151315
std::list<COutputEntry> listReceived;

src/wallet/wallet.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,7 +3172,7 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
31723172
{
31733173
bool fUpdated = false;
31743174
{
3175-
LOCK(cs_wallet); // mapAddressBook
3175+
LOCK(cs_wallet);
31763176
std::map<CTxDestination, CAddressBookData>::iterator mi = mapAddressBook.find(address);
31773177
fUpdated = mi != mapAddressBook.end();
31783178
mapAddressBook[address].name = strName;
@@ -3189,7 +3189,7 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
31893189
bool CWallet::DelAddressBook(const CTxDestination& address)
31903190
{
31913191
{
3192-
LOCK(cs_wallet); // mapAddressBook
3192+
LOCK(cs_wallet);
31933193

31943194
// Delete destdata tuples associated with address
31953195
std::string strAddress = EncodeDestination(address);
@@ -3869,7 +3869,6 @@ bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, st
38693869

38703870
std::vector<std::string> CWallet::GetDestValues(const std::string& prefix) const
38713871
{
3872-
LOCK(cs_wallet);
38733872
std::vector<std::string> values;
38743873
for (const auto& address : mapAddressBook) {
38753874
for (const auto& data : address.second.destdata) {

src/wallet/wallet.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
788788
int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
789789
uint64_t nAccountingEntryNumber = 0;
790790

791-
std::map<CTxDestination, CAddressBookData> mapAddressBook;
791+
std::map<CTxDestination, CAddressBookData> mapAddressBook GUARDED_BY(cs_wallet);
792792

793793
std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet);
794794

@@ -865,15 +865,15 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
865865
bool LoadCScript(const CScript& redeemScript);
866866

867867
//! Adds a destination data tuple to the store, and saves it to disk
868-
bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
868+
bool AddDestData(const CTxDestination& dest, const std::string& key, const std::string& value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
869869
//! Erases a destination data tuple in the store and on disk
870-
bool EraseDestData(const CTxDestination &dest, const std::string &key);
870+
bool EraseDestData(const CTxDestination& dest, const std::string& key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
871871
//! Adds a destination data tuple to the store, without saving it to disk
872-
void LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
872+
void LoadDestData(const CTxDestination& dest, const std::string& key, const std::string& value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
873873
//! Look up a destination data tuple in the store, return true if found false otherwise
874-
bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const;
874+
bool GetDestData(const CTxDestination& dest, const std::string& key, std::string* value) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
875875
//! Get all destination values matching a prefix.
876-
std::vector<std::string> GetDestValues(const std::string& prefix) const;
876+
std::vector<std::string> GetDestValues(const std::string& prefix) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
877877

878878
//! Adds a watch-only address to the store, and saves it to disk.
879879
bool AddWatchOnly(const CScript& dest, int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
@@ -1041,7 +1041,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
10411041

10421042
bool DelAddressBook(const CTxDestination& address);
10431043

1044-
const std::string& GetLabelName(const CScript& scriptPubKey) const;
1044+
const std::string& GetLabelName(const CScript& scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
10451045

10461046
void GetScriptForMining(std::shared_ptr<CReserveScript> &script);
10471047

src/wallet/wallettool.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ static std::shared_ptr<CWallet> LoadWallet(const std::string& name, const fs::pa
9494

9595
static void WalletShowInfo(CWallet* wallet_instance)
9696
{
97-
// lock required because of some AssertLockHeld()
9897
LOCK(wallet_instance->cs_wallet);
9998

10099
fprintf(stdout, "Wallet info\n===========\n");

0 commit comments

Comments
 (0)