Changeset View
Changeset View
Standalone View
Standalone View
src/test/validation_block_tests.cpp
Show First 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering) { | ||||
bool ignored; | bool ignored; | ||||
BlockValidationState state; | BlockValidationState state; | ||||
std::vector<CBlockHeader> headers; | std::vector<CBlockHeader> headers; | ||||
std::transform( | std::transform( | ||||
blocks.begin(), blocks.end(), std::back_inserter(headers), | blocks.begin(), blocks.end(), std::back_inserter(headers), | ||||
[](std::shared_ptr<const CBlock> b) { return b->GetBlockHeader(); }); | [](std::shared_ptr<const CBlock> b) { return b->GetBlockHeader(); }); | ||||
// Process all the headers so we understand the toplogy of the chain | // Process all the headers so we understand the toplogy of the chain | ||||
BOOST_CHECK( | BOOST_CHECK(Assert(m_node.chainman) | ||||
EnsureChainman(m_node).ProcessNewBlockHeaders(config, headers, state)); | ->ProcessNewBlockHeaders(config, headers, state)); | ||||
// Connect the genesis block and drain any outstanding events | // Connect the genesis block and drain any outstanding events | ||||
BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlock( | BOOST_CHECK(Assert(m_node.chainman) | ||||
config, std::make_shared<CBlock>(chainParams.GenesisBlock()), true, | ->ProcessNewBlock( | ||||
&ignored)); | config, | ||||
std::make_shared<CBlock>(chainParams.GenesisBlock()), | |||||
true, &ignored)); | |||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
// subscribe to events (this subscriber will validate event ordering) | // subscribe to events (this subscriber will validate event ordering) | ||||
const CBlockIndex *initial_tip = nullptr; | const CBlockIndex *initial_tip = nullptr; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
initial_tip = ::ChainActive().Tip(); | initial_tip = ::ChainActive().Tip(); | ||||
} | } | ||||
TestSubscriber sub(initial_tip->GetBlockHash()); | TestSubscriber sub(initial_tip->GetBlockHash()); | ||||
RegisterValidationInterface(&sub); | RegisterValidationInterface(&sub); | ||||
// create a bunch of threads that repeatedly process a block generated above | // create a bunch of threads that repeatedly process a block generated above | ||||
// at random this will create parallelism and randomness inside validation - | // at random this will create parallelism and randomness inside validation - | ||||
// the ValidationInterface will subscribe to events generated during block | // the ValidationInterface will subscribe to events generated during block | ||||
// validation and assert on ordering invariance | // validation and assert on ordering invariance | ||||
std::vector<std::thread> threads; | std::vector<std::thread> threads; | ||||
for (int i = 0; i < 10; i++) { | for (int i = 0; i < 10; i++) { | ||||
threads.emplace_back([&]() { | threads.emplace_back([&]() { | ||||
bool tlignored; | bool tlignored; | ||||
FastRandomContext insecure; | FastRandomContext insecure; | ||||
for (int j = 0; j < 1000; j++) { | for (int j = 0; j < 1000; j++) { | ||||
auto block = blocks[insecure.randrange(blocks.size() - 1)]; | auto block = blocks[insecure.randrange(blocks.size() - 1)]; | ||||
EnsureChainman(m_node).ProcessNewBlock(config, block, true, | Assert(m_node.chainman) | ||||
&tlignored); | ->ProcessNewBlock(config, block, true, &tlignored); | ||||
} | } | ||||
// to make sure that eventually we process the full chain - do it | // to make sure that eventually we process the full chain - do it | ||||
// here | // here | ||||
for (auto block : blocks) { | for (auto block : blocks) { | ||||
if (block->vtx.size() == 1) { | if (block->vtx.size() == 1) { | ||||
bool processed = EnsureChainman(m_node).ProcessNewBlock( | bool processed = | ||||
config, block, true, &tlignored); | Assert(m_node.chainman) | ||||
->ProcessNewBlock(config, block, true, &tlignored); | |||||
assert(processed); | assert(processed); | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
} | } | ||||
for (auto &t : threads) { | for (auto &t : threads) { | ||||
t.join(); | t.join(); | ||||
Show All 28 Lines | |||||
* with some intermediate state during the reorg. | * with some intermediate state during the reorg. | ||||
*/ | */ | ||||
BOOST_AUTO_TEST_CASE(mempool_locks_reorg) { | BOOST_AUTO_TEST_CASE(mempool_locks_reorg) { | ||||
GlobalConfig config; | GlobalConfig config; | ||||
const CChainParams &chainParams = config.GetChainParams(); | const CChainParams &chainParams = config.GetChainParams(); | ||||
bool ignored; | bool ignored; | ||||
auto ProcessBlock = [&](std::shared_ptr<const CBlock> block) -> bool { | auto ProcessBlock = [&](std::shared_ptr<const CBlock> block) -> bool { | ||||
return EnsureChainman(m_node).ProcessNewBlock( | return Assert(m_node.chainman) | ||||
config, block, /* fForceProcessing */ true, | ->ProcessNewBlock(config, block, /* fForceProcessing */ true, | ||||
/* fNewBlock */ &ignored); | /* fNewBlock */ &ignored); | ||||
}; | }; | ||||
// Process all mined blocks | // Process all mined blocks | ||||
BOOST_REQUIRE( | BOOST_REQUIRE( | ||||
ProcessBlock(std::make_shared<CBlock>(chainParams.GenesisBlock()))); | ProcessBlock(std::make_shared<CBlock>(chainParams.GenesisBlock()))); | ||||
auto last_mined = GoodBlock(config, chainParams.GenesisBlock().GetHash()); | auto last_mined = GoodBlock(config, chainParams.GenesisBlock().GetHash()); | ||||
BOOST_REQUIRE(ProcessBlock(last_mined)); | BOOST_REQUIRE(ProcessBlock(last_mined)); | ||||
▲ Show 20 Lines • Show All 108 Lines • Show Last 20 Lines |