fix calculation of (unconfirmed) anonymizable balance (#1477)

* fix calculation of (unconfirmed) anonymizable balance

* store cache with the same param combination as in use
This commit is contained in:
UdjinM6 2017-06-06 02:47:12 +03:00 committed by GitHub
parent a28fa724c2
commit 2daea77a5b
3 changed files with 14 additions and 14 deletions

View File

@ -355,12 +355,12 @@ void OverviewPage::updatePrivateSendProgress()
{
nDenominatedConfirmedBalance = pwalletMain->GetDenominatedBalance();
nDenominatedUnconfirmedBalance = pwalletMain->GetDenominatedBalance(true);
nAnonymizableBalance = pwalletMain->GetAnonymizableBalance();
nAnonymizableBalance = pwalletMain->GetAnonymizableBalance(false, false);
nNormalizedAnonymizedBalance = pwalletMain->GetNormalizedAnonymizedBalance();
nAverageAnonymizedRounds = pwalletMain->GetAverageAnonymizedRounds();
}
CAmount nMaxToAnonymize = nAnonymizableBalance + currentAnonymizedBalance + nDenominatedUnconfirmedBalance;
CAmount nMaxToAnonymize = nAnonymizableBalance + currentAnonymizedBalance;
// If it's more than the anon threshold, limit to that.
if(nMaxToAnonymize > privateSendClient.nPrivateSendAmount*COIN) nMaxToAnonymize = privateSendClient.nPrivateSendAmount*COIN;

View File

@ -2144,12 +2144,12 @@ CAmount CWallet::GetBalance() const
return nTotal;
}
CAmount CWallet::GetAnonymizableBalance(bool fSkipDenominated) const
CAmount CWallet::GetAnonymizableBalance(bool fSkipDenominated, bool fSkipUnconfirmed) const
{
if(fLiteMode) return 0;
std::vector<CompactTallyItem> vecTally;
if(!SelectCoinsGrouppedByAddresses(vecTally, fSkipDenominated)) return 0;
if(!SelectCoinsGrouppedByAddresses(vecTally, fSkipDenominated, true, fSkipUnconfirmed)) return 0;
CAmount nTotal = 0;
@ -2837,22 +2837,22 @@ struct CompareByAmount
}
};
bool CWallet::SelectCoinsGrouppedByAddresses(std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated, bool fAnonymizable) const
bool CWallet::SelectCoinsGrouppedByAddresses(std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated, bool fAnonymizable, bool fSkipUnconfirmed) const
{
LOCK2(cs_main, cs_wallet);
isminefilter filter = ISMINE_SPENDABLE;
// try to use cache
if(fAnonymizable) {
// try to use cache for already confirmed anonymizable inputs
if(fAnonymizable && fSkipUnconfirmed) {
if(fSkipDenominated && fAnonymizableTallyCachedNonDenom) {
vecTallyRet = vecAnonymizableTallyCachedNonDenom;
LogPrint("selectcoins", "SelectCoinsGrouppedByAddresses - using cache for non-denom inputs\n");
LogPrint("selectcoins", "SelectCoinsGrouppedByAddresses - using cache for non-denom inputs %d\n", vecTallyRet.size());
return vecTallyRet.size() > 0;
}
if(!fSkipDenominated && fAnonymizableTallyCached) {
vecTallyRet = vecAnonymizableTallyCached;
LogPrint("selectcoins", "SelectCoinsGrouppedByAddresses - using cache for all inputs\n");
LogPrint("selectcoins", "SelectCoinsGrouppedByAddresses - using cache for all inputs %d\n", vecTallyRet.size());
return vecTallyRet.size() > 0;
}
}
@ -2863,7 +2863,7 @@ bool CWallet::SelectCoinsGrouppedByAddresses(std::vector<CompactTallyItem>& vecT
const CWalletTx& wtx = (*it).second;
if(wtx.IsCoinBase() && wtx.GetBlocksToMaturity() > 0) continue;
if(!fAnonymizable && !wtx.IsTrusted()) continue;
if(fSkipUnconfirmed && !wtx.IsTrusted()) continue;
for (unsigned int i = 0; i < wtx.vout.size(); i++) {
CTxDestination address;
@ -2904,8 +2904,8 @@ bool CWallet::SelectCoinsGrouppedByAddresses(std::vector<CompactTallyItem>& vecT
// order by amounts per address, from smallest to largest
sort(vecTallyRet.rbegin(), vecTallyRet.rend(), CompareByAmount());
// cache anonymizable for later use
if(fAnonymizable) {
// cache already confirmed anonymizable entries for later use
if(fAnonymizable && fSkipUnconfirmed) {
if(fSkipDenominated) {
vecAnonymizableTallyCachedNonDenom = vecTallyRet;
fAnonymizableTallyCachedNonDenom = true;

View File

@ -771,7 +771,7 @@ public:
bool SelectCoinsByDenominations(int nDenom, CAmount nValueMin, CAmount nValueMax, std::vector<CTxIn>& vecTxInRet, std::vector<COutput>& vCoinsRet, CAmount& nValueRet, int nPrivateSendRoundsMin, int nPrivateSendRoundsMax);
bool GetCollateralTxIn(CTxIn& txinRet, CAmount& nValueRet) const;
bool SelectCoinsDark(CAmount nValueMin, CAmount nValueMax, std::vector<CTxIn>& vecTxInRet, CAmount& nValueRet, int nPrivateSendRoundsMin, int nPrivateSendRoundsMax) const;
bool SelectCoinsGrouppedByAddresses(std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated = true, bool fAnonymizable = true) const;
bool SelectCoinsGrouppedByAddresses(std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated = true, bool fAnonymizable = true, bool fSkipUnconfirmed = true) const;
/// Get 1000DASH output and keys which can be used for the Masternode
bool GetMasternodeVinAndKeys(CTxIn& txinRet, CPubKey& pubKeyRet, CKey& keyRet, std::string strTxHash = "", std::string strOutputIndex = "");
@ -871,7 +871,7 @@ public:
CAmount GetUnconfirmedWatchOnlyBalance() const;
CAmount GetImmatureWatchOnlyBalance() const;
CAmount GetAnonymizableBalance(bool fSkipDenominated = false) const;
CAmount GetAnonymizableBalance(bool fSkipDenominated = false, bool fSkipUnconfirmed = true) const;
CAmount GetAnonymizedBalance() const;
float GetAverageAnonymizedRounds() const;
CAmount GetNormalizedAnonymizedBalance() const;