From 3b9a748d5ee5f631a7b9c82407a98d9d41116326 Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Mon, 9 Jan 2017 10:09:42 -0500 Subject: [PATCH] Fix locking order (#1252) * Add cs_main locks prior to governance locks to ensure correct locking order --- src/governance.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/governance.cpp b/src/governance.cpp index 53d31b158..5cace8741 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -155,7 +155,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C return; } - LOCK(cs); + LOCK2(cs_main, cs); if(mapSeenGovernanceObjects.count(nHash)) { // TODO - print error code? what if it's GOVOBJ_ERROR_IMMATURE? @@ -284,7 +284,7 @@ void CGovernanceManager::CheckOrphanVotes(CGovernanceObject& govobj, CGovernance bool CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj) { - LOCK(cs); + LOCK2(cs_main, cs); std::string strError = ""; DBG( cout << "CGovernanceManager::AddGovernanceObject START" << endl; ); @@ -564,8 +564,9 @@ void CGovernanceManager::NewBlock() // IF WE'RE NOT SYNCED, EXIT if(!masternodeSync.IsSynced()) return; - TRY_LOCK(cs, fBudgetNewBlock); - if(!fBudgetNewBlock || !pCurrentBlockIndex) return; + if(!pCurrentBlockIndex) return; + LOCK(cs); + // CHECK OBJECTS WE'VE ASKED FOR, REMOVE OLD ENTRIES @@ -652,7 +653,7 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp) LogPrint("gobject", "CGovernanceManager::Sync -- syncing to peer=%d, nProp = %s\n", pfrom->id, nProp.ToString()); { - LOCK(cs); + LOCK2(cs_main, cs); fRateChecksEnabled = false; for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) { uint256 h = it->first;