Skip to content

Conversation

@ajtowns
Copy link
Contributor

@ajtowns ajtowns commented Sep 18, 2020

This fixes LockAssertion's incorrect line number reporting, with minimal changes.

PR is compared with alternatives in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/AssertLockHeld-PRs

@DrahtBot DrahtBot added the P2P label Sep 18, 2020
@ajtowns ajtowns force-pushed the 202009-lockassertion branch from 39e8f5b to 07ccd1d Compare September 18, 2020 04:43
@ajtowns ajtowns force-pushed the 202009-lockassertion branch from 07ccd1d to df7a0ab Compare September 18, 2020 05:22
Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK df7a0ab

That is an improvement over the current state of affairs.

Feel free to rename LOCK_ASSERTION() to SUPPRESS_THREAD_SAFETY_ANALYSIS_AND_FORCE_THE_COMPILER_TO_THINK_THAT_WE_OWN_THE_MUTEX_HERE().

@ryanofsky
Copy link
Contributor

ryanofsky commented Sep 18, 2020

Code review ACK df7a0ab. Code change looks fine, but I think this is a bad approach for a few reasons:

  • The approach is more complicated than it needs to be. There is no need to have a macro-wrapped fake lock class just to assert a mutex is locked. The ASSERT_CAPABILITY annotation literally exists for this purpose. If you have a can of beans, I'm sure you can probably open it with a hammer and screwdriver, but you are probably better off using the can opener.

  • This is introducing a new macro to do what clang developers specifically told us not to do: "please don't use ACQUIRE when the capability is assumed to be held previously"

  • This change makes LOCK_ASSERTION look like safer alternative to AssertLockHeld when actually it more dangerous (it is not checked at compile time unlike AssertLockHeld). It would be nice if the naming could give an indication of which assert should be preferred. (Of course we can get rid of two asserts with scripted-diff: Restore AssertLockHeld after #19668, remove LockAssertion #19865).

  • Unclear why it's called a "quick fix". It's basically the same size as sync: Replace LockAssertion with AssertLockHeldUnverified #19918 except it has fewer comments and an incomplete description with no stated rationale

@ajtowns
Copy link
Contributor Author

ajtowns commented Sep 19, 2020

Code review ACK df7a0ab. Code change looks fine, but I think this is a bad approach for a few reasons:

* The approach is more complicated than it needs to be. There is no need to have a macro-wrapped fake lock class just to assert a mutex is locked. The ASSERT_CAPABILITY annotation literally exists for this purpose. If you have a can of beans, I'm sure you can probably open it with a hammer and screwdriver, but you are probably better off using the can opener.
* This is introducing a new macro to do what clang developers specifically told us [not to do](https://reviews.llvm.org/D87629#2272676): "please don't use [ACQUIRE](https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#acquire-acquire-shared-release-release-shared-release-generic) when the capability is assumed to be held previously"

Both of those are appropriate justifications for a PR to change the approach. They'd be a valid objection to something that somehow prevents future PRs from changing the approach, but this PR doesn't do that.

* This change makes LOCK_ASSERTION look like safer alternative to AssertLockHeld when actually it more dangerous (it is not checked at compile time unlike AssertLockHeld). It would be nice if the naming could give an indication of which assert should be preferred. (Of course we can get rid of two asserts with #19865).

The developer notes state that using compile-time annotations are to be used consistently, and LOCK_ASSERTION is only to be used when that fails. The implementation of LOCK_ASSERTION as it stands will cause compile errors if you use the wrong assertion. I think you're completely mistaken in thinking LOCK_ASSERTION looks "safer" than "AssertLockHeld".

* Unclear why it's called a "quick fix". It's basically the same size as #19918 except it has fewer comments and an incomplete description with no stated rationale

It's a "fix" because it corrects obviously broken behaviour, and it's "quick" because it leaves the issues where there's debate about what to do them to be addressed elsewhere. This isn't an "alternative" to other approaches as you suggest in your edit to the PR description, it's just a first step.

@maflcko maflcko added Refactoring and removed P2P labels Sep 19, 2020
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK df7a0ab

This doesn't change the use of EXCLUSIVE_LOCK_FUNCTION, which can be changed in independent follow-up prs. This only passes the correct line numbers to AssertLockHeldInternal, which is a fix.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 19, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

@ajtowns
Copy link
Contributor Author

ajtowns commented Sep 24, 2020

No longer relevant

@ajtowns ajtowns closed this Sep 24, 2020
tecnovert added a commit to tecnovert/particl-core that referenced this pull request Oct 21, 2020
Signet
    38332, 38334 -> 31932, 31934
m_onion_service_target_port
    main: 51734, test: 51934, regtest: 51931
sendtoaddress gets new parameter: verbose
    Argument names are enforced.
    Changed functional tests to pass by position instead of by name.
AcceptToMemoryPool returns fee instead of taking absurdfee parameter
OP_CHECKSIGADD
    SCRIPT_VERIFY_TAPROOT in GetBlockScriptFlags
CheckSig renamed to CheckECDSASignature
Replaced PrecomputedTransactionData::m_spent_outputs CTxOut with CTxOutSign
Add walletinitinterface.h to Makefile
CHDWalletDB removed open_mode
Replaced boost::bind in smessage.cpp
Default wallets no longer created
    ParticlTestFramework start_nodes, insert -wallet to extra_args
    functional test extra_args are not being passed anymore
        hasattr in ParticlTestFramework::start_nodes
LockAssertion is gone
    Clang thread analysis can't track mutex aliases, cs_wallet on CWallet is not seen when used through CHDWallet
    Used LOCK_ASSERTION from bitcoin#19970
Converted CODEOWNERS file
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants