Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show All 26 Lines | |||||
#include <miner.h> | #include <miner.h> | ||||
#include <net.h> | #include <net.h> | ||||
#include <net_processing.h> | #include <net_processing.h> | ||||
#include <netbase.h> | #include <netbase.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <rpc/blockchain.h> | #include <rpc/blockchain.h> | ||||
#include <rpc/register.h> | #include <rpc/register.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | |||||
#include <scheduler.h> | #include <scheduler.h> | ||||
#include <script/scriptcache.h> | #include <script/scriptcache.h> | ||||
#include <script/sigcache.h> | #include <script/sigcache.h> | ||||
#include <script/standard.h> | #include <script/standard.h> | ||||
#include <shutdown.h> | #include <shutdown.h> | ||||
#include <timedata.h> | #include <timedata.h> | ||||
#include <torcontrol.h> | #include <torcontrol.h> | ||||
#include <txdb.h> | #include <txdb.h> | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | void Interrupt() { | ||||
if (g_connman) { | if (g_connman) { | ||||
g_connman->Interrupt(); | g_connman->Interrupt(); | ||||
} | } | ||||
if (g_txindex) { | if (g_txindex) { | ||||
g_txindex->Interrupt(); | g_txindex->Interrupt(); | ||||
} | } | ||||
} | } | ||||
void Shutdown() { | void Shutdown(InitInterfaces &interfaces) { | ||||
LogPrintf("%s: In progress...\n", __func__); | LogPrintf("%s: In progress...\n", __func__); | ||||
static CCriticalSection cs_Shutdown; | static CCriticalSection cs_Shutdown; | ||||
TRY_LOCK(cs_Shutdown, lockShutdown); | TRY_LOCK(cs_Shutdown, lockShutdown); | ||||
if (!lockShutdown) { | if (!lockShutdown) { | ||||
return; | return; | ||||
} | } | ||||
/// Note: Shutdown() must be able to handle cases in which initialization | /// Note: Shutdown() must be able to handle cases in which initialization | ||||
▲ Show 20 Lines • Show All 1,642 Lines • ▼ Show 20 Lines | bool AppInitLockDataDirectory() { | ||||
if (!LockDataDirectory(false)) { | if (!LockDataDirectory(false)) { | ||||
// Detailed error printed inside LockDataDirectory | // Detailed error printed inside LockDataDirectory | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool AppInitMain(Config &config, RPCServer &rpcServer, | bool AppInitMain(Config &config, RPCServer &rpcServer, | ||||
HTTPRPCRequestProcessor &httpRPCRequestProcessor) { | HTTPRPCRequestProcessor &httpRPCRequestProcessor, | ||||
InitInterfaces &interfaces) { | |||||
// Step 4a: application initialization | // Step 4a: application initialization | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
CreatePidFile(GetPidFile(), getpid()); | CreatePidFile(GetPidFile(), getpid()); | ||||
#endif | #endif | ||||
BCLog::Logger &logger = LogInstance(); | BCLog::Logger &logger = LogInstance(); | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | #endif | ||||
GetMainSignals().RegisterWithMempoolSignals(g_mempool); | GetMainSignals().RegisterWithMempoolSignals(g_mempool); | ||||
/** | /** | ||||
* Register RPC commands regardless of -server setting so they will be | * Register RPC commands regardless of -server setting so they will be | ||||
* available in the GUI RPC console even if external calls are disabled. | * available in the GUI RPC console even if external calls are disabled. | ||||
*/ | */ | ||||
RegisterAllRPCCommands(config, rpcServer, tableRPC); | RegisterAllRPCCommands(config, rpcServer, tableRPC); | ||||
g_wallet_init_interface.RegisterRPC(tableRPC); | g_wallet_init_interface.RegisterRPC(tableRPC); | ||||
g_rpc_interfaces = &interfaces; | |||||
#if ENABLE_ZMQ | #if ENABLE_ZMQ | ||||
RegisterZMQRPCCommands(tableRPC); | RegisterZMQRPCCommands(tableRPC); | ||||
#endif | #endif | ||||
/** | /** | ||||
* Start the RPC server. It will be started in "warmup" mode and not | * Start the RPC server. It will be started in "warmup" mode and not | ||||
* process calls yet (but it will verify that the server is there and will | * process calls yet (but it will verify that the server is there and will | ||||
* be ready later). Warmup mode will be completed when initialisation is | * be ready later). Warmup mode will be completed when initialisation is | ||||
* finished. | * finished. | ||||
*/ | */ | ||||
if (gArgs.GetBoolArg("-server", false)) { | if (gArgs.GetBoolArg("-server", false)) { | ||||
uiInterface.InitMessage.connect(SetRPCWarmupStatus); | uiInterface.InitMessage.connect(SetRPCWarmupStatus); | ||||
if (!AppInitServers(config, httpRPCRequestProcessor)) { | if (!AppInitServers(config, httpRPCRequestProcessor)) { | ||||
return InitError( | return InitError( | ||||
_("Unable to start HTTP server. See debug log for details.")); | _("Unable to start HTTP server. See debug log for details.")); | ||||
} | } | ||||
} | } | ||||
// Step 5: verify wallet database integrity | // Step 5: verify wallet database integrity | ||||
if (!g_wallet_init_interface.Verify(chainparams)) { | if (!g_wallet_init_interface.Verify(chainparams, *interfaces.chain)) { | ||||
return false; | return false; | ||||
} | } | ||||
// Step 6: network initialization | // Step 6: network initialization | ||||
// Note that we absolutely cannot open any actual connections | // Note that we absolutely cannot open any actual connections | ||||
// until the very end ("start node") as the UTXO/block state | // until the very end ("start node") as the UTXO/block state | ||||
// is not yet setup and may end up being set up twice if we | // is not yet setup and may end up being set up twice if we | ||||
▲ Show 20 Lines • Show All 377 Lines • ▼ Show 20 Lines | #endif | ||||
// Step 8: load indexers | // Step 8: load indexers | ||||
if (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) { | if (gArgs.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(); | g_txindex->Start(); | ||||
} | } | ||||
// Step 9: load wallet | // Step 9: load wallet | ||||
if (!g_wallet_init_interface.Open(chainparams)) { | if (!g_wallet_init_interface.Open(chainparams, *interfaces.chain)) { | ||||
return false; | return false; | ||||
} | } | ||||
// Step 10: data directory maintenance | // Step 10: data directory maintenance | ||||
// if pruning, unset the service bit and perform the initial blockstore | // if pruning, unset the service bit and perform the initial blockstore | ||||
// prune after any wallet rescanning has taken place. | // prune after any wallet rescanning has taken place. | ||||
if (fPruneMode) { | if (fPruneMode) { | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |