diff --git a/src/test/avalanche_tests.cpp b/src/test/avalanche_tests.cpp --- a/src/test/avalanche_tests.cpp +++ b/src/test/avalanche_tests.cpp @@ -221,7 +221,11 @@ CBlock block = CreateAndProcessBlock({}, CScript()); const BlockHash blockHash = block.GetHash(); - const CBlockIndex *pindex = mapBlockIndex[blockHash]; + const CBlockIndex *pindex; + { + LOCK(cs_main); + pindex = LookupBlockIndex(blockHash); + } // Create nodes that supports avalanche. auto avanodes = @@ -392,11 +396,16 @@ // Make sure the block has a hash. CBlock blockA = CreateAndProcessBlock({}, CScript()); const BlockHash blockHashA = blockA.GetHash(); - const CBlockIndex *pindexA = mapBlockIndex[blockHashA]; CBlock blockB = CreateAndProcessBlock({}, CScript()); const BlockHash blockHashB = blockB.GetHash(); - const CBlockIndex *pindexB = mapBlockIndex[blockHashB]; + const CBlockIndex *pindexA; + const CBlockIndex *pindexB; + { + LOCK(cs_main); + pindexA = LookupBlockIndex(blockHashA); + pindexB = LookupBlockIndex(blockHashB); + } // Querying for random block returns false. BOOST_CHECK(!p.isAccepted(pindexA)); @@ -498,7 +507,11 @@ CBlock block = CreateAndProcessBlock({}, CScript()); const BlockHash blockHash = block.GetHash(); - const CBlockIndex *pindex = mapBlockIndex[blockHash]; + const CBlockIndex *pindex; + { + LOCK(cs_main); + pindex = LookupBlockIndex(blockHash); + } // There is no node to query. BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), NO_NODE); @@ -595,7 +608,11 @@ // Out of order response are rejected. CBlock block2 = CreateAndProcessBlock({}, CScript()); const BlockHash blockHash2 = block2.GetHash(); - CBlockIndex *pindex2 = mapBlockIndex[blockHash2]; + CBlockIndex *pindex2; + { + LOCK(cs_main); + pindex2 = LookupBlockIndex(blockHash2); + } BOOST_CHECK(p.addBlockToReconcile(pindex2)); resp = {AvalancheTest::getRound(p), @@ -645,7 +662,11 @@ CBlock block = CreateAndProcessBlock({}, CScript()); const BlockHash blockHash = block.GetHash(); - const CBlockIndex *pindex = mapBlockIndex[blockHash]; + const CBlockIndex *pindex; + { + LOCK(cs_main); + pindex = LookupBlockIndex(blockHash); + } // Add the block BOOST_CHECK(p.addBlockToReconcile(pindex)); @@ -715,7 +736,11 @@ // Add a block to poll CBlock block = CreateAndProcessBlock({}, CScript()); const BlockHash blockHash = block.GetHash(); - const CBlockIndex *pindex = mapBlockIndex[blockHash]; + const CBlockIndex *pindex; + { + LOCK(cs_main); + pindex = LookupBlockIndex(blockHash); + } BOOST_CHECK(p.addBlockToReconcile(pindex)); // Ensure there are enough requests in flight. @@ -767,7 +792,11 @@ CBlock block = CreateAndProcessBlock({}, CScript()); const BlockHash blockHash = block.GetHash(); - const CBlockIndex *pindex = mapBlockIndex[blockHash]; + const CBlockIndex *pindex; + { + LOCK(cs_main); + pindex = LookupBlockIndex(blockHash); + } // Create nodes that supports avalanche. auto avanodes = @@ -839,7 +868,11 @@ CBlock block = CreateAndProcessBlock({}, CScript()); const BlockHash blockHash = block.GetHash(); - const CBlockIndex *pindex = mapBlockIndex[blockHash]; + const CBlockIndex *pindex; + { + LOCK(cs_main); + pindex = LookupBlockIndex(blockHash); + } // Starting the event loop. BOOST_CHECK(p.startEventLoop(s));