Page MenuHomePhabricator

refactor: Add lock annotations to Active* methods
AbandonedPublicDraft

Authored by PiRK on Oct 16 2023, 08:08.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

This is a refactor, putting the burden to think about thread safety to
the caller. Otherwise, there is a risk that the caller will assume
thread safety where none exists, as is evident in the previous two
commits.

This concludes backport of core#25077

Depends on D14643

Test Plan

TBD (debug + tsan)

Event Timeline

Tail of the build log:

[412/486] Running utility command for check-bitcoin-intmath_tests
[413/486] bitcoin: testing blockfilter_tests
[414/486] bitcoin: testing scheduler_tests
[415/486] bitcoin: testing key_io_tests
[416/486] Running utility command for check-bitcoin-blockfilter_tests
[417/486] bitcoin: testing scriptpubkeyman_tests
[418/486] Running utility command for check-bitcoin-scheduler_tests
[419/486] Running utility command for check-bitcoin-key_io_tests
[420/486] Running utility command for check-bitcoin-scriptpubkeyman_tests
[421/486] bitcoin: testing crypto_tests
[422/486] bitcoin: testing txvalidationcache_tests
[423/486] Running utility command for check-bitcoin-crypto_tests
[424/486] bitcoin: testing cuckoocache_tests
[425/486] Running utility command for check-bitcoin-txvalidationcache_tests
[426/486] Running utility command for check-bitcoin-cuckoocache_tests
[427/486] bitcoin: testing walletdb_tests
[428/486] bitcoin: testing logging_tests
[429/486] Running utility command for check-bitcoin-walletdb_tests
[430/486] Running utility command for check-bitcoin-logging_tests
[431/486] bitcoin: testing psbt_wallet_tests
[432/486] Running utility command for check-bitcoin-psbt_wallet_tests
[433/486] bitcoin: testing miner_tests
[434/486] bitcoin: testing merkle_tests
[435/486] bitcoin: testing init_tests
[436/486] Running utility command for check-bitcoin-miner_tests
[437/486] Running utility command for check-bitcoin-merkle_tests
[438/486] Running utility command for check-bitcoin-init_tests
[439/486] bitcoin: testing uint256_tests
[440/486] bitcoin: testing denialofservice_tests
[441/486] Running utility command for check-bitcoin-uint256_tests
[442/486] Running utility command for check-bitcoin-denialofservice_tests
[443/486] bitcoin: testing coinstatsindex_tests
[444/486] Running utility command for check-bitcoin-coinstatsindex_tests
[445/486] bitcoin: testing rcu_tests
[446/486] Running utility command for check-bitcoin-rcu_tests
[447/486] Linking CXX executable src/qt/test/test_bitcoin-qt
[448/486] bitcoin: testing wallet_crypto_tests
[449/486] Running utility command for check-bitcoin-wallet_crypto_tests
[450/486] bitcoin: testing txrequest_tests
[451/486] Running utility command for check-bitcoin-txrequest_tests
[452/486] bitcoin-qt: testing test_bitcoin-qt
[453/486] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[454/486] bitcoin: testing blockcheck_tests
[455/486] Running utility command for check-bitcoin-blockcheck_tests
[456/486] bitcoin: testing coinselector_tests
[457/486] Running utility command for check-bitcoin-coinselector_tests
[458/486] bitcoin: testing wallet_tests
[459/486] Running utility command for check-bitcoin-wallet_tests
[460/486] secp256k1: testing secp256k1-tests
[461/486] Running secp256k1 test suite
PASSED: secp256k1 test suite
[462/486] bitcoin: testing transaction_tests
[463/486] Running utility command for check-bitcoin-transaction_tests
[464/486] bitcoin: testing coins_tests
[465/486] Running utility command for check-bitcoin-coins_tests
[466/486] Running bitcoin test suite
PASSED: bitcoin test suite
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang failed with exit code 1

Tail of the build log:

