Skip to content

Commit 34d7030

Browse files
author
MarcoFalke
committed
Merge #21202: [validation] Two small clang lock annotation improvements
25c57d6 [doc] Add a note about where lock annotations should go. (Amiti Uttarwar) ad5f01b [validation] Move the lock annotation from function definition to declaration (Amiti Uttarwar) Pull request description: Based on reviewing #21188 the first commit switches the lock annotations on `CheckInputScripts` to be on the function declaration instead of on the function definition. this ensures that all call sites are checked, not just ones that come after the definition. the second commit adds a note to the developer-notes section to clarify where the annotations should be applied. ACKs for top commit: MarcoFalke: ACK 25c57d6 🥘 promag: Code review ACK 25c57d6. Tree-SHA512: 61b6ef856bf6c6016d535fbdd19daf57b9e59fe54a1f30d47282a071b9b9d60b2466b044ee57929e0320cb1bdef52e7a1687cacaa27031bbc43d058ffffe22ba
2 parents 4b6ca4a + 25c57d6 commit 34d7030

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

doc/developer-notes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,11 @@ Threads and synchronization
785785
get compile-time warnings about potential race conditions in code. Combine annotations in function declarations with
786786
run-time asserts in function definitions:
787787
788+
- In functions that are declared separately from where they are defined, the
789+
thread safety annotations should be added exclusively to the function
790+
declaration. Annotations on the definition could lead to false positives
791+
(lack of compile failure) at call sites between the two.
792+
788793
```C++
789794
// txmempool.h
790795
class CTxMemPool

src/test/txvalidationcache_tests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
#include <boost/test/unit_test.hpp>
1515

16-
bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks);
16+
bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
17+
const CCoinsViewCache& inputs, unsigned int flags, bool cacheSigStore,
18+
bool cacheFullScriptStore, PrecomputedTransactionData& txdata,
19+
std::vector<CScriptCheck>* pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1720

1821
BOOST_AUTO_TEST_SUITE(txvalidationcache_tests)
1922

src/validation.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ CBlockIndex* BlockManager::FindForkInGlobalIndex(const CChain& chain, const CBlo
199199

200200
std::unique_ptr<CBlockTreeDB> pblocktree;
201201

202-
bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = nullptr);
202+
bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
203+
const CCoinsViewCache& inputs, unsigned int flags, bool cacheSigStore,
204+
bool cacheFullScriptStore, PrecomputedTransactionData& txdata,
205+
std::vector<CScriptCheck>* pvChecks = nullptr)
206+
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
203207
static FILE* OpenUndoFile(const FlatFilePos &pos, bool fReadOnly = false);
204208
static FlatFileSeq BlockFileSeq();
205209
static FlatFileSeq UndoFileSeq();
@@ -1481,7 +1485,10 @@ void InitScriptExecutionCache() {
14811485
*
14821486
* Non-static (and re-declared) in src/test/txvalidationcache_tests.cpp
14831487
*/
1484-
bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1488+
bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
1489+
const CCoinsViewCache& inputs, unsigned int flags, bool cacheSigStore,
1490+
bool cacheFullScriptStore, PrecomputedTransactionData& txdata,
1491+
std::vector<CScriptCheck>* pvChecks)
14851492
{
14861493
if (tx.IsCoinBase()) return true;
14871494

0 commit comments

Comments
 (0)