aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAntoine Riard <ariard@student.42.fr>2019-04-22 14:22:25 -0400
committerAntoine Riard <ariard@student.42.fr>2019-11-06 13:36:43 -0500
commit0ff03871add000f8b4d8f82aeb168eed2fc9dc5f (patch)
tree8700c1569ae9e6d419f4f0d6d3dc51c7221e0185 /src
parentf77b1de16feee097a88e99d2ecdd4d84beb4f915 (diff)
downloadbitcoin-0ff03871add000f8b4d8f82aeb168eed2fc9dc5f.tar.xz
Use CWallet::m_last_block_processed_height in GetDepthInMainChain
Avoid to lock chain to query state thanks to tracking last block height in CWallet.
Diffstat (limited to 'src')
-rw-r--r--src/wallet/wallet.cpp4
-rw-r--r--src/wallet/wallet.h8
2 files changed, 10 insertions, 2 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 9fdb07ce84..949977104b 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -3936,9 +3936,11 @@ CKeyPool::CKeyPool(const CPubKey& vchPubKeyIn, bool internalIn)
int CWalletTx::GetDepthInMainChain(interfaces::Chain::Lock& locked_chain) const
{
+ assert(pwallet != nullptr);
+ AssertLockHeld(pwallet->cs_wallet);
if (isUnconfirmed() || isAbandoned()) return 0;
- return locked_chain.getBlockDepth(m_confirm.hashBlock) * (isConflicted() ? -1 : 1);
+ return (pwallet->GetLastBlockHeight() - m_confirm.block_height + 1) * (isConflicted() ? -1 : 1);
}
int CWalletTx::GetBlocksToMaturity(interfaces::Chain::Lock& locked_chain) const
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index f3691a6218..e1dab8d37e 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -499,7 +499,13 @@ public:
* 0 : in memory pool, waiting to be included in a block
* >=1 : this many blocks deep in the main chain
*/
- int GetDepthInMainChain(interfaces::Chain::Lock& locked_chain) 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(interfaces::Chain::Lock& locked_chain) const NO_THREAD_SAFETY_ANALYSIS;
bool IsInMainChain(interfaces::Chain::Lock& locked_chain) const { return GetDepthInMainChain(locked_chain) > 0; }
/**