Skip to content

Commit

Permalink
Merge bitcoin#15365: wallet: Add lock annotation for mapAddressBook
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MarcoFalke committed Feb 8, 2019
2 parents 30495d1 + faa4647 commit 0206956
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class WalletImpl : public Wallet
}
std::vector<std::string> getDestValues(const std::string& prefix) override
{
LOCK(m_wallet.cs_wallet);
return m_wallet.GetDestValues(prefix);
}
void lockCoin(const COutPoint& output) override
Expand Down
1 change: 1 addition & 0 deletions src/qt/test/addressbooktests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void TestAddAddressesToSendBook()
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static std::string DecodeDumpString(const std::string &str) {
return ret.str();
}

static bool GetWalletAddressesForKey(CWallet * const pwallet, const CKeyID &keyid, std::string &strAddr, std::string &strLabel)
static bool GetWalletAddressesForKey(CWallet* const pwallet, const CKeyID& keyid, std::string& strAddr, std::string& strLabel) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
{
bool fLabelFound = false;
CKey key;
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
* @param filter_ismine The "is mine" filter flags.
* @param filter_label Optional label string to filter incoming transactions.
*/
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)
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)
{
CAmount nFee;
std::list<COutputEntry> listReceived;
Expand Down
5 changes: 2 additions & 3 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3172,7 +3172,7 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
{
bool fUpdated = false;
{
LOCK(cs_wallet); // mapAddressBook
LOCK(cs_wallet);
std::map<CTxDestination, CAddressBookData>::iterator mi = mapAddressBook.find(address);
fUpdated = mi != mapAddressBook.end();
mapAddressBook[address].name = strName;
Expand All @@ -3189,7 +3189,7 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
bool CWallet::DelAddressBook(const CTxDestination& address)
{
{
LOCK(cs_wallet); // mapAddressBook
LOCK(cs_wallet);

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

std::vector<std::string> CWallet::GetDestValues(const std::string& prefix) const
{
LOCK(cs_wallet);
std::vector<std::string> values;
for (const auto& address : mapAddressBook) {
for (const auto& data : address.second.destdata) {
Expand Down
14 changes: 7 additions & 7 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
uint64_t nAccountingEntryNumber = 0;

std::map<CTxDestination, CAddressBookData> mapAddressBook;
std::map<CTxDestination, CAddressBookData> mapAddressBook GUARDED_BY(cs_wallet);

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

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

//! 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);
bool AddDestData(const CTxDestination& dest, const std::string& key, 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);
void LoadDestData(const CTxDestination& dest, const std::string& key, 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;
bool GetDestData(const CTxDestination& dest, const std::string& key, std::string* value) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
//! Get all destination values matching a prefix.
std::vector<std::string> GetDestValues(const std::string& prefix) const;
std::vector<std::string> 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) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
Expand Down Expand Up @@ -1041,7 +1041,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface

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<CReserveScript> &script);

Expand Down
1 change: 0 additions & 1 deletion src/wallet/wallettool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ static std::shared_ptr<CWallet> LoadWallet(const std::string& name, const fs::pa

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

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

0 comments on commit 0206956

Please sign in to comment.