MCPcopy Create free account
hub / github.com/ElementsProject/elements / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/validation_block_tests.cpp:151–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149}
150
151BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
152{
153 // build a large-ish chain that's likely to have some forks
154 std::vector<std::shared_ptr<const CBlock>> blocks;
155 while (blocks.size() < 50) {
156 blocks.clear();
157 BuildChain(Params().GenesisBlock().GetHash(), 100, 15, 10, 500, blocks);
158 }
159
160 bool ignored;
161 // Connect the genesis block and drain any outstanding events
162 BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(Params(), std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored));
163 SyncWithValidationInterfaceQueue();
164
165 // subscribe to events (this subscriber will validate event ordering)
166 const CBlockIndex* initial_tip = nullptr;
167 {
168 LOCK(cs_main);
169 initial_tip = m_node.chainman->ActiveChain().Tip();
170 }
171 auto sub = std::make_shared<TestSubscriber>(initial_tip->GetBlockHash());
172 RegisterSharedValidationInterface(sub);
173
174 // create a bunch of threads that repeatedly process a block generated above at random
175 // this will create parallelism and randomness inside validation - the ValidationInterface
176 // will subscribe to events generated during block validation and assert on ordering invariance
177 std::vector<std::thread> threads;
178 for (int i = 0; i < 10; i++) {
179 threads.emplace_back([&]() {
180 bool ignored;
181 FastRandomContext insecure;
182 for (int i = 0; i < 1000; i++) {
183 auto block = blocks[insecure.randrange(blocks.size() - 1)];
184 Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored);
185 }
186
187 // to make sure that eventually we process the full chain - do it here
188 for (auto block : blocks) {
189 if (block->vtx.size() == 1) {
190 bool processed = Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored);
191 assert(processed);
192 }
193 }
194 });
195 }
196
197 for (auto& t : threads) {
198 t.join();
199 }
200 SyncWithValidationInterfaceQueue();
201
202 UnregisterSharedValidationInterface(sub);
203
204 LOCK(cs_main);
205 BOOST_CHECK_EQUAL(sub->m_expected_tip, m_node.chainman->ActiveChain().Tip()->GetBlockHash());
206}
207
208/**

Callers

nothing calls this directly

Calls 15

BlockAssemblerClass · 0.85
ProcessNewBlockMethod · 0.80
emplace_backMethod · 0.80
randrangeMethod · 0.80
GetAmountMethod · 0.80
ProcessTransactionMethod · 0.80
CreateNewBlockMethod · 0.80
ParamsClass · 0.50

Tested by

no test coverage detected