From 4fe845bf1530ad1b59dcfddebe50f323e1977402 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 27 Feb 2015 02:12:43 +0300 Subject: [PATCH 1/3] Fix crashes on remove from vector Few more locks and slight iterators optimization --- src/masternodeman.cpp | 10 ++++++---- src/masternodeman.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 5e530b9ec..720141c38 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -166,7 +166,7 @@ void CMasternodeMan::CheckAndRemove() while(it != vMasternodes.end()){ if((*it).activeState == 4 || (*it).activeState == 3){ LogPrintf("Removing inactive masternode %s\n", (*it).addr.ToString().c_str()); - vMasternodes.erase(it++); + it = vMasternodes.erase(it); } else { ++it; } @@ -178,7 +178,7 @@ void CMasternodeMan::CheckAndRemove() if((*it1).second < GetTime()) { mAskedUsForMasternodeList.erase(it1++); } else { - it1++; + ++it1; } } @@ -188,7 +188,7 @@ void CMasternodeMan::CheckAndRemove() if((*it1).second < GetTime()){ mWeAskedForMasternodeList.erase(it1++); } else { - it1++; + ++it1; } } @@ -198,7 +198,7 @@ void CMasternodeMan::CheckAndRemove() if((*it2).second < GetTime()){ mWeAskedForMasternodeListEntry.erase(it2++); } else { - it2++; + ++it2; } } @@ -231,6 +231,8 @@ int CMasternodeMan::CountMasternodesAboveProtocol(int protocolVersion) void CMasternodeMan::DsegUpdate(CNode* pnode) { + LOCK(cs); + std::map::iterator it = mWeAskedForMasternodeList.find(pnode->addr); if (it != mWeAskedForMasternodeList.end()) { diff --git a/src/masternodeman.h b/src/masternodeman.h index 4cfc274c8..95f0d7236 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -84,7 +84,7 @@ public: void CheckAndRemove(); // Clear masternode vector - void Clear() { vMasternodes.clear(); } + void Clear() { LOCK(cs); vMasternodes.clear(); } int CountEnabled(); From 14ecda348611c37e043b546ba7697c7a1d711b78 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 27 Feb 2015 04:41:17 +0300 Subject: [PATCH 2/3] With persistant storage this restriction was way too hard and could lead to dramatically shrinking/not updating masternode list after few restarts with some timeouts --- src/masternodeman.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 720141c38..ce073c23b 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -576,7 +576,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData LogPrintf("dseep - Asking source node for missing entry %s\n", vin.ToString().c_str()); pfrom->PushMessage("dseg", vin); - int64_t askAgain = GetTime()+(60*60*24); + int64_t askAgain = GetTime() + MASTERNODE_MIN_DSEEP_SECONDS; mWeAskedForMasternodeListEntry[vin.prevout] = askAgain; } else if (strCommand == "dseg") { //Get masternode list or specific entry From e7bf8d0fe6434941ba0b9790c7b307b3146c885d Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 27 Feb 2015 04:49:12 +0300 Subject: [PATCH 3/3] Few small log output fixes: - fix DumpMasternodes log output (wasn't really working) - add log output on CMasternodeMan::Add - slightly edit CMasternodeMan::CheckAndRemove log output --- src/masternodeman.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 720141c38..185e436d5 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -123,8 +123,7 @@ void DumpMasternodes() CMasternodeDB mndb; mndb.Write(mnodeman); - LogPrint("masternode", "Flushed %d masternodes to masternodes.dat %dms\n", - mnodeman.size(), GetTimeMillis() - nStart); + LogPrintf("Flushed %d masternodes to masternodes.dat %dms\n", mnodeman.size(), GetTimeMillis() - nStart); } CMasternodeMan::CMasternodeMan() {} @@ -140,6 +139,7 @@ bool CMasternodeMan::Add(CMasternode &mn) if (pmn == NULL) { + LogPrintf("CMasternodeMan: Adding new masternode %s\n", mn.addr.ToString().c_str()); vMasternodes.push_back(mn); return true; } @@ -165,7 +165,7 @@ void CMasternodeMan::CheckAndRemove() vector::iterator it = vMasternodes.begin(); while(it != vMasternodes.end()){ if((*it).activeState == 4 || (*it).activeState == 3){ - LogPrintf("Removing inactive masternode %s\n", (*it).addr.ToString().c_str()); + LogPrintf("CMasternodeMan: Removing inactive masternode %s\n", (*it).addr.ToString().c_str()); it = vMasternodes.erase(it); } else { ++it;