fix potential deadlock in CMasternodeMan::CheckMnbAndUpdateMasternodeList (#1543)

governance.cs -> mnodeman.cs:
CGovernanceManager::ProcessMessage - LOCK2(cs_main, governance.cs) -> AddGovernanceObject -> UpdateSentinelVariables -> CountEnabled - LOCK(mnodeman.cs)

mnodeman.cs -> governance.cs:
CheckMnbAndUpdateMasternodeList - LOCK2(cs_main, mnodeman.cs) -> activeMasternode.ManageState -> ManageStateLocal -> NotifyMasternodeUpdates -> СheckMasternodeOrphanObjects - LOCK2(cs_main, governance.cs)
... -> NotifyMasternodeUpdates -> CheckMasternodeOrphanVotes - LOCK2(cs_main, governance.cs)
... -> NotifyMasternodeUpdates -> UpdateCachesAndClean - LOCK2(cs_main, governance.cs)
This commit is contained in:
Ilya Savinov 2017-07-21 18:21:09 +03:00 committed by UdjinM6
parent 1c4e2946af
commit 4942884c71

View File

@ -1405,9 +1405,11 @@ void CMasternodeMan::UpdateMasternodeList(CMasternodeBroadcast mnb)
bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBroadcast mnb, int& nDos)
{
// Need LOCK2 here to ensure consistent locking order because the SimpleCheck call below locks cs_main
LOCK2(cs_main, cs);
// Need to lock cs_main here to ensure consistent locking order because the SimpleCheck call below locks cs_main
LOCK(cs_main);
{
LOCK(cs);
nDos = 0;
LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s\n", mnb.vin.prevout.ToStringShort());
@ -1463,7 +1465,10 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr
if(hash != mnbOld.GetHash()) {
mapSeenMasternodeBroadcast.erase(mnbOld.GetHash());
}
} else {
return true;
}
}
if(mnb.CheckOutpoint(nDos)) {
Add(mnb);
masternodeSync.AddedMasternodeList();
@ -1487,7 +1492,6 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr
LogPrintf("CMasternodeMan::CheckMnbAndUpdateMasternodeList -- Rejected Masternode entry: %s addr=%s\n", mnb.vin.prevout.ToStringShort(), mnb.addr.ToString());
return false;
}
}
return true;
}