Skip to content

Commit 68d4282

Browse files
committed
Fix calculation of balances and available coins.
No longer consider coins which aren't in our mempool. Add test for regression in abandonconflict.py
1 parent f034bce commit 68d4282

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

qa/rpc-tests/abandonconflict.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ def run_test(self):
8383
# inputs are still spent, but change not received
8484
newbalance = self.nodes[0].getbalance()
8585
assert(newbalance == balance - Decimal("24.9996"))
86+
# Unconfirmed received funds that are not in mempool, also shouldn't show
87+
# up in unconfirmed balance
88+
unconfbalance = self.nodes[0].getunconfirmedbalance() + self.nodes[0].getbalance()
89+
assert(unconfbalance == newbalance)
90+
# Also shouldn't show up in listunspent
91+
assert(not txABC2 in [utxo["txid"] for utxo in self.nodes[0].listunspent(0)])
8692
balance = newbalance
8793

8894
# Abandon original transaction and verify inputs are available again

src/wallet/wallet.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ CAmount CWallet::GetUnconfirmedBalance() const
15781578
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
15791579
{
15801580
const CWalletTx* pcoin = &(*it).second;
1581-
if (!CheckFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0))
1581+
if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && pcoin->InMempool())
15821582
nTotal += pcoin->GetAvailableCredit();
15831583
}
15841584
}
@@ -1623,7 +1623,7 @@ CAmount CWallet::GetUnconfirmedWatchOnlyBalance() const
16231623
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
16241624
{
16251625
const CWalletTx* pcoin = &(*it).second;
1626-
if (!CheckFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0))
1626+
if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && pcoin->InMempool())
16271627
nTotal += pcoin->GetAvailableWatchOnlyCredit();
16281628
}
16291629
}
@@ -1668,6 +1668,11 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
16681668
if (nDepth < 0)
16691669
continue;
16701670

1671+
// We should not consider coins which aren't at least in our mempool
1672+
// It's possible for these to be conflicted via ancestors which we may never be able to detect
1673+
if (nDepth == 0 && !pcoin->InMempool())
1674+
continue;
1675+
16711676
for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
16721677
isminetype mine = IsMine(pcoin->vout[i]);
16731678
if (!(IsSpent(wtxid, i)) && mine != ISMINE_NO &&

0 commit comments

Comments
 (0)