From 190122bc7e66ca3cd6f81aae8639693a67f1edab Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 4 Dec 2014 05:17:18 +0300 Subject: [PATCH 1/7] DS fix --- src/darksend.cpp | 87 +++++++++++++++++++++++++----------------------- src/wallet.cpp | 24 +++++++------ 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index ba1aaeb8c7fc..2c93c746b678 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1415,60 +1415,74 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) // ** find the coins we'll use std::vector vCoins; - int64 nValueMin = 0.01*COIN; - int64 nValueMax = DARKSEND_POOL_MAX; + int64 nValueMin = 0.1*COIN + 1; // select at least one smallest denom int64 nValueIn = 0; int minRounds = -2; //non denominated funds are rounds of less than 0 - int maxAmount = DARKSEND_POOL_MAX/COIN; + int64 balance = pwalletMain->GetBalance(); + int64 balanceNeedsDenominated = nAnonymizeDarkcoinAmount*COIN; // set target value on init + int64 balanceNeedsAnonymized = nAnonymizeDarkcoinAmount*COIN; // set target value on init bool hasFeeInput = false; - // if we have more denominated funds (of any maturity) than the nAnonymizeDarkcoinAmount, we should use use those - if(pwalletMain->GetDenominatedBalance(true) >= nAnonymizeDarkcoinAmount*COIN) { - minRounds = 0; - } - //if we're set to less than a thousand, don't submit for than that to the pool - if(nAnonymizeDarkcoinAmount < DARKSEND_POOL_MAX/COIN) maxAmount = nAnonymizeDarkcoinAmount; + // do we have enough balance? + if(balanceNeedsDenominated > balance) balanceNeedsDenominated = balance; + if(balanceNeedsAnonymized > balance) balanceNeedsAnonymized = balance; - int64 balanceNeedsAnonymized = pwalletMain->GetBalance() - pwalletMain->GetAnonymizedBalance(); - if(balanceNeedsAnonymized > maxAmount*COIN) balanceNeedsAnonymized= maxAmount*COIN; - if(balanceNeedsAnonymized < COIN*2.5){ - LogPrintf("DoAutomaticDenominating : No funds detected in need of denominating \n"); - return false; - } + // count in what is already done + balanceNeedsDenominated -= pwalletMain->GetDenominatedBalance(true); + balanceNeedsAnonymized -= pwalletMain->GetAnonymizedBalance(); - // if the balance is more the pool max, take the pool max - if(balanceNeedsAnonymized > nValueMax) { - balanceNeedsAnonymized = nValueMax; + // is there anything left to do? + // if no more denomination needed do not select non-denom inputs + if(balanceNeedsDenominated <= 0) minRounds = 0; + + // is amount to anonymize still higher then pool allows? + if(balanceNeedsAnonymized > DARKSEND_POOL_MAX) balanceNeedsAnonymized = DARKSEND_POOL_MAX; + + // if there is nothing more to anonymize + if(balanceNeedsAnonymized <= 1*COIN){ + LogPrintf("DoAutomaticDenominating : No funds detected in need of anonymizing \n"); + return false; } // select coins that should be given to the pool - if (!pwalletMain->SelectCoinsDark(nValueMin, maxAmount*COIN, vCoins, nValueIn, minRounds, nDarksendRounds, hasFeeInput)) + if (!pwalletMain->SelectCoinsDark(nValueMin, balanceNeedsAnonymized, vCoins, nValueIn, minRounds, nDarksendRounds, hasFeeInput)) { nValueIn = 0; vCoins.clear(); // look for inputs larger than the max amount, if we find anything we need to split it up - if (pwalletMain->SelectCoinsDark(maxAmount*COIN, 9999999*COIN, vCoins, nValueIn, minRounds, nDarksendRounds, hasFeeInput)) + if (pwalletMain->SelectCoinsDark(balanceNeedsAnonymized, 9999999*COIN, vCoins, nValueIn, minRounds, nDarksendRounds, hasFeeInput)) { if(!fDryRun) SplitUpMoney(); return true; } - LogPrintf("DoAutomaticDenominating : No funds detected in need of denominating (2)\n"); + LogPrintf("DoAutomaticDenominating : No funds detected in need of denominating %"PRI64d" %"PRI64d" %d %"PRI64d" %"PRI64d" %"PRI64d" %"PRI64d"\n", + balanceNeedsDenominated, + balanceNeedsAnonymized, + minRounds, + nAnonymizeDarkcoinAmount, + balance, + pwalletMain->GetDenominatedBalance(true), + pwalletMain->GetAnonymizedBalance() + ); return false; } - // the darksend pool can only take 1.1DRK minimum - if(nValueIn < COIN*1.1){ - //simply look for non-denominated coins - if (pwalletMain->SelectCoinsDark(maxAmount*COIN, 9999999*COIN, vCoins, nValueIn, minRounds, nDarksendRounds, hasFeeInput)) - { - if(!fDryRun) SplitUpMoney(); - return true; + if(vecDisabledDenominations.size() == 0){ + //if we have 20x 0.1DRk and 1DRK inputs, we can start just anonymizing 10DRK and 100DRK inputs only. + if(pwalletMain->CountInputsWithAmount((1 * COIN)+1) >= 20 && + pwalletMain->CountInputsWithAmount((.1 * COIN)+1) >= 20){ + vecDisabledDenominations.push_back((1 * COIN)+1); + vecDisabledDenominations.push_back((.1 * COIN)+1); } + } - LogPrintf("DoAutomaticDenominating : Too little to denominate (must have 1.1DRK) \n"); - return false; + // but if we tried to split last time and didn't find anything + // then this time we'll fallback back to 1s and 0.1s to complete anonymization + if(nValueIn < 10*COIN){ + vecDisabledDenominations.clear(); + LogPrintf("DoAutomaticDenominating : Splitting the rest to 0.1s and 1s \n"); } //check to see if we have the fee sized inputs, it requires these @@ -1479,15 +1493,6 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) if(fDryRun) return true; - if(vecDisabledDenominations.size() == 0){ - //if we have 20x 0.1DRk and 1DRK inputs, we can start just anonymizing 10DRK inputs. - if(pwalletMain->CountInputsWithAmount((1 * COIN)+1) >= 20 && - pwalletMain->CountInputsWithAmount((.1 * COIN)+1) >= 20){ - vecDisabledDenominations.push_back((1 * COIN)+1); - vecDisabledDenominations.push_back((.1 * COIN)+1); - } - } - // initial phase, find a masternode if(!sessionFoundMasternode){ int nUseQueue = rand()%100; @@ -1499,7 +1504,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) if(minRounds == 0 || pwalletMain->GetDenominatedBalance(true) * 0.05 > pwalletMain->GetDenominatedBalance(false)) { for(int a = 0; a < 10; a++){ //try 10 amounts and see if we match a queue - int r = (rand()%(maxAmount-(nValueMin/COIN)))+(nValueMin/COIN); + int r = (rand()%((balanceNeedsAnonymized-nValueMin)/COIN))+(nValueMin/COIN); vCoins.clear(); nValueIn = 0; @@ -1524,7 +1529,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) } } } - if(sessionTotalValue > maxAmount*COIN) sessionTotalValue = maxAmount*COIN; + if(sessionTotalValue > balanceNeedsAnonymized) sessionTotalValue = balanceNeedsAnonymized; double fDarkcoinSubmitted = sessionTotalValue / COIN; diff --git a/src/wallet.cpp b/src/wallet.cpp index e1b05b41d83f..da5d1dfc9595 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1049,21 +1049,25 @@ int64 CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed) const { const CWalletTx* pcoin = &(*it).second; - bool isDenom = false; - for (unsigned int i = 0; i < pcoin->vout.size(); i++) + for (unsigned int i = 0; i < pcoin->vout.size(); i++){ + + if(pcoin->IsSpent(i) || !IsMine(pcoin->vout[i])) continue; + + bool isDenom = false; BOOST_FOREACH(int64 d, darkSendDenominations) if(pcoin->vout[i].nValue == d) isDenom = true; - if(onlyUnconfirmed){ - if (!pcoin->IsFinal() || !pcoin->IsConfirmed()){ - if(onlyDenom == isDenom){ - nTotal += pcoin->GetAvailableCredit(); + if(onlyUnconfirmed){ + if (!pcoin->IsFinal() || !pcoin->IsConfirmed()){ + if(onlyDenom == isDenom){ + nTotal += pcoin->vout[i].nValue; + } + } + } else if (pcoin->IsConfirmed()) { + if(onlyDenom == isDenom) { + nTotal += pcoin->vout[i].nValue; } - } - } else if (pcoin->IsConfirmed()) { - if(onlyDenom == isDenom) { - nTotal += pcoin->GetAvailableCredit(); } } } From e85ef096af1533099592cffdd58ee35be333c8dc Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 4 Dec 2014 06:37:32 +0300 Subject: [PATCH 2/7] another fallback - minRounds --- src/darksend.cpp | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index 2c93c746b678..985ece9b8b64 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1444,29 +1444,35 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) return false; } + // select coins that should be given to the pool if (!pwalletMain->SelectCoinsDark(nValueMin, balanceNeedsAnonymized, vCoins, nValueIn, minRounds, nDarksendRounds, hasFeeInput)) { - nValueIn = 0; - vCoins.clear(); - - // look for inputs larger than the max amount, if we find anything we need to split it up - if (pwalletMain->SelectCoinsDark(balanceNeedsAnonymized, 9999999*COIN, vCoins, nValueIn, minRounds, nDarksendRounds, hasFeeInput)) + // fall back to non-denom + minRounds = -2; + if (!pwalletMain->SelectCoinsDark(nValueMin, balanceNeedsAnonymized, vCoins, nValueIn, minRounds, nDarksendRounds, hasFeeInput)) { - if(!fDryRun) SplitUpMoney(); - return true; - } + nValueIn = 0; + vCoins.clear(); - LogPrintf("DoAutomaticDenominating : No funds detected in need of denominating %"PRI64d" %"PRI64d" %d %"PRI64d" %"PRI64d" %"PRI64d" %"PRI64d"\n", - balanceNeedsDenominated, - balanceNeedsAnonymized, - minRounds, - nAnonymizeDarkcoinAmount, - balance, - pwalletMain->GetDenominatedBalance(true), - pwalletMain->GetAnonymizedBalance() - ); - return false; + // look for inputs larger than the max amount, if we find anything we need to split it up + if (pwalletMain->SelectCoinsDark(balanceNeedsAnonymized, 9999999*COIN, vCoins, nValueIn, minRounds, nDarksendRounds, hasFeeInput)) + { + if(!fDryRun) SplitUpMoney(); + return true; + } + + LogPrintf("DoAutomaticDenominating : No funds detected in need of denominating %"PRI64d" %"PRI64d" %d %"PRI64d" %"PRI64d" %"PRI64d" %"PRI64d"\n", + balanceNeedsDenominated, + balanceNeedsAnonymized, + minRounds, + nAnonymizeDarkcoinAmount, + balance, + pwalletMain->GetDenominatedBalance(true), + pwalletMain->GetAnonymizedBalance() + ); + return false; + } } if(vecDisabledDenominations.size() == 0){ @@ -1479,10 +1485,10 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) } // but if we tried to split last time and didn't find anything - // then this time we'll fallback back to 1s and 0.1s to complete anonymization + // then this time we'll fall back to 1s and 0.1s to complete anonymization if(nValueIn < 10*COIN){ vecDisabledDenominations.clear(); - LogPrintf("DoAutomaticDenominating : Splitting the rest to 0.1s and 1s \n"); + LogPrintf("DoAutomaticDenominating : falling back to 0.1s and 1s\n"); } //check to see if we have the fee sized inputs, it requires these From ee53764cafe2633e7b75fec025d31284df5d25a0 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 4 Dec 2014 22:29:05 +0300 Subject: [PATCH 3/7] fix maxRounds / simplify conditions --- src/darksend.cpp | 110 +++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 60 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index 5d526ee85971..cbfe1e3d0b3d 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1418,7 +1418,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) int64 nValueMin = 0.1*COIN + 1; // select at least one smallest denom int64 nValueIn = 0; int minRounds = -2; //non denominated funds are rounds of less than 0 - int maxRounds = -2; + int maxRounds = 0; int64 balance = pwalletMain->GetBalance(); int64 balanceNeedsDenominated = nAnonymizeDarkcoinAmount*COIN; // set target value on init int64 balanceNeedsAnonymized = nAnonymizeDarkcoinAmount*COIN; // set target value on init @@ -1454,7 +1454,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) { // fall back to non-denom minRounds = -2; - maxRounds = -2; + maxRounds = 0; if (!pwalletMain->SelectCoinsDark(nValueMin, balanceNeedsAnonymized, vCoins, nValueIn, minRounds, maxRounds, hasFeeInput)) { nValueIn = 0; @@ -1468,13 +1468,13 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) } LogPrintf("DoAutomaticDenominating : No funds detected in need of denominating %"PRI64d" %"PRI64d" %d %"PRI64d" %"PRI64d" %"PRI64d" %"PRI64d"\n", - balanceNeedsDenominated, - balanceNeedsAnonymized, + balanceNeedsDenominated/COIN, + balanceNeedsAnonymized/COIN, minRounds, nAnonymizeDarkcoinAmount, - balance, - pwalletMain->GetDenominatedBalance(true), - pwalletMain->GetAnonymizedBalance() + balance/COIN, + pwalletMain->GetDenominatedBalance(true)/COIN, + pwalletMain->GetAnonymizedBalance()/COIN ); return false; } @@ -1512,37 +1512,37 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) //randomize the amounts we mix // if we have minRounds set, or if our non-demon is less than 5% of denom coins - if(minRounds == 0 || - pwalletMain->GetDenominatedBalance(true) * 0.05 > pwalletMain->GetDenominatedBalance(false)) { - for(int a = 0; a < 10; a++){ //try 10 amounts and see if we match a queue - int r = (rand()%((balanceNeedsAnonymized-nValueMin)/COIN))+(nValueMin/COIN); - - vCoins.clear(); - nValueIn = 0; - if (pwalletMain->SelectCoinsDark(nValueMin, r*COIN, vCoins, nValueIn, minRounds, maxRounds, hasFeeInput)){ - sessionTotalValue = pwalletMain->GetTotalValue(vCoins); - - // if it's in the queue, take it - if(nUseQueue > 33 && vecDarksendQueue.size() > 0){ - BOOST_FOREACH(CDarksendQueue& dsq, vecDarksendQueue){ - CService addr; - if(dsq.time == 0) continue; - if(!dsq.GetAddress(addr)) continue; - - std::vector vecAmounts; - pwalletMain->ConvertList(vCoins, vecAmounts); - - if(dsq.nDenom == GetDenominationsByAmounts(vecAmounts)) { - break; - } - } - } else { - break; - } - - } - } - } +// if(minRounds == 0 || +// pwalletMain->GetDenominatedBalance(true) * 0.05 > pwalletMain->GetDenominatedBalance(false)) { +// for(int a = 0; a < 10; a++){ //try 10 amounts and see if we match a queue +// int r = (rand()%((balanceNeedsAnonymized-nValueMin)/COIN))+(nValueMin/COIN); + +// vCoins.clear(); +// nValueIn = 0; +// if (pwalletMain->SelectCoinsDark(nValueMin, r*COIN, vCoins, nValueIn, minRounds, maxRounds, hasFeeInput)){ +// sessionTotalValue = pwalletMain->GetTotalValue(vCoins); + +// // if it's in the queue, take it +// if(nUseQueue > 33 && vecDarksendQueue.size() > 0){ +// BOOST_FOREACH(CDarksendQueue& dsq, vecDarksendQueue){ +// CService addr; +// if(dsq.time == 0) continue; +// if(!dsq.GetAddress(addr)) continue; + +// std::vector vecAmounts; +// pwalletMain->ConvertList(vCoins, vecAmounts); + +// if(dsq.nDenom == GetDenominationsByAmounts(vecAmounts)) { +// break; +// } +// } +// } else { +// break; +// } + +// } +// } +// } if(sessionTotalValue > balanceNeedsAnonymized) sessionTotalValue = balanceNeedsAnonymized; double fDarkcoinSubmitted = sessionTotalValue / COIN; @@ -1554,6 +1554,16 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) return false; } + if(minRounds >= 0){ + //use same denominations + std::vector vecAmounts; + pwalletMain->ConvertList(vCoins, vecAmounts); + sessionDenom = GetDenominationsByAmounts(vecAmounts); + } else { + //use all possible denominations + sessionDenom = GetDenominationsByAmount(sessionTotalValue); + } + //don't use the queues all of the time for mixing if(nUseQueue > 33){ @@ -1576,8 +1586,8 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) } // If we don't match the denominations, we don't want to submit our inputs - if(dsq.nDenom != GetDenominationsByAmount(sessionTotalValue)) { - if(fDebug) LogPrintf(" dsq.nDenom != GetDenominationsByAmount %d %d \n", dsq.nDenom, GetDenominationsByAmount(sessionTotalValue)); + if(dsq.nDenom != sessionDenom) { + if(fDebug) LogPrintf(" dsq.nDenom != GetDenominationsByAmount %d %d \n", dsq.nDenom, sessionDenom); continue; } dsq.time = 0; //remove node @@ -1600,16 +1610,6 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) vecMasternodesUsed.push_back(dsq.vin); - if(minRounds >= 0){ - //use same denominations - std::vector vecAmounts; - pwalletMain->ConvertList(vCoins, vecAmounts); - sessionDenom = GetDenominationsByAmounts(vecAmounts); - } else { - //use all possible denominations - sessionDenom = GetDenominationsByAmount(sessionTotalValue); - } - pnode->PushMessage("dsa", sessionDenom, txCollateral); LogPrintf("DoAutomaticDenominating --- connected (from queue), sending dsa for %d %d - %s\n", sessionDenom, GetDenominationsByAmount(sessionTotalValue), pnode->addr.ToString().c_str()); return true; @@ -1662,16 +1662,6 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) vecMasternodesUsed.push_back(darkSendMasterNodes[i].vin); - if(minRounds >= 0){ - //use same denominations - std::vector vecAmounts; - pwalletMain->ConvertList(vCoins, vecAmounts); - sessionDenom = GetDenominationsByAmounts(vecAmounts); - } else { - //use all possible denominations - sessionDenom = GetDenominationsByAmount(sessionTotalValue); - } - pnode->PushMessage("dsa", sessionDenom, txCollateral); LogPrintf("DoAutomaticDenominating --- connected, sending dsa for %d - denom %d\n", sessionDenom, GetDenominationsByAmount(sessionTotalValue)); return true; From 5e8288541a716eee7f3b02395d9b067253b6af1e Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 5 Dec 2014 02:39:28 +0300 Subject: [PATCH 4/7] fix progress bar --- src/darksend.cpp | 10 +--------- src/qt/overviewpage.cpp | 31 ++++++++++++++++--------------- src/wallet.cpp | 27 +++++++++++++++++++++++++++ src/wallet.h | 1 + 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index cbfe1e3d0b3d..8ec59d748416 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1467,15 +1467,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) return true; } - LogPrintf("DoAutomaticDenominating : No funds detected in need of denominating %"PRI64d" %"PRI64d" %d %"PRI64d" %"PRI64d" %"PRI64d" %"PRI64d"\n", - balanceNeedsDenominated/COIN, - balanceNeedsAnonymized/COIN, - minRounds, - nAnonymizeDarkcoinAmount, - balance/COIN, - pwalletMain->GetDenominatedBalance(true)/COIN, - pwalletMain->GetAnonymizedBalance()/COIN - ); + LogPrintf("DoAutomaticDenominating : No funds detected in need of denominating \n"); return false; } } diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 2b0d364bb7e2..d1aa45014ab4 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -246,21 +246,22 @@ void OverviewPage::updateDarksendProgress(){ } std::ostringstream convert; - //Get average rounds of inputs - double a = ((double)pwalletMain->GetAverageAnonymizedRounds() / (double)nDarksendRounds)*100; - //Get the anon threshold - double max = nAnonymizeDarkcoinAmount; - //If it's more than the wallet amount, limit to that. - if(max > (double)(pwalletMain->GetBalance()/COIN)-1) max = (double)(pwalletMain->GetBalance()/COIN)-1; - //denominated balance / anon threshold -- the percentage that we've completed - double b = ((double)(pwalletMain->GetDenominatedBalance()/COIN) / max); - - double val = a*b; - if(val < 0) val = 0; - if(val > 100) val = 100; - - ui->darksendProgress->setValue(val);//rounds avg * denom progress - convert << "Inputs have an average of " << pwalletMain->GetAverageAnonymizedRounds() << " of " << nDarksendRounds << " rounds (" << a << "/" << b << ")"; + + // Get the anon threshold + int64 max = nAnonymizeDarkcoinAmount*COIN; + + // If it's more than the wallet amount, limit to that. + if(max > balance) max = balance; + + if(max == 0) return; + + // calculate progress + double progress = pwalletMain->GetNormalizedAnonymizedBalance() / max * 100; + + if(progress > 100) progress = 100; + + ui->darksendProgress->setValue(progress); + convert << "Inputs have an average of " << pwalletMain->GetAverageAnonymizedRounds() << " of " << nDarksendRounds << " rounds"; QString s(convert.str().c_str()); ui->darksendProgress->setToolTip(s); } diff --git a/src/wallet.cpp b/src/wallet.cpp index 4d69bedb80b1..df678a02143b 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1039,6 +1039,33 @@ double CWallet::GetAverageAnonymizedRounds() const return fTotal/fCount; } +int64 CWallet::GetNormalizedAnonymizedBalance() const +{ + int64 nTotal = 0; + + { + LOCK(cs_wallet); + for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + { + const CWalletTx* pcoin = &(*it).second; + for (unsigned int i = 0; i < pcoin->vout.size(); i++) { + + COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain()); + CTxIn vin = CTxIn(out.tx->GetHash(), out.i); + + if(pcoin->IsSpent(i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue; + + int rounds = GetInputDarksendRounds(vin); + if(rounds < nDarksendRounds) + nTotal += pcoin->vout[i].nValue * rounds / 2; + else + nTotal += pcoin->vout[i].nValue * nDarksendRounds; + } + } + } + + return nTotal / nDarksendRounds; +} int64 CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed) const { diff --git a/src/wallet.h b/src/wallet.h index efeeb3f12778..bfca8e6ea50e 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -204,6 +204,7 @@ class CWallet : public CCryptoKeyStore int64 GetBalance() const; int64 GetAnonymizedBalance() const; double GetAverageAnonymizedRounds() const; + int64 GetNormalizedAnonymizedBalance() const; int64 GetDenominatedBalance(bool onlyDenom=true, bool onlyUnconfirmed=false) const; int64 GetUnconfirmedBalance() const; int64 GetImmatureBalance() const; From 8d276a8741d5c4c497ab3e5057c0765a31709165 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 5 Dec 2014 03:20:13 +0300 Subject: [PATCH 5/7] fix --- src/qt/overviewpage.cpp | 2 +- src/wallet.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index d1aa45014ab4..942848746c93 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -256,7 +256,7 @@ void OverviewPage::updateDarksendProgress(){ if(max == 0) return; // calculate progress - double progress = pwalletMain->GetNormalizedAnonymizedBalance() / max * 100; + int progress = 100 * pwalletMain->GetNormalizedAnonymizedBalance() / max; if(progress > 100) progress = 100; diff --git a/src/wallet.cpp b/src/wallet.cpp index df678a02143b..54c42fa3c06b 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1057,14 +1057,14 @@ int64 CWallet::GetNormalizedAnonymizedBalance() const int rounds = GetInputDarksendRounds(vin); if(rounds < nDarksendRounds) - nTotal += pcoin->vout[i].nValue * rounds / 2; + nTotal += pcoin->vout[i].nValue * rounds / nDarksendRounds / 2; else - nTotal += pcoin->vout[i].nValue * nDarksendRounds; + nTotal += pcoin->vout[i].nValue; } } } - return nTotal / nDarksendRounds; + return nTotal; } int64 CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed) const From 1af1366ff3b26598c1f2adef97be028cfcb0d2e7 Mon Sep 17 00:00:00 2001 From: deusstultus Date: Fri, 5 Dec 2014 09:00:07 -0600 Subject: [PATCH 6/7] Revert 25a07f10 -- makefile.unix STATIC=1 not cleanly implemented --- src/makefile.unix | 1 - 1 file changed, 1 deletion(-) diff --git a/src/makefile.unix b/src/makefile.unix index 913b1472d788..48fcd3117692 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -23,7 +23,6 @@ ifdef UNIT_TEST DEFS+=-DUNIT_TEST=1 endif -STATIC = 1 LMODE = dynamic LMODE2 = dynamic ifdef STATIC From 0f6a2d254eb9f403fe22223ff5d4b94d25c5d696 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sat, 6 Dec 2014 02:31:48 +0300 Subject: [PATCH 7/7] reenable random --- src/darksend.cpp | 62 ++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index de6978ce1ae1..40c68bf68713 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1504,37 +1504,37 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready) //randomize the amounts we mix // if we have minRounds set, or if our non-demon is less than 5% of denom coins -// if(minRounds == 0 || -// pwalletMain->GetDenominatedBalance(true) * 0.05 > pwalletMain->GetDenominatedBalance(false)) { -// for(int a = 0; a < 10; a++){ //try 10 amounts and see if we match a queue -// int r = (rand()%((balanceNeedsAnonymized-nValueMin)/COIN))+(nValueMin/COIN); - -// vCoins.clear(); -// nValueIn = 0; -// if (pwalletMain->SelectCoinsDark(nValueMin, r*COIN, vCoins, nValueIn, minRounds, maxRounds, hasFeeInput)){ -// sessionTotalValue = pwalletMain->GetTotalValue(vCoins); - -// // if it's in the queue, take it -// if(nUseQueue > 33 && vecDarksendQueue.size() > 0){ -// BOOST_FOREACH(CDarksendQueue& dsq, vecDarksendQueue){ -// CService addr; -// if(dsq.time == 0) continue; -// if(!dsq.GetAddress(addr)) continue; - -// std::vector vecAmounts; -// pwalletMain->ConvertList(vCoins, vecAmounts); - -// if(dsq.nDenom == GetDenominationsByAmounts(vecAmounts)) { -// break; -// } -// } -// } else { -// break; -// } - -// } -// } -// } + if(minRounds == 0 || + pwalletMain->GetDenominatedBalance(true) * 0.05 > pwalletMain->GetDenominatedBalance(false)) { + for(int a = 0; a < 10; a++){ //try 10 amounts and see if we match a queue + int r = (rand()%((balanceNeedsAnonymized-nValueMin)/COIN))+(nValueMin/COIN); + + vCoins.clear(); + nValueIn = 0; + if (pwalletMain->SelectCoinsDark(nValueMin, r*COIN, vCoins, nValueIn, minRounds, maxRounds, hasFeeInput)){ + sessionTotalValue = pwalletMain->GetTotalValue(vCoins); + + // if it's in the queue, take it + if(nUseQueue > 33 && vecDarksendQueue.size() > 0){ + BOOST_FOREACH(CDarksendQueue& dsq, vecDarksendQueue){ + CService addr; + if(dsq.time == 0) continue; + if(!dsq.GetAddress(addr)) continue; + + std::vector vecAmounts; + pwalletMain->ConvertList(vCoins, vecAmounts); + + if(dsq.nDenom == GetDenominationsByAmounts(vecAmounts)) { + break; + } + } + } else { + break; + } + + } + } + } if(sessionTotalValue > balanceNeedsAnonymized) sessionTotalValue = balanceNeedsAnonymized; double fDarkcoinSubmitted = sessionTotalValue / COIN;