Fix dsq/dsa conditions (#2487)

* Apply new dsq rules in StartNewQueue and DSACCEPT

* Apply similar logic to vecMasternodesUsed

* Add extra check for DSACCEPT
This commit is contained in:
UdjinM6 2018-11-25 16:27:43 +03:00 committed by GitHub
parent 9d4df466b9
commit 67483cd340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -951,10 +951,10 @@ bool CPrivateSendClientManager::DoAutomaticDenominating(CConnman& connman, bool
return false; 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% // 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; int nThreshold_low = nThreshold_high * 0.7;
LogPrint("privatesend", "Checking vecMasternodesUsed: size: %d, threshold: %d\n", (int)vecMasternodesUsed.size(), nThreshold_high); 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; if (!pwalletMain) return false;
int nTries = 0; int nTries = 0;
int nMnCountEnabled = mnodeman.CountEnabled(MIN_PRIVATESEND_PEER_PROTO_VERSION); int nMnCount = mnodeman.CountMasternodes();
// ** find the coins we'll use // ** find the coins we'll use
std::vector<CTxIn> vecTxIn; std::vector<CTxIn> vecTxIn;
@ -1098,11 +1098,11 @@ bool CPrivateSendClientSession::StartNewQueue(CAmount nValueMin, CAmount nBalanc
continue; 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!" LogPrintf("CPrivateSendClientSession::StartNewQueue -- Too early to mix on this masternode!"
" masternode=%s addr=%s nLastDsq=%d CountEnabled/5=%d nDsqCount=%d\n", " masternode=%s addr=%s nLastDsq=%d CountEnabled/5=%d nDsqCount=%d\n",
infoMn.outpoint.ToStringShort(), infoMn.addr.ToString(), infoMn.nLastDsq, infoMn.outpoint.ToStringShort(), infoMn.addr.ToString(), infoMn.nLastDsq,
nMnCountEnabled / 5, mnodeman.nDsqCount); nMnCount / 5, mnodeman.nDsqCount);
nTries++; nTries++;
continue; continue;
} }

View File

@ -50,8 +50,21 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, const std::string& strComm
return; 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 && 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()); LogPrintf("DSACCEPT -- last dsq too recent, must wait: addr=%s\n", pfrom->addr.ToString());
PushStatus(pfrom, STATUS_REJECTED, ERR_RECENT, connman); PushStatus(pfrom, STATUS_REJECTED, ERR_RECENT, connman);
return; return;