Skip to content

Commit

Permalink
fix the way anonymizable balance calculated and fix conditions for DS
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Nov 6, 2015
1 parent 6df51c9 commit 3ce4909
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/darksend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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()){
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3ce4909

Please sign in to comment.