diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -495,7 +495,8 @@ const uint32_t flags, bool sigCacheStore, bool scriptCacheStore, const PrecomputedTransactionData &txdata, - std::vector *pvChecks = nullptr); + std::vector *pvChecks = nullptr) + EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** * Mark all the coins corresponding to a given transaction inputs as spent. @@ -654,7 +655,8 @@ * A finalized block can not be reorged in any way. */ bool FinalizeBlockAndInvalidate(const Config &config, CValidationState &state, - CBlockIndex *pindex); + CBlockIndex *pindex) + EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** Mark a block as invalid. */ bool InvalidateBlock(const Config &config, CValidationState &state, diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -174,7 +174,8 @@ void ResetBlockFailureFlags(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); template - void UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f); + void UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f) + EXCLUSIVE_LOCKS_REQUIRED(cs_main); template void UpdateFlags(CBlockIndex *pindex, F f, C fchild) EXCLUSIVE_LOCKS_REQUIRED(cs_main); @@ -870,6 +871,7 @@ const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, int64_t nAcceptTime, bool fOverrideMempoolLimit, const Amount nAbsurdFee, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { + AssertLockHeld(cs_main); std::vector coins_to_uncache; bool res = AcceptToMemoryPoolWorker( config, pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, @@ -1168,8 +1170,9 @@ CheckForkWarningConditions(); } -void static InvalidChainFound(CBlockIndex *pindexNew) +static void InvalidChainFound(CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { + AssertLockHeld(cs_main); if (!pindexBestInvalid || pindexNew->nChainWork > pindexBestInvalid->nChainWork) { pindexBestInvalid = pindexNew; @@ -1257,8 +1260,8 @@ const uint32_t flags, bool sigCacheStore, bool scriptCacheStore, const PrecomputedTransactionData &txdata, - std::vector *pvChecks) - EXCLUSIVE_LOCKS_REQUIRED(cs_main) { + std::vector *pvChecks) { + AssertLockHeld(cs_main); assert(!tx.IsCoinBase()); if (pvChecks) { @@ -1689,8 +1692,8 @@ bool CChainState::ConnectBlock(const CBlock &block, CValidationState &state, CBlockIndex *pindex, CCoinsViewCache &view, const CChainParams ¶ms, - BlockValidationOptions options, bool fJustCheck) - EXCLUSIVE_LOCKS_REQUIRED(cs_main) { + BlockValidationOptions options, + bool fJustCheck) { AssertLockHeld(cs_main); assert(pindex); assert(*pindex->phashBlock == block.GetHash()); @@ -2229,8 +2232,8 @@ * in any case). */ bool CChainState::DisconnectTip(const Config &config, CValidationState &state, - DisconnectedBlockTransactions *disconnectpool) - EXCLUSIVE_LOCKS_REQUIRED(cs_main) { + DisconnectedBlockTransactions *disconnectpool) { + AssertLockHeld(cs_main); CBlockIndex *pindexDelete = chainActive.Tip(); const Consensus::Params &consensusParams = config.GetChainParams().GetConsensus(); @@ -3136,8 +3139,7 @@ } bool FinalizeBlockAndInvalidate(const Config &config, CValidationState &state, - CBlockIndex *pindex) - EXCLUSIVE_LOCKS_REQUIRED(cs_main) { + CBlockIndex *pindex) { AssertLockHeld(cs_main); if (!FinalizeBlockInternal(config, state, pindex)) { // state is set by FinalizeBlockInternal. @@ -3190,8 +3192,7 @@ } template -void CChainState::UpdateFlags(CBlockIndex *pindex, F f, C fchild) - EXCLUSIVE_LOCKS_REQUIRED(cs_main) { +void CChainState::UpdateFlags(CBlockIndex *pindex, F f, C fchild) { AssertLockHeld(cs_main); // Update the current block. @@ -3218,9 +3219,7 @@ } } -template -void CChainState::UpdateFlags(CBlockIndex *pindex, F f) - EXCLUSIVE_LOCKS_REQUIRED(cs_main) { +template void CChainState::UpdateFlags(CBlockIndex *pindex, F f) { // Handy shorthand. UpdateFlags(pindex, f, f); } @@ -3291,8 +3290,7 @@ pindexFinalized->GetAncestor(pindex->nHeight) == pindex; } -CBlockIndex *CChainState::AddToBlockIndex(const CBlockHeader &block) - EXCLUSIVE_LOCKS_REQUIRED(cs_main) { +CBlockIndex *CChainState::AddToBlockIndex(const CBlockHeader &block) { AssertLockHeld(cs_main); // Check for duplicate @@ -4467,6 +4465,7 @@ bool CChainState::LoadBlockIndex(const Config &config, CBlockTreeDB &blocktree) { + AssertLockHeld(cs_main); if (!blocktree.LoadBlockIndexGuts( config.GetChainParams().GetConsensus(), [this](const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { @@ -4546,7 +4545,7 @@ return true; } -bool static LoadBlockIndexDB(const Config &config) +static bool LoadBlockIndexDB(const Config &config) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { if (!g_chainstate.LoadBlockIndex(config, *pblocktree)) { return false;