From 6cc4a62c0e696dcb9d90ba0504f688e4f644a10f Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Fri, 26 Aug 2011 14:37:23 -0400 Subject: Fix rpc-hanging deadlocks Collapsed multiple wallet mutexes to a single cs_wallet, to avoid deadlocks with wallet methods that acquired locks in different order. Also change master RPC call handler to acquire cs_main and cs_wallet locks before executing RPC calls; requiring each RPC call to acquire the right set of locks in the right order was too error-prone. --- src/wallet.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/wallet.h') diff --git a/src/wallet.h b/src/wallet.h index 499f2a63ac..032284dd3a 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -20,14 +20,14 @@ private: bool SelectCoins(int64 nTargetValue, std::set >& setCoinsRet, int64& nValueRet) const; CWalletDB *pwalletdbEncryption; - CCriticalSection cs_pwalletdbEncryption; public: + mutable CCriticalSection cs_wallet; + bool fFileBacked; std::string strWalletFile; std::set setKeyPool; - CCriticalSection cs_setKeyPool; typedef std::map MasterKeyMap; MasterKeyMap mapMasterKeys; @@ -47,15 +47,12 @@ public: pwalletdbEncryption = NULL; } - mutable CCriticalSection cs_mapWallet; std::map mapWallet; std::vector vWalletUpdated; std::map mapRequestCount; - mutable CCriticalSection cs_mapRequestCount; std::map mapAddressBook; - mutable CCriticalSection cs_mapAddressBook; std::vector vchDefaultKey; @@ -107,7 +104,7 @@ public: { CBitcoinAddress address; if (ExtractAddress(txout.scriptPubKey, this, address)) - CRITICAL_BLOCK(cs_mapAddressBook) + CRITICAL_BLOCK(cs_wallet) if (!mapAddressBook.count(address)) return true; return false; @@ -171,15 +168,13 @@ public: int LoadWallet(bool& fFirstRunRet); // bool BackupWallet(const std::string& strDest); - // requires cs_mapAddressBook lock bool SetAddressBookName(const CBitcoinAddress& address, const std::string& strName); - // requires cs_mapAddressBook lock bool DelAddressBookName(const CBitcoinAddress& address); void UpdatedTransaction(const uint256 &hashTx) { - CRITICAL_BLOCK(cs_mapWallet) + CRITICAL_BLOCK(cs_wallet) vWalletUpdated.push_back(hashTx); } @@ -187,7 +182,7 @@ public: void Inventory(const uint256 &hash) { - CRITICAL_BLOCK(cs_mapRequestCount) + CRITICAL_BLOCK(cs_wallet) { std::map::iterator mi = mapRequestCount.find(hash); if (mi != mapRequestCount.end()) -- cgit v1.2.3