Skip to content

Commit

Permalink
[Logging][Startup]
Browse files Browse the repository at this point in the history
 * Stop loading block indexes on wallet startup if shutdown was requested.
 * Wallet loading, wallet rescan and block index load time logged in a more understandable way.
  • Loading branch information
furszy committed Sep 29, 2019
1 parent ad87023 commit e0e9498
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
18 changes: 8 additions & 10 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,6 @@ bool AppInit2()
else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS)
nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS;

fServer = GetBoolArg("-server", false);
setvbuf(stdout, NULL, _IOLBF, 0); /// ***TODO*** do we still need this after -printtoconsole is gone?

// Staking needs a CWallet instance, so make sure wallet is enabled
Expand Down Expand Up @@ -1114,14 +1113,12 @@ bool AppInit2()
* that the server is there and will be ready later). Warmup mode will
* be disabled when initialisation is finished.
*/
if (fServer) {
if (GetBoolArg("-server", false)) {
uiInterface.InitMessage.connect(SetRPCWarmupStatus);
if (!AppInitServers())
return InitError(_("Unable to start HTTP server. See debug log for details."));
}

int64_t nStart;

// ********************************************************* Step 5: Backup wallet and verify wallet database integrity
#ifdef ENABLE_WALLET
if (!fDisableWallet) {
Expand Down Expand Up @@ -1443,8 +1440,9 @@ bool AppInit2()

uiInterface.InitMessage(_("Loading block index..."));

nStart = GetTimeMillis();
do {
const int64_t load_block_index_start_time = GetTimeMillis();

try {
UnloadBlockIndex();
delete pcoinsTip;
Expand Down Expand Up @@ -1615,6 +1613,7 @@ bool AppInit2()

fVerifyingBlocks = false;
fLoaded = true;
LogPrintf(" block index %15dms\n", GetTimeMillis() - load_block_index_start_time);
} while (false);

if (!fLoaded && !ShutdownRequested()) {
Expand Down Expand Up @@ -1643,7 +1642,6 @@ bool AppInit2()
LogPrintf("Shutdown requested. Exiting.\n");
return false;
}
LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart);

boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
CAutoFile est_filein(fopen(est_path.string().c_str(), "rb"), SER_DISK, CLIENT_VERSION);
Expand Down Expand Up @@ -1679,7 +1677,7 @@ bool AppInit2()
uiInterface.InitMessage(_("Loading wallet..."));
fVerifyingBlocks = true;

nStart = GetTimeMillis();
const int64_t nWalletStartTime = GetTimeMillis();
bool fFirstRun = true;
pwalletMain = new CWallet(strWalletFile);
DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun);
Expand Down Expand Up @@ -1727,7 +1725,7 @@ bool AppInit2()
}

LogPrintf("%s", strErrors.str());
LogPrintf(" wallet %15dms\n", GetTimeMillis() - nStart);
LogPrintf("Wallet completed loading in %15dms\n", GetTimeMillis() - nWalletStartTime);
zwalletMain = new CzPIVWallet(pwalletMain->strWalletFile);
pwalletMain->setZWallet(zwalletMain);

Expand All @@ -1747,9 +1745,9 @@ bool AppInit2()
if (chainActive.Tip() && chainActive.Tip() != pindexRescan) {
uiInterface.InitMessage(_("Rescanning..."));
LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight);
nStart = GetTimeMillis();
const int64_t nWalletRescanTime = GetTimeMillis();
pwalletMain->ScanForWalletTransactions(pindexRescan, true);
LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart);
LogPrintf("Rescan completed in %15dms\n", GetTimeMillis() - nWalletRescanTime);
pwalletMain->SetBestChain(chainActive.GetLocator());
nWalletDBUpdated++;

Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5293,6 +5293,9 @@ bool static LoadBlockIndexDB(std::string& strError)
}
std::sort(vSortedByHeight.begin(), vSortedByHeight.end());
for (const PAIRTYPE(int, CBlockIndex*) & item : vSortedByHeight) {
// Stop if shutdown was requested
if (ShutdownRequested()) return false;

CBlockIndex* pindex = item.second;
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
if (pindex->nStatus & BLOCK_HAVE_DATA) {
Expand Down
1 change: 0 additions & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ bool fDebug = false;
bool fPrintToConsole = false;
bool fPrintToDebugLog = true;
bool fDaemon = false;
bool fServer = false;
std::string strMiscWarning;
bool fLogTimestamps = false;
bool fLogIPs = false;
Expand Down
1 change: 0 additions & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
extern bool fDebug;
extern bool fPrintToConsole;
extern bool fPrintToDebugLog;
extern bool fServer;
extern std::string strMiscWarning;
extern bool fLogTimestamps;
extern bool fLogIPs;
Expand Down

0 comments on commit e0e9498

Please sign in to comment.