wallet_txn_doublespend.py --mineblock      | ✓ Passed  | 3 s
wallet_watchonly.py                        | ✓ Passed  | 1 s
wallet_watchonly.py --usecli               | ✓ Passed  | 1 s
chronik_avalanche.py                       | ○ Skipped | 0 s
chronik_block.py                           | ○ Skipped | 0 s
chronik_block_info.py                      | ○ Skipped | 0 s
chronik_block_txs.py                       | ○ Skipped | 0 s
chronik_blockchain_info.py                 | ○ Skipped | 0 s
chronik_blocks.py                          | ○ Skipped | 0 s
chronik_disallow_prune.py                  | ○ Skipped | 0 s
chronik_pause.py                           | ○ Skipped | 0 s
chronik_raw_tx.py                          | ○ Skipped | 0 s
chronik_resync.py                          | ○ Skipped | 0 s
chronik_script_confirmed_txs.py            | ○ Skipped | 0 s
chronik_script_history.py                  | ○ Skipped | 0 s
chronik_script_unconfirmed_txs.py          | ○ Skipped | 0 s
chronik_script_utxos.py                    | ○ Skipped | 0 s
chronik_serve.py                           | ○ Skipped | 0 s
chronik_spent_by.py                        | ○ Skipped | 0 s
chronik_tx.py                              | ○ Skipped | 0 s
chronik_ws.py                              | ○ Skipped | 0 s
chronik_ws_script.py                       | ○ Skipped | 0 s
interface_usdt_net.py                      | ○ Skipped | 0 s
interface_usdt_utxocache.py                | ○ Skipped | 0 s
interface_usdt_validation.py               | ○ Skipped | 0 s

ALL                                        | ✓ Passed  | 2091 s (accumulated) 
Runtime: 419 s

[161/487] Test Bitcoin RPC authentication...
...
----------------------------------------------------------------------
Ran 3 tests in 0.006s

OK
[163/487] cd /work/contrib/devtools/chainparams && /usr/bin/python3.9 ./test_make_chainparams.py
.....
----------------------------------------------------------------------
Ran 5 tests in 0.001s

OK
[211/487] Running seeder test suite
PASSED: seeder test suite
[368/487] Running secp256k1 test suite
PASSED: secp256k1 test suite
[457/487] Running pow test suite
PASSED: pow test suite
[458/487] bitcoin: testing wallet_tests
FAILED: src/test/CMakeFiles/check-bitcoin-wallet_tests 
cd /work/abc-ci-builds/build-debug/src/test && /usr/bin/cmake -E make_directory /work/abc-ci-builds/build-debug/test/junit && /usr/bin/cmake -E make_directory /work/abc-ci-builds/build-debug/test/log && /usr/bin/cmake -E env /work/cmake/utils/log-and-print-on-failure.sh /work/abc-ci-builds/build-debug/test/log/bitcoin-wallet_tests.log /work/abc-ci-builds/build-debug/src/test/test_bitcoin --run_test=wallet_tests --logger=HRF,message:JUNIT,message,bitcoin-wallet_tests.xml --catch_system_errors=no
Running 13 test cases...
0  0  0  0  0  0  0  0  0  0  0  Assertion failed: detected inconsistent lock order for '::cs_main' in ../../src/validation.cpp:6129 (in thread ''), details in debug log.
Aborted (core dumped)
[461/487] Running avalanche test suite
PASSED: avalanche test suite
[468/487] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[484/487] Running utility command for check-bitcoin-coins_tests
ninja: build stopped: cannot make progress due to previous errors.
Build build-debug failed with exit code 1

add more locks in the avalanche tests

Tail of the build log:

