From 9a4fac6bb64aa66d9685cf472b146510a78de3c7 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 25 Jan 2015 02:57:55 +0300 Subject: [PATCH 1/4] fixing pre-mix process of creation denominated amounts --- src/darksend.cpp | 22 ++++++++++++---------- src/wallet.cpp | 17 ++++++++--------- src/wallet.h | 3 ++- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index 4787199331..4160a87ca7 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1461,22 +1461,24 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) // if balanceNeedsAnonymized is more than pool max, take the pool max if(nBalanceNeedsAnonymized > DARKSEND_POOL_MAX) nBalanceNeedsAnonymized = DARKSEND_POOL_MAX; - // if balanceNeedsAnonymized is more than (non-anonymized - COIN), take (non-anonymized - COIN) - int64_t nBalanceNotYetAnonymized = pwalletMain->GetBalance() - pwalletMain->GetAnonymizedBalance() - COIN; + // if balanceNeedsAnonymized is more than non-anonymized, take non-anonymized + int64_t nBalanceNotYetAnonymized = pwalletMain->GetBalance() - pwalletMain->GetAnonymizedBalance(); if(nBalanceNeedsAnonymized > nBalanceNotYetAnonymized) nBalanceNeedsAnonymized = nBalanceNotYetAnonymized; if(nBalanceNeedsAnonymized < nLowestDenom) { - if(nBalanceNeedsAnonymized > 0) - nBalanceNeedsAnonymized = nLowestDenom; - else - { +// if(nBalanceNeedsAnonymized > nValueMin) +// nBalanceNeedsAnonymized = nLowestDenom; +// else +// { LogPrintf("DoAutomaticDenominating : No funds detected in need of denominating \n"); strAutoDenomResult = "No funds detected in need of denominating"; return false; - } +// } } + if (fDebug) LogPrintf("DoAutomaticDenominating : nLowestDenom=%d, nBalanceNeedsAnonymized=%d\n", nLowestDenom, nBalanceNeedsAnonymized); + // select coins that should be given to the pool if (!pwalletMain->SelectCoinsDark(nValueMin, nBalanceNeedsAnonymized, vCoins, nValueIn, 0, nDarksendRounds)) { @@ -1488,8 +1490,8 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) if(!fDryRun) return CreateDenominated(nBalanceNeedsAnonymized); return true; } else { - LogPrintf("DoAutomaticDenominating : No funds detected in need of denominating (2)\n"); - strAutoDenomResult = "No funds detected in need of denominating (2)"; + LogPrintf("DoAutomaticDenominating : Can't denominate - no compatible inputs left\n"); + strAutoDenomResult = "Can't denominate - no compatible inputs left"; return false; } @@ -1855,7 +1857,7 @@ bool CDarkSendPool::CreateDenominated(int64_t nTotalValue) CCoinControl *coinControl=NULL; bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekey, - nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED); + nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED_MN); if(!success){ LogPrintf("CreateDenominated: Error - %s\n", strFail.c_str()); return false; diff --git a/src/wallet.cpp b/src/wallet.cpp index 79411828cb..fa25c29038 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1237,12 +1237,12 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CTxIn vin = CTxIn(out.tx->GetHash(), out.i); int rounds = GetInputDarksendRounds(vin); if(rounds >= 0) found = true; - } else if(coin_type == ONLY_NONDENOMINATED) { + } else if(coin_type == ONLY_NONDENOMINATED || coin_type == ONLY_NONDENOMINATED_MN) { found = true; BOOST_FOREACH(int64_t d, darkSendDenominations) if(pcoin->vout[i].nValue == d) found = false; - + if(coin_type == ONLY_NONDENOMINATED_MN) found = found && (pcoin->vout[i].nValue != 1000*COIN); } else { found = true; } @@ -1459,9 +1459,6 @@ bool CWallet::SelectCoins(int64_t nTargetValue, set vOut; - // Make outputs by looping through denominations, from large to small BOOST_FOREACH(int64_t v, darkSendDenominations) { @@ -1699,7 +1696,7 @@ bool CWallet::HasDarksendFeeInputs() const vector vCoins; AvailableCoins(vCoins, false, coinControl, ALL_COINS); - bool found_collateral = false; + int nFound = 0; BOOST_FOREACH(const COutput& out, vCoins) { if( @@ -1708,11 +1705,11 @@ bool CWallet::HasDarksendFeeInputs() const out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 3)+DARKSEND_FEE || out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 2)+DARKSEND_FEE || out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 1)+DARKSEND_FEE - ) found_collateral = true; + ) nFound++; } - return found_collateral; + return nFound > 1; // should have more than one just in case } bool CWallet::SelectCoinsWithoutDenomination(int64_t nTargetValue, set >& setCoinsRet, int64_t& nValueRet) const @@ -1852,6 +1849,8 @@ bool CWallet::CreateTransaction(const vector >& vecSend, strFailReason = _("Insufficient funds"); else if (coin_type == ONLY_NONDENOMINATED) strFailReason = _("Unable to locate enough Darksend non-denominated funds for this transaction"); + else if (coin_type == ONLY_NONDENOMINATED_MN) + strFailReason = _("Unable to locate enough Darksend non-denominated funds for this transaction that are not equal 1000 DRK"); else strFailReason = _("Unable to locate enough Darksend denominated funds for this transaction"); @@ -2017,7 +2016,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, std: if (!wtxNew.AcceptToMemoryPool(false)) { // This must not fail. The transaction has already been signed and recorded. - LogPrintf("CommitTransaction() : Error: Transaction not valid"); + LogPrintf("CommitTransaction() : Error: Transaction not valid\n"); return false; } wtxNew.RelayWalletTransaction(strCommand); diff --git a/src/wallet.h b/src/wallet.h index 2cb1f4cf50..1082b13dc1 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -55,7 +55,8 @@ enum AvailableCoinsType { ALL_COINS = 1, ONLY_DENOMINATED = 2, - ONLY_NONDENOMINATED = 3 + ONLY_NONDENOMINATED = 3, + ONLY_NONDENOMINATED_MN = 4 // ONLY_NONDENOMINATED and not 1000 DRK at the same time }; From 144b24bee5164a8d0b72051cdd2a7cfb74a4d213 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 26 Jan 2015 00:18:26 +0300 Subject: [PATCH 2/4] more fixes/cleanup/debug output to DS mixing --- src/darksend.cpp | 81 ++++++++++++++---------------------------------- src/darksend.h | 6 +--- src/wallet.cpp | 8 ++--- src/wallet.h | 2 +- 4 files changed, 30 insertions(+), 67 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index 4160a87ca7..ef7df25a44 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1388,7 +1388,6 @@ void CDarkSendPool::CompletedTransaction(bool error, std::string lastMessageNew) // To avoid race conditions, we'll only let DS run once per block cachedLastSuccess = chainActive.Tip()->nHeight; - splitUpInARow = 0; } lastMessage = lastMessageNew; @@ -1414,9 +1413,9 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) if(fMasterNode) return false; if(state == POOL_STATUS_ERROR || state == POOL_STATUS_SUCCESS) return false; - if(chainActive.Tip()->nHeight-cachedLastSuccess < minBlockSpacing) { - LogPrintf("CDarkSendPool::DoAutomaticDenominating - Last successful darksend was too recent\n"); - strAutoDenomResult = "Last successful darksend was too recent"; + if(chainActive.Tip()->nHeight - cachedLastSuccess < minBlockSpacing) { + LogPrintf("CDarkSendPool::DoAutomaticDenominating - Last successful darksend action was too recent\n"); + strAutoDenomResult = "Last successful darksend action was too recent"; return false; } if(!fEnableDarksend) { @@ -1445,7 +1444,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) // ** find the coins we'll use std::vector vCoins; std::vector vCoins2; - int64_t nValueMin = 0.01*COIN; + int64_t nValueMin = CENT; int64_t nValueIn = 0; // should not be less than fees in DARKSEND_FEE + few (lets say 5) smallest denoms @@ -1499,7 +1498,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) //check to see if we have the fee sized inputs, it requires these if(!pwalletMain->HasDarksendFeeInputs()){ - if(!fDryRun) SplitUpMoney(true); + if(!fDryRun) MakeCollateralAmounts(); return true; } @@ -1713,31 +1712,17 @@ bool CDarkSendPool::SendRandomPaymentToSelf() } // Split up large inputs or create fee sized inputs -bool CDarkSendPool::SplitUpMoney(bool justCollateral) +bool CDarkSendPool::MakeCollateralAmounts() { - if((chainActive.Tip()->nHeight - lastSplitUpBlock) < 10){ - LogPrintf("SplitUpMoney - Too soon to split up again\n"); - return false; - } - - if(splitUpInARow >= 2){ - LogPrintf("Error: Darksend SplitUpMoney was called multiple times in a row. This should not happen. Please submit a detailed explanation of the steps it took to create this error and submit to evan@darkcoin.io. \n"); - fEnableDarksend = false; - return false; - } - // should split up to remaining amount only... int64_t nTotalBalance = pwalletMain->GetDenominatedBalance(false); int64_t nSplitBalance = nAnonymizeDarkcoinAmount*COIN - pwalletMain->GetDenominatedBalance(); if(nSplitBalance > nTotalBalance) nSplitBalance = nTotalBalance; - // ...or up to 1 DRK if it's just collateral - if(justCollateral && nSplitBalance > 1*COIN) nSplitBalance = 1*COIN; + // ...but up to 1 DRK only + if(nSplitBalance > 1*COIN) nSplitBalance = 1*COIN; int64_t nTotalOut = 0; - lastSplitUpBlock = chainActive.Tip()->nHeight; - LogPrintf("DoAutomaticDenominating: Split up large input (justCollateral %d):\n", justCollateral); - LogPrintf(" -- nSplitBalance %d\n", nSplitBalance); - LogPrintf(" -- denom %d \n", pwalletMain->GetDenominatedBalance(false)); + LogPrintf("DoAutomaticDenominating: MakeCollateralAmounts: nSplitBalance %d nTotalBalance %d\n", nSplitBalance, pwalletMain->GetDenominatedBalance(false)); // make our change address CReserveKey reservekey(pwalletMain); @@ -1752,54 +1737,31 @@ bool CDarkSendPool::SplitUpMoney(bool justCollateral) std::string strFail = ""; vector< pair > vecSend; - int64_t a = 1*COIN; - // ****** Add fees ************ / vecSend.push_back(make_pair(scriptChange, (DARKSEND_COLLATERAL*2)+DARKSEND_FEE)); nTotalOut += (DARKSEND_COLLATERAL*2)+DARKSEND_FEE; vecSend.push_back(make_pair(scriptChange, (DARKSEND_COLLATERAL*2)+DARKSEND_FEE)); nTotalOut += (DARKSEND_COLLATERAL*2)+DARKSEND_FEE; - // ****** Add outputs in bases of two from 1 darkcoin *** / - if(!justCollateral){ - bool continuing = true; - - while(continuing){ - if(nTotalOut + a < nSplitBalance){ - //LogPrintf(" nTotalOut %d, added %d\n", nTotalOut, a); - - vecSend.push_back(make_pair(scriptChange, a)); - nTotalOut += a; - } else { - continuing = false; - } - - a = a * 2; - } - } - - if((justCollateral && nTotalOut <= 0.1*COIN) || vecSend.size() < 1) { - LogPrintf("SplitUpMoney: Not enough outputs to make a transaction\n"); - return false; - } - if((!justCollateral && nTotalOut <= 1*COIN) || vecSend.size() < 1){ - LogPrintf("SplitUpMoney: Not enough outputs to make a transaction\n"); + if(nTotalOut > nSplitBalance) { + LogPrintf("MakeCollateralAmounts: Not enough outputs to make a transaction\n"); return false; } CCoinControl *coinControl=NULL; bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekey, - nFeeRet, strFail, coinControl, justCollateral ? ALL_COINS : ONLY_NONDENOMINATED); + nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED_NOTMN); if(!success){ - LogPrintf("SplitUpMoney: Error - %s\n", strFail.c_str()); + LogPrintf("MakeCollateralAmounts: Error - %s\n", strFail.c_str()); return false; } - pwalletMain->CommitTransaction(wtx, reservekey); + // use the same cachedLastSuccess as for DS mixinx to prevent race + if(pwalletMain->CommitTransaction(wtx, reservekey)) + cachedLastSuccess = chainActive.Tip()->nHeight; - LogPrintf("SplitUpMoney Success: tx %s\n", wtx.GetHash().GetHex().c_str()); + LogPrintf("MakeCollateralAmounts Success: tx %s\n", wtx.GetHash().GetHex().c_str()); - splitUpInARow++; return true; } @@ -1857,13 +1819,15 @@ bool CDarkSendPool::CreateDenominated(int64_t nTotalValue) CCoinControl *coinControl=NULL; bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekey, - nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED_MN); + nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED_NOTMN); if(!success){ LogPrintf("CreateDenominated: Error - %s\n", strFail.c_str()); return false; } - pwalletMain->CommitTransaction(wtx, reservekey); + // use the same cachedLastSuccess as for DS mixinx to prevent race + if(pwalletMain->CommitTransaction(wtx, reservekey)) + cachedLastSuccess = chainActive.Tip()->nHeight; LogPrintf("CreateDenominated Success: tx %s\n", wtx.GetHash().GetHex().c_str()); @@ -2125,6 +2089,9 @@ bool CDarkSendSigner::VerifyMessage(CPubKey pubkey, vector& vchSi return false; } + if (fDebug && pubkey2.GetID() != pubkey.GetID()) + LogPrintf("CDarkSendSigner::VerifyMessage -- keys don't match: %s %s", pubkey2.GetID().ToString(), pubkey.GetID().ToString()); + return (pubkey2.GetID() == pubkey.GetID()); } diff --git a/src/darksend.h b/src/darksend.h index f6307fc6ce..c7968e355c 100644 --- a/src/darksend.h +++ b/src/darksend.h @@ -259,8 +259,6 @@ public: int64_t sessionTotalValue; //used for autoDenom std::vector vecSessionCollateral; - int lastSplitUpBlock; - int splitUpInARow; // how many splits we've done since a success? int cachedLastSuccess; int cachedNumBlocks; //used for the overview screen int minBlockSpacing; //required blocks between mixes @@ -277,11 +275,9 @@ public: /* DarkSend uses collateral addresses to trust parties entering the pool to behave themselves. If they don't it takes their money. */ - lastSplitUpBlock = 0; cachedLastSuccess = 0; cachedNumBlocks = 0; unitTest = false; - splitUpInARow = 0; txCollateral = CTransaction(); minBlockSpacing = 1; nDsqCount = 0; @@ -420,7 +416,7 @@ public: // used for liquidity providers bool SendRandomPaymentToSelf(); // split up large inputs or make fee sized inputs - bool SplitUpMoney(bool justCollateral=false); + bool MakeCollateralAmounts(); bool CreateDenominated(int64_t nTotalValue); // get the denominations for a list of outputs (returns a bitshifted integer) int GetDenominations(const std::vector& vout); diff --git a/src/wallet.cpp b/src/wallet.cpp index fa25c29038..b19a3bafe4 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1237,12 +1237,12 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CTxIn vin = CTxIn(out.tx->GetHash(), out.i); int rounds = GetInputDarksendRounds(vin); if(rounds >= 0) found = true; - } else if(coin_type == ONLY_NONDENOMINATED || coin_type == ONLY_NONDENOMINATED_MN) { + } else if(coin_type == ONLY_NONDENOMINATED || coin_type == ONLY_NONDENOMINATED_NOTMN) { found = true; BOOST_FOREACH(int64_t d, darkSendDenominations) if(pcoin->vout[i].nValue == d) found = false; - if(coin_type == ONLY_NONDENOMINATED_MN) found = found && (pcoin->vout[i].nValue != 1000*COIN); + if(coin_type == ONLY_NONDENOMINATED_NOTMN) found = found && (pcoin->vout[i].nValue != 1000*COIN); } else { found = true; } @@ -1590,7 +1590,7 @@ bool CWallet::SelectCoinsDark(int64_t nValueMin, int64_t nValueMax, std::vector< nValueRet = 0; vector vCoins; - AvailableCoins(vCoins, false, coinControl, nDarksendRoundsMin < 0 ? ONLY_NONDENOMINATED : ONLY_DENOMINATED); + AvailableCoins(vCoins, false, coinControl, nDarksendRoundsMin < 0 ? ONLY_NONDENOMINATED_NOTMN : ONLY_DENOMINATED); set > setCoinsRet2; @@ -1849,7 +1849,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, strFailReason = _("Insufficient funds"); else if (coin_type == ONLY_NONDENOMINATED) strFailReason = _("Unable to locate enough Darksend non-denominated funds for this transaction"); - else if (coin_type == ONLY_NONDENOMINATED_MN) + else if (coin_type == ONLY_NONDENOMINATED_NOTMN) strFailReason = _("Unable to locate enough Darksend non-denominated funds for this transaction that are not equal 1000 DRK"); else strFailReason = _("Unable to locate enough Darksend denominated funds for this transaction"); diff --git a/src/wallet.h b/src/wallet.h index 1082b13dc1..fbd0240df8 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -56,7 +56,7 @@ enum AvailableCoinsType ALL_COINS = 1, ONLY_DENOMINATED = 2, ONLY_NONDENOMINATED = 3, - ONLY_NONDENOMINATED_MN = 4 // ONLY_NONDENOMINATED and not 1000 DRK at the same time + ONLY_NONDENOMINATED_NOTMN = 4 // ONLY_NONDENOMINATED and not 1000 DRK at the same time }; From a07d637a481bb1ea29f009f432d64544d1e991bd Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 27 Jan 2015 07:13:34 +0300 Subject: [PATCH 3/4] don't use collateral amounts on CreateDenominated / make collateral inputs from all available coins and not only from non-denominated / IsCollateralAmount function --- src/darksend.cpp | 21 +++++++++------------ src/wallet.cpp | 34 +++++++++++++++------------------- src/wallet.h | 3 ++- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index ef7df25a44..16bace84e7 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1450,8 +1450,8 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) // should not be less than fees in DARKSEND_FEE + few (lets say 5) smallest denoms int64_t nLowestDenom = DARKSEND_FEE + darkSendDenominations[darkSendDenominations.size() - 1]*5; - // if there is no DS fee yet - if(!pwalletMain->HasDarksendFeeInputs()) + // if there are no DS collateral inputs yet + if(!pwalletMain->HasCollateralInputs()) // should have some additional amount for them nLowestDenom += (DARKSEND_COLLATERAL*4)+DARKSEND_FEE*2; @@ -1496,8 +1496,8 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) } - //check to see if we have the fee sized inputs, it requires these - if(!pwalletMain->HasDarksendFeeInputs()){ + //check to see if we have the collateral sized inputs, it requires these + if(!pwalletMain->HasCollateralInputs()){ if(!fDryRun) MakeCollateralAmounts(); return true; } @@ -1715,11 +1715,9 @@ bool CDarkSendPool::SendRandomPaymentToSelf() bool CDarkSendPool::MakeCollateralAmounts() { // should split up to remaining amount only... - int64_t nTotalBalance = pwalletMain->GetDenominatedBalance(false); + int64_t nTotalBalance = pwalletMain->GetBalance(); int64_t nSplitBalance = nAnonymizeDarkcoinAmount*COIN - pwalletMain->GetDenominatedBalance(); if(nSplitBalance > nTotalBalance) nSplitBalance = nTotalBalance; - // ...but up to 1 DRK only - if(nSplitBalance > 1*COIN) nSplitBalance = 1*COIN; int64_t nTotalOut = 0; LogPrintf("DoAutomaticDenominating: MakeCollateralAmounts: nSplitBalance %d nTotalBalance %d\n", nSplitBalance, pwalletMain->GetDenominatedBalance(false)); @@ -1737,20 +1735,19 @@ bool CDarkSendPool::MakeCollateralAmounts() std::string strFail = ""; vector< pair > vecSend; - // ****** Add fees ************ / vecSend.push_back(make_pair(scriptChange, (DARKSEND_COLLATERAL*2)+DARKSEND_FEE)); nTotalOut += (DARKSEND_COLLATERAL*2)+DARKSEND_FEE; vecSend.push_back(make_pair(scriptChange, (DARKSEND_COLLATERAL*2)+DARKSEND_FEE)); nTotalOut += (DARKSEND_COLLATERAL*2)+DARKSEND_FEE; if(nTotalOut > nSplitBalance) { - LogPrintf("MakeCollateralAmounts: Not enough outputs to make a transaction\n"); + LogPrintf("MakeCollateralAmounts: Not enough balance to split\n"); return false; } CCoinControl *coinControl=NULL; bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekey, - nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED_NOTMN); + nFeeRet, strFail, coinControl, ALL_COINS); if(!success){ LogPrintf("MakeCollateralAmounts: Error - %s\n", strFail.c_str()); return false; @@ -1782,8 +1779,8 @@ bool CDarkSendPool::CreateDenominated(int64_t nTotalValue) vector< pair > vecSend; int64_t nValueLeft = nTotalValue; - // ****** Add fees ************ / - if(!pwalletMain->HasDarksendFeeInputs()) { + // ****** Add collateral outputs ************ / + if(!pwalletMain->HasCollateralInputs()) { vecSend.push_back(make_pair(scriptChange, (DARKSEND_COLLATERAL*2)+DARKSEND_FEE)); nValueLeft -= (DARKSEND_COLLATERAL*2)+DARKSEND_FEE; vecSend.push_back(make_pair(scriptChange, (DARKSEND_COLLATERAL*2)+DARKSEND_FEE)); diff --git a/src/wallet.cpp b/src/wallet.cpp index b19a3bafe4..c8c3a5a9ab 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1239,10 +1239,11 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if(rounds >= 0) found = true; } else if(coin_type == ONLY_NONDENOMINATED || coin_type == ONLY_NONDENOMINATED_NOTMN) { found = true; + if (IsCollateralAmount(pcoin->vout[i].nValue)) continue; // do not use collateral amounts BOOST_FOREACH(int64_t d, darkSendDenominations) if(pcoin->vout[i].nValue == d) found = false; - if(coin_type == ONLY_NONDENOMINATED_NOTMN) found = found && (pcoin->vout[i].nValue != 1000*COIN); + if(found && coin_type == ONLY_NONDENOMINATED_NOTMN) found = (pcoin->vout[i].nValue != 1000*COIN); // do not use MN funds } else { found = true; } @@ -1640,13 +1641,8 @@ bool CWallet::SelectCoinsCollateral(std::vector& setCoinsRet, int64_t& nV BOOST_FOREACH(const COutput& out, vCoins) { // collateral inputs will always be a multiple of DARSEND_COLLATERAL, up to five - if( - out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 5)+DARKSEND_FEE || - out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 4)+DARKSEND_FEE || - out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 3)+DARKSEND_FEE || - out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 2)+DARKSEND_FEE || - out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 1)+DARKSEND_FEE - ){ + if(IsCollateralAmount(out.tx->vout[out.i].nValue)) + { CTxIn vin = CTxIn(out.tx->GetHash(),out.i); vin.prevPubKey = out.tx->vout[out.i].scriptPubKey; // the inputs PubKey @@ -1689,7 +1685,7 @@ int CWallet::CountInputsWithAmount(int64_t nInputAmount) return nTotal; } -bool CWallet::HasDarksendFeeInputs() const +bool CWallet::HasCollateralInputs() const { CCoinControl *coinControl=NULL; @@ -1698,20 +1694,20 @@ bool CWallet::HasDarksendFeeInputs() const int nFound = 0; BOOST_FOREACH(const COutput& out, vCoins) - { - if( - out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 5)+DARKSEND_FEE || - out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 4)+DARKSEND_FEE || - out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 3)+DARKSEND_FEE || - out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 2)+DARKSEND_FEE || - out.tx->vout[out.i].nValue == (DARKSEND_COLLATERAL * 1)+DARKSEND_FEE - ) nFound++; - - } + if(IsCollateralAmount(out.tx->vout[out.i].nValue)) nFound++; return nFound > 1; // should have more than one just in case } +bool CWallet::IsCollateralAmount(int64_t nInputAmount) const +{ + return nInputAmount == (DARKSEND_COLLATERAL * 5)+DARKSEND_FEE || + nInputAmount == (DARKSEND_COLLATERAL * 4)+DARKSEND_FEE || + nInputAmount == (DARKSEND_COLLATERAL * 3)+DARKSEND_FEE || + nInputAmount == (DARKSEND_COLLATERAL * 2)+DARKSEND_FEE || + nInputAmount == (DARKSEND_COLLATERAL * 1)+DARKSEND_FEE; +} + bool CWallet::SelectCoinsWithoutDenomination(int64_t nTargetValue, set >& setCoinsRet, int64_t& nValueRet) const { CCoinControl *coinControl=NULL; diff --git a/src/wallet.h b/src/wallet.h index fbd0240df8..906a16a04c 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -137,7 +137,8 @@ public: bool SelectCoinsByDenominations(int nDenom, int64_t nValueMin, int64_t nValueMax, std::vector& setCoinsRet, vector& vCoins, int64_t& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax); bool SelectCoinsDarkDenominated(int64_t nTargetValue, std::vector& setCoinsRet, int64_t& nValueRet) const; bool SelectCoinsMasternode(CTxIn& vin, int64_t& nValueRet, CScript& pubScript) const; - bool HasDarksendFeeInputs() const; + bool HasCollateralInputs() const; + bool IsCollateralAmount(int64_t nInputAmount) const; int CountInputsWithAmount(int64_t nInputAmount); bool SelectCoinsCollateral(std::vector& setCoinsRet, int64_t& nValueRet) const ; From 287ea11a25747537c21658d20b51cd8a197893a2 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 27 Jan 2015 07:39:27 +0300 Subject: [PATCH 4/4] make collateral inputs from all available inputs but not from mn-like --- src/darksend.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index 16bace84e7..9caa588d36 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1746,11 +1746,18 @@ bool CDarkSendPool::MakeCollateralAmounts() } CCoinControl *coinControl=NULL; - bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekey, - nFeeRet, strFail, coinControl, ALL_COINS); + // try to use non-denominated and not mn-like funds + bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekey, + nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED_NOTMN); if(!success){ - LogPrintf("MakeCollateralAmounts: Error - %s\n", strFail.c_str()); - return false; + // if we failed (most likeky not enough funds), try to use denominated instead - + // MN-like funds should not be touched in any case and we can't mix denominated without collaterals anyway + success = pwalletMain->CreateTransaction(vecSend, wtx, reservekey, + nFeeRet, strFail, coinControl, ONLY_DENOMINATED); + if(!success){ + LogPrintf("MakeCollateralAmounts: Error - %s\n", strFail.c_str()); + return false; + } } // use the same cachedLastSuccess as for DS mixinx to prevent race