From 67483cd340d8c3dc3c68a2f9c9782d35f73ccd27 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 25 Nov 2018 16:27:43 +0300 Subject: [PATCH] Fix dsq/dsa conditions (#2487) * Apply new dsq rules in StartNewQueue and DSACCEPT * Apply similar logic to vecMasternodesUsed * Add extra check for DSACCEPT --- src/privatesend-client.cpp | 10 +++++----- src/privatesend-server.cpp | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/privatesend-client.cpp b/src/privatesend-client.cpp index be9c870f6..556c063fb 100644 --- a/src/privatesend-client.cpp +++ b/src/privatesend-client.cpp @@ -951,10 +951,10 @@ bool CPrivateSendClientManager::DoAutomaticDenominating(CConnman& connman, bool return false; } - int nMnCountEnabled = mnodeman.CountEnabled(MIN_PRIVATESEND_PEER_PROTO_VERSION); + int nMnCount = mnodeman.CountMasternodes(); // If we've used 90% of the Masternode list then drop the oldest first ~30% - int nThreshold_high = nMnCountEnabled * 0.9; + int nThreshold_high = nMnCount * 0.9; int nThreshold_low = nThreshold_high * 0.7; LogPrint("privatesend", "Checking vecMasternodesUsed: size: %d, threshold: %d\n", (int)vecMasternodesUsed.size(), nThreshold_high); @@ -1067,7 +1067,7 @@ bool CPrivateSendClientSession::StartNewQueue(CAmount nValueMin, CAmount nBalanc if (!pwalletMain) return false; int nTries = 0; - int nMnCountEnabled = mnodeman.CountEnabled(MIN_PRIVATESEND_PEER_PROTO_VERSION); + int nMnCount = mnodeman.CountMasternodes(); // ** find the coins we'll use std::vector vecTxIn; @@ -1098,11 +1098,11 @@ bool CPrivateSendClientSession::StartNewQueue(CAmount nValueMin, CAmount nBalanc continue; } - if (infoMn.nLastDsq != 0 && infoMn.nLastDsq + nMnCountEnabled / 5 > mnodeman.nDsqCount) { + if (infoMn.nLastDsq != 0 && infoMn.nLastDsq + nMnCount / 5 > mnodeman.nDsqCount) { LogPrintf("CPrivateSendClientSession::StartNewQueue -- Too early to mix on this masternode!" " masternode=%s addr=%s nLastDsq=%d CountEnabled/5=%d nDsqCount=%d\n", infoMn.outpoint.ToStringShort(), infoMn.addr.ToString(), infoMn.nLastDsq, - nMnCountEnabled / 5, mnodeman.nDsqCount); + nMnCount / 5, mnodeman.nDsqCount); nTries++; continue; } diff --git a/src/privatesend-server.cpp b/src/privatesend-server.cpp index 69a9972f5..89b0ab2db 100644 --- a/src/privatesend-server.cpp +++ b/src/privatesend-server.cpp @@ -50,8 +50,21 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, const std::string& strComm return; } + { + TRY_LOCK(cs_vecqueue, lockRecv); + if (!lockRecv) return; + + for (const auto& q : vecPrivateSendQueue) { + if (q.masternodeOutpoint == activeMasternodeInfo.outpoint) { + // refuse to create another queue this often + LogPrint("privatesend", "DSACCEPT -- last dsq is still in queue, refuse to mix\n"); + return; + } + } + } + if (vecSessionCollaterals.size() == 0 && mnInfo.nLastDsq != 0 && - mnInfo.nLastDsq + mnodeman.CountEnabled(MIN_PRIVATESEND_PEER_PROTO_VERSION) / 5 > mnodeman.nDsqCount) { + mnInfo.nLastDsq + mnodeman.CountMasternodes() / 5 > mnodeman.nDsqCount) { LogPrintf("DSACCEPT -- last dsq too recent, must wait: addr=%s\n", pfrom->addr.ToString()); PushStatus(pfrom, STATUS_REJECTED, ERR_RECENT, connman); return;