From a07d637a481bb1ea29f009f432d64544d1e991bd Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 27 Jan 2015 07:13:34 +0300 Subject: [PATCH] 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 ;