47 CBlockIndex* genesis = chainman.ActiveChainstate().m_chain[0];
48 int nonce_counter = 0;
49 std::vector<CBlockIndex*> blocks;
50 blocks.push_back(genesis);
51 bool abort_run{
false};
53 std::vector<CBlockIndex*> pruned_blocks;
66 CBlockIndex* index = blockman.AddToBlockIndex(header, chainman.m_best_header);
69 blocks.push_back(index);
81 chainman.InvalidBlockFound(index, state);
85 block.
vtx = std::vector<CTransactionRef>(nTx);
87 chainman.ReceivedBlockTransactions(block, index, pos);
96 auto& chain = chainman.ActiveChain();
100 CBlockIndex* best_tip = chainman.FindMostWorkChain();
102 if (best_tip == chain.Tip())
break;
104 const CBlockIndex* fork = chain.FindFork(best_tip);
110 assert(blockman.m_have_pruned);
116 chain.SetTip(*chain[fork->
nHeight]);
119 std::vector<CBlockIndex*> to_connect;
122 to_connect.push_back(it);
126 for (
CBlockIndex* block : to_connect | std::views::reverse) {
133 chainman.InvalidBlockFound(block, state);
135 chainman.InvalidChainFound(to_connect.front());
142 chain.SetTip(*block);
143 chainman.ActiveChainstate().PruneBlockIndexCandidates();
158 auto& chain = chainman.ActiveChain();
161 if (prune_block != chain.Tip() && (prune_block->nStatus &
BLOCK_HAVE_DATA)) {
162 blockman.m_have_pruned =
true;
165 prune_block->nFile = 0;
166 prune_block->nDataPos = 0;
167 prune_block->nUndoPos = 0;
168 auto range = blockman.m_blocks_unlinked.equal_range(prune_block->
pprev);
169 while (range.first != range.second) {
170 std::multimap<CBlockIndex*, CBlockIndex*>::iterator _it = range.first;
172 if (_it->second == prune_block) {
173 blockman.m_blocks_unlinked.erase(_it);
176 pruned_blocks.push_back(prune_block);
182 size_t num_pruned = pruned_blocks.size();
183 if (num_pruned == 0)
return;
188 block.
vtx = std::vector<CTransactionRef>(index->nTx);
190 chainman.ReceivedBlockTransactions(block, index, pos);
193 pruned_blocks.erase(pruned_blocks.begin() + i);
197 chainman.CheckBlockIndex();
205 chainman.m_best_header = genesis;
206 chainman.ResetBestInvalid();
207 chainman.nBlockSequenceId = 2;
208 chainman.ActiveChain().SetTip(*genesis);
209 chainman.ActiveChainstate().setBlockIndexCandidates.clear();
210 chainman.m_cached_is_ibd =
true;
211 blockman.m_blocks_unlinked.clear();
212 blockman.m_have_pruned =
false;
213 blockman.CleanupForFuzzing();
216 for (
auto it = blockman.m_block_index.begin(); it != blockman.m_block_index.end();) {
217 if (it->first != genesis_hash) {
218 it = blockman.m_block_index.erase(it);
223 chainman.ActiveChainstate().TryAddBlockIndexCandidate(genesis);
224 assert(blockman.m_block_index.size() == 1);
225 assert(chainman.ActiveChainstate().setBlockIndexCandidates.size() == 1);
226 assert(chainman.ActiveChain().Height() == 0);
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.