Page MenuHomePhabricator

wallet: Reorder locks in dumpwallet to avoid lock order assertion
ClosedPublic

Authored by Fabien on Oct 13 2022, 15:32.

Details

Summary
When a wallet is loaded which has an unconfirmed transaction in the mempool, it will end up establishing the lock order of cs_wallet -> cs_main -> cs_KeyStore. If dumpwallet is used on this wallet, then a lock order of cs_wallet -> cs_KeyStore -> cs_main will be used, which causes a lock order assertion. This PR fixes this by reordering dumpwallet and GetKeyBirthTimes (only used by dumpwallet). Specifically, in both functions, the function calls which lock cs_main are done prior to locking cs_KeyStore. This avoids the lock order issue.

Additionally, I have added a test case to wallet_dump.py. Of course testing this requires --enable-debug.

Backport of core#22492.

Test Plan

With Debug and Clang:

ninja all check-all

Run the TSAN build.

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable