Skip to content

validation: Add compile-time checking for negative locking requirement in LimitValidationInterfaceQueue - #15971

Merged
maflcko merged 1 commit into
bitcoin:masterfrom
practicalswift:negative-locks
May 8, 2019
Merged

maflcko merged 1 commit into
bitcoin:masterfrom
practicalswift:negative-locks

Conversation

@practicalswift

@practicalswift practicalswift commented May 7, 2019 •

Copy link
Copy Markdown
Contributor

This PR adds compile-time checking for negative locking requirements that follow from the run-time locking requirement AssertLockNotHeld(cs_main) in LimitValidationInterfaceQueue(...).

Changes:

  • Add LOCKS_EXCLUDED(cs_main) to LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main)
  • Add LOCKS_EXCLUDED(cs_main) to CChainState::ActivateBestChain(…), CChainState:: InvalidateBlock(…) and CChainState::RewindBlockIndex(…) which all call LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main)
  • Add LOCKS_EXCLUDED(cs_main) to InvalidateBlock(…) which calls CChainState::InvalidateBlock(...) which in turn calls LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main)
  • Add LOCKS_EXCLUDED(cs_main) to RewindBlockIndex(…) which calls CChainState::RewindBlockIndex(...) which in turn calls LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main)

@practicalswift practicalswift changed the title validation: Add compile-time checking for negative locking requirements in LimitValidationInterfaceQueue validation: Add compile-time checking for negative locking requirement in LimitValidationInterfaceQueue May 7, 2019
@DrahtBot

DrahtBot commented May 7, 2019 •

Copy link
Copy Markdown
Contributor

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #15976 (refactor: move methods under CChainState (pt. 1) by jamesob)
  • #15921 (Tidy up ValidationState interface by jnewbery)
  • #15606 ([experimental] UTXO snapshots by jamesob)

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.

@maflcko

maflcko commented May 7, 2019

Copy link
Copy Markdown
Member

Could squash the 6-line patch into one commit?

…ch does AssertLockNotHeld(cs_main)

Add LOCKS_EXCLUDED(cs_main) to functions calling LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main)

Add LOCKS_EXCLUDED(cs_main) to functions calling CChainState::InvalidateBlock(...) which calls LimitValidationInterfaceQueue(...) which in turn does AssertLockNotHeld(cs_main)

Add LOCKS_EXCLUDED(cs_main) to functions calling CChainState::RewindBlockIndex(...) which calls LimitValidationInterfaceQueue(...) which in turn does AssertLockNotHeld(cs_main)
@practicalswift

Copy link
Copy Markdown
Contributor Author

@MarcoFalke Good idea! Now squashed. Please re-review :-)

@maflcko

maflcko commented May 8, 2019

Copy link
Copy Markdown
Member

utACK 62d50ef

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

utACK 62d50ef308
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUim4Av/RLUDl9SDFcOuGM5cBlpQmyQQKIBgVzKydburyLKhFCm8jnBEELyuercc
dka91GjGW2NCaeHXZInwjKQbuXytrjvdwdt19OW0x1YESGRaKQGiTXzSaTBXXtWd
INHkoIoXR8X0lmMFC6aKv+euGh+ZijHIIUp0xwJym4uOVlEPN4eu0LPg1f43RebC
N+Pu1+WETQZN+slBPMys9+dc7HXq2U2CS3Rim6Jkn/UCbGOnpeq4fDE8SX3v5ZEb
TfT+XZR+tQx4dQk48MmCdNPv/Ey+81B2h8ceNkcZTNcz/NJ6qs+ozqOw54LHuEEK
Eb9pLOnvyR2ilhSVZZ4Cpu6UZxexYqaiByIXUj7zeuj5HSqEAh/fncTI974NvxNB
qGvKFDIIbu6RWVlgNucp5G83OOHti8qhniPkmiBNYqfmDckeWae/l/S8ana7sEP1
Ou1eUp1h1jbEoxc96/vdeEIbaUrCxzyr2qhIZcvUQxfYJ2m8wD5ADAkhSsYZoNHZ
E0YHdHaq
=66rs
-----END PGP SIGNATURE-----

Timestamp of file with hash bda0ebcaa8c906a633271bd3b89c8167474a1a46bfec01511af80cc4bb5a4bb5 -

@maflcko
maflcko merged commit 62d50ef into bitcoin:master May 8, 2019
maflcko pushed a commit that referenced this pull request May 8, 2019
…ing requirement in LimitValidationInterfaceQueue

62d50ef Add LOCKS_EXCLUDED(cs_main) to LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main) (practicalswift)

