CWallet::MarkConflicted
may acquire the cs_main
lock after CWalletDB::LoadWallet
acquires the cs_wallet
lock during wallet initialization. (CWalletDB::LoadWallet
calls ReadKeyValue
which calls CWallet::LoadToWallet
which calls CWallet::MarkConflicted
). This is the opposite order that cs_main
and cs_wallet
locks are acquired in the rest of the code, and so leads to POTENTIAL DEADLOCK DETECTED
errors if bitcoin is built with -DDEBUG_LOCKORDER
.
This commit changes CWallet::LoadWallet
(which calls CWalletDB::LoadWallet
) to acquire both locks in the standard order.
Error was reported by @luke-jr in https://botbot.me/freenode/bitcoin-core-dev/msg/90244330/