[412/486] Running utility command for check-bitcoin-txvalidationcache_tests
[413/486] bitcoin: testing walletdb_tests
[414/486] bitcoin: testing crypto_tests
[415/486] Running utility command for check-bitcoin-walletdb_tests
[416/486] Running utility command for check-bitcoin-crypto_tests
[417/486] bitcoin: testing psbt_wallet_tests
[418/486] Running utility command for check-bitcoin-psbt_wallet_tests
[419/486] bitcoin: testing merkle_tests
[420/486] Running utility command for check-bitcoin-merkle_tests
[421/486] bitcoin: testing logging_tests
[422/486] Running utility command for check-bitcoin-logging_tests
[423/486] bitcoin: testing miner_tests
[424/486] Running utility command for check-bitcoin-miner_tests
[425/486] bitcoin: testing denialofservice_tests
[426/486] Running utility command for check-bitcoin-denialofservice_tests
[427/486] bitcoin: testing init_tests
[428/486] bitcoin: testing cuckoocache_tests
[429/486] bitcoin: testing uint256_tests
[430/486] Running utility command for check-bitcoin-cuckoocache_tests
[431/486] Running utility command for check-bitcoin-init_tests
[432/486] Running utility command for check-bitcoin-uint256_tests
[433/486] bitcoin: testing coinstatsindex_tests
[434/486] Running utility command for check-bitcoin-coinstatsindex_tests
[435/486] Linking CXX executable src/seeder/test/test-seeder
[436/486] seeder: testing options_tests
[437/486] seeder: testing message_writer_tests
[438/486] seeder: testing parse_name_tests
[439/486] Running utility command for check-seeder-options_tests
[440/486] seeder: testing p2p_messaging_tests
[441/486] Running utility command for check-seeder-parse_name_tests
[442/486] bitcoin: testing wallet_crypto_tests
[443/486] Running utility command for check-seeder-message_writer_tests
[444/486] Running utility command for check-seeder-p2p_messaging_tests
[445/486] Running utility command for check-bitcoin-wallet_crypto_tests
[446/486] bitcoin: testing rcu_tests
[447/486] Linking CXX executable src/qt/test/test_bitcoin-qt
[448/486] seeder: testing write_name_tests
[449/486] Running utility command for check-bitcoin-rcu_tests
[450/486] Running utility command for check-seeder-write_name_tests
[451/486] Running seeder test suite
PASSED: seeder test suite
[452/486] bitcoin: testing txrequest_tests
[453/486] Running utility command for check-bitcoin-txrequest_tests
[454/486] bitcoin: testing blockcheck_tests
[455/486] Running utility command for check-bitcoin-blockcheck_tests
[456/486] bitcoin-qt: testing test_bitcoin-qt
[457/486] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[458/486] bitcoin: testing coinselector_tests
[459/486] Running utility command for check-bitcoin-coinselector_tests
[460/486] bitcoin: testing wallet_tests
[461/486] Running utility command for check-bitcoin-wallet_tests
[462/486] bitcoin: testing transaction_tests
[463/486] Running utility command for check-bitcoin-transaction_tests
[464/486] bitcoin: testing coins_tests
[465/486] Running utility command for check-bitcoin-coins_tests
[466/486] Running bitcoin test suite
PASSED: bitcoin test suite
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang failed with exit code 1

Tail of the build log:

wallet_txn_doublespend.py --mineblock      | ✓ Passed  | 4 s
wallet_watchonly.py                        | ✓ Passed  | 1 s
wallet_watchonly.py --usecli               | ✓ Passed  | 1 s
chronik_avalanche.py                       | ○ Skipped | 0 s
chronik_block.py                           | ○ Skipped | 0 s
chronik_block_info.py                      | ○ Skipped | 0 s
chronik_block_txs.py                       | ○ Skipped | 0 s
chronik_blockchain_info.py                 | ○ Skipped | 0 s
chronik_blocks.py                          | ○ Skipped | 0 s
chronik_disallow_prune.py                  | ○ Skipped | 0 s
chronik_pause.py                           | ○ Skipped | 0 s
chronik_raw_tx.py                          | ○ Skipped | 0 s
chronik_resync.py                          | ○ Skipped | 0 s
chronik_script_confirmed_txs.py            | ○ Skipped | 0 s
chronik_script_history.py                  | ○ Skipped | 0 s
chronik_script_unconfirmed_txs.py          | ○ Skipped | 0 s
chronik_script_utxos.py                    | ○ Skipped | 0 s
chronik_serve.py                           | ○ Skipped | 0 s
chronik_spent_by.py                        | ○ Skipped | 0 s
chronik_tx.py                              | ○ Skipped | 0 s
chronik_ws.py                              | ○ Skipped | 0 s
chronik_ws_script.py                       | ○ Skipped | 0 s
interface_usdt_net.py                      | ○ Skipped | 0 s
interface_usdt_utxocache.py                | ○ Skipped | 0 s
interface_usdt_validation.py               | ○ Skipped | 0 s

