Skip to content

Commit c1c671f

Browse files
committed
Merge #10919: Fix more init bugs.
e7539f8 Fix some broken init-time prints/constants (Matt Corallo) 13ab353 Check for empty coinsview instead of just-reset coinsview in init (Matt Corallo) fce3f4f Fix resume-of-reindex-after-restart (Matt Corallo) efac91e Always wait for threadGroup to exit in bitcoind shutdown (Matt Corallo) Pull request description: This is a follow-on to #10758 to help move 10758 along. The first fixes a regression in master that was partially fixed in 10758, the second I'm not sure if its a regression or not, but its clearly a bug that should be fixed. Tree-SHA512: aca7b97a97dca66e1a218a33cc6f4aa002292ff1bb0af64e35b81fbaa91b9504f2605375808b43e93a63fc73634ad079b30ef6c9f4ba338d3b5f72d816dfeaff
2 parents c8b62c7 + e7539f8 commit c1c671f

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/bitcoind.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ bool AppInit(int argc, char* argv[])
176176
if (!fRet)
177177
{
178178
Interrupt(threadGroup);
179-
// threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
180-
// the startup-failure cases to make sure they don't result in a hang due to some
181-
// thread-blocking-waiting-for-another-thread-during-startup case
179+
threadGroup.join_all();
182180
} else {
183181
WaitForShutdown(&threadGroup);
184182
}

src/init.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,9 +1400,9 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
14001400
delete pcoinscatcher;
14011401
delete pblocktree;
14021402

1403-
pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex);
1403+
pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReset);
14041404

1405-
if (fReindex) {
1405+
if (fReset) {
14061406
pblocktree->WriteReindexing(true);
14071407
//If we're reindexing in prune mode, wipe away unusable block files and all undo data files
14081408
if (fPruneMode)
@@ -1414,6 +1414,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
14141414
// LoadBlockIndex will load fTxIndex from the db, or set it if
14151415
// we're reindexing. It will also load fHavePruned if we've
14161416
// 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!
14171419
if (!LoadBlockIndex(chainparams)) {
14181420
strLoadError = _("Error loading block database");
14191421
break;
@@ -1438,8 +1440,9 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
14381440
}
14391441

14401442
// 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.
14431446
if (!fReindex && !LoadGenesisBlock(chainparams)) {
14441447
strLoadError = _("Error initializing block database");
14451448
break;
@@ -1448,7 +1451,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
14481451
// At this point we're either in reindex or we've loaded a useful
14491452
// block tree into mapBlockIndex!
14501453

1451-
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex || fReindexChainState);
1454+
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReset || fReindexChainState);
14521455
pcoinscatcher = new CCoinsViewErrorCatcher(pcoinsdbview);
14531456

14541457
// If necessary, upgrade from older database format.
@@ -1467,7 +1470,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
14671470
// The on-disk coinsdb is now in a good state, create the cache
14681471
pcoinsTip = new CCoinsViewCache(pcoinscatcher);
14691472

1470-
if (!fReindex && !fReindexChainState) {
1473+
bool is_coinsview_empty = fReset || fReindexChainState || pcoinsTip->GetBestBlock().IsNull();
1474+
if (!is_coinsview_empty) {
14711475
// LoadChainTip sets chainActive based on pcoinsTip's best block
14721476
if (!LoadChainTip(chainparams)) {
14731477
strLoadError = _("Error initializing block database");
@@ -1476,7 +1480,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
14761480
assert(chainActive.Tip() != NULL);
14771481
}
14781482

1479-
if (!fReindex) {
1483+
if (!fReset) {
14801484
// Note that RewindBlockIndex MUST run even if we're about to -reindex-chainstate.
14811485
// It both disconnects blocks based on chainActive, and drops block data in
14821486
// mapBlockIndex based on lack of available witness data.
@@ -1487,7 +1491,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
14871491
}
14881492
}
14891493

1490-
if (!fReindex && !fReindexChainState) {
1494+
if (!is_coinsview_empty) {
14911495
uiInterface.InitMessage(_("Verifying blocks..."));
14921496
if (fHavePruned && GetArg("-checkblocks", DEFAULT_CHECKBLOCKS) > MIN_BLOCKS_TO_KEEP) {
14931497
LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks",

src/test/test_bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
7575
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
7676
pcoinsTip = new CCoinsViewCache(pcoinsdbview);
7777
if (!LoadGenesisBlock(chainparams)) {
78-
throw std::runtime_error("InitBlockIndex failed.");
78+
throw std::runtime_error("LoadGenesisBlock failed.");
7979
}
8080
{
8181
CValidationState state;

src/validation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3916,7 +3916,6 @@ bool LoadGenesisBlock(const CChainParams& chainparams)
39163916
if (mapBlockIndex.count(chainparams.GenesisBlock().GetHash()))
39173917
return true;
39183918

3919-
// Only add the genesis block if not reindexing (in which case we reuse the one already on disk)
39203919
try {
39213920
CBlock &block = const_cast<CBlock&>(chainparams.GenesisBlock());
39223921
// Start new block file

0 commit comments

Comments
 (0)