@@ -1400,9 +1400,9 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1400
1400
delete pcoinscatcher;
1401
1401
delete pblocktree;
1402
1402
1403
- pblocktree = new CBlockTreeDB (nBlockTreeDBCache, false , fReindex );
1403
+ pblocktree = new CBlockTreeDB (nBlockTreeDBCache, false , fReset );
1404
1404
1405
- if (fReindex ) {
1405
+ if (fReset ) {
1406
1406
pblocktree->WriteReindexing (true );
1407
1407
// If we're reindexing in prune mode, wipe away unusable block files and all undo data files
1408
1408
if (fPruneMode )
@@ -1414,6 +1414,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1414
1414
// LoadBlockIndex will load fTxIndex from the db, or set it if
1415
1415
// we're reindexing. It will also load fHavePruned if we've
1416
1416
// ever removed a block file from disk.
1417
+ // Note that it also sets fReindex based on the disk flag!
1418
+ // From here on out fReindex and fReset mean something different!
1417
1419
if (!LoadBlockIndex (chainparams)) {
1418
1420
strLoadError = _ (" Error loading block database" );
1419
1421
break ;
@@ -1438,8 +1440,9 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1438
1440
}
1439
1441
1440
1442
// At this point blocktree args are consistent with what's on disk.
1441
- // If we're not mid-reindex (based on disk + args), add a genesis block on disk.
1442
- // This is called again in ThreadImport in the reindex completes.
1443
+ // If we're not mid-reindex (based on disk + args), add a genesis block on disk
1444
+ // (otherwise we use the one already on disk).
1445
+ // This is called again in ThreadImport after the reindex completes.
1443
1446
if (!fReindex && !LoadGenesisBlock (chainparams)) {
1444
1447
strLoadError = _ (" Error initializing block database" );
1445
1448
break ;
@@ -1448,7 +1451,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1448
1451
// At this point we're either in reindex or we've loaded a useful
1449
1452
// block tree into mapBlockIndex!
1450
1453
1451
- pcoinsdbview = new CCoinsViewDB (nCoinDBCache, false , fReindex || fReindexChainState );
1454
+ pcoinsdbview = new CCoinsViewDB (nCoinDBCache, false , fReset || fReindexChainState );
1452
1455
pcoinscatcher = new CCoinsViewErrorCatcher (pcoinsdbview);
1453
1456
1454
1457
// If necessary, upgrade from older database format.
@@ -1467,7 +1470,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1467
1470
// The on-disk coinsdb is now in a good state, create the cache
1468
1471
pcoinsTip = new CCoinsViewCache (pcoinscatcher);
1469
1472
1470
- if (!fReindex && !fReindexChainState ) {
1473
+ bool is_coinsview_empty = fReset || fReindexChainState || pcoinsTip->GetBestBlock ().IsNull ();
1474
+ if (!is_coinsview_empty) {
1471
1475
// LoadChainTip sets chainActive based on pcoinsTip's best block
1472
1476
if (!LoadChainTip (chainparams)) {
1473
1477
strLoadError = _ (" Error initializing block database" );
@@ -1476,7 +1480,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1476
1480
assert (chainActive.Tip () != NULL );
1477
1481
}
1478
1482
1479
- if (!fReindex ) {
1483
+ if (!fReset ) {
1480
1484
// Note that RewindBlockIndex MUST run even if we're about to -reindex-chainstate.
1481
1485
// It both disconnects blocks based on chainActive, and drops block data in
1482
1486
// mapBlockIndex based on lack of available witness data.
@@ -1487,7 +1491,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1487
1491
}
1488
1492
}
1489
1493
1490
- if (!fReindex && ! fReindexChainState ) {
1494
+ if (!is_coinsview_empty ) {
1491
1495
uiInterface.InitMessage (_ (" Verifying blocks..." ));
1492
1496
if (fHavePruned && GetArg (" -checkblocks" , DEFAULT_CHECKBLOCKS) > MIN_BLOCKS_TO_KEEP) {
1493
1497
LogPrintf (" Prune: pruned datadir may not have more than %d blocks; only checking available blocks" ,
0 commit comments