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
commented at 4:08 pm on November 8, 2017:
Now moved before the line above. Without that lock we’ll trigger Clang thread safety analysis warnings when #11634 is merged due to:
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!).
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?
practicalswift
commented at 9:55 pm on November 8, 2017:
Yes, you’re right - the annotations are added in #11226 :-)
practicalswift force-pushed
on Nov 8, 2017
promag
commented at 8:36 pm on November 8, 2017:
member
utACK007fcbf.
luke-jr referenced this in commit
a6b3c637e6
on Nov 11, 2017
practicalswift force-pushed
on Nov 21, 2017
practicalswift
commented at 4:58 pm on November 21, 2017:
contributor
Added another commit with two more missing locks:
calling function IsSpent requires holding mutex pwallet->cs_wallet exclusively
in
src/wallet/wallet.cpp:4283
in
fba0830bcaoutdated
3995@@ -3991,8 +3996,11 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
39963997 // No need to read and scan block if block was created before
3998 // our wallet birthday (as adjusted for block time variability)
3999- while (pindexRescan && walletInstance->nTimeFirstKey && (pindexRescan->GetBlockTime() < (walletInstance->nTimeFirstKey - TIMESTAMP_WINDOW))) {
4000- pindexRescan = chainActive.Next(pindexRescan);
4001+ {
4002+ LOCK(walletInstance->cs_wallet);
TheBlueMatt
commented at 10:38 pm on December 12, 2017:
Given this is effectively just the wallet’s constructor, might as well just take the lock further up and hold it the whole time.
@TheBlueMatt Moving it further up will make the scope of the walletInstance->cs_wallet lock cover the ScanForWalletTransactions call. ScanForWalletTransactions locks cs_main giving us the lock order:
cs_wallet
cs_main
This is a potential deadlock given that the opposite lock order is used extensively:
practicalswift
commented at 1:27 pm on March 10, 2018:
contributor
@MarcoFalke@TheBlueMatt@promag Thanks for reviewing. I’ve now addressed the feedback and added corresponding GUARDED_BY/EXCLUSIVE_LOCKS_REQUIRED annotations. Please re-review :-)
in
src/wallet/wallet.cpp:3900
in
8dcfcb265doutdated
MarcoFalke
commented at 10:12 pm on March 11, 2018:
Note that LoadWallet takes LOCK2(cs_main, cs_wallet), so taking cs_wallet before cs_main leads to a deadlock in case another thread takes cs_main and then cs_wallet, no?
@promag I think I’m unable to resolve this. Are you able to make this work with EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) on CWalletTx::GetAvailableCredit when compiling with Clang’s thread-safety analysis enabled?
MarcoFalke
commented at 1:10 pm on August 13, 2018:
Agree with @promag . We wouldn’t want to add LOCKs just to please a static analyser that isn’t smart enough to figure out the lock is already taken.
in
src/wallet/wallet.cpp:1990
in
ce156e6653outdated
@promag See above. In theory you’re right, but I’ve been unable to convince Clang’s thread-safety analysis that so is the case in practice. See comment above. I might need some help here :-)
sipa
commented at 0:49 am on March 15, 2018:
member
Concept ACK
practicalswift force-pushed
on Mar 23, 2018
practicalswift force-pushed
on Mar 29, 2018
practicalswift force-pushed
on Apr 9, 2018
practicalswift force-pushed
on Apr 9, 2018
practicalswift
commented at 1:22 pm on April 9, 2018:
contributor
Rebased!
in
src/wallet/wallet.h:711
in
83d2186da4outdated
707@@ -708,7 +708,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
708 int64_t m_max_keypool_index = 0;
709 std::map<CKeyID, int64_t> m_pool_key_to_index;
710711- int64_t nTimeFirstKey = 0;
712+ int64_t nTimeFirstKey GUARDED_BY(cs_wallet);
Ouch, that was not the intention. Now fixed. Thanks for noticing. Please re-review.
practicalswift force-pushed
on Apr 9, 2018
practicalswift force-pushed
on Apr 9, 2018
practicalswift
commented at 10:58 pm on April 9, 2018:
contributor
Rebased!
practicalswift force-pushed
on May 5, 2018
in
src/wallet/wallet.cpp:322
in
0c6f50067doutdated
318@@ -319,7 +319,7 @@ bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigne
319 * Update wallet first key creation time. This should be called whenever keys
320 * are added to the wallet, with the oldest key creation time.
321 */
322-void CWallet::UpdateTimeFirstKey(int64_t nCreateTime)
323+void CWallet::UpdateTimeFirstKey(int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
0In file included from wallet/feebumper.cpp:6:
1In file included from ./wallet/coincontrol.h:11:
2./wallet/wallet.h:496:76: error: member access into incomplete type 'const CWallet'3 std::set<uint256> GetConflicts() const EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet);
4^
0wallet/wallet.cpp:1874:27: error: calling function 'GetConflicts' requires holding mutex 'pwallet->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis]
1 result = pwallet->GetConflicts(myHash);
2 ^
practicalswift
commented at 12:53 pm on June 6, 2018:
contributor
@MarcoFalke Another alternative could be to add NO_THREAD_SAFETY_ANALYSIS here to disable the analysis locally.
What would you suggest as the recommended way to proceed?
MarcoFalke
commented at 1:11 pm on June 6, 2018:
member
@practicalswift I like your latest suggestion (NO_THREAD_SAFETY_ANALYSIS). Make sure to include a comment to explain this is only temporary. Also, explain that this is safe to do, since we have a run-time AssertLockHeld in place.
practicalswift force-pushed
on Jun 6, 2018
practicalswift force-pushed
on Jun 6, 2018
practicalswift force-pushed
on Jun 6, 2018
practicalswift force-pushed
on Jun 6, 2018
practicalswift force-pushed
on Jun 6, 2018
practicalswift
commented at 3:16 pm on June 6, 2018:
contributor
@MarcoFalke Good point! Added and documented NO_THREAD_SAFETY_ANALYSIS. Please review :-)
practicalswift force-pushed
on Jul 11, 2018
practicalswift
commented at 11:33 pm on July 11, 2018:
contributor
Rebased!
DrahtBot added the label
Needs rebase
on Jul 14, 2018
practicalswift force-pushed
on Jul 15, 2018
practicalswift force-pushed
on Jul 15, 2018
practicalswift
commented at 7:53 am on July 16, 2018:
contributor
Rebased!
DrahtBot removed the label
Needs rebase
on Jul 16, 2018
practicalswift force-pushed
on Jul 20, 2018
DrahtBot added the label
Needs rebase
on Jul 24, 2018
practicalswift force-pushed
on Aug 1, 2018
practicalswift
commented at 8:33 am on August 1, 2018:
contributor
Rebased!
DrahtBot removed the label
Needs rebase
on Aug 1, 2018
practicalswift force-pushed
on Aug 6, 2018
practicalswift
commented at 4:16 pm on August 6, 2018:
contributor
Rebased!
practicalswift force-pushed
on Aug 13, 2018
practicalswift
commented at 10:47 am on August 13, 2018:
contributor
Rebase number eight performed! :-)
practicalswift force-pushed
on Aug 25, 2018
practicalswift
commented at 10:44 pm on August 25, 2018:
contributor
Rebased!
practicalswift force-pushed
on Aug 26, 2018
practicalswift force-pushed
on Aug 26, 2018
practicalswift force-pushed
on Aug 26, 2018
practicalswift
commented at 3:41 pm on August 26, 2018:
contributor
DrahtBot
commented at 1:30 pm on September 21, 2018:
member
#14498 (rpcwallet: listsentbyaddress RPC by mrwhythat)
#14437 (Refactor: Start to separate wallet from node by ryanofsky)
#14144 (Refactoring: Clarify code using encrypted_batch in CWallet by domob1812)
#13756 (wallet: -avoidreuse feature for improved privacy by kallewoof)
#9381 (Remove CWalletTx merging logic from AddToWallet by ryanofsky)
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Add GUARDED_BY(cs_wallet) for encrypted_batch, nWalletMaxVersion, m_max_keypool_index and nOrderPosNext
* AddKeyPubKeyWithDB(...) reads encrypted_batch which potentially races with write in the same method.
* IncOrderPosNext(...) reads nOrderPosNext which potentially races with write in BlockDisconnected(...).
* LoadKeyPool(...) reads m_max_keypool_index which potentially races with write in BlockDisconnected(...).
* LoadMinVersion(...) reads nWalletMaxVersion which potentially races with write in BlockDisconnected(...).
37b2538c2d
practicalswift force-pushed
on Oct 9, 2018
practicalswift
commented at 10:19 am on October 9, 2018:
contributor
Updated!
Added GUARDED_BY(cs_wallet) annotations also for encrypted_batch, nWalletMaxVersion, m_max_keypool_index and nOrderPosNext.
Rationale:
AddKeyPubKeyWithDB(...) reads encrypted_batch which potentially races with write in the same method
IncOrderPosNext(...) reads nOrderPosNext which potentially races with write in BlockDisconnected(...)
LoadKeyPool(...) reads m_max_keypool_index which potentially races with write in BlockDisconnected(...)
LoadMinVersion(...) reads nWalletMaxVersion which potentially races with write in BlockDisconnected(...)
Please review :-)
practicalswift
commented at 12:00 pm on October 9, 2018:
contributor
Added GUARDED_BY(cs_wallet) for setExternalKeyPool, mapKeyMetadata, m_script_metadata and setLockedCoins.
MarcoFalke
commented at 8:52 am on October 24, 2018:
member
utACK69e7ee2dd8173597e766262fd9a8caae569ddf5e
MarcoFalke referenced this in commit
e895fdc9fc
on Oct 24, 2018
MarcoFalke merged this
on Oct 24, 2018
MarcoFalke closed this
on Oct 24, 2018
in
src/wallet/wallet.cpp:4096
in
69e7ee2dd8
4092@@ -4093,7 +4093,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(const std::string& name,
4093 // Try to top up keypool. No-op if the wallet is locked.
4094 walletInstance->TopUpKeyPool();
40954096- LOCK(cs_main);
4097+ LOCK2(cs_main, walletInstance->cs_wallet);
I think that currently there is no harm in calling uiInterface.LoadWallet() with the lock held but if it’s not necessary then I wouldn’t change that. The diff looks ok.
promag
commented at 9:09 am on October 24, 2018:
member
utACK69e7ee2.
LarryRuane referenced this in commit
e1c6c472e9
on Apr 5, 2021
LarryRuane referenced this in commit
d5439c7386
on Apr 5, 2021
LarryRuane referenced this in commit
affdf23507
on Apr 5, 2021
LarryRuane referenced this in commit
ed497c99af
on Apr 5, 2021
practicalswift deleted the branch
on Apr 10, 2021
LarryRuane referenced this in commit
b2cdcd07c1
on Apr 29, 2021
LarryRuane referenced this in commit
a0df9acb00
on Apr 29, 2021
LarryRuane referenced this in commit
10f07f2ad1
on Apr 29, 2021
LarryRuane referenced this in commit
973d009148
on Apr 29, 2021
LarryRuane referenced this in commit
20ce9cce7e
on Jun 1, 2021
LarryRuane referenced this in commit
12a307c6e1
on Jun 1, 2021
LarryRuane referenced this in commit
96b1669b6d
on Jun 1, 2021
LarryRuane referenced this in commit
4bae811116
on Jun 1, 2021
PastaPastaPasta referenced this in commit
dab5cfb8ca
on Jul 17, 2021
gades referenced this in commit
a188a9ea87
on May 31, 2022
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2024-11-17 06:12 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me