Skip to content

Commit

Permalink
Fix calculation of balances and available coins.
Browse files Browse the repository at this point in the history
No longer consider coins which aren't in our mempool.

Add test for regression in abandonconflict.py
  • Loading branch information
morcos authored and Stamek committed Aug 22, 2020
1 parent af29139 commit ce25177
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ CAmount CWallet::GetUnconfirmedBalance() const
LOCK2(cs_main, cs_wallet);
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) {
const CWalletTx* pcoin = &(*it).second;
if (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0))
if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && pcoin->InMempool())
nTotal += pcoin->GetAvailableCredit();
}
}
Expand Down Expand Up @@ -1587,7 +1587,7 @@ CAmount CWallet::GetUnconfirmedWatchOnlyBalance() const
LOCK2(cs_main, cs_wallet);
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) {
const CWalletTx* pcoin = &(*it).second;
if (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0))
if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && pcoin->InMempool())
nTotal += pcoin->GetAvailableWatchOnlyCredit();
}
}
Expand Down Expand Up @@ -1660,6 +1660,11 @@ void CWallet::AvailableCoins(
if (nDepth == 0 && !pcoin->InMempool())
continue;

// We should not consider coins which aren't at least in our mempool
// It's possible for these to be conflicted via ancestors which we may never be able to detect
if (nDepth == 0 && !pcoin->InMempool())
continue;

for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
bool found = false;
if (nCoinType == ONLY_DENOMINATED) {
Expand Down

0 comments on commit ce25177

Please sign in to comment.