Skip to content

Commit 8392051

Browse files
committed
Add AssertLockHeld assertions in CWallet::ListCoins
Also update wallet tests to acquire the cs_main lock correctly when calling ListCoins, and to release the cs_wallet lock before calling ScanForWalletTransactions (because ScanForWalletTransactions acquired cs_main internally, which should never be acquired after cs_wallet because that would trigger anti-deadlock warnings).
1 parent f088a1b commit 8392051

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/wallet/wallet.cpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -2193,22 +2193,14 @@ void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const
21932193

21942194
std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins() const
21952195
{
2196-
// TODO: Add AssertLockHeld(cs_wallet) here.
2197-
//
2198-
// Because the return value from this function contains pointers to
2199-
// CWalletTx objects, callers to this function really should acquire the
2200-
// cs_wallet lock before calling it. However, the current caller doesn't
2201-
// acquire this lock yet. There was an attempt to add the missing lock in
2202-
// https://github.com/bitcoin/bitcoin/pull/10340, but that change has been
2203-
// postponed until after https://github.com/bitcoin/bitcoin/pull/10244 to
2204-
// avoid adding some extra complexity to the Qt code.
2196+
AssertLockHeld(cs_main);
2197+
AssertLockHeld(cs_wallet);
22052198

22062199
std::map<CTxDestination, std::vector<COutput>> result;
22072200

22082201
std::vector<COutput> availableCoins;
22092202
AvailableCoins(availableCoins);
22102203

2211-
LOCK2(cs_main, cs_wallet);
22122204
for (auto& coin : availableCoins) {
22132205
CTxDestination address;
22142206
if (coin.fSpendable &&

0 commit comments

Comments
 (0)