diff --git a/src/darksend.cpp b/src/darksend.cpp index 51e203880c6ef..c141d6efd9e1e 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1400,10 +1400,9 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun) CAmount nOnlyDenominatedBalance; CAmount nBalanceNeedsDenominated; - // should not be less than fees in DARKSEND_COLLATERAL + few (lets say 5) smallest denoms - CAmount nLowestDenom = DARKSEND_COLLATERAL + darkSendDenominations[darkSendDenominations.size() - 1]*5; + CAmount nLowestDenom = darkSendDenominations[darkSendDenominations.size() - 1]; - // if there are no DS collateral inputs yet + // if there are no confirmed DS collateral inputs yet if(!pwalletMain->HasCollateralInputs()) // should have some additional amount for them nLowestDenom += DARKSEND_COLLATERAL*4; @@ -1413,17 +1412,22 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun) // 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, take non-anonymized + // try to overshoot target DS balance up to nLowestDenom + nBalanceNeedsAnonymized += nLowestDenom; + CAmount nAnonymizableBalance = pwalletMain->GetAnonymizableBalance(); - if(nBalanceNeedsAnonymized > nAnonymizableBalance) nBalanceNeedsAnonymized = nAnonymizableBalance; - if(nBalanceNeedsAnonymized < nLowestDenom) + // anonymizable balance is way too small + if(nAnonymizableBalance < nLowestDenom) { LogPrintf("DoAutomaticDenominating : No funds detected in need of denominating \n"); strAutoDenomResult = _("No funds detected in need of denominating."); return false; } + // not enough funds to anonymze amount we want, try the max we can + if(nBalanceNeedsAnonymized > nAnonymizableBalance) nBalanceNeedsAnonymized = nAnonymizableBalance; + LogPrint("darksend", "DoAutomaticDenominating : nLowestDenom=%d, nBalanceNeedsAnonymized=%d\n", nLowestDenom, nBalanceNeedsAnonymized); // select coins that should be given to the pool @@ -1479,7 +1483,7 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun) return false; } - //check our collateral nad create new if needed + //check our collateral and create new if needed std::string strReason; CValidationState state; if(txCollateral == CMutableTransaction()){ @@ -1767,7 +1771,7 @@ bool CDarksendPool::CreateDenominated(int64_t nTotalValue) int nOutputs = 0; // add each output up to 10 times until it can't be added again - while(nValueLeft - v >= DARKSEND_COLLATERAL && nOutputs <= 10) { + while(nValueLeft - v >= 0 && nOutputs <= 10) { CScript scriptDenom; CPubKey vchPubKey; //use a unique change address diff --git a/src/wallet.h b/src/wallet.h index f65ed8b9832ae..08e5e064a823a 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -902,7 +902,11 @@ class CWalletTx : public CMerkleTx const CTxIn vin = CTxIn(hashTx, i); if(pwallet->IsSpent(hashTx, i) || pwallet->IsLockedCoin(hashTx, i)) continue; - if(fMasterNode && vout[i].nValue == 1000*COIN) continue; // do not count MN-like outputs + // do not count MN-like outputs + if(fMasterNode && vout[i].nValue == 1000*COIN) continue; + // do not count outputs that are 10 times smaller then the smallest denomination + // otherwise they will just lead to higher fee / lower priority + if(vout[i].nValue <= darkSendDenominations[darkSendDenominations.size() - 1]/10) continue; const int rounds = pwallet->GetInputDarksendRounds(vin); if(rounds >=-2 && rounds < nDarksendRounds) {