Skip to content

Commit 8cfe93e

Browse files
committed
Add proper thread safety annotation to CWallet::GetTxConflicts()
1 parent ca446f2 commit 8cfe93e

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

src/wallet/rpc/transactions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using interfaces::FoundBlock;
1515

1616
namespace wallet {
1717
static void WalletTxToJSON(const CWallet& wallet, const CWalletTx& wtx, UniValue& entry)
18+
EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
1819
{
1920
interfaces::Chain& chain = wallet.chain();
2021
int confirms = wallet.GetTxDepthInMainChain(wtx);

src/wallet/wallet.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,12 +1869,11 @@ bool CWallet::SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string
18691869

18701870
std::set<uint256> CWallet::GetTxConflicts(const CWalletTx& wtx) const
18711871
{
1872-
std::set<uint256> result;
1873-
{
1874-
uint256 myHash = wtx.GetHash();
1875-
result = GetConflicts(myHash);
1876-
result.erase(myHash);
1877-
}
1872+
AssertLockHeld(cs_wallet);
1873+
1874+
const uint256 myHash{wtx.GetHash()};
1875+
std::set<uint256> result{GetConflicts(myHash)};
1876+
result.erase(myHash);
18781877
return result;
18791878
}
18801879

src/wallet/wallet.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
415415

416416
const CWalletTx* GetWalletTx(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
417417

418-
// TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
419-
// annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation
420-
// "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid having to
421-
// resolve the issue of member access into incomplete type CWallet. Note
422-
// that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)"
423-
// in place.
424-
std::set<uint256> GetTxConflicts(const CWalletTx& wtx) const NO_THREAD_SAFETY_ANALYSIS;
418+
std::set<uint256> GetTxConflicts(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
425419

426420
/**
427421
* Return depth of transaction in blockchain:

0 commit comments

Comments
 (0)