@@ -91,16 +91,17 @@ static void AddKey(CWallet& wallet, const CKey& key)
91
91
BOOST_FIXTURE_TEST_CASE (scan_for_wallet_transactions, TestChain100Setup)
92
92
{
93
93
// Cap last block file size, and mine new block in a new block file.
94
- CBlockIndex* oldTip = m_node.chainman -> ActiveChain ().Tip ();
94
+ CBlockIndex* oldTip = WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain ().Tip () );
95
95
WITH_LOCK (::cs_main, m_node.chainman ->m_blockman .GetBlockFileInfo (oldTip->GetBlockPos ().nFile )->nSize = MAX_BLOCKFILE_SIZE);
96
96
CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
97
- CBlockIndex* newTip = m_node.chainman -> ActiveChain ().Tip ();
97
+ CBlockIndex* newTip = WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain ().Tip () );
98
98
99
99
// Verify ScanForWalletTransactions fails to read an unknown start block.
100
100
{
101
101
CWallet wallet (m_node.chain .get (), " " , m_args, CreateDummyWalletDatabase ());
102
102
{
103
103
LOCK (wallet.cs_wallet );
104
+ LOCK (Assert (m_node.chainman )->GetMutex ());
104
105
wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
105
106
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
106
107
}
@@ -121,6 +122,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
121
122
CWallet wallet (m_node.chain .get (), " " , m_args, CreateMockWalletDatabase ());
122
123
{
123
124
LOCK (wallet.cs_wallet );
125
+ LOCK (Assert (m_node.chainman )->GetMutex ());
124
126
wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
125
127
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
126
128
}
@@ -165,6 +167,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
165
167
CWallet wallet (m_node.chain .get (), " " , m_args, CreateDummyWalletDatabase ());
166
168
{
167
169
LOCK (wallet.cs_wallet );
170
+ LOCK (Assert (m_node.chainman )->GetMutex ());
168
171
wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
169
172
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
170
173
}
@@ -192,6 +195,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
192
195
CWallet wallet (m_node.chain .get (), " " , m_args, CreateDummyWalletDatabase ());
193
196
{
194
197
LOCK (wallet.cs_wallet );
198
+ LOCK (Assert (m_node.chainman )->GetMutex ());
195
199
wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
196
200
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
197
201
}
@@ -210,10 +214,10 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
210
214
BOOST_FIXTURE_TEST_CASE (importmulti_rescan, TestChain100Setup)
211
215
{
212
216
// Cap last block file size, and mine new block in a new block file.
213
- CBlockIndex* oldTip = m_node.chainman -> ActiveChain ().Tip ();
217
+ CBlockIndex* oldTip = WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain ().Tip () );
214
218
WITH_LOCK (::cs_main, m_node.chainman ->m_blockman .GetBlockFileInfo (oldTip->GetBlockPos ().nFile )->nSize = MAX_BLOCKFILE_SIZE);
215
219
CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
216
- CBlockIndex* newTip = m_node.chainman -> ActiveChain ().Tip ();
220
+ CBlockIndex* newTip = WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain ().Tip () );
217
221
218
222
// Prune the older block file.
219
223
int file_number;
@@ -277,7 +281,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
277
281
{
278
282
// Create two blocks with same timestamp to verify that importwallet rescan
279
283
// will pick up both blocks, not just the first.
280
- const int64_t BLOCK_TIME = m_node.chainman -> ActiveChain ().Tip ()->GetBlockTimeMax () + 5 ;
284
+ const int64_t BLOCK_TIME = WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain ().Tip ()->GetBlockTimeMax () + 5 ) ;
281
285
SetMockTime (BLOCK_TIME);
282
286
m_coinbase_txns.emplace_back (CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ())).vtx [0 ]);
283
287
m_coinbase_txns.emplace_back (CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ())).vtx [0 ]);
@@ -302,6 +306,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
302
306
spk_man->AddKeyPubKey (coinbaseKey, coinbaseKey.GetPubKey ());
303
307
304
308
AddWallet (context, wallet);
309
+ LOCK (Assert (m_node.chainman )->GetMutex ());
305
310
wallet->SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
306
311
}
307
312
JSONRPCRequest request;
@@ -327,6 +332,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
327
332
request.params .setArray ();
328
333
request.params .push_back (backup_file);
329
334
AddWallet (context, wallet);
335
+ LOCK (Assert (m_node.chainman )->GetMutex ());
330
336
wallet->SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
331
337
wallet::importwallet ().HandleRequest (request);
332
338
RemoveWallet (context, wallet, /* load_on_start= */ std::nullopt);
@@ -350,9 +356,10 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
350
356
BOOST_FIXTURE_TEST_CASE (coin_mark_dirty_immature_credit, TestChain100Setup)
351
357
{
352
358
CWallet wallet (m_node.chain .get (), " " , m_args, CreateDummyWalletDatabase ());
353
- CWalletTx wtx{m_coinbase_txns.back (), TxStateConfirmed{m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash (), m_node.chainman ->ActiveChain ().Height (), /* index=*/ 0 }};
354
359
355
360
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 }};
356
363
wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
357
364
wallet.SetupDescriptorScriptPubKeyMans ();
358
365
@@ -520,7 +527,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
520
527
ListCoinsTestingSetup ()
521
528
{
522
529
CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
523
- wallet = CreateSyncedWallet (*m_node.chain , m_node.chainman -> ActiveChain (), m_args, coinbaseKey);
530
+ wallet = CreateSyncedWallet (*m_node.chain , WITH_LOCK ( Assert ( m_node.chainman )-> GetMutex (), return m_node. chainman -> ActiveChain () ), m_args, coinbaseKey);
524
531
}
525
532
526
533
~ListCoinsTestingSetup ()
@@ -547,6 +554,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
547
554
CreateAndProcessBlock ({CMutableTransaction (blocktx)}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
548
555
549
556
LOCK (wallet->cs_wallet );
557
+ LOCK (Assert (m_node.chainman )->GetMutex ());
550
558
wallet->SetLastBlockProcessed (wallet->GetLastBlockHeight () + 1 , m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
551
559
auto it = wallet->mapWallet .find (tx->GetHash ());
552
560
BOOST_CHECK (it != wallet->mapWallet .end ());
0 commit comments