@@ -412,7 +412,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, SnapshotTestSetup)
412
412
// ! - Then mark a region of the chain BLOCK_ASSUMED_VALID and introduce a second chainstate
413
413
// ! that will tolerate assumed-valid blocks. Run LoadBlockIndex() and ensure that the first
414
414
// ! chainstate only contains fully validated blocks and the other chainstate contains all blocks,
415
- // ! even those assumed -valid.
415
+ // ! except those marked assume -valid, because those entries don't HAVE_DATA .
416
416
// !
417
417
BOOST_FIXTURE_TEST_CASE (chainstatemanager_loadblockindex, TestChain100Setup)
418
418
{
@@ -444,16 +444,17 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup)
444
444
WITH_LOCK (::cs_main, chainman.LoadBlockIndex ());
445
445
};
446
446
447
- // Ensure that without any assumed-valid BlockIndex entries, all entries are considered
448
- // tip candidates .
447
+ // Ensure that without any assumed-valid BlockIndex entries, only the current tip is
448
+ // considered as a candidate .
449
449
reload_all_block_indexes ();
450
- BOOST_CHECK_EQUAL (cs1.setBlockIndexCandidates .size (), cs1. m_chain . Height () + 1 );
450
+ BOOST_CHECK_EQUAL (cs1.setBlockIndexCandidates .size (), 1 );
451
451
452
- // Mark some region of the chain assumed-valid.
452
+ // Mark some region of the chain assumed-valid, and remove the HAVE_DATA flag .
453
453
for (int i = 0 ; i <= cs1.m_chain .Height (); ++i) {
454
454
LOCK (::cs_main);
455
455
auto index = cs1.m_chain [i];
456
456
457
+ // Blocks with heights in range [20, 40) are marked ASSUMED_VALID
457
458
if (i < last_assumed_valid_idx && i >= assumed_valid_start_idx) {
458
459
index->nStatus = BlockStatus::BLOCK_VALID_TREE | BlockStatus::BLOCK_ASSUMED_VALID;
459
460
}
@@ -466,33 +467,41 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup)
466
467
validated_tip = index;
467
468
BOOST_CHECK (!index->IsAssumedValid ());
468
469
}
469
- // Note the block after the last assumed valid block as the snapshot base
470
- if (i == last_assumed_valid_idx) {
470
+ // Note the last assumed valid block as the snapshot base
471
+ if (i == last_assumed_valid_idx - 1 ) {
471
472
assumed_base = index;
473
+ BOOST_CHECK (index->IsAssumedValid ());
474
+ } else if (i == last_assumed_valid_idx) {
472
475
BOOST_CHECK (!index->IsAssumedValid ());
473
476
}
474
477
}
475
478
476
479
BOOST_CHECK_EQUAL (expected_assumed_valid, num_assumed_valid);
477
480
481
+ // Note: cs2's tip is not set when ActivateExistingSnapshot is called.
478
482
Chainstate& cs2 = WITH_LOCK (::cs_main,
479
483
return chainman.ActivateExistingSnapshot (&mempool, *assumed_base->phashBlock ));
480
484
481
485
// Set tip of the fully validated chain to be the validated tip
482
486
cs1.m_chain .SetTip (*validated_tip);
483
487
488
+ // Set tip of the assume-valid-based chain to the assume-valid block
489
+ cs2.m_chain .SetTip (*assumed_base);
490
+
484
491
reload_all_block_indexes ();
485
492
486
- // The fully validated chain only has candidates up to the start of the assumed-valid
487
- // blocks.
493
+ // The fully validated chain should have the current validated tip
494
+ // and the assumed valid base as candidates.
495
+ BOOST_CHECK_EQUAL (cs1.setBlockIndexCandidates .size (), 2 );
488
496
BOOST_CHECK_EQUAL (cs1.setBlockIndexCandidates .count (validated_tip), 1 );
489
- BOOST_CHECK_EQUAL (cs1.setBlockIndexCandidates .count (assumed_tip), 0 );
490
- BOOST_CHECK_EQUAL (cs1.setBlockIndexCandidates .size (), assumed_valid_start_idx);
497
+ BOOST_CHECK_EQUAL (cs1.setBlockIndexCandidates .count (assumed_base), 1 );
491
498
492
- // The assumed-valid tolerant chain has all blocks as candidates.
493
- BOOST_CHECK_EQUAL (cs2.setBlockIndexCandidates .count (validated_tip), 1 );
499
+ // The assumed-valid tolerant chain has the assumed valid base as a
500
+ // candidate, but otherwise has none of the assumed-valid (which do not
501
+ // HAVE_DATA) blocks as candidates.
502
+ BOOST_CHECK_EQUAL (cs2.setBlockIndexCandidates .count (validated_tip), 0 );
494
503
BOOST_CHECK_EQUAL (cs2.setBlockIndexCandidates .count (assumed_tip), 1 );
495
- BOOST_CHECK_EQUAL (cs2.setBlockIndexCandidates .size (), num_indexes);
504
+ BOOST_CHECK_EQUAL (cs2.setBlockIndexCandidates .size (), num_indexes - last_assumed_valid_idx + 1 );
496
505
}
497
506
498
507
// ! Ensure that snapshot chainstates initialize properly when found on disk.
0 commit comments