@@ -1474,11 +1474,11 @@ bool AppInitMain(InitInterfaces& interfaces)
1474
1474
1475
1475
uiInterface.InitMessage (_ (" Loading block index..." ));
1476
1476
1477
- LOCK (cs_main);
1478
-
1479
1477
do {
1480
1478
const int64_t load_block_index_start_time = GetTimeMillis ();
1479
+ bool is_coinsview_empty;
1481
1480
try {
1481
+ LOCK (cs_main);
1482
1482
UnloadBlockIndex ();
1483
1483
pcoinsTip.reset ();
1484
1484
pcoinsdbview.reset ();
@@ -1550,7 +1550,7 @@ bool AppInitMain(InitInterfaces& interfaces)
1550
1550
// The on-disk coinsdb is now in a good state, create the cache
1551
1551
pcoinsTip.reset (new CCoinsViewCache (pcoinscatcher.get ()));
1552
1552
1553
- bool is_coinsview_empty = fReset || fReindexChainState || pcoinsTip->GetBestBlock ().IsNull ();
1553
+ is_coinsview_empty = fReset || fReindexChainState || pcoinsTip->GetBestBlock ().IsNull ();
1554
1554
if (!is_coinsview_empty) {
1555
1555
// LoadChainTip sets chainActive based on pcoinsTip's best block
1556
1556
if (!LoadChainTip (chainparams)) {
@@ -1559,18 +1559,25 @@ bool AppInitMain(InitInterfaces& interfaces)
1559
1559
}
1560
1560
assert (chainActive.Tip () != nullptr );
1561
1561
}
1562
+ } catch (const std::exception& e) {
1563
+ LogPrintf (" %s\n " , e.what ());
1564
+ strLoadError = _ (" Error opening block database" );
1565
+ break ;
1566
+ }
1562
1567
1563
- if (!fReset ) {
1564
- // Note that RewindBlockIndex MUST run even if we're about to -reindex-chainstate.
1565
- // It both disconnects blocks based on chainActive, and drops block data in
1566
- // mapBlockIndex based on lack of available witness data.
1567
- uiInterface.InitMessage (_ (" Rewinding blocks..." ));
1568
- if (!RewindBlockIndex (chainparams)) {
1569
- strLoadError = _ (" Unable to rewind the database to a pre-fork state. You will need to redownload the blockchain" );
1570
- break ;
1571
- }
1568
+ if (!fReset ) {
1569
+ // Note that RewindBlockIndex MUST run even if we're about to -reindex-chainstate.
1570
+ // It both disconnects blocks based on chainActive, and drops block data in
1571
+ // mapBlockIndex based on lack of available witness data.
1572
+ uiInterface.InitMessage (_ (" Rewinding blocks..." ));
1573
+ if (!RewindBlockIndex (chainparams)) {
1574
+ strLoadError = _ (" Unable to rewind the database to a pre-fork state. You will need to redownload the blockchain" );
1575
+ break ;
1572
1576
}
1577
+ }
1573
1578
1579
+ try {
1580
+ LOCK (cs_main);
1574
1581
if (!is_coinsview_empty) {
1575
1582
uiInterface.InitMessage (_ (" Verifying blocks..." ));
1576
1583
if (fHavePruned && gArgs .GetArg (" -checkblocks" , DEFAULT_CHECKBLOCKS) > MIN_BLOCKS_TO_KEEP) {
0 commit comments