Skip to content

Conversation

@practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Apr 25, 2018

Add compile time checking for ::mempool.cs runtime locking assertions.

This PR is a subset of #12665. The PR was broken up to make reviewing easier.

The intention is that literally all EXCLUSIVE_LOCKS_REQUIRED/LOCKS_EXCLUDED:s added in this PR should follow either directly or indirectly from AssertLockHeld(…)/AssertLockNotHeld(…):s already existing in the repo.

Consider the case where function A(…) contains AssertLockHeld(cs_foo) (without
first locking cs_foo in A), and that B(…) calls A(…) (without first locking cs_main):

  • It directly follows that: A(…) should have an EXCLUSIVE_LOCKS_REQUIRED(cs_foo) annotation.
  • It indirectly follows that: B(…) should have an EXCLUSIVE_LOCKS_REQUIRED(cs_foo) annotation.

Copy link
Member

Choose a reason for hiding this comment

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

All the locks are taken. I don't see why this is necessary.

Copy link
Contributor Author

@practicalswift practicalswift Apr 26, 2018

Choose a reason for hiding this comment

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

@MarcoFalke invalidateblock(…) calls InvalidateBlock(…) without first locking ::mempool.cs. Calling InvalidateBlock(…) requires holding mutex mempool.cs exclusively. Then it follows that calling invalidateblock(…) should require ::mempool.cs too which is what the annotation says? What am I missing? :-)

Copy link
Member

Choose a reason for hiding this comment

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

Calling InvalidateBlock(…) requires holding mutex mempool.cs

Yeah, I looked and it seems all the locks are taken here, which one did I miss?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, sorry. The InvalidateBlock(…) annotation seems incorrect. Thanks!

@practicalswift
Copy link
Contributor Author

@MarcoFalke Updated! Please re-review :-)

@maflcko
Copy link
Member

maflcko commented Apr 26, 2018

utACK 03774eff0e6f5242f02125cecb4d61fa74c00300

Copy link
Contributor

Choose a reason for hiding this comment

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

How'd this slip in here? I'm kinda surprised it even linked with this.

@practicalswift
Copy link
Contributor Author

@TheBlueMatt Thanks! Updated. Please re-review :-)

@maflcko
Copy link
Member

maflcko commented Apr 28, 2018

re-utACK aa8341e3ae934587149dd609b542b21f9cf6017f (Only change was to get rid of unrelated change)

@practicalswift practicalswift changed the title Add compile time checking for all ::mempool.cs runtime locking assertions mempool: Add compile time checking for all ::mempool.cs runtime locking assertions Apr 30, 2018
@TheBlueMatt
Copy link
Contributor

Missing CheckSequenceLocks.

@practicalswift
Copy link
Contributor Author

practicalswift commented May 2, 2018

@TheBlueMatt Given that @MarcoFalke has utACK:ed aa8341e and in light of #13081 (comment), what about adding CheckSequenceLocks(…) (and GetConflicts(…) from #13081) in a follow-up PR post merge where I re-check all the AssertLockHeld(…):s manually? That's OK? :-)

Both CheckSequenceLocks and GetConflicts will require moving stuff around in the header files in order to avoid member access into incomplete types.

@practicalswift practicalswift changed the title mempool: Add compile time checking for all ::mempool.cs runtime locking assertions mempool: Add compile time checking for ::mempool.cs runtime locking assertions May 3, 2018
@maflcko
Copy link
Member

maflcko commented May 5, 2018

re-utACK cbba1d2

@maflcko maflcko merged commit cbba1d2 into bitcoin:master May 5, 2018
maflcko pushed a commit that referenced this pull request May 5, 2018
…time locking assertions

cbba1d2 Add compile time checking for all ::mempool.cs runtime locking assertions (practicalswift)

Pull request description:

  Add compile time checking for `::mempool.cs` runtime locking assertions.

  This PR is a subset of #12665. The PR was broken up to make reviewing easier.

  The intention is that literally all `EXCLUSIVE_LOCKS_REQUIRED`/`LOCKS_EXCLUDED`:s added in this PR should follow either directly or indirectly from `AssertLockHeld(…)`/`AssertLockNotHeld(…)`:s already existing in the repo.

  Consider the case where function `A(…)` contains `AssertLockHeld(cs_foo)` (without
  first locking `cs_foo` in `A`), and that `B(…)` calls `A(…)` (without first locking `cs_main`):
  * It _directly_ follows that: `A(…)` should have an `EXCLUSIVE_LOCKS_REQUIRED(cs_foo)` annotation.
  * It _indirectly_ follows that: `B(…)` should have an `EXCLUSIVE_LOCKS_REQUIRED(cs_foo)` annotation.

Tree-SHA512: 1b5ec1cfca6be67edd1298fea1a52b5572ce833dd4ad05c4583f753c2d3229402663373675df87e950151d5c41aeb3ee02f0ad935ed83fe2f45ca8e4d55d901e
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 27, 2020
….cs runtime locking assertions

cbba1d2 Add compile time checking for all ::mempool.cs runtime locking assertions (practicalswift)

Pull request description:

  Add compile time checking for `::mempool.cs` runtime locking assertions.

  This PR is a subset of bitcoin#12665. The PR was broken up to make reviewing easier.

  The intention is that literally all `EXCLUSIVE_LOCKS_REQUIRED`/`LOCKS_EXCLUDED`:s added in this PR should follow either directly or indirectly from `AssertLockHeld(…)`/`AssertLockNotHeld(…)`:s already existing in the repo.

  Consider the case where function `A(…)` contains `AssertLockHeld(cs_foo)` (without
  first locking `cs_foo` in `A`), and that `B(…)` calls `A(…)` (without first locking `cs_main`):
  * It _directly_ follows that: `A(…)` should have an `EXCLUSIVE_LOCKS_REQUIRED(cs_foo)` annotation.
  * It _indirectly_ follows that: `B(…)` should have an `EXCLUSIVE_LOCKS_REQUIRED(cs_foo)` annotation.

Tree-SHA512: 1b5ec1cfca6be67edd1298fea1a52b5572ce833dd4ad05c4583f753c2d3229402663373675df87e950151d5c41aeb3ee02f0ad935ed83fe2f45ca8e4d55d901e
@practicalswift practicalswift deleted the mempool.cs branch April 10, 2021 19:34
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Mar 16, 2022
….cs runtime locking assertions

cbba1d2 Add compile time checking for all ::mempool.cs runtime locking assertions (practicalswift)

Pull request description:

  Add compile time checking for `::mempool.cs` runtime locking assertions.

  This PR is a subset of bitcoin#12665. The PR was broken up to make reviewing easier.

  The intention is that literally all `EXCLUSIVE_LOCKS_REQUIRED`/`LOCKS_EXCLUDED`:s added in this PR should follow either directly or indirectly from `AssertLockHeld(…)`/`AssertLockNotHeld(…)`:s already existing in the repo.

  Consider the case where function `A(…)` contains `AssertLockHeld(cs_foo)` (without
  first locking `cs_foo` in `A`), and that `B(…)` calls `A(…)` (without first locking `cs_main`):
  * It _directly_ follows that: `A(…)` should have an `EXCLUSIVE_LOCKS_REQUIRED(cs_foo)` annotation.
  * It _indirectly_ follows that: `B(…)` should have an `EXCLUSIVE_LOCKS_REQUIRED(cs_foo)` annotation.

Tree-SHA512: 1b5ec1cfca6be67edd1298fea1a52b5572ce833dd4ad05c4583f753c2d3229402663373675df87e950151d5c41aeb3ee02f0ad935ed83fe2f45ca8e4d55d901e
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 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.

4 participants