qa: Add lock order annotation for TxMempool::cs
What changed, and why it matters
This is a tiny quality-assurance change that adds a compiler-checked note saying the mempool mutex must be acquired after the main chain mutex. It does not change program behavior at runtime; it only helps automated tools detect potential lock-order mistakes during development. There is no direct security fix for users here.
No urgent action. Treat as normal code-quality/maintenance merge. Reviewers should verify the chosen lock ordering (cs_main before mempool.cs) matches the project's intended invariant and that existing call sites already comply, since adding the annotation could surface new static-analysis warnings.
Security signals we found
Adds lock-order annotation ACQUIRED_AFTER(::cs_main) to CTxMempool::cs
Compile-time static-analysis aid only; no runtime behavior change
Commit title explicitly labels change as 'qa' (quality assurance)
Single-line header-only change
Evidence from the diff
The commit adds the Clang thread-safety annotation ACQUIRED_AFTER(::cs_main) to CTxMempool::cs. This documents and enforces the intended lock ordering cs_main -> mempool.cs, which is the reverse of the previously documented mempool.cs -> cs_main in some comments. The annotation itself is compile-time only and has no runtime effect; it enables the Clang static analyzer (and compatible tools) to warn if code acquires these locks in the wrong order. The change is one line in a header file and is labeled ‘qa’ (quality assurance).
Changed components
src/txmempool.hCTxMempool::cs mutex lock-order annotationInspect captured patch +1 / −1
diff --git a/src/txmempool.h b/src/txmempool.h
index d7b7de6e..d172c78e 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -257,7 +257,7 @@ public:
* changing the chain tip. It's necessary to keep both mutexes locked until
* the mempool is consistent with the new chain tip and fully populated.
*/
- mutable RecursiveMutex cs;
+ mutable RecursiveMutex cs ACQUIRED_AFTER(::cs_main);
std::unique_ptr<TxGraph> m_txgraph GUARDED_BY(cs);
mutable std::unique_ptr<TxGraph::BlockBuilder> m_builder GUARDED_BY(cs);
indexed_transaction_set mapTx GUARDED_BY(cs);
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.