Changeset View
Changeset View
Standalone View
Standalone View
src/test/validation_block_tests.cpp
Show All 33 Lines | void BuildChain(const Config &config, const BlockHash &root, int height, | ||||
const unsigned int invalid_rate, | const unsigned int invalid_rate, | ||||
const unsigned int branch_rate, const unsigned int max_size, | const unsigned int branch_rate, const unsigned int max_size, | ||||
std::vector<std::shared_ptr<const CBlock>> &blocks); | std::vector<std::shared_ptr<const CBlock>> &blocks); | ||||
}; | }; | ||||
} // namespace validation_block_tests | } // namespace validation_block_tests | ||||
BOOST_FIXTURE_TEST_SUITE(validation_block_tests, MinerTestingSetup) | BOOST_FIXTURE_TEST_SUITE(validation_block_tests, MinerTestingSetup) | ||||
struct TestSubscriber : public CValidationInterface { | struct TestSubscriber final : public CValidationInterface { | ||||
uint256 m_expected_tip; | uint256 m_expected_tip; | ||||
explicit TestSubscriber(uint256 tip) : m_expected_tip(tip) {} | explicit TestSubscriber(uint256 tip) : m_expected_tip(tip) {} | ||||
void UpdatedBlockTip(const CBlockIndex *pindexNew, | void UpdatedBlockTip(const CBlockIndex *pindexNew, | ||||
const CBlockIndex *pindexFork, | const CBlockIndex *pindexFork, | ||||
bool fInitialDownload) override { | bool fInitialDownload) override { | ||||
BOOST_CHECK_EQUAL(m_expected_tip, pindexNew->GetBlockHash()); | BOOST_CHECK_EQUAL(m_expected_tip, pindexNew->GetBlockHash()); | ||||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering) { | ||||
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()); | auto sub = std::make_shared<TestSubscriber>(initial_tip->GetBlockHash()); | ||||
RegisterValidationInterface(&sub); | RegisterSharedValidationInterface(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([&]() { | ||||
Show All 18 Lines | for (int i = 0; i < 10; i++) { | ||||
}); | }); | ||||
} | } | ||||
for (auto &t : threads) { | for (auto &t : threads) { | ||||
t.join(); | t.join(); | ||||
} | } | ||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
UnregisterValidationInterface(&sub); | UnregisterSharedValidationInterface(sub); | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
BOOST_CHECK_EQUAL(sub.m_expected_tip, | BOOST_CHECK_EQUAL(sub->m_expected_tip, | ||||
::ChainActive().Tip()->GetBlockHash()); | ::ChainActive().Tip()->GetBlockHash()); | ||||
} | } | ||||
/** | /** | ||||
* Test that mempool updates happen atomically with reorgs. | * Test that mempool updates happen atomically with reorgs. | ||||
* | * | ||||
* This prevents RPC clients, among others, from retrieving | * This prevents RPC clients, among others, from retrieving | ||||
* immediately-out-of-date mempool data during large reorgs. | * immediately-out-of-date mempool data during large reorgs. | ||||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |