Skip to content

Commit e0e9498

Browse files
committed
[Logging][Startup]
* 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.
1 parent ad87023 commit e0e9498

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

src/init.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,6 @@ bool AppInit2()
958958
else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS)
959959
nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS;
960960

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

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

1123-
int64_t nStart;
1124-
11251122
// ********************************************************* Step 5: Backup wallet and verify wallet database integrity
11261123
#ifdef ENABLE_WALLET
11271124
if (!fDisableWallet) {
@@ -1443,8 +1440,9 @@ bool AppInit2()
14431440

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

1446-
nStart = GetTimeMillis();
14471443
do {
1444+
const int64_t load_block_index_start_time = GetTimeMillis();
1445+
14481446
try {
14491447
UnloadBlockIndex();
14501448
delete pcoinsTip;
@@ -1615,6 +1613,7 @@ bool AppInit2()
16151613

16161614
fVerifyingBlocks = false;
16171615
fLoaded = true;
1616+
LogPrintf(" block index %15dms\n", GetTimeMillis() - load_block_index_start_time);
16181617
} while (false);
16191618

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

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

1682-
nStart = GetTimeMillis();
1680+
const int64_t nWalletStartTime = GetTimeMillis();
16831681
bool fFirstRun = true;
16841682
pwalletMain = new CWallet(strWalletFile);
16851683
DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun);
@@ -1727,7 +1725,7 @@ bool AppInit2()
17271725
}
17281726

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

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

src/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5293,6 +5293,9 @@ bool static LoadBlockIndexDB(std::string& strError)
52935293
}
52945294
std::sort(vSortedByHeight.begin(), vSortedByHeight.end());
52955295
for (const PAIRTYPE(int, CBlockIndex*) & item : vSortedByHeight) {
5296+
// Stop if shutdown was requested
5297+
if (ShutdownRequested()) return false;
5298+
52965299
CBlockIndex* pindex = item.second;
52975300
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
52985301
if (pindex->nStatus & BLOCK_HAVE_DATA) {

src/util.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ bool fDebug = false;
114114
bool fPrintToConsole = false;
115115
bool fPrintToDebugLog = true;
116116
bool fDaemon = false;
117-
bool fServer = false;
118117
std::string strMiscWarning;
119118
bool fLogTimestamps = false;
120119
bool fLogIPs = false;

src/util.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
5353
extern bool fDebug;
5454
extern bool fPrintToConsole;
5555
extern bool fPrintToDebugLog;
56-
extern bool fServer;
5756
extern std::string strMiscWarning;
5857
extern bool fLogTimestamps;
5958
extern bool fLogIPs;

0 commit comments

Comments
 (0)