ALL                                        | ✓ Passed  | 2109 s (accumulated) 
Runtime: 435 s

[174/487] Test Bitcoin RPC authentication...
...
----------------------------------------------------------------------
Ran 3 tests in 0.005s

OK
[175/487] cd /work/contrib/devtools/chainparams && /usr/bin/python3.9 ./test_make_chainparams.py
.....
----------------------------------------------------------------------
Ran 5 tests in 0.001s

OK
[381/487] Running secp256k1 test suite
PASSED: secp256k1 test suite
[444/487] Running pow test suite
PASSED: pow test suite
[455/487] Running avalanche test suite
PASSED: avalanche test suite
[458/487] Running seeder test suite
PASSED: seeder test suite
[459/487] bitcoin: testing wallet_tests
FAILED: src/test/CMakeFiles/check-bitcoin-wallet_tests 
cd /work/abc-ci-builds/build-debug/src/test && /usr/bin/cmake -E make_directory /work/abc-ci-builds/build-debug/test/junit && /usr/bin/cmake -E make_directory /work/abc-ci-builds/build-debug/test/log && /usr/bin/cmake -E env /work/cmake/utils/log-and-print-on-failure.sh /work/abc-ci-builds/build-debug/test/log/bitcoin-wallet_tests.log /work/abc-ci-builds/build-debug/src/test/test_bitcoin --run_test=wallet_tests --logger=HRF,message:JUNIT,message,bitcoin-wallet_tests.xml --catch_system_errors=no
Running 13 test cases...
0  0  0  0  0  0  0  0  0  0  0  Assertion failed: detected inconsistent lock order for '::cs_main' in ../../src/validation.cpp:6129 (in thread ''), details in debug log.
Aborted (core dumped)
[476/487] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[484/487] Running utility command for check-bitcoin-coins_tests
ninja: build stopped: cannot make progress due to previous errors.
Build build-debug failed with exit code 1

rebase, add another missing lock in avalanche tests
wallet_tests is still crashing due to lock order issues

@bot build-debug build-tsan

Tail of the build log:

wallet_txn_doublespend.py --mineblock      | ✓ Passed  | 4 s
wallet_watchonly.py                        | ✓ Passed  | 2 s
wallet_watchonly.py --usecli               | ✓ Passed  | 1 s
chronik_avalanche.py                       | ○ Skipped | 0 s
chronik_block.py                           | ○ Skipped | 0 s
chronik_block_info.py                      | ○ Skipped | 0 s
chronik_block_txs.py                       | ○ Skipped | 0 s
chronik_blockchain_info.py                 | ○ Skipped | 0 s
chronik_blocks.py                          | ○ Skipped | 0 s
chronik_disallow_prune.py                  | ○ Skipped | 0 s
chronik_pause.py                           | ○ Skipped | 0 s
chronik_raw_tx.py                          | ○ Skipped | 0 s
chronik_resync.py                          | ○ Skipped | 0 s
chronik_script_confirmed_txs.py            | ○ Skipped | 0 s
chronik_script_history.py                  | ○ Skipped | 0 s
chronik_script_unconfirmed_txs.py          | ○ Skipped | 0 s
chronik_script_utxos.py                    | ○ Skipped | 0 s
chronik_serve.py                           | ○ Skipped | 0 s
chronik_spent_by.py                        | ○ Skipped | 0 s
chronik_tx.py                              | ○ Skipped | 0 s
chronik_ws.py                              | ○ Skipped | 0 s
chronik_ws_script.py                       | ○ Skipped | 0 s
interface_usdt_net.py                      | ○ Skipped | 0 s
interface_usdt_utxocache.py                | ○ Skipped | 0 s
interface_usdt_validation.py               | ○ Skipped | 0 s

