Skip to content

Commit 543ef7d

Browse files
tests: Add missing cs_main locks required when accessing pcoinsdbview, pcoinsTip or pblocktree
1 parent c576979 commit 543ef7d

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/bench/block_assemble.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ static void AssembleBlock(benchmark::State& state)
7373
boost::thread_group thread_group;
7474
CScheduler scheduler;
7575
{
76+
LOCK(cs_main);
7677
::pblocktree.reset(new CBlockTreeDB(1 << 20, true));
7778
::pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true));
7879
::pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get()));
79-
80+
}
81+
{
8082
const CChainParams& chainparams = Params();
8183
thread_group.create_thread(std::bind(&CScheduler::serviceQueue, &scheduler));
8284
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);

src/bench/duplicate_inputs.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ static void DuplicateInputs(benchmark::State& state)
3737
CScheduler scheduler;
3838
const CChainParams& chainparams = Params();
3939
{
40+
LOCK(cs_main);
4041
::pblocktree.reset(new CBlockTreeDB(1 << 20, true));
4142
::pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true));
4243
::pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get()));
43-
44+
}
45+
{
4446
thread_group.create_thread(std::bind(&CScheduler::serviceQueue, &scheduler));
4547
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
4648
LoadGenesisBlock(chainparams);

src/test/txvalidationcache_tests.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
102102
// should fail.
103103
// Capture this interaction with the upgraded_nop argument: set it when evaluating
104104
// any script flag that is implemented as an upgraded NOP code.
105-
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache)
105+
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
106106
{
107107
PrecomputedTransactionData txdata(tx);
108108
// If we add many more flags, this loop can get too expensive, but we can
@@ -219,11 +219,10 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
219219
CBlock block;
220220

221221
block = CreateAndProcessBlock({spend_tx}, p2pk_scriptPubKey);
222+
LOCK(cs_main);
222223
BOOST_CHECK(chainActive.Tip()->GetBlockHash() == block.GetHash());
223224
BOOST_CHECK(pcoinsTip->GetBestBlock() == block.GetHash());
224225

225-
LOCK(cs_main);
226-
227226
// Test P2SH: construct a transaction that is valid without P2SH, and
228227
// then test validity with P2SH.
229228
{

0 commit comments

Comments
 (0)