From 5c2a0cc9ecdd9854145562e877145a745886f774 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 2 Mar 2016 13:53:39 +0300 Subject: [PATCH] Fix bug that prevented new blocks to update tip during mixing Closes #706 --- src/activemasternode.cpp | 8 +++++--- src/darksend-relay.cpp | 3 ++- src/darksend.cpp | 19 +++++++++++-------- src/masternodeman.cpp | 3 ++- src/net.h | 5 +++++ src/rpcmasternode.cpp | 4 +++- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 0adf2571e..62c78e683 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -69,8 +69,6 @@ void CActiveMasternode::ManageStatus() service = CService(strMasterNodeAddr); } - LogPrintf("CActiveMasternode::ManageStatus() - Checking inbound connection to '%s'\n", service.ToString()); - int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); if(Params().NetworkIDString() == CBaseChainParams::MAIN) { if(service.GetPort() != mainnetDefaultPort) { @@ -84,11 +82,15 @@ void CActiveMasternode::ManageStatus() return; } - if(!ConnectNode((CAddress)service, NULL, true)){ + LogPrintf("CActiveMasternode::ManageStatus() - Checking inbound connection to '%s'\n", service.ToString()); + + CNode *pnode = ConnectNode((CAddress)service, NULL, false); + if(!pnode){ notCapableReason = "Could not connect to " + service.ToString(); LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason); return; } + pnode->Release(); // Choose coins to use CPubKey pubKeyCollateralAddress; diff --git a/src/darksend-relay.cpp b/src/darksend-relay.cpp index 9ef77fafd..ec4da68ca 100644 --- a/src/darksend-relay.cpp +++ b/src/darksend-relay.cpp @@ -105,10 +105,11 @@ void CDarkSendRelay::RelayThroughNode(int nRank) if(pmn != NULL){ //printf("RelayThroughNode %s\n", pmn->addr.ToString().c_str()); - CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, true); + CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, false); if(pnode){ //printf("Connected\n"); pnode->PushMessage("dsr", (*this)); + pnode->Release(); return; } } else { diff --git a/src/darksend.cpp b/src/darksend.cpp index b590faa8b..3d0edfd7c 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1544,20 +1544,23 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun) std::vector vTempCoins2; // Try to match their denominations if possible if (!pwalletMain->SelectCoinsByDenominations(dsq.nDenom, nValueMin, nBalanceNeedsAnonymized, vTempCoins, vTempCoins2, nValueIn, 0, nDarksendRounds)){ - LogPrintf("DoAutomaticDenominating - Couldn't match denominations %d\n", dsq.nDenom); + LogPrintf("DoAutomaticDenominating --- Couldn't match denominations %d\n", dsq.nDenom); continue; } + CMasternode* pmn = mnodeman.Find(dsq.vin); + if(pmn == NULL) + { + LogPrintf("DoAutomaticDenominating --- dsq vin %s is not in masternode list!", dsq.vin.ToString()); + continue; + } + + LogPrintf("DoAutomaticDenominating --- attempt to connect to masternode from queue %s\n", pmn->addr.ToString()); + lastTimeChanged = GetTimeMillis(); // connect to Masternode and submit the queue request CNode* pnode = ConnectNode((CAddress)addr, NULL, true); if(pnode != 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; @@ -1599,7 +1602,7 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun) } lastTimeChanged = GetTimeMillis(); - LogPrintf("DoAutomaticDenominating -- attempt %d connection to Masternode %s\n", i, pmn->addr.ToString()); + LogPrintf("DoAutomaticDenominating --- attempt %d connection to Masternode %s\n", i, pmn->addr.ToString()); CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, true); if(pnode != NULL){ pSubmittedToMasternode = pmn; diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 3e75e5432..392b9e99b 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -669,7 +669,8 @@ void CMasternodeMan::ProcessMasternodeConnections() if(pnode->fDarkSendMaster){ if(darkSendPool.pSubmittedToMasternode != NULL && pnode->addr == darkSendPool.pSubmittedToMasternode->addr) continue; LogPrintf("Closing Masternode connection %s \n", pnode->addr.ToString()); - pnode->fDisconnect = true; + pnode->fDarkSendMaster = false; + pnode->Release(); } } } diff --git a/src/net.h b/src/net.h index b22fb1c0c..959c9f013 100644 --- a/src/net.h +++ b/src/net.h @@ -355,6 +355,11 @@ public: // b) the peer may tell us in its version message that we should not relay tx invs // unless it loads a bloom filter. bool fRelayTxes; + // Should be 'true' only if we connected to this node to actually mix funds. + // In this case node will be released automatically via CMasternodeMan::ProcessMasternodeConnections(). + // Connecting to verify connectability/status or connecting for sending/relaying single message + // (even if it's relative to mixing e.g. for blinding) should NOT set this to 'true'. + // For such cases node should be released manually (preferably right after corresponding code). bool fDarkSendMaster; CSemaphoreGrant grantOutbound; CCriticalSection cs_filter; diff --git a/src/rpcmasternode.cpp b/src/rpcmasternode.cpp index db8865bcf..1cbfef9f3 100644 --- a/src/rpcmasternode.cpp +++ b/src/rpcmasternode.cpp @@ -137,7 +137,9 @@ UniValue masternode(const UniValue& params, bool fHelp) CService addr = CService(strAddress); - if(ConnectNode((CAddress)addr, NULL, true)){ + CNode *pnode = ConnectNode((CAddress)addr, NULL, false); + if(pnode){ + pnode->Release(); return "successfully connected"; } else { throw runtime_error("error connecting\n");