ALL                                        | ✓ Passed  | 2133 s (accumulated) 
Runtime: 427 s

[196/487] Test Bitcoin RPC authentication...
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
[197/487] cd /work/contrib/devtools/chainparams && /usr/bin/python3.9 ./test_make_chainparams.py
.....
----------------------------------------------------------------------
Ran 5 tests in 0.001s

OK
[217/487] Running seeder test suite
PASSED: seeder test suite
[458/487] Running avalanche test suite
PASSED: avalanche test suite
[460/487] Running secp256k1 test suite
PASSED: secp256k1 test suite
[462/487] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[463/487] Running pow test suite
PASSED: pow test suite
[464/487] bitcoin: testing wallet_tests
FAILED: src/test/CMakeFiles/check-bitcoin-wallet_tests 
cd /work/abc-ci-builds/build-debug/src/test && /usr/bin/cmake -E make_directory /work/abc-ci-builds/build-debug/test/junit && /usr/bin/cmake -E make_directory /work/abc-ci-builds/build-debug/test/log && /usr/bin/cmake -E env /work/cmake/utils/log-and-print-on-failure.sh /work/abc-ci-builds/build-debug/test/log/bitcoin-wallet_tests.log /work/abc-ci-builds/build-debug/src/test/test_bitcoin --run_test=wallet_tests --logger=HRF,message:JUNIT,message,bitcoin-wallet_tests.xml --catch_system_errors=no
Running 13 test cases...
0  0  0  0  0  0  0  0  0  0  0  Assertion failed: detected inconsistent lock order for '::cs_main' in ../../src/validation.cpp:6128 (in thread ''), details in debug log.
Aborted (core dumped)
[484/487] Running utility command for check-bitcoin-coins_tests
ninja: build stopped: cannot make progress due to previous errors.
Build build-debug failed with exit code 1

Tail of the build log:

wallet_txn_doublespend.py --mineblock      | ✓ Passed  | 3 s
wallet_watchonly.py                        | ✓ Passed  | 1 s
wallet_watchonly.py --usecli               | ✓ Passed  | 1 s
chronik_avalanche.py                       | ○ Skipped | 0 s
chronik_block.py                           | ○ Skipped | 0 s
chronik_block_info.py                      | ○ Skipped | 0 s
chronik_block_txs.py                       | ○ Skipped | 0 s
chronik_blockchain_info.py                 | ○ Skipped | 0 s
chronik_blocks.py                          | ○ Skipped | 0 s
chronik_disallow_prune.py                  | ○ Skipped | 0 s
chronik_pause.py                           | ○ Skipped | 0 s
chronik_raw_tx.py                          | ○ Skipped | 0 s
chronik_resync.py                          | ○ Skipped | 0 s
chronik_script_confirmed_txs.py            | ○ Skipped | 0 s
chronik_script_history.py                  | ○ Skipped | 0 s
chronik_script_unconfirmed_txs.py          | ○ Skipped | 0 s
chronik_script_utxos.py                    | ○ Skipped | 0 s
chronik_serve.py                           | ○ Skipped | 0 s
chronik_spent_by.py                        | ○ Skipped | 0 s
chronik_tx.py                              | ○ Skipped | 0 s
chronik_ws.py                              | ○ Skipped | 0 s
chronik_ws_script.py                       | ○ Skipped | 0 s
interface_usdt_net.py                      | ○ Skipped | 0 s
interface_usdt_utxocache.py                | ○ Skipped | 0 s
interface_usdt_validation.py               | ○ Skipped | 0 s

ALL                                        | ✓ Passed  | 1982 s (accumulated) 
Runtime: 397 s

