This adds missing LockAnnotation lock(::cs_main); to src/interfaces/chain.cpp (as well as tests and benchmarks)
[refactor] interfaces: Add missing LockAnnotation for cs_main #15855
pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:1904-interfacesLock changing 11 files +55 −20-
MarcoFalke commented at 4:40 PM on April 19, 2019: member
- MarcoFalke added the label Refactoring on Apr 19, 2019
- MarcoFalke force-pushed on Apr 19, 2019
-
DrahtBot commented at 5:43 PM on April 19, 2019: member
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #15931 (Remove GetDepthInMainChain dependency on locked chain interface by ariard)
- #15921 (Tidy up ValidationState interface by jnewbery)
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.
- MarcoFalke force-pushed on Apr 19, 2019
-
in src/wallet/test/wallet_tests.cpp:250 in fa90b1a2e1 outdated
245 | @@ -245,9 +246,11 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) 246 | BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup) 247 | { 248 | auto chain = interfaces::MakeChain(); 249 | + LockAnnotation lock(::cs_main); 250 | + auto locked_chain = chain->lock();
promag commented at 10:50 PM on April 21, 2019:Why was this moved?
in src/test/txvalidationcache_tests.cpp:80 in fa90b1a2e1 outdated
78 | - BOOST_CHECK(chainActive.Tip()->GetBlockHash() != block.GetHash()); 79 | - mempool.clear(); 80 | + { 81 | + LOCK(cs_main); 82 | + BOOST_CHECK(chainActive.Tip()->GetBlockHash() != block.GetHash()); 83 | + mempool.clear();
promag commented at 10:52 PM on April 21, 2019:This gives the bad impression
cs_mainis necessary.promag commented at 10:53 PM on April 21, 2019: memberConcept ACK.
MarcoFalke force-pushed on Apr 22, 2019MarcoFalke commented at 1:08 PM on April 22, 2019: memberAddressed feedback by @promag
MarcoFalke force-pushed on May 1, 2019MarcoFalke force-pushed on May 1, 2019DrahtBot added the label Needs rebase on May 7, 2019MarcoFalke force-pushed on May 7, 2019practicalswift commented at 4:30 PM on May 7, 2019: contributorConcept ACK
MarcoFalke force-pushed on May 7, 2019DrahtBot removed the label Needs rebase on May 7, 2019MarcoFalke force-pushed on May 10, 2019MarcoFalke force-pushed on May 10, 2019promag commented at 3:04 PM on May 13, 2019: memberutACK face05a080c081fc426ff34ecb39ac072710034b.
in src/wallet/test/wallet_tests.cpp:40 in face05a080 outdated
36 | @@ -37,14 +37,14 @@ static void AddKey(CWallet& wallet, const CKey& key) 37 | BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup) 38 | { 39 | auto chain = interfaces::MakeChain(); 40 | + LockAnnotation lock(::cs_main);
practicalswift commented at 4:47 PM on May 13, 2019:I might be missing something but shouldn't
LockAnnotationbe used only when we are holding the mutex but the compiler thread analysis doesn't understand it? In this case we aren't holdingcs_mainhere, right?If it is used simply to opt-out of thread-safety analysis (when we are not holding the mutex) then
NO_THREAD_SAFETY_ANALYSISshould be used, no?
MarcoFalke commented at 4:51 PM on May 13, 2019:The tests are single threaded, so taking a lock is equivalent to pretending it is taken.
Not sure how I can use
NO_THREAD_SAFETY_ANALYSISto achieve that.
practicalswift commented at 5:04 PM on May 13, 2019:Yes, I know the tests are single-threaded but I think it might be confusing for newcomers if we use
LockAnnotationto both a.) guarantee to the compiler that the lock is taken (like insrc/interfaces/chain.cpp), and b.) to opt-out of thread safety analysis when the lock is not taken (like in this file).Just to make it crystal clear to readers what we are doing we could use different names for these two use-cases? (If using
NO_THREAD_SAFETY_ANALYSISis not an option.)Something like
struct SCOPED_LOCKABLE DisableThreadSafetyAnalysis(likeLockAnnotation) or#define DISABLE_THREAD_SAFETY_ANALYSIS(cs, code) [&] NO_THREAD_SAFETY_ANALYSIS { code; }()(likeWITH_LOCK)?
MarcoFalke commented at 5:33 PM on May 13, 2019:Added a comment instead. Is that fine?
MarcoFalke force-pushed on May 13, 2019practicalswift commented at 6:30 PM on May 13, 2019: contributor@MarcoFalke The added comment makes it easier to understand for human reviewers. That is good, but I still think we would be better off if we used different annotations for the "opt-out of analysis" and "give the compiler a locking guarantee when it fails to understand our code" use cases:
When analysing locks using static analysis etc I want to be able to let
LockAnnotationimply the stronger "AssertLockHeld(…)" (instead of the weakerNO_THREAD_SAFETY_ANALYSIS).This change breaks that implication.
Perhaps
--enable-debugbuilds should doAssertLockHeld(…)as part of theLockAnnotationctor to make sure theLockAnnotationguarantees hold up over time? The opt-out variant shouldn't have that (obviously) :-)[refactor] interfaces: Add missing LockAnnotation for cs_main fa3c651143MarcoFalke force-pushed on May 13, 2019MarcoFalke commented at 6:47 PM on May 13, 2019: memberPerhaps --enable-debug builds should do AssertLockHeld(…) as part of the LockAnnotationctor to make sure the LockAnnotation guarantees hold up over time
Sounds good. I have addressed your concerns, but this suggestion should go into a follow-up pull request?
ryanofsky approvedryanofsky commented at 8:15 PM on May 13, 2019: memberutACK fa3c6511435149782545ac0d09d4722dc115d709
practicalswift commented at 5:25 AM on May 14, 2019: contributorutACK fa3c6511435149782545ac0d09d4722dc115d709
MarcoFalke merged this on May 14, 2019MarcoFalke closed this on May 14, 2019MarcoFalke referenced this in commit 40c66bb3d1 on May 14, 2019MarcoFalke deleted the branch on May 14, 2019deadalnix referenced this in commit 0ae0f30d6b on May 27, 2020kittywhiskers referenced this in commit a723fa65fb on Oct 21, 2021kittywhiskers referenced this in commit 02c1f4324e on Oct 21, 2021kittywhiskers referenced this in commit 004979b67e on Oct 21, 2021kittywhiskers referenced this in commit f5fbcdc2f7 on Oct 21, 2021kittywhiskers referenced this in commit 9d091af9db on Oct 21, 2021kittywhiskers referenced this in commit 07ee416e5e on Oct 24, 2021UdjinM6 referenced this in commit f1a2cdb680 on Oct 25, 2021PastaPastaPasta referenced this in commit 6c681a3685 on Oct 25, 2021PastaPastaPasta referenced this in commit 462e9b826c on Nov 1, 2021PastaPastaPasta referenced this in commit e7d6a8fb93 on Nov 1, 2021PastaPastaPasta referenced this in commit 38b2bfa29c on Nov 1, 2021PastaPastaPasta referenced this in commit 0bc782dfcb on Nov 3, 2021pravblockc referenced this in commit aaee20b769 on Nov 18, 2021pravblockc referenced this in commit ff1be08588 on Nov 18, 2021DrahtBot locked this on Dec 16, 2021ContributorsLabels
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: 2026-04-17 06:14 UTC
More mirrored repositories can be found on mirror.b10c.me