Skip to content

Commit

Permalink
Fix the way anonymizable balance calculated and fix conditions for OBF (
Browse files Browse the repository at this point in the history
#10)

Reference:

dashpay@3ce4909
  • Loading branch information
MitchellCash authored and Cevap Master committed Jan 6, 2019
1 parent 94cb5ad commit dc74472
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/obfuscation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,10 +1426,9 @@ bool CObfuscationPool::DoAutomaticDenominating(bool fDryRun)
CAmount nOnlyDenominatedBalance;
CAmount nBalanceNeedsDenominated;

// should not be less than fees in OBFUSCATION_COLLATERAL + few (lets say 5) smallest denoms
CAmount nLowestDenom = OBFUSCATION_COLLATERAL + obfuScationDenominations[obfuScationDenominations.size() - 1] * 5;
CAmount nLowestDenom = obfuScationDenominations[obfuScationDenominations.size() - 1];

// if there are no OBF collateral inputs yet
// if there are no confirmed OBF collateral inputs yet
if (!pwalletMain->HasCollateralInputs())
// should have some additional amount for them
nLowestDenom += OBFUSCATION_COLLATERAL * 4;
Expand All @@ -1439,16 +1438,20 @@ bool CObfuscationPool::DoAutomaticDenominating(bool fDryRun)
// if balanceNeedsAnonymized is more than pool max, take the pool max
if (nBalanceNeedsAnonymized > OBFUSCATION_POOL_MAX) nBalanceNeedsAnonymized = OBFUSCATION_POOL_MAX;

// if balanceNeedsAnonymized is more than non-anonymized, take non-anonymized
// try to overshoot target OBF 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("obfuscation", "DoAutomaticDenominating : nLowestDenom=%d, nBalanceNeedsAnonymized=%d\n", nLowestDenom, nBalanceNeedsAnonymized);

// select coins that should be given to the pool
Expand Down Expand Up @@ -1501,7 +1504,7 @@ bool CObfuscationPool::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 @@ -1796,7 +1799,7 @@ bool CObfuscationPool::CreateDenominated(CAmount nTotalValue)
int nOutputs = 0;

// add each output up to 10 times until it can't be added again
while (nValueLeft - v >= OBFUSCATION_COLLATERAL && nOutputs <= 10) {
while (nValueLeft - v >= 0 && nOutputs <= 10) {
CScript scriptDenom;
CPubKey vchPubKey;
//use a unique change address
Expand Down
6 changes: 6 additions & 0 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,9 @@ CAmount CWalletTx::GetAnonymizableCredit(bool fUseCache) const
const CTxIn vin = CTxIn(hashTx, i);

if (pwallet->IsSpent(hashTx, i) || pwallet->IsLockedCoin(hashTx, i)) 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 <= obfuScationDenominations[obfuScationDenominations.size() - 1]/10) continue;
if (fMasterNode && vout[i].nValue == MASTERNODE_COLLATERAL_AMOUNT * COIN) continue; // do not count MN-like outputs

const int rounds = pwallet->GetInputObfuscationRounds(vin);
Expand Down Expand Up @@ -1180,6 +1183,9 @@ CAmount CWalletTx::GetUnlockedCredit() const

if (pwallet->IsSpent(hashTx, i) || pwallet->IsLockedCoin(hashTx, i)) continue;
if (fMasterNode && vout[i].nValue == MASTERNODE_COLLATERAL_AMOUNT * COIN) continue; // do not count MN-like outputs
// 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 <= obfuScationDenominations[obfuScationDenominations.size() - 1]/10) continue;

nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE);
if (!MoneyRange(nCredit))
Expand Down

0 comments on commit dc74472

Please sign in to comment.