From 2b72d46f4232b58835d44aa3abd711df399d4728 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Wed, 12 Feb 2014 13:43:07 -0500 Subject: Handle "conflicted" transactions properly Extend CMerkleTx::GetDepthInMainChain with the concept of a "conflicted" transaction-- a transaction generated by the wallet that is not in the main chain or in the mempool, and, therefore, will likely never be confirmed. GetDepthInMainChain() now returns -1 for conflicted transactions (0 for unconfirmed-but-in-the-mempool, and >1 for confirmed). This makes getbalance, getbalance '*', and listunspent all agree when there are mutated transactions in the wallet. Before: listunspent: one 49BTC output getbalance: 96 BTC (change counted twice) getbalance '*': 46 BTC (spends counted twice) After: all agree, 49 BTC available to spend. --- src/wallet.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/wallet.h') diff --git a/src/wallet.h b/src/wallet.h index ca40ba8185..ed63e2a714 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -700,8 +700,11 @@ public: // Quick answer in most cases if (!IsFinalTx(*this)) return false; - if (GetDepthInMainChain() >= 1) + int nDepth = GetDepthInMainChain(); + if (nDepth >= 1) return true; + if (nDepth < 0) + return false; if (!bSpendZeroConfChange || !IsFromMe()) // using wtx's cached debit return false; @@ -717,8 +720,11 @@ public: if (!IsFinalTx(*ptx)) return false; - if (ptx->GetDepthInMainChain() >= 1) + int nPDepth = ptx->GetDepthInMainChain(); + if (nPDepth >= 1) continue; + if (nPDepth < 0) + return false; if (!pwallet->IsFromMe(*ptx)) return false; -- cgit v1.2.3