@@ -211,9 +211,7 @@ CBlockIndex* BlockManager::InsertBlockIndex(const uint256& hash)
211
211
return pindex;
212
212
}
213
213
214
- bool BlockManager::LoadBlockIndex (
215
- const Consensus::Params& consensus_params,
216
- ChainstateManager& chainman)
214
+ bool BlockManager::LoadBlockIndex (const Consensus::Params& consensus_params)
217
215
{
218
216
if (!m_block_tree_db->LoadBlockIndexGuts (consensus_params, [this ](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED (cs_main) { return this ->InsertBlockIndex (hash); })) {
219
217
return false ;
@@ -230,26 +228,6 @@ bool BlockManager::LoadBlockIndex(
230
228
return pa->nHeight < pb->nHeight ;
231
229
});
232
230
233
- // Find start of assumed-valid region.
234
- int first_assumed_valid_height = std::numeric_limits<int >::max ();
235
-
236
- for (const CBlockIndex* block : vSortedByHeight) {
237
- if (block->IsAssumedValid ()) {
238
- auto chainstates = chainman.GetAll ();
239
-
240
- // If we encounter an assumed-valid block index entry, ensure that we have
241
- // one chainstate that tolerates assumed-valid entries and another that does
242
- // not (i.e. the background validation chainstate), since assumed-valid
243
- // entries should always be pending validation by a fully-validated chainstate.
244
- auto any_chain = [&](auto fnc) { return std::any_of (chainstates.cbegin (), chainstates.cend (), fnc); };
245
- assert (any_chain ([](auto chainstate) { return chainstate->reliesOnAssumedValid (); }));
246
- assert (any_chain ([](auto chainstate) { return !chainstate->reliesOnAssumedValid (); }));
247
-
248
- first_assumed_valid_height = block->nHeight ;
249
- break ;
250
- }
251
- }
252
-
253
231
for (CBlockIndex* pindex : vSortedByHeight) {
254
232
if (ShutdownRequested ()) return false ;
255
233
pindex->nChainWork = (pindex->pprev ? pindex->pprev ->nChainWork : 0 ) + GetBlockProof (*pindex);
@@ -275,43 +253,6 @@ bool BlockManager::LoadBlockIndex(
275
253
pindex->nStatus |= BLOCK_FAILED_CHILD;
276
254
m_dirty_blockindex.insert (pindex);
277
255
}
278
- if (pindex->IsAssumedValid () ||
279
- (pindex->IsValid (BLOCK_VALID_TRANSACTIONS) &&
280
- (pindex->HaveTxsDownloaded () || pindex->pprev == nullptr ))) {
281
-
282
- // Fill each chainstate's block candidate set. Only add assumed-valid
283
- // blocks to the tip candidate set if the chainstate is allowed to rely on
284
- // assumed-valid blocks.
285
- //
286
- // If all setBlockIndexCandidates contained the assumed-valid blocks, the
287
- // background chainstate's ActivateBestChain() call would add assumed-valid
288
- // blocks to the chain (based on how FindMostWorkChain() works). Obviously
289
- // we don't want this since the purpose of the background validation chain
290
- // is to validate assued-valid blocks.
291
- //
292
- // Note: This is considering all blocks whose height is greater or equal to
293
- // the first assumed-valid block to be assumed-valid blocks, and excluding
294
- // them from the background chainstate's setBlockIndexCandidates set. This
295
- // does mean that some blocks which are not technically assumed-valid
296
- // (later blocks on a fork beginning before the first assumed-valid block)
297
- // might not get added to the background chainstate, but this is ok,
298
- // because they will still be attached to the active chainstate if they
299
- // actually contain more work.
300
- //
301
- // Instead of this height-based approach, an earlier attempt was made at
302
- // detecting "holistically" whether the block index under consideration
303
- // relied on an assumed-valid ancestor, but this proved to be too slow to
304
- // be practical.
305
- for (CChainState* chainstate : chainman.GetAll ()) {
306
- if (chainstate->reliesOnAssumedValid () ||
307
- pindex->nHeight < first_assumed_valid_height) {
308
- chainstate->setBlockIndexCandidates .insert (pindex);
309
- }
310
- }
311
- }
312
- if (pindex->nStatus & BLOCK_FAILED_MASK && (!chainman.m_best_invalid || pindex->nChainWork > chainman.m_best_invalid ->nChainWork )) {
313
- chainman.m_best_invalid = pindex;
314
- }
315
256
if (pindex->pprev ) {
316
257
pindex->BuildSkip ();
317
258
}
@@ -355,9 +296,9 @@ bool BlockManager::WriteBlockIndexDB()
355
296
return true ;
356
297
}
357
298
358
- bool BlockManager::LoadBlockIndexDB (ChainstateManager& chainman )
299
+ bool BlockManager::LoadBlockIndexDB ()
359
300
{
360
- if (!LoadBlockIndex (::Params ().GetConsensus (), chainman )) {
301
+ if (!LoadBlockIndex (::Params ().GetConsensus ())) {
361
302
return false ;
362
303
}
363
304
0 commit comments