aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/init.cpp b/src/init.cpp
index f403f90b08..99dab605ac 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -19,6 +19,7 @@
#include <fs.h>
#include <httpserver.h>
#include <httprpc.h>
+#include <index/txindex.h>
#include <key.h>
#include <validation.h>
#include <miner.h>
@@ -30,7 +31,6 @@
#include <policy/policy.h>
#include <rpc/server.h>
#include <rpc/register.h>
-#include <rpc/safemode.h>
#include <rpc/blockchain.h>
#include <script/standard.h>
#include <script/sigcache.h>
@@ -182,6 +182,9 @@ void Interrupt()
InterruptMapPort();
if (g_connman)
g_connman->Interrupt();
+ if (g_txindex) {
+ g_txindex->Interrupt();
+ }
}
void Shutdown()
@@ -212,6 +215,9 @@ void Shutdown()
if (g_connman) g_connman->Stop();
peerLogic.reset();
g_connman.reset();
+ if (g_txindex) {
+ g_txindex.reset();
+ }
StopTorControl();
@@ -441,9 +447,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-checkblockindex", strprintf("Do a full consistency check for mapBlockIndex, setBlockIndexCandidates, chainActive and mapBlocksUnlinked occasionally. (default: %u)", defaultChainParams->DefaultConsistencyChecks()));
strUsage += HelpMessageOpt("-checkmempool=<n>", strprintf("Run checks every <n> transactions (default: %u)", defaultChainParams->DefaultConsistencyChecks()));
strUsage += HelpMessageOpt("-checkpoints", strprintf("Disable expensive verification for known chain history (default: %u)", DEFAULT_CHECKPOINTS_ENABLED));
- strUsage += HelpMessageOpt("-disablesafemode", strprintf("Disable safemode, override a real safe mode event (default: %u)", DEFAULT_DISABLE_SAFEMODE));
strUsage += HelpMessageOpt("-deprecatedrpc=<method>", "Allows deprecated RPC method(s) to be used");
- strUsage += HelpMessageOpt("-testsafemode", strprintf("Force safe mode (default: %u)", DEFAULT_TESTSAFEMODE));
strUsage += HelpMessageOpt("-dropmessagestest=<n>", "Randomly drop 1 of every <n> network messages");
strUsage += HelpMessageOpt("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", DEFAULT_STOPAFTERBLOCKIMPORT));
strUsage += HelpMessageOpt("-stopatheight", strprintf("Stop running after reaching the given height in the main chain (default: %u)", DEFAULT_STOPATHEIGHT));
@@ -1414,9 +1418,10 @@ bool AppInitMain()
int64_t nTotalCache = (gArgs.GetArg("-dbcache", nDefaultDbCache) << 20);
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); // total cache cannot be greater than nMaxDbcache
- int64_t nBlockTreeDBCache = nTotalCache / 8;
- nBlockTreeDBCache = std::min(nBlockTreeDBCache, (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? nMaxBlockDBAndTxIndexCache : nMaxBlockDBCache) << 20);
+ int64_t nBlockTreeDBCache = std::min(nTotalCache / 8, nMaxBlockDBCache << 20);
nTotalCache -= nBlockTreeDBCache;
+ int64_t nTxIndexCache = std::min(nTotalCache / 8, gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? nMaxTxIndexCache << 20 : 0);
+ nTotalCache -= nTxIndexCache;
int64_t nCoinDBCache = std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); // use 25%-50% of the remainder for disk cache
nCoinDBCache = std::min(nCoinDBCache, nMaxCoinsDBCache << 20); // cap total coins db cache
nTotalCache -= nCoinDBCache;
@@ -1424,6 +1429,9 @@ bool AppInitMain()
int64_t nMempoolSizeMax = gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
LogPrintf("Cache configuration:\n");
LogPrintf("* Using %.1fMiB for block index database\n", nBlockTreeDBCache * (1.0 / 1024 / 1024));
+ if (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
+ LogPrintf("* Using %.1fMiB for transaction index database\n", nTxIndexCache * (1.0 / 1024 / 1024));
+ }
LogPrintf("* Using %.1fMiB for chain state database\n", nCoinDBCache * (1.0 / 1024 / 1024));
LogPrintf("* Using %.1fMiB for in-memory UTXO set (plus up to %.1fMiB of unused mempool space)\n", nCoinCacheUsage * (1.0 / 1024 / 1024), nMempoolSizeMax * (1.0 / 1024 / 1024));
@@ -1457,9 +1465,8 @@ bool AppInitMain()
if (fRequestShutdown) break;
- // LoadBlockIndex will load fTxIndex from the db, or set it if
- // we're reindexing. It will also load fHavePruned if we've
- // ever removed a block file from disk.
+ // LoadBlockIndex will load fHavePruned if we've 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(chainparams)) {
@@ -1473,12 +1480,6 @@ bool AppInitMain()
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
}
- // Check for changed -txindex state
- if (fTxIndex != gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
- strLoadError = _("You need to rebuild the database using -reindex to change -txindex");
- break;
- }
-
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
// in the past, but is now trying to run unpruned.
if (fHavePruned && !fPruneMode) {
@@ -1608,10 +1609,17 @@ bool AppInitMain()
::feeEstimator.Read(est_filein);
fFeeEstimatesInitialized = true;
- // ********************************************************* Step 8: load wallet
+ // ********************************************************* Step 8: start indexers
+ if (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
+ auto txindex_db = MakeUnique<TxIndexDB>(nTxIndexCache, false, fReindex);
+ g_txindex = MakeUnique<TxIndex>(std::move(txindex_db));
+ g_txindex->Start();
+ }
+
+ // ********************************************************* Step 9: load wallet
if (!g_wallet_init_interface.Open()) return false;
- // ********************************************************* Step 9: data directory maintenance
+ // ********************************************************* Step 10: data directory maintenance
// if pruning, unset the service bit and perform the initial blockstore prune
// after any wallet rescanning has taken place.
@@ -1633,7 +1641,7 @@ bool AppInitMain()
nLocalServices = ServiceFlags(nLocalServices | NODE_WITNESS);
}
- // ********************************************************* Step 10: import blocks
+ // ********************************************************* Step 11: import blocks
if (!CheckDiskSpace() && !CheckDiskSpace(0, true))
return false;
@@ -1672,7 +1680,7 @@ bool AppInitMain()
return false;
}
- // ********************************************************* Step 11: start node
+ // ********************************************************* Step 12: start node
int chain_active_height;
@@ -1750,7 +1758,7 @@ bool AppInitMain()
return false;
}
- // ********************************************************* Step 12: finished
+ // ********************************************************* Step 13: finished
SetRPCWarmupFinished();
uiInterface.InitMessage(_("Done loading"));