From d9d6d4f6eba88f871e39768d74a75c3df112bbde Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 30 Oct 2016 23:40:30 +0400 Subject: [PATCH] fix deadlock on sync (#1104) --- src/masternode-sync.cpp | 3 +-- src/masternodeman.cpp | 6 ++++-- src/masternodeman.h | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index 34ffb940d..35a045d38 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -210,8 +210,7 @@ void CMasternodeSync::ProcessTick() return; } - TRY_LOCK(cs_vNodes, lockRecv); - if(!lockRecv) return; + LOCK2(mnodeman.cs, cs_vNodes); if(nRequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL || (nRequestedMasternodeAssets == MASTERNODE_SYNC_SPORKS && IsBlockchainSynced())) diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index f046fd264..4d840dedd 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -608,8 +608,6 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData if(fLiteMode) return; // disable all Dash specific functionality if(!masternodeSync.IsBlockchainSynced()) return; - LOCK(cs); - if (strCommand == NetMsgType::MNANNOUNCE) { //Masternode Broadcast CMasternodeBroadcast mnb; @@ -634,6 +632,8 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s\n", mnp.vin.prevout.ToStringShort()); + LOCK(cs); + if(mapSeenMasternodePing.count(mnp.GetHash())) return; //seen mapSeenMasternodePing.insert(std::make_pair(mnp.GetHash(), mnp)); @@ -668,6 +668,8 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData LogPrint("masternode", "DSEG -- Masternode list, masternode=%s\n", vin.prevout.ToStringShort()); + LOCK(cs); + if(vin == CTxIn()) { //only should ask for this once //local network bool isLocal = (pfrom->addr.IsRFC1918() || pfrom->addr.IsLocal()); diff --git a/src/masternodeman.h b/src/masternodeman.h index 6c83aae8f..7b5838e06 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -49,6 +49,8 @@ private: int64_t nLastWatchdogVoteTime; + friend class CMasternodeSync; + public: // Keep track of all broadcasts I've seen std::map mapSeenMasternodeBroadcast;