@@ -104,17 +104,18 @@ static void AddKey(CWallet& wallet, const CKey& key)
104
104
BOOST_FIXTURE_TEST_CASE (scan_for_wallet_transactions, TestChain100Setup)
105
105
{
106
106
// 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 () );
108
108
WITH_LOCK (::cs_main, m_node.chainman ->m_blockman .GetBlockFileInfo (oldTip->GetBlockPos ().nFile )->nSize = MAX_BLOCKFILE_SIZE);
109
109
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 () );
111
111
112
112
// Verify ScanForWalletTransactions fails to read an unknown start block.
113
113
{
114
114
CWallet wallet (m_node.chain .get (), m_node.coinjoin_loader .get (), " " , CreateDummyWalletDatabase ());
115
115
wallet.SetupLegacyScriptPubKeyMan ();
116
116
{
117
117
LOCK (wallet.cs_wallet );
118
+ LOCK (Assert (m_node.chainman )->GetMutex ());
118
119
wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
119
120
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
120
121
}
@@ -135,6 +136,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
135
136
CWallet wallet (m_node.chain .get (), m_node.coinjoin_loader .get (), " " , CreateDummyWalletDatabase ());
136
137
{
137
138
LOCK (wallet.cs_wallet );
139
+ LOCK (Assert (m_node.chainman )->GetMutex ());
138
140
wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
139
141
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
140
142
}
@@ -164,6 +166,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
164
166
CWallet wallet (m_node.chain .get (), m_node.coinjoin_loader .get (), " " , CreateDummyWalletDatabase ());
165
167
{
166
168
LOCK (wallet.cs_wallet );
169
+ LOCK (Assert (m_node.chainman )->GetMutex ());
167
170
wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
168
171
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
169
172
}
@@ -191,6 +194,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
191
194
CWallet wallet (m_node.chain .get (), m_node.coinjoin_loader .get (), " " , CreateDummyWalletDatabase ());
192
195
{
193
196
LOCK (wallet.cs_wallet );
197
+ LOCK (Assert (m_node.chainman )->GetMutex ());
194
198
wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
195
199
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
196
200
}
@@ -209,10 +213,10 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
209
213
BOOST_FIXTURE_TEST_CASE (importmulti_rescan, TestChain100Setup)
210
214
{
211
215
// 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 () );
213
217
WITH_LOCK (::cs_main, m_node.chainman ->m_blockman .GetBlockFileInfo (oldTip->GetBlockPos ().nFile )->nSize = MAX_BLOCKFILE_SIZE);
214
218
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 () );
216
220
217
221
// Prune the older block file.
218
222
int file_number;
@@ -276,7 +280,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
276
280
{
277
281
// Create two blocks with same timestamp to verify that importwallet rescan
278
282
// 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 ) ;
280
284
SetMockTime (BLOCK_TIME);
281
285
m_coinbase_txns.emplace_back (CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ())).vtx [0 ]);
282
286
m_coinbase_txns.emplace_back (CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ())).vtx [0 ]);
@@ -301,6 +305,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
301
305
spk_man->AddKeyPubKey (coinbaseKey, coinbaseKey.GetPubKey ());
302
306
303
307
AddWallet (context, wallet);
308
+ LOCK (Assert (m_node.chainman )->GetMutex ());
304
309
wallet->SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
305
310
}
306
311
JSONRPCRequest request;
@@ -326,6 +331,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
326
331
request.params .setArray ();
327
332
request.params .push_back (backup_file);
328
333
AddWallet (context, wallet);
334
+ LOCK (Assert (m_node.chainman )->GetMutex ());
329
335
wallet->SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
330
336
::importwallet ().HandleRequest(request);
331
337
RemoveWallet (context, wallet, /* load_on_start=*/ std::nullopt);
@@ -352,6 +358,8 @@ BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
352
358
CWalletTx wtx (&wallet, m_coinbase_txns.back ());
353
359
354
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 }};
355
363
wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
356
364
wallet.SetupDescriptorScriptPubKeyMans ();
357
365
@@ -524,7 +532,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
524
532
ListCoinsTestingSetup ()
525
533
{
526
534
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);
528
536
}
529
537
530
538
~ListCoinsTestingSetup ()
@@ -550,6 +558,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
550
558
CreateAndProcessBlock ({CMutableTransaction (blocktx)}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
551
559
552
560
LOCK (wallet->cs_wallet );
561
+ LOCK (Assert (m_node.chainman )->GetMutex ());
553
562
wallet->SetLastBlockProcessed (wallet->GetLastBlockHeight () + 1 , m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
554
563
auto it = wallet->mapWallet .find (tx->GetHash ());
555
564
BOOST_CHECK (it != wallet->mapWallet .end ());
0 commit comments