aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2013-12-12 08:07:59 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2013-12-19 09:46:11 +0100
commit956916806a932b3502d8a1add410fd393c005df0 (patch)
tree8e7de16c6066e6698966456e93aef0c089b39cec /src/wallet.h
parent19a5676280370148492cf59a5103584cf37893ac (diff)
Document cs_wallet lock and add AssertLockHeld
Add locking assertions to wallet to all methods that access internal fields and do not aquire the cs_wallet mutex.
Diffstat (limited to 'src/wallet.h')
-rw-r--r--src/wallet.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/wallet.h b/src/wallet.h
index 8e879c5e1a..feb5cbf0c7 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -102,6 +102,11 @@ private:
int64_t nLastResend;
public:
+ /// Main wallet lock.
+ /// This lock protects all the fields added by CWallet
+ /// except for:
+ /// fFileBacked (immutable after instantiation)
+ /// strWalletFile (immutable after instantiation)
mutable CCriticalSection cs_wallet;
bool fFileBacked;
@@ -151,10 +156,11 @@ public:
int64_t nTimeFirstKey;
// check whether we are allowed to upgrade (or already support) to the named feature
- bool CanSupportFeature(enum WalletFeature wf) { return nWalletMaxVersion >= wf; }
+ bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL) const;
bool SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const;
+
bool IsLockedCoin(uint256 hash, unsigned int n) const;
void LockCoin(COutPoint& output);
void UnlockCoin(COutPoint& output);
@@ -171,7 +177,7 @@ public:
// Load metadata (used by LoadWallet)
bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata);
- bool LoadMinVersion(int nVersion) { nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
+ bool LoadMinVersion(int nVersion) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
// Adds an encrypted key to the store, and saves it to disk.
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
@@ -320,6 +326,7 @@ public:
unsigned int GetKeyPoolSize()
{
+ AssertLockHeld(cs_wallet); // setKeyPool
return setKeyPool.size();
}
@@ -332,7 +339,7 @@ public:
bool SetMaxVersion(int nVersion);
// get the current wallet format (the oldest client version guaranteed to understand this wallet)
- int GetVersion() { return nWalletVersion; }
+ int GetVersion() { AssertLockHeld(cs_wallet); return nWalletVersion; }
/** Address book entry changed.
* @note called with lock cs_wallet held.