HomePhabricator

wallet: Reorder locks in dumpwallet to avoid lock order assertion

Description

wallet: Reorder locks in dumpwallet to avoid lock order assertion

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.

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D12239

Details

Provenance
Andrew Chow <achow101-github@achow101.com>Authored on Jul 19 2021, 02:53
FabienCommitted on Oct 13 2022, 15:48
FabienPushed on Oct 13 2022, 15:48
Reviewer
Restricted Project
Differential Revision
D12239: wallet: Reorder locks in dumpwallet to avoid lock order assertion
Parents
rABCbc9e25418326: [Cashtab] Extension version bump 1.1.2
Branches
Unknown
Tags
Unknown