mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-26 15:36:19 +01:00
Merge #14963: mempool, validation: Explain cs_main locking semantics
fa5e373365validation: Add cs_main locking annotations (MarcoFalke)fa5c346c5adoc: Add comment to cs_main and mempool::cs (MarcoFalke)fafe941bddtest: Add missing validation locks (MarcoFalke)fac4558462sync: Add RecursiveMutex type alias (MarcoFalke) Pull request description: Both the chain state and the transaction pool are validation specific, but access to them is protected by two locks. The two locks have the following semantics: * Writing to the chain state or adding transactions to the transaction pool -> Take both `cs_main` and `mempool::cs` * Reading either or removing transactions from the the transaction pool -> Take only the appropriate lock Tree-SHA512: 6f6e612ffc391904c6434a79a4f3f8de1b928bf0a3e3434b73561037b395e2b40a70a5a4bd8472dd230e9eacc8e5d5374c904a3c509910cf3971dd7ff59a626c
This commit is contained in:
@@ -173,7 +173,7 @@ public:
|
||||
CCoinsViewCache& view, const CChainParams& chainparams, bool fJustCheck = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
// Block disconnection on our pcoinsTip:
|
||||
bool DisconnectTip(CValidationState& state, const CChainParams& chainparams, DisconnectedBlockTransactions *disconnectpool);
|
||||
bool DisconnectTip(CValidationState& state, const CChainParams& chainparams, DisconnectedBlockTransactions* disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
// Manual block validity manipulation:
|
||||
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
|
||||
@@ -210,9 +210,17 @@ private:
|
||||
bool RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& inputs, const CChainParams& params) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
} g_chainstate;
|
||||
|
||||
|
||||
|
||||
CCriticalSection cs_main;
|
||||
/**
|
||||
* Mutex to guard access to validation specific variables, such as reading
|
||||
* or changing the chainstate.
|
||||
*
|
||||
* This may also need to be locked when updating the transaction pool, e.g. on
|
||||
* AcceptToMemoryPool. See CTxMemPool::cs comment for details.
|
||||
*
|
||||
* The transaction pool has a separate lock to allow reading from it and the
|
||||
* chainstate at the same time.
|
||||
*/
|
||||
RecursiveMutex cs_main;
|
||||
|
||||
BlockMap& mapBlockIndex = g_chainstate.mapBlockIndex;
|
||||
CChain& chainActive = g_chainstate.chainActive;
|
||||
|
||||
Reference in New Issue
Block a user