dashpay / dash

Dash - Reinventing Cryptocurrency
https://www.dash.org
MIT License
1.49k stars 1.2k forks source link

fix: resolve potential deadlocks in CJ #6006

Closed UdjinM6 closed 2 months ago

UdjinM6 commented 2 months ago

Issue being fixed or feature implemented

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 one is for ResetPool().

What was done?

Lock cs_wallet when calling keyHolderStorage.ReturnAll() in some places* to ensure the right order of locks.

(*In other places cs_wallet is held already, no need to double lock).

How Has This Been Tested?

Mixing

Breaking Changes

n/a

Checklist: