Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show All 38 Lines | |||||
#include "txdb.h" | #include "txdb.h" | ||||
#include "txmempool.h" | #include "txmempool.h" | ||||
#include "ui_interface.h" | #include "ui_interface.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "utilmoneystr.h" | #include "utilmoneystr.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
#include "validationinterface.h" | #include "validationinterface.h" | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
#include "wallet/init.h" | |||||
#include "wallet/rpcdump.h" | #include "wallet/rpcdump.h" | ||||
#endif | #endif | ||||
#include "walletinitinterface.h" | |||||
#include "warnings.h" | #include "warnings.h" | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <memory> | #include <memory> | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
#include <signal.h> | #include <signal.h> | ||||
Show All 12 Lines | |||||
bool fFeeEstimatesInitialized = false; | bool fFeeEstimatesInitialized = false; | ||||
static const bool DEFAULT_PROXYRANDOMIZE = true; | static const bool DEFAULT_PROXYRANDOMIZE = true; | ||||
static const bool DEFAULT_REST_ENABLE = false; | static const bool DEFAULT_REST_ENABLE = false; | ||||
static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false; | static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false; | ||||
std::unique_ptr<CConnman> g_connman; | std::unique_ptr<CConnman> g_connman; | ||||
std::unique_ptr<PeerLogicValidation> peerLogic; | std::unique_ptr<PeerLogicValidation> peerLogic; | ||||
std::unique_ptr<WalletInitInterface> g_wallet_init_interface; | |||||
#if ENABLE_ZMQ | #if ENABLE_ZMQ | ||||
static CZMQNotificationInterface *pzmqNotificationInterface = nullptr; | static CZMQNotificationInterface *pzmqNotificationInterface = nullptr; | ||||
#endif | #endif | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
// Win32 LevelDB doesn't use filedescriptors, and the ones used for accessing | // Win32 LevelDB doesn't use filedescriptors, and the ones used for accessing | ||||
// block files don't count towards the fd_set size limit anyway. | // block files don't count towards the fd_set size limit anyway. | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | void Shutdown() { | ||||
/// does this if the respective module was initialized. | /// does this if the respective module was initialized. | ||||
RenameThread("bitcoin-shutoff"); | RenameThread("bitcoin-shutoff"); | ||||
g_mempool.AddTransactionsUpdated(1); | g_mempool.AddTransactionsUpdated(1); | ||||
StopHTTPRPC(); | StopHTTPRPC(); | ||||
StopREST(); | StopREST(); | ||||
StopRPC(); | StopRPC(); | ||||
StopHTTPServer(); | StopHTTPServer(); | ||||
#ifdef ENABLE_WALLET | g_wallet_init_interface->Flush(); | ||||
FlushWallets(); | |||||
#endif | |||||
StopMapPort(); | StopMapPort(); | ||||
// Because these depend on each-other, we make sure that neither can be | // Because these depend on each-other, we make sure that neither can be | ||||
// using the other before destroying them. | // using the other before destroying them. | ||||
UnregisterValidationInterface(peerLogic.get()); | UnregisterValidationInterface(peerLogic.get()); | ||||
g_connman->Stop(); | g_connman->Stop(); | ||||
peerLogic.reset(); | peerLogic.reset(); | ||||
g_connman.reset(); | g_connman.reset(); | ||||
Show All 38 Lines | // cases and make next startup faster by avoiding rescan. | ||||
if (pcoinsTip != nullptr) { | if (pcoinsTip != nullptr) { | ||||
FlushStateToDisk(); | FlushStateToDisk(); | ||||
} | } | ||||
pcoinsTip.reset(); | pcoinsTip.reset(); | ||||
pcoinscatcher.reset(); | pcoinscatcher.reset(); | ||||
pcoinsdbview.reset(); | pcoinsdbview.reset(); | ||||
pblocktree.reset(); | pblocktree.reset(); | ||||
} | } | ||||
#ifdef ENABLE_WALLET | g_wallet_init_interface->Stop(); | ||||
StopWallets(); | |||||
#endif | |||||
#if ENABLE_ZMQ | #if ENABLE_ZMQ | ||||
if (pzmqNotificationInterface) { | if (pzmqNotificationInterface) { | ||||
UnregisterValidationInterface(pzmqNotificationInterface); | UnregisterValidationInterface(pzmqNotificationInterface); | ||||
delete pzmqNotificationInterface; | delete pzmqNotificationInterface; | ||||
pzmqNotificationInterface = nullptr; | pzmqNotificationInterface = nullptr; | ||||
} | } | ||||
#endif | #endif | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
try { | try { | ||||
fs::remove(GetPidFile()); | fs::remove(GetPidFile()); | ||||
} catch (const fs::filesystem_error &e) { | } catch (const fs::filesystem_error &e) { | ||||
LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what()); | LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what()); | ||||
} | } | ||||
#endif | #endif | ||||
UnregisterAllValidationInterfaces(); | UnregisterAllValidationInterfaces(); | ||||
GetMainSignals().UnregisterBackgroundSignalScheduler(); | GetMainSignals().UnregisterBackgroundSignalScheduler(); | ||||
#ifdef ENABLE_WALLET | g_wallet_init_interface->Close(); | ||||
CloseWallets(); | g_wallet_init_interface.reset(); | ||||
#endif | |||||
globalVerifyHandle.reset(); | globalVerifyHandle.reset(); | ||||
ECC_Stop(); | ECC_Stop(); | ||||
LogPrintf("%s: done\n", __func__); | LogPrintf("%s: done\n", __func__); | ||||
} | } | ||||
/** | /** | ||||
* Signal handlers are very limited in what they are allowed to do, so: | * Signal handlers are very limited in what they are allowed to do, so: | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 306 Lines • ▼ Show 20 Lines | strUsage += HelpMessageOpt( | ||||
"if they violate local relay policy (default: %d)"), | "if they violate local relay policy (default: %d)"), | ||||
DEFAULT_WHITELISTFORCERELAY)); | DEFAULT_WHITELISTFORCERELAY)); | ||||
strUsage += HelpMessageOpt( | strUsage += HelpMessageOpt( | ||||
"-maxuploadtarget=<n>", | "-maxuploadtarget=<n>", | ||||
strprintf(_("Tries to keep outbound traffic under the given target (in " | strprintf(_("Tries to keep outbound traffic under the given target (in " | ||||
"MiB per 24h), 0 = no limit (default: %d)"), | "MiB per 24h), 0 = no limit (default: %d)"), | ||||
DEFAULT_MAX_UPLOAD_TARGET)); | DEFAULT_MAX_UPLOAD_TARGET)); | ||||
#ifdef ENABLE_WALLET | strUsage += g_wallet_init_interface->GetHelpString(showDebug); | ||||
strUsage += GetWalletHelpString(showDebug); | |||||
#endif | |||||
#if ENABLE_ZMQ | #if ENABLE_ZMQ | ||||
strUsage += HelpMessageGroup(_("ZeroMQ notification options:")); | strUsage += HelpMessageGroup(_("ZeroMQ notification options:")); | ||||
strUsage += HelpMessageOpt("-zmqpubhashblock=<address>", | strUsage += HelpMessageOpt("-zmqpubhashblock=<address>", | ||||
_("Enable publish hash block in <address>")); | _("Enable publish hash block in <address>")); | ||||
strUsage += | strUsage += | ||||
HelpMessageOpt("-zmqpubhashtx=<address>", | HelpMessageOpt("-zmqpubhashtx=<address>", | ||||
_("Enable publish hash transaction in <address>")); | _("Enable publish hash transaction in <address>")); | ||||
▲ Show 20 Lines • Show All 960 Lines • ▼ Show 20 Lines | if (nPruneArg == 1) { | ||||
} | } | ||||
LogPrintf("Prune configured to target %uMiB on disk for block and undo " | LogPrintf("Prune configured to target %uMiB on disk for block and undo " | ||||
"files.\n", | "files.\n", | ||||
nPruneTarget / 1024 / 1024); | nPruneTarget / 1024 / 1024); | ||||
fPruneMode = true; | fPruneMode = true; | ||||
} | } | ||||
RegisterAllRPCCommands(config, rpcServer, tableRPC); | RegisterAllRPCCommands(config, rpcServer, tableRPC); | ||||
g_wallet_init_interface->RegisterRPC(tableRPC); | |||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
RegisterWalletRPC(tableRPC); | |||||
RegisterDumpRPCCommands(tableRPC); | RegisterDumpRPCCommands(tableRPC); | ||||
#endif | #endif | ||||
nConnectTimeout = gArgs.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT); | nConnectTimeout = gArgs.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT); | ||||
if (nConnectTimeout <= 0) { | if (nConnectTimeout <= 0) { | ||||
nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; | nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | fRequireStandard = | ||||
!gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard()); | !gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard()); | ||||
if (chainparams.RequireStandard() && !fRequireStandard) { | if (chainparams.RequireStandard() && !fRequireStandard) { | ||||
return InitError( | return InitError( | ||||
strprintf("acceptnonstdtxn is not currently supported for %s chain", | strprintf("acceptnonstdtxn is not currently supported for %s chain", | ||||
chainparams.NetworkIDString())); | chainparams.NetworkIDString())); | ||||
} | } | ||||
nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp); | nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp); | ||||
#ifdef ENABLE_WALLET | if (!g_wallet_init_interface->ParameterInteraction()) { | ||||
if (!WalletParameterInteraction()) { | |||||
return false; | return false; | ||||
} | } | ||||
#endif | |||||
fIsBareMultisigStd = | fIsBareMultisigStd = | ||||
gArgs.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); | gArgs.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); | ||||
fAcceptDatacarrier = | fAcceptDatacarrier = | ||||
gArgs.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); | gArgs.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); | ||||
// Option to startup with mocktime set (used for regression testing): | // Option to startup with mocktime set (used for regression testing): | ||||
SetMockTime(gArgs.GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op | SetMockTime(gArgs.GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | #endif | ||||
if (gArgs.GetBoolArg("-server", false)) { | if (gArgs.GetBoolArg("-server", false)) { | ||||
uiInterface.InitMessage.connect(SetRPCWarmupStatus); | uiInterface.InitMessage.connect(SetRPCWarmupStatus); | ||||
if (!AppInitServers(config, httpRPCRequestProcessor, threadGroup)) { | if (!AppInitServers(config, httpRPCRequestProcessor, threadGroup)) { | ||||
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 | ||||
#ifdef ENABLE_WALLET | if (!g_wallet_init_interface->Verify(chainparams)) { | ||||
if (!VerifyWallets(chainparams)) { | |||||
return false; | return false; | ||||
} | } | ||||
#endif | |||||
// 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 | ||||
// need to reindex later. | // need to reindex later. | ||||
assert(!g_connman); | assert(!g_connman); | ||||
▲ Show 20 Lines • Show All 366 Lines • ▼ Show 20 Lines | #endif | ||||
} | } | ||||
fFeeEstimatesInitialized = true; | fFeeEstimatesInitialized = true; | ||||
// Encoded addresses using cashaddr instead of base58 | // Encoded addresses using cashaddr instead of base58 | ||||
// Activates by default on Jan, 14 | // Activates by default on Jan, 14 | ||||
config.SetCashAddrEncoding( | config.SetCashAddrEncoding( | ||||
gArgs.GetBoolArg("-usecashaddr", GetAdjustedTime() > 1515900000)); | gArgs.GetBoolArg("-usecashaddr", GetAdjustedTime() > 1515900000)); | ||||
// Step 8: load wallet | // Step 8: load wallet | ||||
#ifdef ENABLE_WALLET | if (!g_wallet_init_interface->Open(chainparams)) { | ||||
if (!OpenWallets(chainparams)) { | |||||
return false; | return false; | ||||
} | } | ||||
#else | |||||
LogPrintf("No wallet support compiled in!\n"); | |||||
#endif | |||||
// Step 9: data directory maintenance | // Step 9: 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) { | ||||
LogPrintf("Unsetting NODE_NETWORK on prune mode\n"); | LogPrintf("Unsetting NODE_NETWORK on prune mode\n"); | ||||
nLocalServices = ServiceFlags(nLocalServices & ~NODE_NETWORK); | nLocalServices = ServiceFlags(nLocalServices & ~NODE_NETWORK); | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | if (!connman.Start(scheduler, connOptions)) { | ||||
return false; | return false; | ||||
} | } | ||||
// Step 12: finished | // Step 12: finished | ||||
SetRPCWarmupFinished(); | SetRPCWarmupFinished(); | ||||
uiInterface.InitMessage(_("Done loading")); | uiInterface.InitMessage(_("Done loading")); | ||||
#ifdef ENABLE_WALLET | g_wallet_init_interface->Start(scheduler); | ||||
StartWallets(scheduler); | |||||
#endif | |||||
return !fRequestShutdown; | return !fRequestShutdown; | ||||
} | } |