Skip to content

Commit 0ff0387

Browse files
author
Antoine Riard
committed
Use CWallet::m_last_block_processed_height in GetDepthInMainChain
Avoid to lock chain to query state thanks to tracking last block height in CWallet.
1 parent f77b1de commit 0ff0387

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/wallet/wallet.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3936,9 +3936,11 @@ CKeyPool::CKeyPool(const CPubKey& vchPubKeyIn, bool internalIn)
39363936

39373937
int CWalletTx::GetDepthInMainChain(interfaces::Chain::Lock& locked_chain) const
39383938
{
3939+
assert(pwallet != nullptr);
3940+
AssertLockHeld(pwallet->cs_wallet);
39393941
if (isUnconfirmed() || isAbandoned()) return 0;
39403942

3941-
return locked_chain.getBlockDepth(m_confirm.hashBlock) * (isConflicted() ? -1 : 1);
3943+
return (pwallet->GetLastBlockHeight() - m_confirm.block_height + 1) * (isConflicted() ? -1 : 1);
39423944
}
39433945

39443946
int CWalletTx::GetBlocksToMaturity(interfaces::Chain::Lock& locked_chain) const

src/wallet/wallet.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,13 @@ class CWalletTx
499499
* 0 : in memory pool, waiting to be included in a block
500500
* >=1 : this many blocks deep in the main chain
501501
*/
502-
int GetDepthInMainChain(interfaces::Chain::Lock& locked_chain) const;
502+
// TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
503+
// annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation
504+
// "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid having to
505+
// resolve the issue of member access into incomplete type CWallet. Note
506+
// that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)"
507+
// in place.
508+
int GetDepthInMainChain(interfaces::Chain::Lock& locked_chain) const NO_THREAD_SAFETY_ANALYSIS;
503509
bool IsInMainChain(interfaces::Chain::Lock& locked_chain) const { return GetDepthInMainChain(locked_chain) > 0; }
504510

505511
/**

0 commit comments

Comments
 (0)