Skip to content

Commit

Permalink
Merge pull request #52 from projectmemetic/master
Browse files Browse the repository at this point in the history
Only disconnect stalled peers if IsSyncing, add lock around node nRefCount, restore cs_masternode lock in dsee and dseep processing
  • Loading branch information
cryptopepe authored Feb 27, 2019
2 parents c40e50a + a8efc35 commit 4f98c35
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5062,7 +5062,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
// Detect stalled peers.
int nSyncTimeout = GetArg("-synctimeout", 60);
int64_t tNow = GetTimeMillis();
if (pto->tGetblocks) {
if (pto->tGetblocks && IsSyncing()) {
if (pto->tBlockRecving > pto->tBlockRecved) {
if (tNow-pto->tBlockRecving > nSyncTimeout * 1000) {
LogPrintf("sync peer=%d: Block download stalled for over %d seconds.\n", pto->id, nSyncTimeout);
Expand Down
4 changes: 2 additions & 2 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void ProcessMessageMasternode(CNode* pfrom, std::string& strCommand, CDataStream


//search existing masternode list, this is where we update existing masternodes with new dsee broadcasts
//LOCK(cs_masternodes);
LOCK(cs_masternodes);
BOOST_FOREACH(CMasterNode& mn, vecMasternodes) {
if(mn.vin.prevout == vin.prevout) {
// count == -1 when it's a new entry
Expand Down Expand Up @@ -248,7 +248,7 @@ void ProcessMessageMasternode(CNode* pfrom, std::string& strCommand, CDataStream
}

// see if we have this masternode
//LOCK(cs_masternodes);
LOCK(cs_masternodes);
BOOST_FOREACH(CMasterNode& mn, vecMasternodes) {
if(mn.vin.prevout == vin.prevout) {
// LogPrintf("dseep - Found corresponding mn for vin: %s\n", vin.ToString().c_str());
Expand Down
6 changes: 3 additions & 3 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ void ThreadSocketHandler()
//
vector<CNode*> vNodesCopy;
{
//LOCK(cs_vNodes);
LOCK(cs_vNodes);
vNodesCopy = vNodes;
BOOST_FOREACH(CNode* pnode, vNodesCopy)
pnode->AddRef();
Expand Down Expand Up @@ -978,7 +978,7 @@ void ThreadSocketHandler()
BOOST_FOREACH(CNode* pnode, vNodesCopy)
pnode->Release();
}
MilliSleep(2); // niceness
MilliSleep(1); // niceness
}
}

Expand Down Expand Up @@ -1568,7 +1568,7 @@ void ThreadMessageHandler(int ncore)
}

// niceness
MilliSleep(10);
MilliSleep(2);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class CNode
bool fDarkSendMaster;
CSemaphoreGrant grantOutbound;
int nRefCount;
CCriticalSection cs_nRefCount;
NodeId id;
protected:

Expand Down Expand Up @@ -417,12 +418,14 @@ class CNode

CNode* AddRef()
{
LOCK(cs_nRefCount);
nRefCount++;
return this;
}

void Release()
{
LOCK(cs_nRefCount);
nRefCount--;
}

Expand Down

0 comments on commit 4f98c35

Please sign in to comment.