[386/487] Running secp256k1 test suite
PASSED: secp256k1 test suite
[441/487] Running pow test suite
PASSED: pow test suite
[450/487] bitcoin: testing wallet_tests
FAILED: src/test/CMakeFiles/check-bitcoin-wallet_tests 
cd /work/abc-ci-builds/build-debug/src/test && /usr/bin/cmake -E make_directory /work/abc-ci-builds/build-debug/test/junit && /usr/bin/cmake -E make_directory /work/abc-ci-builds/build-debug/test/log && /usr/bin/cmake -E env /work/cmake/utils/log-and-print-on-failure.sh /work/abc-ci-builds/build-debug/test/log/bitcoin-wallet_tests.log /work/abc-ci-builds/build-debug/src/test/test_bitcoin --run_test=wallet_tests --logger=HRF,message:JUNIT,message,bitcoin-wallet_tests.xml --catch_system_errors=no
Running 13 test cases...
0  0  0  0  0  0  0  0  0  0  0  Assertion failed: detected inconsistent lock order for '::cs_main' in ../../src/validation.cpp:6128 (in thread ''), details in debug log.
Aborted (core dumped)
[453/487] Running seeder test suite
PASSED: seeder test suite
[456/487] Running avalanche test suite
PASSED: avalanche test suite
[459/487] Test Bitcoin RPC authentication...
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
[460/487] cd /work/contrib/devtools/chainparams && /usr/bin/python3.9 ./test_make_chainparams.py
.....
----------------------------------------------------------------------
Ran 5 tests in 0.001s

OK
[476/487] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[484/487] Running utility command for check-bitcoin-coins_tests
ninja: build stopped: cannot make progress due to previous errors.
Build build-debug failed with exit code 1

