mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Fix off-by-one error w/ nLockTime in the wallet
Previously due to an off-by-one error the wallet ignored
nLockTime-by-height transactions that would be valid in the next block
even though they are accepted into the mempool. The transactions
wouldn't show up until confirmed, nor would they be included in the
unconfirmed balance. Similar to the mempool behavior fix in 665bdd3b,
the wallet code was calling IsFinalTx() directly without taking into
account the fact that doing so tells you if the transaction could have
been mined in the *current* block, rather than the next block.
To fix this we strip IsFinalTx() of non-consensus-critical
functionality, removing the default arguments, and add CheckFinalTx() to
check if a transaction will be final in the next block.
This commit is contained in:
@@ -1317,7 +1317,7 @@ CAmount CWalletTx::GetChange() const
|
||||
bool CWalletTx::IsTrusted() const
|
||||
{
|
||||
// Quick answer in most cases
|
||||
if (!IsFinalTx(*this))
|
||||
if (!CheckFinalTx(*this))
|
||||
return false;
|
||||
int nDepth = GetDepthInMainChain();
|
||||
if (nDepth >= 1)
|
||||
@@ -1423,7 +1423,7 @@ CAmount CWallet::GetUnconfirmedBalance() const
|
||||
for (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 (!CheckFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0))
|
||||
nTotal += pcoin->GetAvailableCredit();
|
||||
}
|
||||
}
|
||||
@@ -1468,7 +1468,7 @@ CAmount CWallet::GetUnconfirmedWatchOnlyBalance() const
|
||||
for (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 (!CheckFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0))
|
||||
nTotal += pcoin->GetAvailableWatchOnlyCredit();
|
||||
}
|
||||
}
|
||||
@@ -1503,7 +1503,7 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
|
||||
const uint256& wtxid = it->first;
|
||||
const CWalletTx* pcoin = &(*it).second;
|
||||
|
||||
if (!IsFinalTx(*pcoin))
|
||||
if (!CheckFinalTx(*pcoin))
|
||||
continue;
|
||||
|
||||
if (fOnlyConfirmed && !pcoin->IsTrusted())
|
||||
@@ -2290,7 +2290,7 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances()
|
||||
{
|
||||
CWalletTx *pcoin = &walletEntry.second;
|
||||
|
||||
if (!IsFinalTx(*pcoin) || !pcoin->IsTrusted())
|
||||
if (!CheckFinalTx(*pcoin) || !pcoin->IsTrusted())
|
||||
continue;
|
||||
|
||||
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0)
|
||||
|
||||
Reference in New Issue
Block a user