Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
privatesend-client.cpp
Go to the documentation of this file.
27 void CPrivateSendClientManager::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman)
36 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::ProcessMessage -- Not enough disk space, disabling PrivateSend.\n");
42 LogPrint(BCLog::PRIVATESEND, "DSQUEUE -- peer=%d using obsolete version %i\n", pfrom->GetId(), pfrom->nVersion);
44 connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::REJECT, strCommand,
65 LogPrint(BCLog::PRIVATESEND, "DSQUEUE -- Peer %s is sending WAY too many dsq messages for a masternode with collateral %s\n", pfrom->GetLogString(), dsq.masternodeOutpoint.ToStringShort());
90 if (session.GetMixingMasternodeInfo(mnMixing) && mnMixing->pdmnState->addr == dmn->pdmnState->addr && session.GetState() == POOL_STATE_QUEUE) {
91 LogPrint(BCLog::PRIVATESEND, "DSQUEUE -- PrivateSend queue (%s) is ready on masternode %s\n", dsq.ToString(), dmn->pdmnState->addr.ToString());
99 LogPrint(BCLog::PRIVATESEND, "DSQUEUE -- nLastDsq: %d nDsqThreshold: %d nDsqCount: %d\n", nLastDsq, nDsqThreshold, mmetaman.GetDsqCount());
102 LogPrint(BCLog::PRIVATESEND, "DSQUEUE -- Masternode %s is sending too many dsq messages\n", dmn->proTxHash.ToString());
108 LogPrint(BCLog::PRIVATESEND, "DSQUEUE -- new PrivateSend queue (%s) from masternode %s\n", dsq.ToString(), dmn->pdmnState->addr.ToString());
113 if (session.GetMixingMasternodeInfo(mnMixing) && mnMixing->collateralOutpoint == dsq.masternodeOutpoint) {
134 void CPrivateSendClientSession::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman)
142 LogPrint(BCLog::PRIVATESEND, "DSSTATUSUPDATE -- peer=%d using obsolete version %i\n", pfrom->GetId(), pfrom->nVersion);
144 connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::REJECT, strCommand,
163 LogPrint(BCLog::PRIVATESEND, "DSFINALTX -- peer=%d using obsolete version %i\n", pfrom->GetId(), pfrom->nVersion);
165 connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::REJECT, strCommand,
182 LogPrint(BCLog::PRIVATESEND, "DSFINALTX -- message doesn't match current PrivateSend session: nSessionID: %d nMsgSessionID: %d\n", nSessionID, nMsgSessionID);
193 LogPrint(BCLog::PRIVATESEND, "DSCOMPLETE -- peer=%d using obsolete version %i\n", pfrom->GetId(), pfrom->nVersion);
195 connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::REJECT, strCommand,
204 LogPrint(BCLog::PRIVATESEND, "DSCOMPLETE -- message doesn't match current Masternode: infoMixingMasternode=%s addr=%s\n", mixingMasternode->pdmnState->addr.ToString(), pfrom->addr.ToString());
213 LogPrint(BCLog::PRIVATESEND, "DSCOMPLETE -- nMsgMessageID is out of bounds: %d\n", nMsgMessageID);
218 LogPrint(BCLog::PRIVATESEND, "DSCOMPLETE -- message doesn't match current PrivateSend session: nSessionID: %d nMsgSessionID: %d\n", nSessionID, nMsgSessionID);
222 LogPrint(BCLog::PRIVATESEND, "DSCOMPLETE -- nMsgSessionID %d nMsgMessageID %d (%s)\n", nMsgSessionID, nMsgMessageID, CPrivateSend::GetMessageByID(nMsgMessageID));
346 bool CPrivateSendClientManager::GetMixingMasternodesInfo(std::vector<CDeterministicMNCPtr>& vecDmnsRet) const
370 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- resetting session %d\n", __func__, nSessionID);
377 int nTimeout = (nState == POOL_STATE_SIGNING) ? PRIVATESEND_SIGNING_TIMEOUT : PRIVATESEND_QUEUE_TIMEOUT;
382 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- %s %d timed out (%ds)\n", __func__,
417 bool CPrivateSendClientSession::SendDenominate(const std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsIn, CConnman& connman)
420 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SendDenominate -- PrivateSend from a Masternode is not supported currently.\n");
425 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClient:SendDenominate -- PrivateSend collateral not set\n");
431 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SendDenominate -- No Masternode has been selected yet.\n");
442 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SendDenominate -- Not enough disk space.\n");
449 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SendDenominate -- Added transaction to pool.\n");
462 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SendDenominate -- Submitting partial tx %s", tx.ToString());
481 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- psssup.nState is out of bounds: %d\n", __func__, psssup.nState);
486 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- psssup.nMessageID is out of bounds: %d\n", __func__, psssup.nMessageID);
495 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- rejected by Masternode: %s\n", __func__, strMessageTmp);
504 if (nState == psssup.nState && psssup.nState == POOL_STATE_QUEUE && nSessionID == 0 && psssup.nSessionID != 0) {
510 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- accepted by Masternode: %s\n", __func__, strMessageTmp);
514 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- psssup.nStatusUpdate is out of bounds: %d\n", __func__, psssup.nStatusUpdate);
525 bool CPrivateSendClientSession::SignFinalTransaction(const CTransaction& finalTransactionNew, CNode* pnode, CConnman& connman)
527 if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
533 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- finalMutableTransaction=%s", __func__, finalMutableTransaction.ToString());
538 sort(finalMutableTransaction.vin.begin(), finalMutableTransaction.vin.end(), CompareInputBIP69());
539 sort(finalMutableTransaction.vout.begin(), finalMutableTransaction.vout.end(), CompareOutputBIP69());
542 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- ERROR! Masternode %s is not BIP69 compliant!\n", __func__, mixingMasternode->proTxHash.ToString());
551 if (!IsValidInOuts(finalMutableTransaction.vin, finalMutableTransaction.vout, nMessageID, nullptr)) {
552 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- ERROR! IsValidInOuts() failed: %s\n", __func__, CPrivateSend::GetMessageByID(nMessageID));
574 // Something went wrong and we'll refuse to sign. It's possible we'll be charged collateral. But that's
576 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- an output is missing, refusing to sign! txout=%s\n", __func__, txout.ToString());
598 // Can't find one of my own inputs, refuse to sign. It's possible we'll be charged collateral. But that's
600 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- missing input! txdsin=%s\n", __func__, txdsin.ToString());
609 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- Signing my input %i\n", __func__, nMyInputIndex);
610 // TODO we're using amount=0 here but we should use the correct amount. This works because Dash ignores the amount while signing/verifying (only used in Bitcoin/Segwit)
611 if (!SignSignature(keystore, prevPubKey, finalMutableTransaction, nMyInputIndex, 0, int(SIGHASH_ALL | SIGHASH_ANYONECANPAY))) { // changes scriptSig
612 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- Unable to sign my own transaction!\n", __func__);
617 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- nMyInputIndex: %d, sigs.size(): %d, scriptSig=%s\n",
618 __func__, nMyInputIndex, (int)sigs.size(), ScriptToAsmStr(finalMutableTransaction.vin[nMyInputIndex].scriptSig));
623 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- can't sign anything!\n", __func__);
632 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- pushing sigs to the masternode, finalMutableTransaction=%s", __func__, finalMutableTransaction.ToString());
680 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::CheckAutomaticBackup -- Automatic backups disabled, no mixing available.\n");
689 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::CheckAutomaticBackup -- ERROR! Failed to create automatic backup.\n");
690 strAutoDenomResult = _("ERROR! Failed to create automatic backup") + ", " + _("see debug.log for details.");
693 // We were able to create automatic backup but keypool was not replenished because wallet is locked.
696 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::CheckAutomaticBackup -- WARNING! Failed to create replenish keypool, please unlock your wallet to do so.\n");
697 strAutoDenomResult = _("WARNING! Failed to replenish keypool, please unlock your wallet to do so.") + ", " + _("see debug.log for details.");
702 // We should never get here via mixing itself but probably something else is still actively using keypool
703 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::CheckAutomaticBackup -- Very low number of keys left: %d, no mixing available.\n", GetWallets()[0]->nKeysLeftSinceAutoBackup);
704 strAutoDenomResult = strprintf(_("Very low number of keys left: %d") + ", " + _("no mixing available."), GetWallets()[0]->nKeysLeftSinceAutoBackup);
710 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::CheckAutomaticBackup -- Very low number of keys left: %d\n", GetWallets()[0]->nKeysLeftSinceAutoBackup);
711 strAutoDenomResult = strprintf(_("Very low number of keys left: %d"), GetWallets()[0]->nKeysLeftSinceAutoBackup);
714 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::CheckAutomaticBackup -- Trying to create new backup.\n");
721 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::CheckAutomaticBackup -- WARNING! Something went wrong on automatic backup: %s\n", warningString);
725 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::CheckAutomaticBackup -- ERROR! Failed to create automatic backup: %s\n", errorString);
726 strAutoDenomResult = strprintf(_("ERROR! Failed to create automatic backup") + ": %s", errorString);
736 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::CheckAutomaticBackup -- Keys left since latest backup: %d\n", GetWallets()[0]->nKeysLeftSinceAutoBackup);
754 if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
780 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- No Masternodes detected\n");
790 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- Nothing to do\n");
808 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- Not enough funds to mix\n");
819 CAmount nBalanceToDenominate = privateSendClient.nPrivateSendAmount * COIN - nBalanceDenominated;
835 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- current stats:\n"
861 if (nBalanceAnonimizableNonDenom >= nValueMin + CPrivateSend::GetCollateralAmount() && nBalanceToDenominate > 0) {
883 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- Found unconfirmed denominated outputs, will wait till they confirm to continue.\n");
884 strAutoDenomResult = _("Found unconfirmed denominated outputs, will wait till they confirm to continue.");
892 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- create collateral error:%s\n", strReason);
897 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- invalid collateral, recreating...\n");
899 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- create collateral error: %s\n", strReason);
943 LogPrint(BCLog::PRIVATESEND, "Checking vecMasternodesUsed: size: %d, threshold: %d\n", (int)vecMasternodesUsed.size(), nThreshold_high);
946 vecMasternodesUsed.erase(vecMasternodesUsed.begin(), vecMasternodesUsed.begin() + vecMasternodesUsed.size() - nThreshold_low);
947 LogPrint(BCLog::PRIVATESEND, " vecMasternodesUsed: new size: %d, threshold: %d\n", (int)vecMasternodesUsed.size(), nThreshold_high);
959 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::DoAutomaticDenominating -- Last successful PrivateSend action was too recent\n");
982 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::%s -- %d enabled masternodes, %d masternodes to choose from\n", __func__, nCountEnabled, nCountNotExcluded);
1006 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::%s -- found, masternode=%s\n", __func__, dmn->collateralOutpoint.ToStringShort());
1014 bool CPrivateSendClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman)
1016 if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
1026 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::JoinExistingQueue -- dsq masternode is not in masternode list, masternode=%s\n", dsq.masternodeOutpoint.ToStringShort());
1032 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::JoinExistingQueue -- skipping winner, masternode=%s\n", dmn->proTxHash.ToString());
1040 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::JoinExistingQueue -- trying queue: %s\n", dsq.ToString());
1045 if (!GetWallets()[0]->SelectPSInOutPairsByDenominations(dsq.nDenom, nBalanceNeedsAnonymized, vecPSInOutPairsTmp)) {
1046 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::JoinExistingQueue -- Couldn't match denomination %d (%s)\n", dsq.nDenom, CPrivateSend::DenominationToString(dsq.nDenom));
1053 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::JoinExistingQueue -- skipping masternode connection, addr=%s\n", dmn->pdmnState->addr.ToString());
1059 pendingDsaRequest = CPendingDsaRequest(dmn->pdmnState->addr, CPrivateSendAccept(nSessionDenom, txMyCollateral));
1064 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::JoinExistingQueue -- pending connection (from queue): nSessionDenom: %d (%s), addr=%s\n",
1065 nSessionDenom, CPrivateSend::DenominationToString(nSessionDenom), dmn->pdmnState->addr.ToString());
1073 bool CPrivateSendClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman)
1075 if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
1086 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::StartNewQueue -- Can't mix: no compatible inputs found!\n");
1096 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::StartNewQueue -- Can't find random masternode!\n");
1105 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::StartNewQueue -- skipping winner, masternode=%s\n", dmn->proTxHash.ToString());
1113 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::StartNewQueue -- Too early to mix on this masternode!"
1122 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::StartNewQueue -- skipping masternode connection, addr=%s\n", dmn->pdmnState->addr.ToString());
1127 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::StartNewQueue -- attempt %d connection to Masternode %s\n", nTries, dmn->pdmnState->addr.ToString());
1140 pendingDsaRequest = CPendingDsaRequest(dmn->pdmnState->addr, CPrivateSendAccept(nSessionDenom, txMyCollateral));
1144 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::StartNewQueue -- pending connection, nSessionDenom: %d (%s), addr=%s\n",
1145 nSessionDenom, CPrivateSend::DenominationToString(nSessionDenom), dmn->pdmnState->addr.ToString());
1160 // TODO: this vvvv should be here after new state POOL_STATE_CONNECTING is added and MIN_PRIVATESEND_PEER_PROTO_VERSION is bumped
1170 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- failed to connect to %s\n", __func__, pendingDsaRequest.GetAddr().ToString());
1196 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- SelectDenominate failed, error: %s\n", strError);
1202 for (int i = 0; i < privateSendClient.nPrivateSendRounds + privateSendClient.nPrivateSendRandomRounds; i++) {
1204 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, success\n", i);
1207 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, error: %s\n", i, strError);
1212 std::sort(vecInputsByRounds.begin(), vecInputsByRounds.end(), [](const auto& a, const auto& b) {
1218 LogPrint(BCLog::PRIVATESEND, "vecInputsByRounds: rounds: %d, inputs: %d\n", pair.first, pair.second);
1223 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, success\n", nRounds);
1228 if (PrepareDenominate(0, privateSendClient.nPrivateSendRounds - 1, strError, vecPSInOutPairs, vecPSInOutPairsTmp)) {
1229 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for all rounds, success\n");
1234 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for all rounds, error: %s\n", strError);
1239 bool CPrivateSendClientSession::SelectDenominate(std::string& strErrorRet, std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet)
1241 if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
1255 bool fSelected = GetWallets()[0]->SelectPSInOutPairsByDenominations(nSessionDenom, CPrivateSend::GetMaxPoolAmount(), vecPSInOutPairsRet);
1264 bool CPrivateSendClientSession::PrepareDenominate(int nMinRounds, int nMaxRounds, std::string& strErrorRet, const std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsIn, std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet, bool fDryRun)
1326 if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
1334 // This still leaves more than enough room for another data of typical MakeCollateralAmounts tx.
1337 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::MakeCollateralAmounts -- SelectCoinsGroupedByAddresses can't find any inputs!\n");
1342 std::sort(vecTally.begin(), vecTally.end(), [](const CompactTallyItem& a, const CompactTallyItem& b) {
1352 // There should be at least some denominated funds we should be able to break in pieces to continue mixing
1359 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::MakeCollateralAmounts -- ERROR: Can't make collaterals!\n");
1364 bool CPrivateSendClientSession::MakeCollateralAmounts(const CompactTallyItem& tallyItem, bool fTryDenominated)
1370 if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
1372 // Denominated input is always a single one, so we can check its amount directly and return early
1373 if (!fTryDenominated && tallyItem.vecOutPoints.size() == 1 && CPrivateSend::IsDenominatedAmount(tallyItem.nAmount)) {
1378 if (tallyItem.vecOutPoints.size() == 1 && CPrivateSend::IsCollateralAmount(tallyItem.nAmount)) {
1384 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- Start %s\n", __func__, txBuilder.ToString());
1392 if (txBuilder.CouldAddOutputs({CPrivateSend::GetMaxCollateralAmount(), CPrivateSend::GetCollateralAmount()})) {
1399 // Note, here we first add a zero amount output to get the remainder after all fees and then assign it
1403 out->UpdateAmount(CPrivateSend::IsDenominatedAmount(nAmountLeft) ? nAmountLeft - 1 : nAmountLeft);
1405 } else if (txBuilder.CouldAddOutputs({CPrivateSend::GetCollateralAmount(), CPrivateSend::GetCollateralAmount()})) {
1415 // Create two equal outputs from the available value. This adds one duff to the fee if txBuilder.GetAmountLeft() is odd.
1434 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- Done with case %d: %s\n", __func__, nCase, txBuilder.ToString());
1440 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- Commit failed: %s\n", __func__, strResult);
1446 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- txid: %s\n", __func__, strResult);
1454 if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
1465 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::CreateDenominated -- SelectCoinsGroupedByAddresses can't find any inputs!\n");
1469 // Start from largest balances first to speed things up by creating txes with larger/largest denoms included
1470 std::sort(vecTally.begin(), vecTally.end(), [](const CompactTallyItem& a, const CompactTallyItem& b) {
1486 bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate, const CompactTallyItem& tallyItem, bool fCreateMixingCollaterals)
1492 if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
1494 // denominated input is always a single one, so we can check its amount directly and return early
1495 if (tallyItem.vecOutPoints.size() == 1 && CPrivateSend::IsDenominatedAmount(tallyItem.nAmount)) {
1501 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- Start %s\n", __func__, txBuilder.ToString());
1505 if (fCreateMixingCollaterals && !txBuilder.AddOutput(CPrivateSend::GetMaxCollateralAmount())) {
1506 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- Failed to add collateral output\n", __func__);
1517 mapDenomCount.insert(std::pair<CAmount, int>(nDenomValue, GetWallets()[0]->CountInputsWithAmount(nDenomValue)));
1523 // it will start with the smallest denom then create 11 of those, then go up to the next biggest denom create 11
1524 // and repeat. Previously, once the largest denom was reached, as many would be created were created as possible and
1525 // then any remaining was put into a change address and denominations were created in the same manner a block later.
1526 // Now, in this system, so long as we don't reach PRIVATESEND_DENOM_OUTPUTS_THRESHOLD outputs the process repeats in
1527 // the same transaction, creating up to nPrivateSendDenomsHardCap per denomination in a single transaction.
1529 while (txBuilder.CouldAddOutput(CPrivateSend::GetSmallestDenomination()) && txBuilder.CountOutputs() < PRIVATESEND_DENOM_OUTPUTS_THRESHOLD) {
1541 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- 1 - FINAL - nDenomValue: %f, nBalanceToDenominate: %f, nOutputs: %d, %s\n",
1542 strFunc, (float) nDenomValue / COIN, (float) nBalanceToDenominate / COIN, nOutputs, txBuilder.ToString());
1551 // add each output up to 11 times or until it can't be added again or until we reach nPrivateSendDenomsGoal
1552 while (needMoreOutputs() && nOutputs <= 10 && currentDenomIt->second < privateSendClient.nPrivateSendDenomsGoal) {
1558 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- 1 - nDenomValue: %f, nBalanceToDenominate: %f, nOutputs: %d, %s\n",
1559 __func__, (float) nDenomValue / COIN, (float) nBalanceToDenominate / COIN, nOutputs, txBuilder.ToString());
1561 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- 1 - Error: AddOutput failed for nDenomValue: %f, nBalanceToDenominate: %f, nOutputs: %d, %s\n",
1562 __func__, (float) nDenomValue / COIN, (float) nBalanceToDenominate / COIN, nOutputs, txBuilder.ToString());
1573 // Check if this specific denom could use another loop, check that there aren't nPrivateSendDenomsGoal of this
1574 // denom and that our nValueLeft/nBalanceToDenominate is enough to create one of these denoms, if so, loop again.
1575 if (it.second < privateSendClient.nPrivateSendDenomsGoal && txBuilder.CouldAddOutput(it.first) && nBalanceToDenominate > 0) {
1577 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- 1 - NOT finished - nDenomValue: %f, count: %d, nBalanceToDenominate: %f, %s\n",
1578 __func__, (float) it.first / COIN, it.second, (float) nBalanceToDenominate / COIN, txBuilder.ToString());
1581 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- 1 - FINSHED - nDenomValue: %f, count: %d, nBalanceToDenominate: %f, %s\n",
1582 __func__, (float) it.first / COIN, it.second, (float) nBalanceToDenominate / COIN, txBuilder.ToString());
1588 // Now that nPrivateSendDenomsGoal worth of each denom have been created or the max number of denoms given the value of the input, do something with the remainder.
1589 if (txBuilder.CouldAddOutput(CPrivateSend::GetSmallestDenomination()) && nBalanceToDenominate >= CPrivateSend::GetSmallestDenomination() && txBuilder.CountOutputs() < PRIVATESEND_DENOM_OUTPUTS_THRESHOLD) {
1592 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- 2 - Process remainder: %s\n", __func__, txBuilder.ToString());
1599 if (!txBuilder.CouldAddOutputs(vecOutputs) || txBuilder.CountOutputs() + vecOutputs.size() > PRIVATESEND_DENOM_OUTPUTS_THRESHOLD) {
1600 // If its not possible to add it due to insufficient amount left or total number of outputs exceeds
1624 int denomsToCreate = denomsToCreateValue > denomsToCreateBal ? denomsToCreateBal : denomsToCreateValue;
1625 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- 2 - nBalanceToDenominate: %f, nDenomValue: %f, denomsToCreateValue: %d, denomsToCreateBal: %d\n",
1626 __func__, (float) nBalanceToDenominate / COIN, (float) nDenomValue / COIN, denomsToCreateValue, denomsToCreateBal);
1630 if (nDenomValue != nLargestDenomValue && it->second >= privateSendClient.nPrivateSendDenomsHardCap) break;
1638 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- 2 - Error: AddOutput failed at %d/%d, %s\n", __func__, i + 1, denomsToCreate, txBuilder.ToString());
1641 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- 2 - nDenomValue: %f, nBalanceToDenominate: %f, nOutputs: %d, %s\n",
1642 __func__, (float) nDenomValue / COIN, (float) nBalanceToDenominate / COIN, nOutputs, txBuilder.ToString());
1649 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- 3 - nBalanceToDenominate: %f, %s\n", __func__, (float) nBalanceToDenominate / COIN, txBuilder.ToString());
1652 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- 3 - DONE - nDenomValue: %f, count: %d\n", __func__, (float) it.first / COIN, it.second);
1656 if ((fCreateMixingCollaterals && txBuilder.CountOutputs() == 1) || txBuilder.CountOutputs() == 0) {
1662 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- Commit failed: %s\n", __func__, strResult);
1669 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- txid: %s\n", __func__, strResult);
1679 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::RelayIn -- found master, relaying message to %s\n", pnode->addr.ToString());
1688 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SetState -- nState: %d, nStateNew: %d\n", nState, nStateNew);
1695 LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientManager::UpdatedBlockTip -- nCachedBlockHeight: %d\n", nCachedBlockHeight);
1713 nDoAutoNextRun = nTick + PRIVATESEND_AUTO_TIMEOUT_MIN + GetRandInt(PRIVATESEND_AUTO_TIMEOUT_MAX - PRIVATESEND_AUTO_TIMEOUT_MIN);
1727 obj.push_back(Pair("denomination", ValueFromAmount(CPrivateSend::DenominationToAmount(nSessionDenom))));
bool SubmitDenominate(CConnman &connman)
As a client, submit part of a future mixing transaction to a Masternode to start the process...
Definition: privatesend-client.cpp:1187
CTxMemPool mempool
int nPrivateSendDenomsGoal
Definition: privatesend-client.h:211
std::string GetStatuses()
Definition: privatesend-client.cpp:317
std::string NetworkIDString() const
Return the BIP70 network string (main, test or regtest)
Definition: chainparams.h:76
Definition: privatesend.h:64
Used to keep track of current status of mixing pool.
Definition: privatesend-client.h:184
static CAmount GetSmallestDenomination()
Definition: privatesend.h:437
int nPrivateSendDenomsHardCap
Definition: privatesend-client.h:212
bool fCreateAutoBackups
Definition: privatesend-client.h:218
Definition: privatesend.h:58
void SetState(PoolState nStateNew)
Definition: privatesend-client.cpp:1686
void UpdatedBlockTip(const CBlockIndex *pindex)
Definition: privatesend-client.cpp:1692
std::string ToString(bool fUseGetnameinfo=true) const
Definition: netaddress.cpp:581
bool Commit(std::string &strResult)
Create and Commit the transaction to the wallet.
Definition: privatesend-util.cpp:258
Definition: privatesend-client.h:59
static bool IsDenominatedAmount(CAmount nInputAmount)
Definition: privatesend.cpp:469
Definition: privatesend.h:69
Definition: privatesend.h:50
Definition: transaction.h:369
std::vector< CPrivateSendEntry > vecEntries
Definition: privatesend.h:364
bool PrepareDenominate(int nMinRounds, int nMaxRounds, std::string &strErrorRet, const std::vector< std::pair< CTxDSIn, CTxOut > > &vecPSInOutPairsIn, std::vector< std::pair< CTxDSIn, CTxOut > > &vecPSInOutPairsRet, bool fDryRun=false)
step 1: prepare denominated inputs and outputs
Definition: privatesend-client.cpp:1264
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType)
Produce a script signature for a transaction.
Definition: sign.cpp:167
int64_t GetDsqThreshold(const uint256 &proTxHash, int nMnCount)
Definition: masternode-meta.cpp:63
bool SendDenominate(const std::vector< std::pair< CTxDSIn, CTxOut > > &vecPSInOutPairsIn, CConnman &connman)
step 2: send denominated inputs and outputs prepared in step 1
Definition: privatesend-client.cpp:417
A currently in progress mixing merge and denomination information.
Definition: privatesend.h:215
Implementation of BIP69 https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki.
Definition: transaction.h:352
std::string strLastMessage
Definition: privatesend-client.h:106
void ProcessPoolStateUpdate(CPrivateSendStatusUpdate psssup)
Process Masternode updates about the progress of mixing.
Definition: privatesend-client.cpp:473
bool CheckAutomaticBackup()
Definition: privatesend-client.cpp:674
static const int PRIVATESEND_KEYS_THRESHOLD_WARNING
Definition: privatesend-client.h:50
Definition: privatesend.h:81
Definition: univalue.h:20
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg)
Definition: net.cpp:3733
std::string strAutoDenomResult
Definition: privatesend-client.h:107
Definition: privatesend.h:77
void GetJsonInfo(UniValue &obj) const
Definition: privatesend-client.cpp:1732
static int AmountToDenomination(CAmount nInputAmount)
Definition: privatesend.cpp:403
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
Definition: deterministicmns.h:249
CMutableTransaction finalMutableTransaction
Definition: privatesend.h:371
Definition: univalue.h:22
bool GetMixingMasternodeInfo(CDeterministicMNCPtr &ret) const
Definition: privatesend-client.cpp:340
static std::vector< CAmount > GetStandardDenominations()
Definition: privatesend.h:436
CDeterministicMNCPtr mixingMasternode
Definition: privatesend-client.h:109
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
Definition: deterministicmns.cpp:24
bool CouldAddOutputs(const std::vector< CAmount > &vecOutputAmounts) const
Check if its possible to add multiple outputs as vector of amounts. Returns true if its possible to a...
Definition: privatesend-util.cpp:186
Definition: privatesend.h:143
Definition: privatesend.h:53
Definition: interpreter.h:27
int nPrivateSendAmount
Definition: privatesend-client.h:210
CAmount GetAmountLeft() const
Get the amount currently left to add more outputs. Does respect fees.
Definition: privatesend-util.h:113
Enables simple transaction generation for a given CWallet object.
Definition: privatesend-util.h:76
std::string strAutoDenomResult
Definition: privatesend-client.h:196
bool CheckDiskSpace(uint64_t nAdditionalBytes)
Check whether enough disk space is available for an incoming block.
Definition: validation.cpp:4022
void Misbehaving(NodeId pnode, int howmuch, const std::string &message)
Increase a node's misbehavior score.
Definition: net_processing.cpp:1024
Definition: univalue.h:22
bool ForNode(NodeId id, std::function< bool(const CNode *pnode)> cond, std::function< bool(CNode *pnode)> func)
Definition: net.cpp:3795
int nWalletBackups
nWalletBackups: 1..10 - number of automatic backups to keep 0 - disabled by command-line -1 - disable...
Definition: util.cpp:102
Definition: privatesend.h:68
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Create the assembly string representation of a CScript object.
Definition: core_write.cpp:86
static bool IsCollateralValid(const CTransaction &txCollateral)
If the collateral is valid given by a client.
Definition: privatesend.cpp:339
bool StartNewQueue(CAmount nBalanceNeedsAnonymized, CConnman &connman)
Definition: privatesend-client.cpp:1073
bool GetQueueItemAndTry(CPrivateSendQueue &dsqRet)
Definition: privatesend.cpp:191
int nPrivateSendRandomRounds
Definition: privatesend-client.h:209
CCriticalSection cs_deqsessions
Definition: privatesend-client.h:192
Definition: privatesend.h:67
Definition: util.h:142
int nCachedBlockHeight
Definition: privatesend-client.h:199
bool DoAutomaticDenominating(CConnman &connman, bool fDryRun=false)
Passively run mixing in the background according to the configuration in settings.
Definition: privatesend-client.cpp:744
Definition: privatesend.h:173
bool ProcessPendingDsaRequest(CConnman &connman)
Definition: privatesend-client.cpp:1153
Definition: wallet.h:107
std::vector< CPrivateSendQueue > vecPrivateSendQueue
Definition: privatesend.h:403
std::vector< COutPoint > vecMasternodesUsed
Definition: privatesend-client.h:188
int64_t nTimeLastSuccessfulStep
Definition: privatesend.h:367
bool SignFinalTransaction(const CTransaction &finalTransactionNew, CNode *pnode, CConnman &connman)
As a client, check and sign the final transaction.
Definition: privatesend-client.cpp:525
Definition: privatesend.h:70
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
Definition: univalue.h:185
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
CDeterministicMNCPtr GetRandomNotUsedMasternode()
Definition: privatesend-client.cpp:975
void CompletedTransaction(PoolMessage nMessageID)
Definition: privatesend-client.cpp:642
bool SelectDenominate(std::string &strErrorRet, std::vector< std::pair< CTxDSIn, CTxOut > > &vecPSInOutPairsRet)
step 0: select denominated inputs and txouts
Definition: privatesend-client.cpp:1239
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
Definition: utilmoneystr.cpp:12
bool CreateDenominated(CAmount nBalanceToDenominate)
Create denominations.
Definition: privatesend-client.cpp:1452
const char * REJECT
The reject message informs the receiving node that one of its previous messages has been rejected...
Definition: protocol.cpp:37
bool fEnablePrivateSend
Definition: privatesend-client.h:213
CKeyHolderStorage keyHolderStorage
Definition: privatesend-client.h:113
bool AddPendingMasternode(const uint256 &proTxHash)
Definition: net.cpp:3305
void ProcessPendingDsaRequest(CConnman &connman)
Definition: privatesend-client.cpp:1177
bool IsDust(CAmount nAmount) const
Check if an amounts should be considered as dust.
Definition: privatesend-util.cpp:253
Used by CTransactionBuilder to represent its transaction outputs.
Definition: privatesend-util.h:44
static const int PRIVATESEND_DENOM_OUTPUTS_THRESHOLD
Definition: privatesend-client.h:46
void ProcessMessage(CNode *pfrom, const std::string &strCommand, CDataStream &vRecv, CConnman &connman)
Definition: privatesend-client.cpp:134
std::string GetStateString() const
Definition: privatesend.cpp:207
void AllowMixing(const uint256 &proTxHash)
Definition: masternode-meta.cpp:74
Definition: privatesend.h:57
static bool IsValidDenomination(int nDenom)
Definition: privatesend.cpp:474
CPendingDsaRequest pendingDsaRequest
Definition: privatesend-client.h:111
int nCachedLastSuccessBlock
Definition: privatesend-client.h:194
int nPrivateSendRounds
Definition: privatesend-client.h:208
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:947
bool CouldAddOutput(CAmount nAmountOutput) const
Check it would be possible to add a single output with the amount nAmount. Returns true if its possib...
Definition: privatesend-util.cpp:176
static const int PRIVATESEND_AUTO_TIMEOUT_MAX
Definition: privatesend.h:23
void DoMaintenance(CConnman &connman)
Definition: privatesend-client.cpp:1698
static const int MIN_PRIVATESEND_PEER_PROTO_VERSION
minimum peer version accepted by mixing pool
Definition: privatesend.h:28
void GetJsonInfo(UniValue &obj) const
Definition: privatesend-client.cpp:1717
std::string GetSessionDenoms()
Definition: privatesend-client.cpp:329
Definition: interpreter.h:24
static std::string GetMessageByID(PoolMessage nMessageID)
Definition: privatesend.cpp:479
void RelayIn(const CPrivateSendEntry &entry, CConnman &connman)
Definition: privatesend-client.cpp:1674
static CAmount GetMaxCollateralAmount()
Definition: privatesend.h:461
bool IsValidInOuts(const std::vector< CTxIn > &vin, const std::vector< CTxOut > &vout, PoolMessage &nMessageIDRet, bool *fConsumeCollateralRet) const
Definition: privatesend.cpp:225
Definition: netmessagemaker.h:12
void UpdatedSuccessBlock()
Definition: privatesend-client.cpp:659
static const int PRIVATESEND_AUTO_TIMEOUT_MIN
Definition: privatesend.h:22
static const int PRIVATESEND_KEYS_THRESHOLD_STOP
Definition: privatesend-client.h:52
std::string GetStatus(bool fWaitForBlock)
Definition: privatesend-client.cpp:277
static bool IsCollateralAmount(CAmount nInputAmount)
Definition: privatesend.cpp:393
bool IsMasternodeOrDisconnectRequested(const CService &addr)
Definition: net.cpp:3808
bool GetMixingMasternodesInfo(std::vector< CDeterministicMNCPtr > &vecDmnsRet) const
Definition: privatesend-client.cpp:346
std::vector< COutPoint > vecOutPointLocked
Definition: privatesend-client.h:104
bool DoAutomaticDenominating(CConnman &connman, bool fDryRun=false)
Passively run mixing in the background according to the configuration in settings.
Definition: privatesend-client.cpp:923
bool JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CConnman &connman)
Definition: privatesend-client.cpp:1014
std::deque< CPrivateSendClientSession > deqSessions
Definition: privatesend-client.h:191
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
bool MakeCollateralAmounts()
Split up large inputs or make fee sized inputs.
Definition: privatesend-client.cpp:1324
bool fPrivateSendMultiSession
Definition: privatesend-client.h:215
bool WaitForAnotherBlock()
Definition: privatesend-client.cpp:665
AssertLockHeld(g_cs_orphans)
void AddUsedMasternode(const COutPoint &outpointMn)
Definition: privatesend-client.cpp:970
Definition: privatesend.h:76
CMutableTransaction txMyCollateral
Definition: privatesend-client.h:110
static CAmount DenominationToAmount(int nDenom)
Definition: privatesend.cpp:419
void ProcessMessage(CNode *pfrom, const std::string &strCommand, CDataStream &vRecv, CConnman &connman)
Definition: privatesend-client.cpp:27
Definition: privatesend.h:66
CMasternodeMetaInfoPtr GetMetaInfo(const uint256 &proTxHash, bool fCreate=true)
Definition: masternode-meta.cpp:45
static std::string DenominationToString(int nDenom)
Definition: privatesend.cpp:453
Definition: privatesend.h:65
Definition: privatesend.h:54
CTransactionBuilderOutput * AddOutput(CAmount nAmountOutput=0)
Add an output with the amount nAmount. Returns a pointer to the output if it could be added and nullp...
Definition: privatesend-util.cpp:202
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
Definition: util.h:92
static const size_t PRIVATESEND_ENTRY_MAX_SIZE
Definition: privatesend.h:30
int nPrivateSendSessions
Definition: privatesend-client.h:207
bool fPrivateSendRunning
Definition: privatesend-client.h:214
bool UpdateAmount(CAmount nAmount)
Try update the amount of this output. Returns true if it was successful and false if not (e...
Definition: privatesend-util.cpp:97