Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
wallet: Add missing cs_wallet/cs_KeyStore locks to wallet #11634
Conversation
fanquake
added
the
Wallet
label
Nov 8, 2017
| @@ -3953,6 +3960,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile) | ||
| for (const CWalletTx& wtxOld : vWtx) | ||
| { | ||
| uint256 hash = wtxOld.GetHash(); | ||
| + LOCK(walletInstance->cs_wallet); |
promag
Nov 8, 2017
Contributor
Either:
- lock once before the loop;
- loop first with the lock to
mapWallet.find(hash)for allvWtxand then loop again without the lock towalletdb.WriteTx(); - lock only the mapWallet.find(hash).
|
@promag Thanks for reviewing! Feedback addressed. Looks good? :-) |
| @@ -3950,6 +3957,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile) | ||
| { | ||
| CWalletDB walletdb(*walletInstance->dbw); | ||
| + LOCK(walletInstance->cs_wallet); |
promag
Nov 8, 2017
Contributor
This should be before the line above. Anyway, there is no need to lock this wallet since it's a fresh instance, unknown to the remaining system. Unless you are adding the lock because of other asserts and if so please commit them to justify this change?
practicalswift
Nov 8, 2017
•
Contributor
Now moved before the line above. Without that lock we'll trigger Clang thread safety analysis warnings when #11634 is merged due to:
src/wallet/wallet.h: std::map<uint256, CWalletTx> mapWallet GUARDED_BY(cs_wallet);
As agreed upon in #11226 (comment) all guard/lock annotations are added in #11634 and all extra locking is submitted as separate PR:s (such as this one).
The annotations are compile-time only whereas the locks change run-time behaviour (and thus needs extra scrunity!).
promag
Nov 8, 2017
Contributor
As agreed upon in #11226 (comment) all guard/lock annotations are added in #11634 and all extra locking is submitted as separate PR:s (such as this one)
I think you swapped the PR numbers?
|
utACK 007fcbf. |
ryanofsky
referenced this pull request
Nov 10, 2017
Open
[WIP] Add Clang thread safety analysis annotations: GUARDED_BY(lock) / EXCLUSIVE_LOCKS_REQUIRED(lock) #11226
added a commit
to bitcoinknots/bitcoin
that referenced
this pull request
Nov 11, 2017
practicalswift
added some commits
Nov 8, 2017
|
Added another commit with two more missing locks:
|
|
@promag Would you mind re-reviewing? :-) |
practicalswift commentedNov 8, 2017
•
Edited 2 times
-
practicalswift
Nov 8, 2017
-
practicalswift
Nov 8, 2017
Add missing
cs_wallet/cs_KeyStorelocks to wallet:mapTxSpendsandmapWallet(via theIsSpent(...)call) require holding the mutexcs_wallet.mapKeysandmapCryptedKeysrequire holding the mutexcs_KeyStore.nTimeFirstKeyrequires holding the mutexcs_wallet.mapWalletrequires holding the mutexcs_wallet.