0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-04 10:07:27 -05:00
bitcoin-bitcoin-core/src/rpc
laanwj cf5bb048e8
Merge bitcoin/bitcoin#22932: Add CBlockIndex lock annotations, guard nStatus/nFile/nDataPos/nUndoPos by cs_main
6ea5682784 Guard CBlockIndex::nStatus/nFile/nDataPos/nUndoPos by cs_main (Jon Atack)
5d59ae0ba8 Remove/inline ReadRawBlockFromDisk(block_data, pindex, message_start) (Hennadii Stepanov)
eaeeb88768 Require IsBlockPruned() to hold mutex cs_main (Jon Atack)
ca47b00577 Require CBlockIndex::IsValid() to hold cs_main (Vasil Dimov)
e9f3aa5f6a Require CBlockIndex::RaiseValidity() to hold cs_main (Vasil Dimov)
8ef457cb83 Require CBlockIndex::IsAssumedValid() to hold cs_main (Vasil Dimov)
572393448b Require CBlockIndex::GetUndoPos() to hold mutex cs_main (Jon Atack)
2e557ced28 Require WriteUndoDataForBlock() to hold mutex cs_main (Jon Atack)
6fd4341c10 Require CBlockIndex::GetBlockPos() to hold mutex cs_main (Jon Atack)

Pull request description:

  Issues:

  - `CBlockIndex` member functions `GetBlockPos()`, `GetUndoPos()`, `IsAssumedValid()`, `RaiseValidity()`, and `IsValid()` and block storage functions `WriteUndoDataForBlock()` and `IsBlockPruned()` are missing thread safety lock annotations to help ensure that they are called with mutex cs_main to avoid bugs like #22895. Doing this also enables the next step:

  - `CBlockIndex::nStatus` may be racy, i.e. potentially accessed by multiple threads, see #17161. A solution is to guard it by cs_main, along with fellow data members `nFile`, `nDataPos` and `nUndoPos`.

  This pull:

  - adds thread safety lock annotations for the functions listed above
  - guards `CBlockIndex::nStatus`, `nFile`, `nDataPos` and `nUndoPos` by cs_main

  How to review and test:
  - debug build with clang and verify there are no `-Wthread-safety-analysis` warnings
  - review the code to verify each annotation or lock is necessary and sensible, or if any are missing
  - look for whether taking a lock can be replaced by a lock annotation instead
  - for more information about Clang thread safety analysis, see
      - https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
      - https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#lockingmutex-usage-notes
      - https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#threads-and-synchronization

  Mitigates/potentially closes #17161.

ACKs for top commit:
  laanwj:
    Code review ACK 6ea5682784

Tree-SHA512: 3ebf429c8623c51f944a7245a2e48d2aa088dec4c4914b40aa6049e89856c1ee8586f6e2e3b65195190566637a33004468b51a781e61a082248748015167569b
2022-01-27 10:57:33 +01:00
..
blockchain.cpp Merge bitcoin/bitcoin#22932: Add CBlockIndex lock annotations, guard nStatus/nFile/nDataPos/nUndoPos by cs_main 2022-01-27 10:57:33 +01:00
blockchain.h Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
client.cpp Merge bitcoin/bitcoin#23706: rpc: getblockfrompeer followups 2022-01-25 18:48:41 +01:00
client.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
external_signer.cpp doc: Fix RPC result documentation 2021-09-21 11:13:29 +02:00
mining.cpp Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
mining.h rpc: create rpc/mining.h, hoist default max tries values to constant 2020-06-01 15:08:36 +02:00
misc.cpp Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
net.cpp scripted-diff: rename cs_mapLocalHost -> g_maplocalhost_mutex 2022-01-19 07:04:52 -03:00
protocol.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
rawtransaction.cpp Merge bitcoin/bitcoin#22932: Add CBlockIndex lock annotations, guard nStatus/nFile/nDataPos/nUndoPos by cs_main 2022-01-27 10:57:33 +01:00
rawtransaction_util.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
rawtransaction_util.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
register.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
request.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
request.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
server.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
server.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
server_util.cpp Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
server_util.h Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
util.cpp doc: Fix rpc docs 2022-01-25 20:05:44 +01:00
util.h doc: Fix rpc docs 2022-01-25 20:05:44 +01:00