From ff159ad7e7cd1d847c1eb8d05ab25b2ac80426d3 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 4 Aug 2015 23:51:16 +0300 Subject: [PATCH] ConnectNode/FindNide: - Use FindNode instead of explicit loops - Do not use FindNode where we can grab node right from ConnectNode (slightly less cs_vNodes) --- src/darksend-relay.cpp | 12 +++---- src/darksend.cpp | 74 ++++++++++++++++++------------------------ src/masternodeman.cpp | 8 ++--- 3 files changed, 38 insertions(+), 56 deletions(-) diff --git a/src/darksend-relay.cpp b/src/darksend-relay.cpp index e0f7724315..9ef77fafd3 100644 --- a/src/darksend-relay.cpp +++ b/src/darksend-relay.cpp @@ -105,15 +105,11 @@ void CDarkSendRelay::RelayThroughNode(int nRank) if(pmn != NULL){ //printf("RelayThroughNode %s\n", pmn->addr.ToString().c_str()); - if(ConnectNode((CAddress)pmn->addr, NULL, true)){ + CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, true); + if(pnode){ //printf("Connected\n"); - CNode* pNode = FindNode(pmn->addr); - if(pNode) - { - //printf("Found\n"); - pNode->PushMessage("dsr", (*this)); - return; - } + pnode->PushMessage("dsr", (*this)); + return; } } else { //printf("RelayThroughNode NULL\n"); diff --git a/src/darksend.cpp b/src/darksend.cpp index c4f9aee4fc..dd16c143d3 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1527,26 +1527,24 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready) } // connect to Masternode and submit the queue request - if(ConnectNode((CAddress)addr, NULL, true)){ - CNode* pnode = FindNode(addr); - if(pnode) + CNode* pnode = ConnectNode((CAddress)addr, NULL, true); + if(pnode != NULL) + { + CMasternode* pmn = mnodeman.Find(dsq.vin); + if(pmn == NULL) { - CMasternode* pmn = mnodeman.Find(dsq.vin); - if(pmn == NULL) - { - LogPrintf("DoAutomaticDenominating --- dsq vin %s is not in masternode list!", dsq.vin.ToString()); - continue; - } - pSubmittedToMasternode = pmn; - vecMasternodesUsed.push_back(dsq.vin); - sessionDenom = dsq.nDenom; - - pnode->PushMessage("dsa", sessionDenom, txCollateral); - LogPrintf("DoAutomaticDenominating --- connected (from queue), sending dsa for %d - %s\n", sessionDenom, pnode->addr.ToString()); - strAutoDenomResult = _("Mixing in progress..."); - dsq.time = 0; //remove node - return true; + LogPrintf("DoAutomaticDenominating --- dsq vin %s is not in masternode list!", dsq.vin.ToString()); + continue; } + pSubmittedToMasternode = pmn; + vecMasternodesUsed.push_back(dsq.vin); + sessionDenom = dsq.nDenom; + + pnode->PushMessage("dsa", sessionDenom, txCollateral); + LogPrintf("DoAutomaticDenominating --- connected (from queue), sending dsa for %d - %s\n", sessionDenom, pnode->addr.ToString()); + strAutoDenomResult = _("Mixing in progress..."); + dsq.time = 0; //remove node + return true; } else { LogPrintf("DoAutomaticDenominating --- error connecting \n"); strAutoDenomResult = _("Error connecting to Masternode."); @@ -1577,27 +1575,21 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready) lastTimeChanged = GetTimeMillis(); LogPrintf("DoAutomaticDenominating -- attempt %d connection to Masternode %s\n", i, pmn->addr.ToString()); - if(ConnectNode((CAddress)pmn->addr, NULL, true)){ + CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, true); + if(pnode != NULL){ + pSubmittedToMasternode = pmn; + vecMasternodesUsed.push_back(pmn->vin); - LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) - { - if((CNetAddr)pnode->addr != (CNetAddr)pmn->addr) continue; + std::vector vecAmounts; + pwalletMain->ConvertList(vCoins, vecAmounts); + // try to get random denoms out of vecAmounts + while(sessionDenom == 0) + sessionDenom = GetDenominationsByAmounts(vecAmounts, true); - pSubmittedToMasternode = pmn; - vecMasternodesUsed.push_back(pmn->vin); - - std::vector vecAmounts; - pwalletMain->ConvertList(vCoins, vecAmounts); - // try to get random denoms out of vecAmounts - while(sessionDenom == 0) - sessionDenom = GetDenominationsByAmounts(vecAmounts, true); - - pnode->PushMessage("dsa", sessionDenom, txCollateral); - LogPrintf("DoAutomaticDenominating --- connected, sending dsa for %d\n", sessionDenom); - strAutoDenomResult = _("Mixing in progress..."); - return true; - } + pnode->PushMessage("dsa", sessionDenom, txCollateral); + LogPrintf("DoAutomaticDenominating --- connected, sending dsa for %d\n", sessionDenom); + strAutoDenomResult = _("Mixing in progress..."); + return true; } else { i++; continue; @@ -2167,6 +2159,7 @@ void CDarksendPool::RelayFinalTransaction(const int sessionID, const CTransactio void CDarksendPool::RelayIn(const std::vector& vin, const int64_t& nAmount, const CTransaction& txCollateral, const std::vector& vout) { + if(!pSubmittedToMasternode) return; std::vector vin2; std::vector vout2; @@ -2177,11 +2170,8 @@ void CDarksendPool::RelayIn(const std::vector& vin, const int64_t& nAmo BOOST_FOREACH(CTxDSOut out, vout) vout2.push_back(out); - LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) - { - if(!pSubmittedToMasternode) return; - if((CNetAddr)pSubmittedToMasternode->addr != (CNetAddr)pnode->addr) continue; + CNode* pnode = FindNode(pSubmittedToMasternode->addr); + if(pnode != NULL) { LogPrintf("RelayIn - found master, relaying message - %s \n", pnode->addr.ToString()); pnode->PushMessage("dsi", vin2, nAmount, txCollateral, vout2); } diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 98755cbf76..aa7b7f9285 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -618,12 +618,8 @@ void CMasternodeMan::ProcessMasternodeConnections() if(!darkSendPool.pSubmittedToMasternode) return; - LOCK(cs_vNodes); - - BOOST_FOREACH(CNode* pnode, vNodes) - { - if(darkSendPool.pSubmittedToMasternode->addr == pnode->addr) continue; - + CNode* pnode = FindNode(darkSendPool.pSubmittedToMasternode->addr); + if(pnode != NULL) { if(pnode->fDarkSendMaster){ LogPrintf("Closing Masternode connection %s \n", pnode->addr.ToString()); pnode->fDisconnect = true;