diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp index 1eed993dde..ba238c57f3 100644 --- a/src/coinjoin/client.cpp +++ b/src/coinjoin/client.cpp @@ -1042,18 +1042,20 @@ CDeterministicMNCPtr CCoinJoinClientManager::GetRandomNotUsedMasternode() return nullptr; } +static int WinnersToSkip() +{ + return (Params().NetworkIDString() == CBaseChainParams::DEVNET || + Params().NetworkIDString() == CBaseChainParams::REGTEST) + ? 1 : 8; +} + bool CCoinJoinClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman) { if (!CCoinJoinClientOptions::IsEnabled()) return false; if (coinJoinClientQueueManager == nullptr) return false; - auto mnList = deterministicMNManager->GetListAtChainTip(); - - int winners_to_skip{8}; - - if (Params().NetworkIDString() == CBaseChainParams::DEVNET || Params().NetworkIDString() == CBaseChainParams::REGTEST) { - winners_to_skip = 0; - } + const auto mnList = deterministicMNManager->GetListAtChainTip(); + const int nWeightedMnCount = mnList.GetValidWeightedMNsCount(); // Look through the queues and see if anything matches CCoinJoinQueue dsq; @@ -1066,7 +1068,7 @@ bool CCoinJoinClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, } // skip next mn payments winners - if (dmn->pdmnState->nLastPaidHeight + int(mnList.GetValidMNsCount()) < mnList.GetHeight() + winners_to_skip) { + if (dmn->pdmnState->nLastPaidHeight + nWeightedMnCount < mnList.GetHeight() + WinnersToSkip()) { LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::JoinExistingQueue -- skipping winner, masternode=%s\n", dmn->proTxHash.ToString()); continue; } @@ -1113,8 +1115,9 @@ bool CCoinJoinClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CCon if (nBalanceNeedsAnonymized <= 0) return false; int nTries = 0; - auto mnList = deterministicMNManager->GetListAtChainTip(); - int nMnCount = mnList.GetValidMNsCount(); + const auto mnList = deterministicMNManager->GetListAtChainTip(); + const int nMnCount = mnList.GetValidMNsCount(); + const int nWeightedMnCount = mnList.GetValidWeightedMNsCount(); // find available denominated amounts std::set setAmounts; @@ -1138,7 +1141,7 @@ bool CCoinJoinClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CCon coinJoinClientManagers.at(mixingWallet.GetName())->AddUsedMasternode(dmn->collateralOutpoint); // skip next mn payments winners - if (dmn->pdmnState->nLastPaidHeight + nMnCount < mnList.GetHeight() + 8) { + if (dmn->pdmnState->nLastPaidHeight + nWeightedMnCount < mnList.GetHeight() + WinnersToSkip()) { LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::StartNewQueue -- skipping winner, masternode=%s\n", dmn->proTxHash.ToString()); nTries++; continue;