Pull request description:

  This PR adds compile-time checking for negative locking requirements that follow from the run-time locking requirement `AssertLockNotHeld(cs_main)` in `LimitValidationInterfaceQueue(...)`.

  Changes:
  * Add `LOCKS_EXCLUDED(cs_main)` to `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `CChainState::ActivateBestChain(…)`, `CChainState:: InvalidateBlock(…)` and `CChainState::RewindBlockIndex(…)` which all call `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `InvalidateBlock(…)` which calls `CChainState::InvalidateBlock(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which  does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `RewindBlockIndex(…)` which calls `CChainState::RewindBlockIndex(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`

ACKs for commit 62d50e:
  MarcoFalke:
    utACK 62d50ef

Tree-SHA512: 73d092ccd08c851ae3c5d60370c369fc030c5793f5507e2faccb6f91c851ddc0ce059fbea3899f2856330d7a8c78f2ac6a2988e8268b03154f946be9e60e3be1
@jamesob

jamesob commented May 8, 2019

Copy link
Copy Markdown
Contributor

This causes a warning during compilation because we call ABC here with cs_main held: https://github.com/bitcoin/bitcoin/blob/master/src/validation.cpp#L3953-L3962

@maflcko

maflcko commented May 8, 2019

Copy link
Copy Markdown
Member

@jamesob This issue is reported in

jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 14, 2020
Summary:
Upcoming Core [[bitcoin/bitcoin#15971 | PR15971]] requires InvalidateBlock to not hold cs_main lock. Currently the function FinalizeBlockAndInvalidate does both things, requires cs_main to be locked and has only one callsite (FinalizeBlock RPC method)

This diff extracts the RPC method exclusive functionality and refactors FinalizeBlockAndInvalidate to FinalizeBlock, requiring cs_main to be held while allowing for the upcoming diff to move the InvalidateBlock call outside the scope of the lock.

Test Plan:
  ninja check-all

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D6861
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Aug 21, 2020
…ocking requirement in LimitValidationInterfaceQueue

Summary:
62d50ef308 Add LOCKS_EXCLUDED(cs_main) to LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main) (practicalswift)

Pull request description:

  This PR adds compile-time checking for negative locking requirements that follow from the run-time locking requirement `AssertLockNotHeld(cs_main)` in `LimitValidationInterfaceQueue(...)`.

  Changes:
  * Add `LOCKS_EXCLUDED(cs_main)` to `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `CChainState::ActivateBestChain(…)`, `CChainState:: InvalidateBlock(…)` and `CChainState::RewindBlockIndex(…)` which all call `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `InvalidateBlock(…)` which calls `CChainState::InvalidateBlock(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which  does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `RewindBlockIndex(…)` which calls `CChainState::RewindBlockIndex(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`

---

Depends on D7213

Backport of Core [[bitcoin/bitcoin#15971 | PR15971]]

Test Plan:
  cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug
  ninja check && ninja check-functional

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D6940
@practicalswift
practicalswift deleted the negative-locks branch April 10, 2021 19:38
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Oct 29, 2021
…ve locking requirement in LimitValidationInterfaceQueue

62d50ef Add LOCKS_EXCLUDED(cs_main) to LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main) (practicalswift)

Pull request description:

  This PR adds compile-time checking for negative locking requirements that follow from the run-time locking requirement `AssertLockNotHeld(cs_main)` in `LimitValidationInterfaceQueue(...)`.

  Changes:
  * Add `LOCKS_EXCLUDED(cs_main)` to `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `CChainState::ActivateBestChain(…)`, `CChainState:: InvalidateBlock(…)` and `CChainState::RewindBlockIndex(…)` which all call `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `InvalidateBlock(…)` which calls `CChainState::InvalidateBlock(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which  does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `RewindBlockIndex(…)` which calls `CChainState::RewindBlockIndex(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`

ACKs for commit 62d50e:
  MarcoFalke:
    utACK 62d50ef

Tree-SHA512: 73d092ccd08c851ae3c5d60370c369fc030c5793f5507e2faccb6f91c851ddc0ce059fbea3899f2856330d7a8c78f2ac6a2988e8268b03154f946be9e60e3be1
pravblockc pushed a commit to pravblockc/dash that referenced this pull request Nov 18, 2021
…ve locking requirement in LimitValidationInterfaceQueue

62d50ef Add LOCKS_EXCLUDED(cs_main) to LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main) (practicalswift)

Pull request description:

  This PR adds compile-time checking for negative locking requirements that follow from the run-time locking requirement `AssertLockNotHeld(cs_main)` in `LimitValidationInterfaceQueue(...)`.

  Changes:
  * Add `LOCKS_EXCLUDED(cs_main)` to `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `CChainState::ActivateBestChain(…)`, `CChainState:: InvalidateBlock(…)` and `CChainState::RewindBlockIndex(…)` which all call `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `InvalidateBlock(…)` which calls `CChainState::InvalidateBlock(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which  does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `RewindBlockIndex(…)` which calls `CChainState::RewindBlockIndex(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`

ACKs for commit 62d50e:
  MarcoFalke:
    utACK 62d50ef

Tree-SHA512: 73d092ccd08c851ae3c5d60370c369fc030c5793f5507e2faccb6f91c851ddc0ce059fbea3899f2856330d7a8c78f2ac6a2988e8268b03154f946be9e60e3be1
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 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