@@ -104,17 +104,18 @@ static void AddKey(CWallet& wallet, const CKey& key)
104104BOOST_FIXTURE_TEST_CASE (scan_for_wallet_transactions, TestChain100Setup)
105105{
106106 // Cap last block file size, and mine new block in a new block file.
107- CBlockIndex* oldTip = m_node.chainman -> ActiveChain ().Tip ();
107+ CBlockIndex* oldTip = WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain ().Tip () );
108108 WITH_LOCK (::cs_main, m_node.chainman ->m_blockman .GetBlockFileInfo (oldTip->GetBlockPos ().nFile )->nSize = MAX_BLOCKFILE_SIZE);
109109 CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
110- CBlockIndex* newTip = m_node.chainman -> ActiveChain ().Tip ();
110+ CBlockIndex* newTip = WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain ().Tip () );
111111
112112 // Verify ScanForWalletTransactions fails to read an unknown start block.
113113 {
114114 CWallet wallet (m_node.chain .get (), m_node.coinjoin_loader .get (), " " , CreateDummyWalletDatabase ());
115115 wallet.SetupLegacyScriptPubKeyMan ();
116116 {
117117 LOCK (wallet.cs_wallet );
118+ LOCK (Assert (m_node.chainman )->GetMutex ());
118119 wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
119120 wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
120121 }
@@ -135,6 +136,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
135136 CWallet wallet (m_node.chain .get (), m_node.coinjoin_loader .get (), " " , CreateDummyWalletDatabase ());
136137 {
137138 LOCK (wallet.cs_wallet );
139+ LOCK (Assert (m_node.chainman )->GetMutex ());
138140 wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
139141 wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
140142 }
@@ -164,6 +166,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
164166 CWallet wallet (m_node.chain .get (), m_node.coinjoin_loader .get (), " " , CreateDummyWalletDatabase ());
165167 {
166168 LOCK (wallet.cs_wallet );
169+ LOCK (Assert (m_node.chainman )->GetMutex ());
167170 wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
168171 wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
169172 }
@@ -191,6 +194,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
191194 CWallet wallet (m_node.chain .get (), m_node.coinjoin_loader .get (), " " , CreateDummyWalletDatabase ());
192195 {
193196 LOCK (wallet.cs_wallet );
197+ LOCK (Assert (m_node.chainman )->GetMutex ());
194198 wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
195199 wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
196200 }
@@ -209,10 +213,10 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
209213BOOST_FIXTURE_TEST_CASE (importmulti_rescan, TestChain100Setup)
210214{
211215 // Cap last block file size, and mine new block in a new block file.
212- CBlockIndex* oldTip = m_node.chainman -> ActiveChain ().Tip ();
216+ CBlockIndex* oldTip = WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain ().Tip () );
213217 WITH_LOCK (::cs_main, m_node.chainman ->m_blockman .GetBlockFileInfo (oldTip->GetBlockPos ().nFile )->nSize = MAX_BLOCKFILE_SIZE);
214218 CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
215- CBlockIndex* newTip = m_node.chainman -> ActiveChain ().Tip ();
219+ CBlockIndex* newTip = WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain ().Tip () );
216220
217221 // Prune the older block file.
218222 int file_number;
@@ -276,7 +280,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
276280{
277281 // Create two blocks with same timestamp to verify that importwallet rescan
278282 // will pick up both blocks, not just the first.
279- const int64_t BLOCK_TIME = m_node.chainman -> ActiveChain ().Tip ()->GetBlockTimeMax () + 5 ;
283+ const int64_t BLOCK_TIME = WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain ().Tip ()->GetBlockTimeMax () + 5 ) ;
280284 SetMockTime (BLOCK_TIME);
281285 m_coinbase_txns.emplace_back (CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ())).vtx [0 ]);
282286 m_coinbase_txns.emplace_back (CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ())).vtx [0 ]);
@@ -301,6 +305,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
301305 spk_man->AddKeyPubKey (coinbaseKey, coinbaseKey.GetPubKey ());
302306
303307 AddWallet (context, wallet);
308+ LOCK (Assert (m_node.chainman )->GetMutex ());
304309 wallet->SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
305310 }
306311 JSONRPCRequest request;
@@ -326,6 +331,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
326331 request.params .setArray ();
327332 request.params .push_back (backup_file);
328333 AddWallet (context, wallet);
334+ LOCK (Assert (m_node.chainman )->GetMutex ());
329335 wallet->SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
330336 ::importwallet ().HandleRequest(request);
331337 RemoveWallet (context, wallet, /* load_on_start=*/ std::nullopt );
@@ -352,6 +358,8 @@ BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
352358 CWalletTx wtx (&wallet, m_coinbase_txns.back ());
353359
354360 LOCK (wallet.cs_wallet );
361+ LOCK (Assert (m_node.chainman )->GetMutex ());
362+ CWalletTx wtx{m_coinbase_txns.back (), TxStateConfirmed{m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash (), m_node.chainman ->ActiveChain ().Height (), /* index=*/ 0 }};
355363 wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
356364 wallet.SetupDescriptorScriptPubKeyMans ();
357365
@@ -524,7 +532,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
524532 ListCoinsTestingSetup ()
525533 {
526534 CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
527- wallet = CreateSyncedWallet (*m_node.chain , *m_node.coinjoin_loader , m_node.chainman -> ActiveChain (), coinbaseKey);
535+ wallet = CreateSyncedWallet (*m_node.chain , *m_node.coinjoin_loader , WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain () ), coinbaseKey);
528536 }
529537
530538 ~ListCoinsTestingSetup ()
@@ -550,6 +558,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
550558 CreateAndProcessBlock ({CMutableTransaction (blocktx)}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
551559
552560 LOCK (wallet->cs_wallet );
561+ LOCK (Assert (m_node.chainman )->GetMutex ());
553562 wallet->SetLastBlockProcessed (wallet->GetLastBlockHeight () + 1 , m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
554563 auto it = wallet->mapWallet .find (tx->GetHash ());
555564 BOOST_CHECK (it != wallet->mapWallet .end ());
0 commit comments