Skip to content

Commit 3572354

Browse files
committed
[Wallet] Fix an error in tx depth computation
1 parent 6928369 commit 3572354

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

src/wallet/wallet.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,30 +3833,28 @@ int CMerkleTx::SetMerkleBranch(const CBlock& block)
38333833
return chainActive.Height() - pindex->nHeight + 1;
38343834
}
38353835

3836-
int CMerkleTx::GetDepthInMainChainINTERNAL(const CBlockIndex*& pindexRet) const
3836+
int CMerkleTx::GetDepthInMainChain(const CBlockIndex*& pindexRet, bool enableIX) const
38373837
{
38383838
if (hashUnset())
38393839
return 0;
38403840
AssertLockHeld(cs_main);
3841+
int nResult;
38413842

38423843
// Find the block it claims to be in
38433844
BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
3844-
if (mi == mapBlockIndex.end())
3845-
return 0;
3846-
CBlockIndex* pindex = (*mi).second;
3847-
if (!pindex || !chainActive.Contains(pindex))
3848-
return 0;
3849-
3850-
pindexRet = pindex;
3851-
return ((nIndex == -1) ? (-1) : 1) * (chainActive.Height() - pindex->nHeight + 1);
3852-
}
3853-
3854-
int CMerkleTx::GetDepthInMainChain(const CBlockIndex*& pindexRet, bool enableIX) const
3855-
{
3856-
AssertLockHeld(cs_main);
3857-
int nResult = GetDepthInMainChainINTERNAL(pindexRet);
3858-
if (nResult == 0 && !mempool.exists(GetHash()))
3859-
return -1; // Not in chain, not in mempool
3845+
if (mi == mapBlockIndex.end()) {
3846+
nResult = 0;
3847+
}
3848+
else {
3849+
CBlockIndex* pindex = (*mi).second;
3850+
if (!pindex || !chainActive.Contains(pindex)) {
3851+
nResult = 0;
3852+
}
3853+
else {
3854+
pindexRet = pindex;
3855+
nResult = ((nIndex == -1) ? (-1) : 1) * (chainActive.Height() - pindex->nHeight + 1);
3856+
}
3857+
}
38603858

38613859
if (enableIX) {
38623860
if (nResult < 6) {

src/wallet/wallet.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ struct COutputEntry {
619619
class CMerkleTx : public CTransaction
620620
{
621621
private:
622-
int GetDepthInMainChainINTERNAL(const CBlockIndex*& pindexRet) const;
623622
/** Constant used in hashBlock to indicate tx has been abandoned */
624623
static const uint256 ABANDON_HASH;
625624

@@ -679,7 +678,7 @@ class CMerkleTx : public CTransaction
679678
bool IsInMainChain() const
680679
{
681680
const CBlockIndex* pindexRet;
682-
return GetDepthInMainChainINTERNAL(pindexRet) > 0;
681+
return GetDepthInMainChain(pindexRet, false) > 0;
683682
}
684683
int GetBlocksToMaturity() const;
685684
bool AcceptToMemoryPool(bool fLimitFree = true, bool fRejectInsaneFee = true, bool ignoreFees = false);

0 commit comments

Comments
 (0)