Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to mix more than one input by default #2275

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/privatesend-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,25 +1195,35 @@ bool CPrivateSendClientSession::SubmitDenominate(CConnman& connman)
// lean towards edges but still mix starting from the middle someties
// Note: liqudity providers always start from 0
bool fScanFromTheMiddle = (privateSendClient.nLiquidityProvider == 0) && (GetRandInt(4) == 0);
// Try to mix more than one input by default. Will fallback to a single input
// if mixing more inputs is impossible atm.
// Note: liqudity providers don't care
bool fAvoidSingle = privateSendClient.nLiquidityProvider == 0;

int nRoundStart = GetStartRound(fMixLowest, fScanFromTheMiddle);
int nRoundEdge = GetStartRound(fMixLowest, false);
int nRoundStartTmp{0};

// Submit transaction to the pool if we get here
while (true) {
for (int i = nRoundStart; i >= 0 && i < privateSendClient.nPrivateSendRounds; i += nLoopStep) {
if (PrepareDenominate(i, i, strError, vecPSInOutPairs, vecPSInOutPairsTmp)) {
LogPrintf("CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, success\n", i);
return SendDenominate(vecPSInOutPairsTmp, connman);
nRoundStartTmp = nRoundStart;
while (true) {
for (int i = nRoundStartTmp; i >= 0 && i < privateSendClient.nPrivateSendRounds; i += nLoopStep) {
if (PrepareDenominate(i, i, strError, vecPSInOutPairs, vecPSInOutPairsTmp, fAvoidSingle)) {
LogPrintf("CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, success\n", i);
return SendDenominate(vecPSInOutPairsTmp, connman);
}
LogPrint("privatesend", "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, error: %s\n", i, strError);
}
LogPrint("privatesend", "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, error: %s\n", i, strError);
if (nRoundStartTmp == nRoundEdge) break;
nRoundStartTmp = nRoundEdge;
}
if (nRoundStart == nRoundEdge) break;
nRoundStart = nRoundEdge;
if (!fAvoidSingle) break;
fAvoidSingle = false;
}

// We failed? That's strange but let's just make final attempt and try to mix everything
if (PrepareDenominate(0, privateSendClient.nPrivateSendRounds - 1, strError, vecPSInOutPairs, vecPSInOutPairsTmp)) {
if (PrepareDenominate(0, privateSendClient.nPrivateSendRounds - 1, strError, vecPSInOutPairs, vecPSInOutPairsTmp, false)) {
LogPrintf("CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for all rounds, success\n");
return SendDenominate(vecPSInOutPairsTmp, connman);
}
Expand Down Expand Up @@ -1259,7 +1269,7 @@ bool CPrivateSendClientSession::SelectDenominate(std::string& strErrorRet, std::
return true;
}

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 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 fAvoidSingle)
{
std::vector<int> vecBits;
if (!CPrivateSend::GetDenominationsBits(nSessionDenom, vecBits)) {
Expand Down Expand Up @@ -1307,7 +1317,7 @@ bool CPrivateSendClientSession::PrepareDenominate(int nMinRounds, int nMaxRounds
}
}

if (nDenomResult != nSessionDenom) {
if (nDenomResult != nSessionDenom || (fAvoidSingle && vecPSInOutPairsRet.size() == 1)) {
// unlock used coins on failure
for (const auto& pair : vecPSInOutPairsRet) {
pwalletMain->UnlockCoin(pair.first.prevout);
Expand Down
2 changes: 1 addition & 1 deletion src/privatesend-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class CPrivateSendClientSession : public CPrivateSendBaseSession
/// step 0: select denominated inputs and txouts
bool SelectDenominate(std::string& strErrorRet, std::vector< std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet);
/// step 1: prepare denominated inputs and outputs
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 PrepareDenominate(int nMinRounds, int nMaxRounds, std::string& strErrorRet, const std::vector< std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsIn, std::vector< std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet, bool fAvoidSingle);
/// step 2: send denominated inputs and outputs prepared in step 1
bool SendDenominate(const std::vector< std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsIn, CConnman& connman);

Expand Down