Skip to content

Commit e1e68b6

Browse files
committed
test: Fix inconsistent lock order in wallet_tests/CreateWallet
1 parent cb23fe0 commit e1e68b6

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/wallet/test/wallet_tests.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ RPCHelpMan importmulti();
2828
RPCHelpMan dumpwallet();
2929
RPCHelpMan importwallet();
3030

31+
extern RecursiveMutex cs_wallets;
32+
3133
// Ensure that fee levels defined in the wallet are at least as high
3234
// as the default levels for node policy.
3335
static_assert(DEFAULT_TRANSACTION_MINFEE >= DEFAULT_MIN_RELAY_TX_FEE, "wallet minimum fee is smaller than default relay fee");
@@ -761,16 +763,18 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
761763
// deadlock during the sync and simulates a new block notification happening
762764
// as soon as possible.
763765
addtx_count = 0;
764-
auto handler = HandleLoadWallet([&](std::unique_ptr<interfaces::Wallet> wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet->wallet()->cs_wallet) {
766+
auto handler = HandleLoadWallet([&](std::unique_ptr<interfaces::Wallet> wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet->wallet()->cs_wallet, cs_wallets) {
765767
BOOST_CHECK(rescan_completed);
766768
m_coinbase_txns.push_back(CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
767769
block_tx = TestSimpleSpend(*m_coinbase_txns[2], 0, coinbaseKey, GetScriptForRawPubKey(key.GetPubKey()));
768770
m_coinbase_txns.push_back(CreateAndProcessBlock({block_tx}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
769771
mempool_tx = TestSimpleSpend(*m_coinbase_txns[3], 0, coinbaseKey, GetScriptForRawPubKey(key.GetPubKey()));
770772
BOOST_CHECK(m_node.chain->broadcastTransaction(MakeTransactionRef(mempool_tx), DEFAULT_TRANSACTION_MAXFEE, false, error));
773+
LEAVE_CRITICAL_SECTION(cs_wallets);
771774
LEAVE_CRITICAL_SECTION(wallet->wallet()->cs_wallet);
772775
SyncWithValidationInterfaceQueue();
773776
ENTER_CRITICAL_SECTION(wallet->wallet()->cs_wallet);
777+
ENTER_CRITICAL_SECTION(cs_wallets);
774778
});
775779
wallet = TestLoadWallet(*m_node.chain);
776780
BOOST_CHECK_EQUAL(addtx_count, 4);

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const std::map<uint64_t,std::string> WALLET_FLAG_CAVEATS{
5252

5353
static const size_t OUTPUT_GROUP_MAX_ENTRIES = 10;
5454

55-
static RecursiveMutex cs_wallets;
55+
RecursiveMutex cs_wallets;
5656
static std::vector<std::shared_ptr<CWallet>> vpwallets GUARDED_BY(cs_wallets);
5757
static std::list<LoadWalletFn> g_load_wallet_fns GUARDED_BY(cs_wallets);
5858

test/sanitizer_suppressions/tsan

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ deadlock:CConnman::ForNode
3232
deadlock:CConnman::GetNodeStats
3333
deadlock:CChainState::ConnectTip
3434
deadlock:UpdateTip
35-
deadlock:wallet_tests::CreateWallet
3635

3736
# WalletBatch (unidentified deadlock)
3837
deadlock:WalletBatch

0 commit comments

Comments
 (0)