Skip to content

Commit 5ba77df

Browse files
author
MarcoFalke
committed
Merge #13114: wallet/keystore: Add Clang thread safety annotations for variables guarded by cs_KeyStore
968b76f Add missing cs_KeyStore lock (practicalswift) 4bcd5bb Add locking annotations for variables guarded by cs_KeyStore (practicalswift) Pull request description: * Add Clang thread safety annotations for variables guarded by `cs_KeyStore` * Add missing `cs_KeyStore` lock Tree-SHA512: 7d93513c2da0cd564b9f1e75aa5156a454a4133eb845020fde8872e685dd5758353e93c33364aeea4a812c08353a810494e503a5ce160cc5be0af5af4bb2e6d7
2 parents e538a95 + 968b76f commit 5ba77df

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/keystore.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ class CBasicKeyStore : public CKeyStore
4949
protected:
5050
mutable CCriticalSection cs_KeyStore;
5151

52-
KeyMap mapKeys;
53-
WatchKeyMap mapWatchKeys;
54-
ScriptMap mapScripts;
55-
WatchOnlySet setWatchOnly;
52+
KeyMap mapKeys GUARDED_BY(cs_KeyStore);
53+
WatchKeyMap mapWatchKeys GUARDED_BY(cs_KeyStore);
54+
ScriptMap mapScripts GUARDED_BY(cs_KeyStore);
55+
WatchOnlySet setWatchOnly GUARDED_BY(cs_KeyStore);
5656

5757
void ImplicitlyLearnRelatedKeyScripts(const CPubKey& pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
5858

src/wallet/crypter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class CCryptoKeyStore : public CBasicKeyStore
116116
{
117117
private:
118118

119-
CKeyingMaterial vMasterKey;
119+
CKeyingMaterial vMasterKey GUARDED_BY(cs_KeyStore);
120120

121121
//! if fUseCrypto is true, mapKeys must be empty
122122
//! if fUseCrypto is false, vMasterKey must be empty
@@ -132,7 +132,7 @@ class CCryptoKeyStore : public CBasicKeyStore
132132
bool EncryptKeys(CKeyingMaterial& vMasterKeyIn);
133133

134134
bool Unlock(const CKeyingMaterial& vMasterKeyIn);
135-
CryptedKeyMap mapCryptedKeys;
135+
CryptedKeyMap mapCryptedKeys GUARDED_BY(cs_KeyStore);
136136

137137
public:
138138
CCryptoKeyStore() : fUseCrypto(false), fDecryptionThoroughlyChecked(false)

src/wallet/wallet.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,8 +3168,11 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
31683168
}
31693169
}
31703170

3171-
// This wallet is in its first run if all of these are empty
3172-
fFirstRunRet = mapKeys.empty() && mapCryptedKeys.empty() && mapWatchKeys.empty() && setWatchOnly.empty() && mapScripts.empty();
3171+
{
3172+
LOCK(cs_KeyStore);
3173+
// This wallet is in its first run if all of these are empty
3174+
fFirstRunRet = mapKeys.empty() && mapCryptedKeys.empty() && mapWatchKeys.empty() && setWatchOnly.empty() && mapScripts.empty();
3175+
}
31733176

31743177
if (nLoadWalletRet != DBErrors::LOAD_OK)
31753178
return nLoadWalletRet;

0 commit comments

Comments
 (0)