Skip to content

Commit b2910fb

Browse files
committed
fix: resolve potential deadlocks in CJ
``` POTENTIAL DEADLOCK DETECTED Previous lock order was: (2) 'cs_wallet' in wallet/wallet.cpp:3826 (in thread 'qt-init') (2) 'pwallet->cs_wallet' in wallet/walletdb.cpp:705 (in thread 'qt-init') (1) 'cs_KeyStore' in wallet/scriptpubkeyman.cpp:971 (in thread 'qt-init') Current lock order is: 'cs_deqsessions' in coinjoin/client.cpp:261 (in thread 'main') (1) 'cs_KeyStore' in wallet/scriptpubkeyman.cpp:1522 (in thread 'main') (2) 'cs_wallet' in wallet/wallet.cpp:1629 (in thread 'main') ```
1 parent c3f34dc commit b2910fb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/coinjoin/client.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void CCoinJoinClientSession::ResetPool()
249249
{
250250
txMyCollateral = CMutableTransaction();
251251
UnlockCoins();
252-
keyHolderStorage.ReturnAll();
252+
WITH_LOCK(m_wallet.cs_wallet, keyHolderStorage.ReturnAll());
253253
WITH_LOCK(cs_coinjoin, SetNull());
254254
}
255255

@@ -410,7 +410,7 @@ bool CCoinJoinClientSession::CheckTimeout()
410410

411411
SetState(POOL_STATE_ERROR);
412412
UnlockCoins();
413-
keyHolderStorage.ReturnAll();
413+
WITH_LOCK(m_wallet.cs_wallet, keyHolderStorage.ReturnAll());
414414
nTimeLastSuccessfulStep = GetTime();
415415
strLastMessage = CoinJoin::GetMessageByID(ERR_SESSION);
416416

@@ -521,7 +521,7 @@ void CCoinJoinClientSession::ProcessPoolStateUpdate(CCoinJoinStatusUpdate psssup
521521
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- rejected by Masternode: %s\n", __func__, strMessageTmp.translated);
522522
SetState(POOL_STATE_ERROR);
523523
UnlockCoins();
524-
keyHolderStorage.ReturnAll();
524+
WITH_LOCK(m_wallet.cs_wallet, keyHolderStorage.ReturnAll());
525525
nTimeLastSuccessfulStep = GetTime();
526526
strLastMessage = strMessageTmp;
527527
break;
@@ -688,7 +688,7 @@ void CCoinJoinClientSession::CompletedTransaction(PoolMessage nMessageID)
688688
keyHolderStorage.KeepAll();
689689
WalletCJLogPrint(m_wallet, "CompletedTransaction -- success\n");
690690
} else {
691-
keyHolderStorage.ReturnAll();
691+
WITH_LOCK(m_wallet.cs_wallet, keyHolderStorage.ReturnAll());
692692
WalletCJLogPrint(m_wallet, "CompletedTransaction -- error\n");
693693
}
694694
UnlockCoins();

0 commit comments

Comments
 (0)