Tail of the build log:

    #18 boost::function0<void>::operator()() const /usr/include/boost/function/function_template.hpp:763:14 (test_bitcoin+0x5f1807)
    #19 boost::detail::forward::operator()() /usr/include/boost/test/impl/execution_monitor.ipp:1388:32 (test_bitcoin+0x5f1807)
    #20 boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) /usr/include/boost/function/function_template.hpp:137:18 (test_bitcoin+0x5f1807)
    #21 boost::function0<int>::operator()() const /usr/include/boost/function/function_template.hpp:763:14 (test_bitcoin+0x57835b)
    #22 int boost::detail::do_invoke<boost::shared_ptr<boost::detail::translator_holder_base>, boost::function<int ()> >(boost::shared_ptr<boost::detail::translator_holder_base> const&, boost::function<int ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:301:30 (test_bitcoin+0x57835b)
    #23 boost::execution_monitor::catch_signals(boost::function<int ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:903:16 (test_bitcoin+0x57835b)
    #24 boost::execution_monitor::execute(boost::function<int ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:1301:16 (test_bitcoin+0x578664)
    #25 boost::execution_monitor::vexecute(boost::function<void ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:1397:5 (test_bitcoin+0x572b50)
    #26 boost::unit_test::unit_test_monitor_t::execute_and_translate(boost::function<void ()> const&, unsigned long) /usr/include/boost/test/impl/unit_test_monitor.ipp:49:9 (test_bitcoin+0x575c1c)
    #27 boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:815:44 (test_bitcoin+0x5a85ce)
    #28 boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:740:54 (test_bitcoin+0x5a8732)
    #29 boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:740:54 (test_bitcoin+0x5a8732)
    #30 boost::unit_test::framework::run(unsigned long, bool) /usr/include/boost/test/impl/framework.ipp:1721:29 (test_bitcoin+0x5751e4)
    #31 boost::unit_test::unit_test_main(boost::unit_test::test_suite* (*)(int, char**), int, char**) /usr/include/boost/test/impl/unit_test_main.ipp:250:9 (test_bitcoin+0x58f68e)
    #32 main /usr/include/boost/test/impl/unit_test_main.ipp:306:12 (test_bitcoin+0x58fdb6)

  Mutex M482020709296573568 acquired here while holding mutex M265247 in main thread:
    #0 pthread_mutex_lock <null> (test_bitcoin+0x4e6786)
    #1 __gthread_mutex_lock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10/bits/gthr-default.h:749:12 (test_bitcoin+0x140c15d)
    #2 std::mutex::lock() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_mutex.h:100:17 (test_bitcoin+0x140c15d)
    #3 std::unique_lock<std::mutex>::lock() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/unique_lock.h:138:17 (test_bitcoin+0x140c15d)
    #4 UniqueLock<AnnotatedMixin<std::mutex>, std::unique_lock<std::mutex> >::Enter(char const*, char const*, int) /work/abc-ci-builds/build-tsan/../../src/./sync.h:151:15 (test_bitcoin+0x140c15d)
    #5 UniqueLock<AnnotatedMixin<std::mutex>, std::unique_lock<std::mutex> >::UniqueLock(AnnotatedMixin<std::mutex>&, char const*, char const*, int, bool) /work/abc-ci-builds/build-tsan/../../src/./sync.h:170:13 (test_bitcoin+0x140c15d)
    #6 Chainstate::ActivateBestChain(Config const&, BlockValidationState&, std::shared_ptr<CBlock const>) /work/abc-ci-builds/build-tsan/../../src/validation.cpp:3126:5 (test_bitcoin+0x140c15d)
    #7 ChainstateManager::ProcessNewBlock(Config const&, std::shared_ptr<CBlock const> const&, bool, bool*) /work/abc-ci-builds/build-tsan/../../src/validation.cpp:4443:29 (test_bitcoin+0x1419c97)
    #8 TestChain100Setup::CreateAndProcessBlock(std::vector<CMutableTransaction, std::allocator<CMutableTransaction> > const&, CScript const&, Chainstate*) /work/abc-ci-builds/build-tsan/../../src/test/util/setup_common.cpp:355:11 (test_bitcoin+0x549f50)
    #9 wallet_tests::CreateWallet::test_method()::$_11::operator()(std::unique_ptr<interfaces::Wallet, std::default_delete<interfaces::Wallet> >) const /work/abc-ci-builds/build-tsan/../../src/wallet/test/wallet_tests.cpp:860:21 (test_bitcoin+0xf82141)
    #10 void std::__invoke_impl<void, wallet_tests::CreateWallet::test_method()::$_11&, std::unique_ptr<interfaces::Wallet, std::default_delete<interfaces::Wallet> > >(std::__invoke_other, wallet_tests::CreateWallet::test_method()::$_11&, std::unique_ptr<interfaces::Wallet, std::default_delete<interfaces::Wallet> >&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14 (test_bitcoin+0xf82141)
    #11 std::enable_if<is_invocable_r_v<void, wallet_tests::CreateWallet::test_method()::$_11&, std::unique_ptr<interfaces::Wallet, std::default_delete<interfaces::Wallet> > >, void>::type std::__invoke_r<void, wallet_tests::CreateWallet::test_method()::$_11&, std::unique_ptr<interfaces::Wallet, std::default_delete<interfaces::Wallet> > >(wallet_tests::CreateWallet::test_method()::$_11&, std::unique_ptr<interfaces::Wallet, std::default_delete<interfaces::Wallet> >&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:110:2 (test_bitcoin+0xf82141)
    #12 std::_Function_handler<void (std::unique_ptr<interfaces::Wallet, std::default_delete<interfaces::Wallet> >), wallet_tests::CreateWallet::test_method()::$_11>::_M_invoke(std::_Any_data const&, std::unique_ptr<interfaces::Wallet, std::default_delete<interfaces::Wallet> >&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:291:9 (test_bitcoin+0xf82141)
    #13 std::function<void (std::unique_ptr<interfaces::Wallet, std::default_delete<interfaces::Wallet> >)>::operator()(std::unique_ptr<interfaces::Wallet, std::default_delete<interfaces::Wallet> >) const /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:622:14 (test_bitcoin+0x15ee9ee)
    #14 CWallet::Create(interfaces::Chain&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::unique_ptr<WalletDatabase, std::default_delete<WalletDatabase> >, unsigned long, bilingual_str&, std::vector<bilingual_str, std::allocator<bilingual_str> >&) /work/abc-ci-builds/build-tsan/../../src/wallet/wallet.cpp:3011:13 (test_bitcoin+0x15ee9ee)
    #15 wallet_tests::TestLoadWallet(interfaces::Chain&) /work/abc-ci-builds/build-tsan/../../src/wallet/test/wallet_tests.cpp:49:19 (test_bitcoin+0xf7cf9f)
    #16 wallet_tests::CreateWallet::test_method() /work/abc-ci-builds/build-tsan/../../src/wallet/test/wallet_tests.cpp:883:14 (test_bitcoin+0xf7b39e)
    #17 wallet_tests::CreateWallet_invoker() /work/abc-ci-builds/build-tsan/../../src/wallet/test/wallet_tests.cpp:777:1 (test_bitcoin+0xf791aa)
    #18 boost::detail::function::void_function_invoker0<void (*)(), void>::invoke(boost::detail::function::function_buffer&) /usr/include/boost/function/function_template.hpp:117:11 (test_bitcoin+0x61714d)
    #19 boost::function0<void>::operator()() const /usr/include/boost/function/function_template.hpp:763:14 (test_bitcoin+0x5f1807)
    #20 boost::detail::forward::operator()() /usr/include/boost/test/impl/execution_monitor.ipp:1388:32 (test_bitcoin+0x5f1807)
    #21 boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) /usr/include/boost/function/function_template.hpp:137:18 (test_bitcoin+0x5f1807)
    #22 boost::function0<int>::operator()() const /usr/include/boost/function/function_template.hpp:763:14 (test_bitcoin+0x57835b)
    #23 int boost::detail::do_invoke<boost::shared_ptr<boost::detail::translator_holder_base>, boost::function<int ()> >(boost::shared_ptr<boost::detail::translator_holder_base> const&, boost::function<int ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:301:30 (test_bitcoin+0x57835b)
    #24 boost::execution_monitor::catch_signals(boost::function<int ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:903:16 (test_bitcoin+0x57835b)
    #25 boost::execution_monitor::execute(boost::function<int ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:1301:16 (test_bitcoin+0x578664)
    #26 boost::execution_monitor::vexecute(boost::function<void ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:1397:5 (test_bitcoin+0x572b50)
    #27 boost::unit_test::unit_test_monitor_t::execute_and_translate(boost::function<void ()> const&, unsigned long) /usr/include/boost/test/impl/unit_test_monitor.ipp:49:9 (test_bitcoin+0x575c1c)
    #28 boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:815:44 (test_bitcoin+0x5a85ce)
    #29 boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:740:54 (test_bitcoin+0x5a8732)
    #30 boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:740:54 (test_bitcoin+0x5a8732)
    #31 boost::unit_test::framework::run(unsigned long, bool) /usr/include/boost/test/impl/framework.ipp:1721:29 (test_bitcoin+0x5751e4)
    #32 boost::unit_test::unit_test_main(boost::unit_test::test_suite* (*)(int, char**), int, char**) /usr/include/boost/test/impl/unit_test_main.ipp:250:9 (test_bitcoin+0x58f68e)
    #33 main /usr/include/boost/test/impl/unit_test_main.ipp:306:12 (test_bitcoin+0x58fdb6)

SUMMARY: ThreadSanitizer: lock-order-inversion (potential deadlock) (/work/abc-ci-builds/build-tsan/src/test/test_bitcoin+0x4e6786) in pthread_mutex_lock
==================
0  
*** No errors detected
ThreadSanitizer: reported 2 warnings
[474/480] bitcoin: testing coins_tests
ninja: build stopped: subcommand failed.
Build build-tsan failed with exit code 1

reduce scope of cs_main lock to avoid a cs_wallet -> cs_main -> cs_wallet deadlock in ::importwallet().