Skip to content

Commit

Permalink
fix MakeCollateralAmounts (#1500)
Browse files Browse the repository at this point in the history
apply same logic as in CreateDenominated to avoid joining inputs from different addresses
  • Loading branch information
UdjinM6 committed Jul 10, 2017
1 parent 739ef9a commit 7abac06
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
35 changes: 25 additions & 10 deletions src/privatesend-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,18 +1129,28 @@ bool CPrivateSendClient::MakeCollateralAmounts()
return false;
}

// First try to use only non-denominated funds
BOOST_FOREACH(CompactTallyItem& item, vecTally) {
if(!MakeCollateralAmounts(item)) continue;
if(!MakeCollateralAmounts(item, false)) continue;
return true;
}

LogPrintf("CPrivateSendClient::MakeCollateralAmounts -- failed!\n");
// There should be at least some denominated funds we should be able to break in pieces to continue mixing
BOOST_FOREACH(CompactTallyItem& item, vecTally) {
if(!MakeCollateralAmounts(item, true)) continue;
return true;
}

// If we got here then smth is terribly broken actually
LogPrintf("CPrivateSendClient::MakeCollateralAmounts -- ERROR: Can't make collaterals!\n");
return false;
}

// Split up large inputs or create fee sized inputs
bool CPrivateSendClient::MakeCollateralAmounts(const CompactTallyItem& tallyItem)
bool CPrivateSendClient::MakeCollateralAmounts(const CompactTallyItem& tallyItem, bool fTryDenominated)
{
LOCK2(cs_main, pwalletMain->cs_wallet);

CWalletTx wtx;
CAmount nFeeRet = 0;
int nChangePosRet = -1;
Expand Down Expand Up @@ -1171,14 +1181,19 @@ bool CPrivateSendClient::MakeCollateralAmounts(const CompactTallyItem& tallyItem
bool fSuccess = pwalletMain->CreateTransaction(vecSend, wtx, reservekeyChange,
nFeeRet, nChangePosRet, strFail, &coinControl, true, ONLY_NONDENOMINATED_NOT1000IFMN);
if(!fSuccess) {
// if we failed (most likeky not enough funds), try to use all coins instead -
// MN-like funds should not be touched in any case and we can't mix denominated without collaterals anyway
LogPrintf("CPrivateSendClient::MakeCollateralAmounts -- ONLY_NONDENOMINATED_NOT1000IFMN Error: %s\n", strFail);
CCoinControl *coinControlNull = NULL;
fSuccess = pwalletMain->CreateTransaction(vecSend, wtx, reservekeyChange,
nFeeRet, nChangePosRet, strFail, coinControlNull, true, ONLY_NOT1000IFMN);
if(!fSuccess) {
LogPrintf("CPrivateSendClient::MakeCollateralAmounts -- ONLY_NOT1000IFMN Error: %s\n", strFail);
// If we failed then most likeky there are not enough funds on this address.
if(fTryDenominated) {
// Try to also use denominated coins (we can't mix denominated without collaterals anyway).
// MN-like funds should not be touched in any case.
if(!pwalletMain->CreateTransaction(vecSend, wtx, reservekeyChange,
nFeeRet, nChangePosRet, strFail, &coinControl, true, ONLY_NOT1000IFMN)) {
LogPrintf("CPrivateSendClient::MakeCollateralAmounts -- ONLY_NOT1000IFMN Error: %s\n", strFail);
reservekeyCollateral.ReturnKey();
return false;
}
} else {
// Nothing else we can do.
reservekeyCollateral.ReturnKey();
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/privatesend-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CPrivateSendClient : public CPrivateSendBase

/// Split up large inputs or make fee sized inputs
bool MakeCollateralAmounts();
bool MakeCollateralAmounts(const CompactTallyItem& tallyItem);
bool MakeCollateralAmounts(const CompactTallyItem& tallyItem, bool fTryDenominated);

/// As a client, submit part of a future mixing transaction to a Masternode to start the process
bool SubmitDenominate();
Expand Down

0 comments on commit 7abac06

Please sign in to comment.