diff --git a/src/evo/cbtx.cpp b/src/evo/cbtx.cpp index 6e44a0dcaaa0a..6cc74d1de796b 100644 --- a/src/evo/cbtx.cpp +++ b/src/evo/cbtx.cpp @@ -111,8 +111,6 @@ bool CheckCbTxMerkleRoots(const CBlock& block, const CBlockIndex* pindex, const bool CalcCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindexPrev, uint256& merkleRootRet, BlockValidationState& state, const CCoinsViewCache& view) { - LOCK(deterministicMNManager->cs); - try { static int64_t nTimeDMN = 0; static int64_t nTimeSMNL = 0; diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 12baa3cfcec96..ebe54f99f4133 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -613,8 +613,6 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde int nHeight = pindex->nHeight; try { - LOCK(cs); - if (!BuildNewListFromBlock(block, pindex->pprev, state, view, newList, true)) { // pass the state returned by the function above return false; @@ -626,6 +624,8 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde newList.SetBlockHash(pindex->GetBlockHash()); + LOCK(cs); + oldList = GetListForBlockInternal(pindex->pprev); diff = oldList.BuildDiff(newList); @@ -708,11 +708,9 @@ void CDeterministicMNManager::UpdatedBlockTip(const CBlockIndex* pindex) bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, BlockValidationState& state, const CCoinsViewCache& view, CDeterministicMNList& mnListRet, bool debugLogs) { - AssertLockHeld(cs); - int nHeight = pindexPrev->nHeight + 1; - CDeterministicMNList oldList = GetListForBlockInternal(pindexPrev); + CDeterministicMNList oldList = this->GetListForBlock(pindexPrev); CDeterministicMNList newList = oldList; newList.SetBlockHash(uint256()); // we can't know the final block hash, so better not return a (invalid) block hash newList.SetHeight(nHeight); diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index 8af688c822897..7d56e3d10331f 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -574,10 +574,8 @@ class CDeterministicMNManager static constexpr int DISK_SNAPSHOTS = llmq_max_blocks() / DISK_SNAPSHOT_PERIOD + 1; static constexpr int LIST_DIFFS_CACHE_SIZE = DISK_SNAPSHOT_PERIOD * DISK_SNAPSHOTS; -public: - Mutex cs; - private: + Mutex cs; Mutex cs_cleanup; // We have performed CleanupCache() on this height. int did_cleanup GUARDED_BY(cs_cleanup) {0}; @@ -607,7 +605,7 @@ class CDeterministicMNManager // the returned list will not contain the correct block hash (we can't know it yet as the coinbase TX is not updated yet) bool BuildNewListFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, BlockValidationState& state, const CCoinsViewCache& view, - CDeterministicMNList& mnListRet, bool debugLogs) EXCLUSIVE_LOCKS_REQUIRED(cs); + CDeterministicMNList& mnListRet, bool debugLogs) LOCKS_EXCLUDED(cs); static void HandleQuorumCommitment(const llmq::CFinalCommitment& qc, const CBlockIndex* pQuorumBaseBlockIndex, CDeterministicMNList& mnList, bool debugLogs); CDeterministicMNList GetListForBlock(const CBlockIndex* pindex) LOCKS_EXCLUDED(cs) {