diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 298e0743cef34..73bde98332603 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4321,24 +4321,11 @@ CWalletKey::CWalletKey(int64_t nExpires) int CWalletTx::GetDepthInMainChain() const { + assert(pwallet != nullptr); + AssertLockHeld(pwallet->cs_wallet); if (isUnconfirmed() || isAbandoned()) return 0; - AssertLockHeld(cs_main); - int nResult; - - // Find the block it claims to be in - BlockMap::iterator mi = mapBlockIndex.find(m_confirm.hashBlock); - if (mi == mapBlockIndex.end()) { - nResult = 0; - } else { - CBlockIndex* pindex = (*mi).second; - if (!pindex || !chainActive.Contains(pindex)) { - nResult = 0; - } else { - nResult = (isConflicted() ? (-1) : 1) * (chainActive.Height() - pindex->nHeight + 1); - } - } - return nResult; + return (pwallet->GetLastBlockHeight() - m_confirm.block_height + 1) * (isConflicted() ? -1 : 1); } int CWalletTx::GetBlocksToMaturity() const diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index efd1ba1af0d01..65e9167c89c61 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -520,7 +520,13 @@ class CWalletTx * 0 : in memory pool, waiting to be included in a block * >=1 : this many blocks deep in the main chain */ - int GetDepthInMainChain() const; + // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct + // annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation + // "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid having to + // resolve the issue of member access into incomplete type CWallet. Note + // that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)" + // in place. + int GetDepthInMainChain() const NO_THREAD_SAFETY_ANALYSIS; bool IsInMainChainImmature() const; int GetBlocksToMaturity() const;