diff --git a/src/evo/cbtx.cpp b/src/evo/cbtx.cpp index 5bf9afb31c584..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); // second! - try { static int64_t nTimeDMN = 0; static int64_t nTimeSMNL = 0; @@ -121,7 +119,7 @@ bool CalcCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindexPrev int64_t nTime1 = GetTimeMicros(); CDeterministicMNList tmpMNList; - if (!deterministicMNManager->BuildNewListFromBlock(block, pindexPrev, state, view, tmpMNList, false)) { // step-0 + if (!deterministicMNManager->BuildNewListFromBlock(block, pindexPrev, state, view, tmpMNList, false)) { // pass the state returned by the function above return false; } diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index bd027f1bb9d33..631613868e9d8 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -611,8 +611,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; @@ -624,6 +622,8 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde newList.SetBlockHash(pindex->GetBlockHash()); + LOCK(cs); + oldList = GetListForBlockInternal(pindex->pprev); diff = oldList.BuildDiff(newList); @@ -706,11 +706,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 0b8934949dd90..e56e825bae64f 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -578,10 +578,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; // mutex - private: + Mutex cs; Mutex cs_cleanup; // We have performed CleanupCache() on this height. int did_cleanup GUARDED_BY(cs_cleanup) {0}; @@ -611,7 +609,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); std::vector ComputeQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex) EXCLUSIVE_LOCKS_REQUIRED(cs); @@ -650,7 +648,7 @@ PreviousQuorumQuarters GetPreviousQuorumQuarterMembers(const Consensus::LLMQPara std::pair GetMNUsageBySnapshot(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex, const llmq::CQuorumSnapshot& snapshot, - int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs); + int nHeight) LOCKS_EXCLUDED(cs); std::vector> GetQuorumQuarterMembersBySnapshot(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex, const llmq::CQuorumSnapshot& snapshot, @@ -660,6 +658,7 @@ PreviousQuorumQuarters GetPreviousQuorumQuarterMembers(const Consensus::LLMQPara std::vector> BuildNewQuorumQuarterMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex, const PreviousQuorumQuarters& previousQuarters) LOCKS_EXCLUDED(cs); + static void DecreasePoSePenalties(CDeterministicMNList& mnList);