Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 2,030 Lines • ▼ Show 20 Lines | while (!fLoaded && !fRequestShutdown) { | ||||
try { | try { | ||||
UnloadBlockIndex(); | UnloadBlockIndex(); | ||||
pcoinsTip.reset(); | pcoinsTip.reset(); | ||||
pcoinsdbview.reset(); | pcoinsdbview.reset(); | ||||
pcoinscatcher.reset(); | pcoinscatcher.reset(); | ||||
pblocktree.reset( | pblocktree.reset( | ||||
new CBlockTreeDB(nBlockTreeDBCache, false, fReset)); | new CBlockTreeDB(nBlockTreeDBCache, false, fReset)); | ||||
if (fReindex) { | if (fReset) { | ||||
pblocktree->WriteReindexing(true); | pblocktree->WriteReindexing(true); | ||||
// If we're reindexing in prune mode, wipe away unusable | // If we're reindexing in prune mode, wipe away unusable | ||||
// block files and all undo data files | // block files and all undo data files | ||||
if (fPruneMode) { | if (fPruneMode) { | ||||
CleanupBlockRevFiles(); | CleanupBlockRevFiles(); | ||||
} | } | ||||
} | } | ||||
if (fRequestShutdown) { | if (fRequestShutdown) { | ||||
break; | break; | ||||
} | } | ||||
// LoadBlockIndex will load fTxIndex from the db, or set it if | // LoadBlockIndex will load fTxIndex from the db, or set it if | ||||
// we're reindexing. It will also load fHavePruned if we've | // we're reindexing. It will also load fHavePruned if we've | ||||
// ever removed a block file from disk. | // ever removed a block file from disk. | ||||
// Note that it also sets fReindex based on the disk flag! | |||||
// From here on out fReindex and fReset mean something | |||||
// different! | |||||
if (!LoadBlockIndex(config)) { | if (!LoadBlockIndex(config)) { | ||||
strLoadError = _("Error loading block database"); | strLoadError = _("Error loading block database"); | ||||
break; | break; | ||||
} | } | ||||
// If the loaded chain has a wrong genesis, bail out immediately | // If the loaded chain has a wrong genesis, bail out immediately | ||||
// (we're likely using a testnet datadir, or the other way | // (we're likely using a testnet datadir, or the other way | ||||
// around). | // around). | ||||
Show All 19 Lines | while (!fLoaded && !fRequestShutdown) { | ||||
_("You need to rebuild the database using -reindex to " | _("You need to rebuild the database using -reindex to " | ||||
"go back to unpruned mode. This will redownload the " | "go back to unpruned mode. This will redownload the " | ||||
"entire blockchain"); | "entire blockchain"); | ||||
break; | break; | ||||
} | } | ||||
// At this point blocktree args are consistent with what's on | // At this point blocktree args are consistent with what's on | ||||
// disk. If we're not mid-reindex (based on disk + args), add a | // disk. If we're not mid-reindex (based on disk + args), add a | ||||
// genesis block on disk. This is called again in ThreadImport | // genesis block on disk (otherwise we use the one already on | ||||
// if the reindex completes. | // disk). | ||||
// This is called again in ThreadImport after the reindex | |||||
// completes. | |||||
if (!fReindex && !LoadGenesisBlock(chainparams)) { | if (!fReindex && !LoadGenesisBlock(chainparams)) { | ||||
strLoadError = _("Error initializing block database"); | strLoadError = _("Error initializing block database"); | ||||
break; | break; | ||||
} | } | ||||
// At this point we're either in reindex or we've loaded a | // At this point we're either in reindex or we've loaded a | ||||
// useful block tree into mapBlockIndex! | // useful block tree into mapBlockIndex! | ||||
Show All 17 Lines | while (!fLoaded && !fRequestShutdown) { | ||||
_("Unable to replay blocks. You will need to rebuild " | _("Unable to replay blocks. You will need to rebuild " | ||||
"the database using -reindex-chainstate."); | "the database using -reindex-chainstate."); | ||||
break; | break; | ||||
} | } | ||||
// The on-disk coinsdb is now in a good state, create the cache | // The on-disk coinsdb is now in a good state, create the cache | ||||
pcoinsTip.reset(new CCoinsViewCache(pcoinscatcher.get())); | pcoinsTip.reset(new CCoinsViewCache(pcoinscatcher.get())); | ||||
if (!fReindex && !fReindexChainState) { | bool is_coinsview_empty = fReset || fReindexChainState || | ||||
pcoinsTip->GetBestBlock().IsNull(); | |||||
if (!is_coinsview_empty) { | |||||
// LoadChainTip sets chainActive based on pcoinsTip's best | // LoadChainTip sets chainActive based on pcoinsTip's best | ||||
// block | // block | ||||
if (!LoadChainTip(config)) { | if (!LoadChainTip(config)) { | ||||
strLoadError = _("Error initializing block database"); | strLoadError = _("Error initializing block database"); | ||||
break; | break; | ||||
} | } | ||||
assert(chainActive.Tip() != nullptr); | assert(chainActive.Tip() != nullptr); | ||||
} | } | ||||
if (!fReindex) { | if (!fReset) { | ||||
// Note that RewindBlockIndex MUST run even if we're about | // Note that RewindBlockIndex MUST run even if we're about | ||||
// to -reindex-chainstate. It both disconnects blocks based | // to -reindex-chainstate. It both disconnects blocks based | ||||
// on chainActive, and drops block data in mapBlockIndex | // on chainActive, and drops block data in mapBlockIndex | ||||
// based on lack of available witness data. | // based on lack of available witness data. | ||||
uiInterface.InitMessage(_("Rewinding blocks...")); | uiInterface.InitMessage(_("Rewinding blocks...")); | ||||
if (!RewindBlockIndex(config)) { | if (!RewindBlockIndex(config)) { | ||||
strLoadError = _("Unable to rewind the database to a " | strLoadError = _("Unable to rewind the database to a " | ||||
"pre-fork state. You will need to " | "pre-fork state. You will need to " | ||||
"redownload the blockchain"); | "redownload the blockchain"); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (!fReindex && !fReindexChainState) { | if (!is_coinsview_empty) { | ||||
uiInterface.InitMessage(_("Verifying blocks...")); | uiInterface.InitMessage(_("Verifying blocks...")); | ||||
if (fHavePruned && | if (fHavePruned && | ||||
gArgs.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS) > | gArgs.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS) > | ||||
MIN_BLOCKS_TO_KEEP) { | MIN_BLOCKS_TO_KEEP) { | ||||
LogPrintf("Prune: pruned datadir may not have more " | LogPrintf("Prune: pruned datadir may not have more " | ||||
"than %d blocks; only checking available " | "than %d blocks; only checking available " | ||||
"blocks", | "blocks", | ||||
MIN_BLOCKS_TO_KEEP); | MIN_BLOCKS_TO_KEEP); | ||||
▲ Show 20 Lines • Show All 234 Lines • Show Last 20 Lines |