Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 2,673 Lines • ▼ Show 20 Lines | while (!fLoaded && !ShutdownRequested()) { | ||||
} | } | ||||
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). | ||||
assert(std::addressof(g_chainman.m_blockman) == | |||||
std::addressof(chainman.m_blockman)); | |||||
if (!chainman.BlockIndex().empty() && | if (!chainman.BlockIndex().empty() && | ||||
!g_chainman.m_blockman.LookupBlockIndex( | !chainman.m_blockman.LookupBlockIndex( | ||||
params.hashGenesisBlock)) { | params.hashGenesisBlock)) { | ||||
return InitError(_("Incorrect or no genesis block found. " | return InitError(_("Incorrect or no genesis block found. " | ||||
"Wrong datadir for network?")); | "Wrong datadir for network?")); | ||||
} | } | ||||
// Check for changed -prune state. What we are concerned about | // Check for changed -prune state. What we are concerned about | ||||
// is a user who has pruned blocks in the past, but is now | // is a user who has pruned blocks in the past, but is now | ||||
// trying to run unpruned. | // trying to run unpruned. | ||||
if (fHavePruned && !fPruneMode) { | if (fHavePruned && !fPruneMode) { | ||||
strLoadError = | strLoadError = | ||||
_("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 (otherwise we use the one already on | // genesis block on disk (otherwise we use the one already on | ||||
// disk). | // disk). | ||||
// This is called again in ThreadImport after the reindex | // This is called again in ThreadImport after the reindex | ||||
// completes. | // completes. | ||||
if (!fReindex && | if (!fReindex && !chainman.ActiveChainstate().LoadGenesisBlock( | ||||
!::ChainstateActive().LoadGenesisBlock(chainparams)) { | 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 BlockIndex()! | // useful block tree into BlockIndex()! | ||||
bool failed_chainstate_init = false; | bool failed_chainstate_init = false; | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | #endif | ||||
// Encoded addresses using cashaddr instead of base58. | // Encoded addresses using cashaddr instead of base58. | ||||
// We do this by default to avoid confusion with BTC addresses. | // We do this by default to avoid confusion with BTC addresses. | ||||
config.SetCashAddrEncoding(args.GetBoolArg("-usecashaddr", true)); | config.SetCashAddrEncoding(args.GetBoolArg("-usecashaddr", true)); | ||||
// Step 8: load indexers | // Step 8: load indexers | ||||
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) { | if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) { | ||||
g_txindex = std::make_unique<TxIndex>(nTxIndexCache, false, fReindex); | g_txindex = std::make_unique<TxIndex>(nTxIndexCache, false, fReindex); | ||||
g_txindex->Start(::ChainstateActive()); | g_txindex->Start(chainman.ActiveChainstate()); | ||||
} | } | ||||
for (const auto &filter_type : g_enabled_filter_types) { | for (const auto &filter_type : g_enabled_filter_types) { | ||||
InitBlockFilterIndex(filter_type, filter_index_cache, false, fReindex); | InitBlockFilterIndex(filter_type, filter_index_cache, false, fReindex); | ||||
GetBlockFilterIndex(filter_type)->Start(::ChainstateActive()); | GetBlockFilterIndex(filter_type)->Start(chainman.ActiveChainstate()); | ||||
} | } | ||||
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) { | if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) { | ||||
g_coin_stats_index = std::make_unique<CoinStatsIndex>( | g_coin_stats_index = std::make_unique<CoinStatsIndex>( | ||||
/* cache size */ 0, false, fReindex); | /* cache size */ 0, false, fReindex); | ||||
g_coin_stats_index->Start(::ChainstateActive()); | g_coin_stats_index->Start(chainman.ActiveChainstate()); | ||||
} | } | ||||
// Step 9: load wallet | // Step 9: load wallet | ||||
for (const auto &client : node.chain_clients) { | for (const auto &client : node.chain_clients) { | ||||
if (!client->load()) { | if (!client->load()) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
Show All 25 Lines | if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) { | ||||
fs::quoted(fs::PathToString(gArgs.GetBlocksDirPath())))); | fs::quoted(fs::PathToString(gArgs.GetBlocksDirPath())))); | ||||
return false; | return false; | ||||
} | } | ||||
// Either install a handler to notify us when genesis activates, or set | // Either install a handler to notify us when genesis activates, or set | ||||
// fHaveGenesis directly. | // fHaveGenesis directly. | ||||
// No locking, as this happens before any background thread is started. | // No locking, as this happens before any background thread is started. | ||||
boost::signals2::connection block_notify_genesis_wait_connection; | boost::signals2::connection block_notify_genesis_wait_connection; | ||||
if (::ChainActive().Tip() == nullptr) { | assert(std::addressof(::ChainActive()) == | ||||
std::addressof(chainman.ActiveChain())); | |||||
if (chainman.ActiveTip() == nullptr) { | |||||
block_notify_genesis_wait_connection = | block_notify_genesis_wait_connection = | ||||
uiInterface.NotifyBlockTip_connect( | uiInterface.NotifyBlockTip_connect( | ||||
std::bind(BlockNotifyGenesisWait, std::placeholders::_2)); | std::bind(BlockNotifyGenesisWait, std::placeholders::_2)); | ||||
} else { | } else { | ||||
fHaveGenesis = true; | fHaveGenesis = true; | ||||
} | } | ||||
#if defined(HAVE_SYSTEM) | #if defined(HAVE_SYSTEM) | ||||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |