Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | bool GetCoin(const COutPoint &outpoint, Coin &coin) const override { | ||||
// should be atomic. | // should be atomic. | ||||
abort(); | abort(); | ||||
} | } | ||||
} | } | ||||
// Writes do not need similar protection, as failure to write is handled by | // Writes do not need similar protection, as failure to write is handled by | ||||
// the caller. | // the caller. | ||||
}; | }; | ||||
static CCoinsViewErrorCatcher *pcoinscatcher = nullptr; | static std::unique_ptr<CCoinsViewErrorCatcher> pcoinscatcher; | ||||
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle; | static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle; | ||||
void Interrupt(boost::thread_group &threadGroup) { | void Interrupt(boost::thread_group &threadGroup) { | ||||
InterruptHTTPServer(); | InterruptHTTPServer(); | ||||
InterruptHTTPRPC(); | InterruptHTTPRPC(); | ||||
InterruptRPC(); | InterruptRPC(); | ||||
InterruptREST(); | InterruptREST(); | ||||
InterruptTorControl(); | InterruptTorControl(); | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | #endif | ||||
// wallet catch up with our current chain to avoid any strange pruning edge | // wallet catch up with our current chain to avoid any strange pruning edge | ||||
// cases and make next startup faster by avoiding rescan. | // cases and make next startup faster by avoiding rescan. | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (pcoinsTip != nullptr) { | if (pcoinsTip != nullptr) { | ||||
FlushStateToDisk(); | FlushStateToDisk(); | ||||
} | } | ||||
delete pcoinsTip; | pcoinsTip.reset(); | ||||
pcoinsTip = nullptr; | pcoinscatcher.reset(); | ||||
delete pcoinscatcher; | pcoinsdbview.reset(); | ||||
pcoinscatcher = nullptr; | pblocktree.reset(); | ||||
delete pcoinsdbview; | |||||
pcoinsdbview = nullptr; | |||||
delete pblocktree; | |||||
pblocktree = nullptr; | |||||
} | } | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
for (CWalletRef pwallet : vpwallets) { | for (CWalletRef pwallet : vpwallets) { | ||||
pwallet->Flush(true); | pwallet->Flush(true); | ||||
} | } | ||||
#endif | #endif | ||||
#if ENABLE_ZMQ | #if ENABLE_ZMQ | ||||
▲ Show 20 Lines • Show All 1,732 Lines • ▼ Show 20 Lines | while (!fLoaded && !fRequestShutdown) { | ||||
std::string strLoadError; | std::string strLoadError; | ||||
uiInterface.InitMessage(_("Loading block index...")); | uiInterface.InitMessage(_("Loading block index...")); | ||||
nStart = GetTimeMillis(); | nStart = GetTimeMillis(); | ||||
do { | do { | ||||
try { | try { | ||||
UnloadBlockIndex(); | UnloadBlockIndex(); | ||||
delete pcoinsTip; | pcoinsTip.reset(); | ||||
delete pcoinsdbview; | pcoinsdbview.reset(); | ||||
delete pcoinscatcher; | pcoinscatcher.reset(); | ||||
delete pblocktree; | pblocktree.reset( | ||||
new CBlockTreeDB(nBlockTreeDBCache, false, fReset)); | |||||
pblocktree = | |||||
new CBlockTreeDB(nBlockTreeDBCache, false, fReindex); | |||||
if (fReindex) { | if (fReindex) { | ||||
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(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | while (!fLoaded && !fRequestShutdown) { | ||||
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! | ||||
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, | pcoinsdbview.reset(new CCoinsViewDB( | ||||
fReindex || fReindexChainState); | nCoinDBCache, false, fReset || fReindexChainState)); | ||||
pcoinscatcher = new CCoinsViewErrorCatcher(pcoinsdbview); | pcoinscatcher.reset( | ||||
new CCoinsViewErrorCatcher(pcoinsdbview.get())); | |||||
// If necessary, upgrade from older database format. | // If necessary, upgrade from older database format. | ||||
// This is a no-op if we cleared the coinsviewdb with -reindex | // This is a no-op if we cleared the coinsviewdb with -reindex | ||||
// or -reindex-chainstate | // or -reindex-chainstate | ||||
if (!pcoinsdbview->Upgrade()) { | if (!pcoinsdbview->Upgrade()) { | ||||
strLoadError = _("Error upgrading chainstate database"); | strLoadError = _("Error upgrading chainstate database"); | ||||
break; | break; | ||||
} | } | ||||
// ReplayBlocks is a no-op if we cleared the coinsviewdb with | // ReplayBlocks is a no-op if we cleared the coinsviewdb with | ||||
// -reindex or -reindex-chainstate | // -reindex or -reindex-chainstate | ||||
if (!ReplayBlocks(config, pcoinsdbview)) { | if (!ReplayBlocks(config, pcoinsdbview.get())) { | ||||
strLoadError = | strLoadError = | ||||
_("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 = new CCoinsViewCache(pcoinscatcher); | pcoinsTip.reset(new CCoinsViewCache(pcoinscatcher.get())); | ||||
if (!fReindex && !fReindexChainState) { | if (!fReindex && !fReindexChainState) { | ||||
// 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; | ||||
} | } | ||||
Show All 38 Lines | while (!fLoaded && !fRequestShutdown) { | ||||
"set incorrectly. Only rebuild the block " | "set incorrectly. Only rebuild the block " | ||||
"database if you are sure that your " | "database if you are sure that your " | ||||
"computer's date and time are correct"); | "computer's date and time are correct"); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (!CVerifyDB().VerifyDB( | if (!CVerifyDB().VerifyDB( | ||||
config, pcoinsdbview, | config, pcoinsdbview.get(), | ||||
gArgs.GetArg("-checklevel", DEFAULT_CHECKLEVEL), | gArgs.GetArg("-checklevel", DEFAULT_CHECKLEVEL), | ||||
gArgs.GetArg("-checkblocks", | gArgs.GetArg("-checkblocks", | ||||
DEFAULT_CHECKBLOCKS))) { | DEFAULT_CHECKBLOCKS))) { | ||||
strLoadError = _("Corrupted block database detected"); | strLoadError = _("Corrupted block database detected"); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
▲ Show 20 Lines • Show All 205 Lines • Show Last 20 Lines |