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')
```
This commit is contained in:
UdjinM6 2024-05-02 22:33:22 +03:00
parent c3f34dcd98
commit b2910fba02
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9

View File

@ -249,7 +249,7 @@ void CCoinJoinClientSession::ResetPool()
{
txMyCollateral = CMutableTransaction();
UnlockCoins();
keyHolderStorage.ReturnAll();
WITH_LOCK(m_wallet.cs_wallet, keyHolderStorage.ReturnAll());
WITH_LOCK(cs_coinjoin, SetNull());
}
@ -410,7 +410,7 @@ bool CCoinJoinClientSession::CheckTimeout()
SetState(POOL_STATE_ERROR);
UnlockCoins();
keyHolderStorage.ReturnAll();
WITH_LOCK(m_wallet.cs_wallet, keyHolderStorage.ReturnAll());
nTimeLastSuccessfulStep = GetTime();
strLastMessage = CoinJoin::GetMessageByID(ERR_SESSION);
@ -521,7 +521,7 @@ void CCoinJoinClientSession::ProcessPoolStateUpdate(CCoinJoinStatusUpdate psssup
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- rejected by Masternode: %s\n", __func__, strMessageTmp.translated);
SetState(POOL_STATE_ERROR);
UnlockCoins();
keyHolderStorage.ReturnAll();
WITH_LOCK(m_wallet.cs_wallet, keyHolderStorage.ReturnAll());
nTimeLastSuccessfulStep = GetTime();
strLastMessage = strMessageTmp;
break;
@ -688,7 +688,7 @@ void CCoinJoinClientSession::CompletedTransaction(PoolMessage nMessageID)
keyHolderStorage.KeepAll();
WalletCJLogPrint(m_wallet, "CompletedTransaction -- success\n");
} else {
keyHolderStorage.ReturnAll();
WITH_LOCK(m_wallet.cs_wallet, keyHolderStorage.ReturnAll());
WalletCJLogPrint(m_wallet, "CompletedTransaction -- error\n");
}
UnlockCoins();