Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | #endif | ||||
MapPort(false); | MapPort(false); | ||||
UnregisterValidationInterface(peerLogic.get()); | UnregisterValidationInterface(peerLogic.get()); | ||||
peerLogic.reset(); | peerLogic.reset(); | ||||
g_connman.reset(); | g_connman.reset(); | ||||
StopTorControl(); | StopTorControl(); | ||||
UnregisterNodeSignals(GetNodeSignals()); | UnregisterNodeSignals(GetNodeSignals()); | ||||
if (fDumpMempoolLater && | if (fDumpMempoolLater && | ||||
GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { | gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { | ||||
DumpMempool(); | DumpMempool(); | ||||
} | } | ||||
if (fFeeEstimatesInitialized) { | if (fFeeEstimatesInitialized) { | ||||
fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; | fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; | ||||
CAutoFile est_fileout(fsbridge::fopen(est_path, "wb"), SER_DISK, | CAutoFile est_fileout(fsbridge::fopen(est_path, "wb"), SER_DISK, | ||||
CLIENT_VERSION); | CLIENT_VERSION); | ||||
if (!est_fileout.IsNull()) | if (!est_fileout.IsNull()) | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | void OnRPCStopped() { | ||||
cvBlockChange.notify_all(); | cvBlockChange.notify_all(); | ||||
LogPrint(BCLog::RPC, "RPC stopped.\n"); | LogPrint(BCLog::RPC, "RPC stopped.\n"); | ||||
} | } | ||||
void OnRPCPreCommand(const CRPCCommand &cmd) { | void OnRPCPreCommand(const CRPCCommand &cmd) { | ||||
// Observe safe mode. | // Observe safe mode. | ||||
std::string strWarning = GetWarnings("rpc"); | std::string strWarning = GetWarnings("rpc"); | ||||
if (strWarning != "" && | if (strWarning != "" && | ||||
!GetBoolArg("-disablesafemode", DEFAULT_DISABLE_SAFEMODE) && | !gArgs.GetBoolArg("-disablesafemode", DEFAULT_DISABLE_SAFEMODE) && | ||||
!cmd.okSafeMode) | !cmd.okSafeMode) | ||||
throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, | throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, | ||||
std::string("Safe mode: ") + strWarning); | std::string("Safe mode: ") + strWarning); | ||||
} | } | ||||
std::string HelpMessage(HelpMessageMode mode) { | std::string HelpMessage(HelpMessageMode mode) { | ||||
const bool showDebug = GetBoolArg("-help-debug", false); | const bool showDebug = gArgs.GetBoolArg("-help-debug", false); | ||||
// When adding new options to the categories, please keep and ensure | // When adding new options to the categories, please keep and ensure | ||||
// alphabetical ordering. Do not translate _(...) -help-debug options, Many | // alphabetical ordering. Do not translate _(...) -help-debug options, Many | ||||
// technical terms, and only a very small audience, so is unnecessary stress | // technical terms, and only a very small audience, so is unnecessary stress | ||||
// to translators. | // to translators. | ||||
std::string strUsage = HelpMessageGroup(_("Options:")); | std::string strUsage = HelpMessageGroup(_("Options:")); | ||||
strUsage += HelpMessageOpt("-?", _("Print this help message and exit")); | strUsage += HelpMessageOpt("-?", _("Print this help message and exit")); | ||||
strUsage += HelpMessageOpt("-version", _("Print version and exit")); | strUsage += HelpMessageOpt("-version", _("Print version and exit")); | ||||
▲ Show 20 Lines • Show All 593 Lines • ▼ Show 20 Lines | return CopyrightHolders( | ||||
"<https://www.openssl.org>") + | "<https://www.openssl.org>") + | ||||
"\n"; | "\n"; | ||||
} | } | ||||
static void BlockNotifyCallback(bool initialSync, | static void BlockNotifyCallback(bool initialSync, | ||||
const CBlockIndex *pBlockIndex) { | const CBlockIndex *pBlockIndex) { | ||||
if (initialSync || !pBlockIndex) return; | if (initialSync || !pBlockIndex) return; | ||||
std::string strCmd = GetArg("-blocknotify", ""); | std::string strCmd = gArgs.GetArg("-blocknotify", ""); | ||||
boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex()); | boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex()); | ||||
boost::thread t(runCommand, strCmd); // thread runs free | boost::thread t(runCommand, strCmd); // thread runs free | ||||
} | } | ||||
static bool fHaveGenesis = false; | static bool fHaveGenesis = false; | ||||
static boost::mutex cs_GenesisWait; | static boost::mutex cs_GenesisWait; | ||||
static CConditionVariable condvar_GenesisWait; | static CConditionVariable condvar_GenesisWait; | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | RenameThread("bitcoin-loadblk"); | ||||
// scan for better chains in the block chain database, that are not yet | // scan for better chains in the block chain database, that are not yet | ||||
// connected in the active best chain | // connected in the active best chain | ||||
CValidationState state; | CValidationState state; | ||||
if (!ActivateBestChain(config, state)) { | if (!ActivateBestChain(config, state)) { | ||||
LogPrintf("Failed to connect best block"); | LogPrintf("Failed to connect best block"); | ||||
StartShutdown(); | StartShutdown(); | ||||
} | } | ||||
if (GetBoolArg("-stopafterblockimport", DEFAULT_STOPAFTERBLOCKIMPORT)) { | if (gArgs.GetBoolArg("-stopafterblockimport", | ||||
DEFAULT_STOPAFTERBLOCKIMPORT)) { | |||||
LogPrintf("Stopping after block import\n"); | LogPrintf("Stopping after block import\n"); | ||||
StartShutdown(); | StartShutdown(); | ||||
} | } | ||||
} // End scope of CImportingNow | } // End scope of CImportingNow | ||||
if (GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { | if (gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { | ||||
LoadMempool(config); | LoadMempool(config); | ||||
fDumpMempoolLater = !fRequestShutdown; | fDumpMempoolLater = !fRequestShutdown; | ||||
} | } | ||||
} | } | ||||
/** Sanity checks | /** Sanity checks | ||||
* Ensure that Bitcoin is running in a usable environment with all | * Ensure that Bitcoin is running in a usable environment with all | ||||
* necessary library support. | * necessary library support. | ||||
Show All 19 Lines | |||||
static bool AppInitServers(Config &config, boost::thread_group &threadGroup) { | static bool AppInitServers(Config &config, boost::thread_group &threadGroup) { | ||||
RPCServer::OnStarted(&OnRPCStarted); | RPCServer::OnStarted(&OnRPCStarted); | ||||
RPCServer::OnStopped(&OnRPCStopped); | RPCServer::OnStopped(&OnRPCStopped); | ||||
RPCServer::OnPreCommand(&OnRPCPreCommand); | RPCServer::OnPreCommand(&OnRPCPreCommand); | ||||
if (!InitHTTPServer(config)) return false; | if (!InitHTTPServer(config)) return false; | ||||
if (!StartRPC()) return false; | if (!StartRPC()) return false; | ||||
if (!StartHTTPRPC()) return false; | if (!StartHTTPRPC()) return false; | ||||
if (GetBoolArg("-rest", DEFAULT_REST_ENABLE) && !StartREST()) return false; | if (gArgs.GetBoolArg("-rest", DEFAULT_REST_ENABLE) && !StartREST()) | ||||
return false; | |||||
if (!StartHTTPServer()) return false; | if (!StartHTTPServer()) return false; | ||||
return true; | return true; | ||||
} | } | ||||
// Parameter interaction based on rules | // Parameter interaction based on rules | ||||
void InitParameterInteraction() { | void InitParameterInteraction() { | ||||
// when specifying an explicit binding address, you want to listen on it | // when specifying an explicit binding address, you want to listen on it | ||||
// even when -connect or -proxy is specified. | // even when -connect or -proxy is specified. | ||||
if (IsArgSet("-bind")) { | if (gArgs.IsArgSet("-bind")) { | ||||
if (SoftSetBoolArg("-listen", true)) | if (gArgs.SoftSetBoolArg("-listen", true)) | ||||
LogPrintf( | LogPrintf( | ||||
"%s: parameter interaction: -bind set -> setting -listen=1\n", | "%s: parameter interaction: -bind set -> setting -listen=1\n", | ||||
__func__); | __func__); | ||||
} | } | ||||
if (IsArgSet("-whitebind")) { | if (gArgs.IsArgSet("-whitebind")) { | ||||
if (SoftSetBoolArg("-listen", true)) | if (gArgs.SoftSetBoolArg("-listen", true)) | ||||
LogPrintf("%s: parameter interaction: -whitebind set -> setting " | LogPrintf("%s: parameter interaction: -whitebind set -> setting " | ||||
"-listen=1\n", | "-listen=1\n", | ||||
__func__); | __func__); | ||||
} | } | ||||
if (gArgs.IsArgSet("-connect")) { | if (gArgs.IsArgSet("-connect")) { | ||||
// when only connecting to trusted nodes, do not seed via DNS, or listen | // when only connecting to trusted nodes, do not seed via DNS, or listen | ||||
// by default. | // by default. | ||||
if (SoftSetBoolArg("-dnsseed", false)) | if (gArgs.SoftSetBoolArg("-dnsseed", false)) | ||||
LogPrintf("%s: parameter interaction: -connect set -> setting " | LogPrintf("%s: parameter interaction: -connect set -> setting " | ||||
"-dnsseed=0\n", | "-dnsseed=0\n", | ||||
__func__); | __func__); | ||||
if (SoftSetBoolArg("-listen", false)) | if (gArgs.SoftSetBoolArg("-listen", false)) | ||||
LogPrintf("%s: parameter interaction: -connect set -> setting " | LogPrintf("%s: parameter interaction: -connect set -> setting " | ||||
"-listen=0\n", | "-listen=0\n", | ||||
__func__); | __func__); | ||||
} | } | ||||
if (IsArgSet("-proxy")) { | if (gArgs.IsArgSet("-proxy")) { | ||||
// to protect privacy, do not listen by default if a default proxy | // to protect privacy, do not listen by default if a default proxy | ||||
// server is specified. | // server is specified. | ||||
if (SoftSetBoolArg("-listen", false)) | if (gArgs.SoftSetBoolArg("-listen", false)) | ||||
LogPrintf( | LogPrintf( | ||||
"%s: parameter interaction: -proxy set -> setting -listen=0\n", | "%s: parameter interaction: -proxy set -> setting -listen=0\n", | ||||
__func__); | __func__); | ||||
// to protect privacy, do not use UPNP when a proxy is set. The user may | // to protect privacy, do not use UPNP when a proxy is set. The user may | ||||
// still specify -listen=1 to listen locally, so don't rely on this | // still specify -listen=1 to listen locally, so don't rely on this | ||||
// happening through -listen below. | // happening through -listen below. | ||||
if (SoftSetBoolArg("-upnp", false)) | if (gArgs.SoftSetBoolArg("-upnp", false)) | ||||
LogPrintf( | LogPrintf( | ||||
"%s: parameter interaction: -proxy set -> setting -upnp=0\n", | "%s: parameter interaction: -proxy set -> setting -upnp=0\n", | ||||
__func__); | __func__); | ||||
// to protect privacy, do not discover addresses by default | // to protect privacy, do not discover addresses by default | ||||
if (SoftSetBoolArg("-discover", false)) | if (gArgs.SoftSetBoolArg("-discover", false)) | ||||
LogPrintf("%s: parameter interaction: -proxy set -> setting " | LogPrintf("%s: parameter interaction: -proxy set -> setting " | ||||
"-discover=0\n", | "-discover=0\n", | ||||
__func__); | __func__); | ||||
} | } | ||||
if (!GetBoolArg("-listen", DEFAULT_LISTEN)) { | if (!gArgs.GetBoolArg("-listen", DEFAULT_LISTEN)) { | ||||
// do not map ports or try to retrieve public IP when not listening | // do not map ports or try to retrieve public IP when not listening | ||||
// (pointless) | // (pointless) | ||||
if (SoftSetBoolArg("-upnp", false)) | if (gArgs.SoftSetBoolArg("-upnp", false)) | ||||
LogPrintf( | LogPrintf( | ||||
"%s: parameter interaction: -listen=0 -> setting -upnp=0\n", | "%s: parameter interaction: -listen=0 -> setting -upnp=0\n", | ||||
__func__); | __func__); | ||||
if (SoftSetBoolArg("-discover", false)) | if (gArgs.SoftSetBoolArg("-discover", false)) | ||||
LogPrintf( | LogPrintf( | ||||
"%s: parameter interaction: -listen=0 -> setting -discover=0\n", | "%s: parameter interaction: -listen=0 -> setting -discover=0\n", | ||||
__func__); | __func__); | ||||
if (SoftSetBoolArg("-listenonion", false)) | if (gArgs.SoftSetBoolArg("-listenonion", false)) | ||||
LogPrintf("%s: parameter interaction: -listen=0 -> setting " | LogPrintf("%s: parameter interaction: -listen=0 -> setting " | ||||
"-listenonion=0\n", | "-listenonion=0\n", | ||||
__func__); | __func__); | ||||
} | } | ||||
if (IsArgSet("-externalip")) { | if (gArgs.IsArgSet("-externalip")) { | ||||
// if an explicit public IP is specified, do not try to find others | // if an explicit public IP is specified, do not try to find others | ||||
if (SoftSetBoolArg("-discover", false)) | if (gArgs.SoftSetBoolArg("-discover", false)) | ||||
LogPrintf("%s: parameter interaction: -externalip set -> setting " | LogPrintf("%s: parameter interaction: -externalip set -> setting " | ||||
"-discover=0\n", | "-discover=0\n", | ||||
__func__); | __func__); | ||||
} | } | ||||
// disable whitelistrelay in blocksonly mode | // disable whitelistrelay in blocksonly mode | ||||
if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) { | if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) { | ||||
if (SoftSetBoolArg("-whitelistrelay", false)) | if (gArgs.SoftSetBoolArg("-whitelistrelay", false)) | ||||
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting " | LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting " | ||||
"-whitelistrelay=0\n", | "-whitelistrelay=0\n", | ||||
__func__); | __func__); | ||||
} | } | ||||
// Forcing relay from whitelisted hosts implies we will accept relays from | // Forcing relay from whitelisted hosts implies we will accept relays from | ||||
// them in the first place. | // them in the first place. | ||||
if (GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) { | if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) { | ||||
if (SoftSetBoolArg("-whitelistrelay", true)) | if (gArgs.SoftSetBoolArg("-whitelistrelay", true)) | ||||
LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> " | LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> " | ||||
"setting -whitelistrelay=1\n", | "setting -whitelistrelay=1\n", | ||||
__func__); | __func__); | ||||
} | } | ||||
} | } | ||||
static std::string ResolveErrMsg(const char *const optname, | static std::string ResolveErrMsg(const char *const optname, | ||||
const std::string &strBind) { | const std::string &strBind) { | ||||
return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind); | return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind); | ||||
} | } | ||||
void InitLogging() { | void InitLogging() { | ||||
fPrintToConsole = GetBoolArg("-printtoconsole", false); | fPrintToConsole = gArgs.GetBoolArg("-printtoconsole", false); | ||||
fLogTimestamps = GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); | fLogTimestamps = gArgs.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); | ||||
fLogTimeMicros = GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); | fLogTimeMicros = gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); | ||||
fLogIPs = GetBoolArg("-logips", DEFAULT_LOGIPS); | fLogIPs = gArgs.GetBoolArg("-logips", DEFAULT_LOGIPS); | ||||
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); | LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); | ||||
LogPrintf("%s version %s\n", CLIENT_NAME, FormatFullVersion()); | LogPrintf("%s version %s\n", CLIENT_NAME, FormatFullVersion()); | ||||
} | } | ||||
namespace { // Variables internal to initialization process only | namespace { // Variables internal to initialization process only | ||||
ServiceFlags nRelevantServices = NODE_NETWORK; | ServiceFlags nRelevantServices = NODE_NETWORK; | ||||
Show All 40 Lines | #endif | ||||
PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress( | PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress( | ||||
GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy"); | GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy"); | ||||
if (setProcDEPPol != nullptr) setProcDEPPol(PROCESS_DEP_ENABLE); | if (setProcDEPPol != nullptr) setProcDEPPol(PROCESS_DEP_ENABLE); | ||||
#endif | #endif | ||||
if (!SetupNetworking()) return InitError("Initializing networking failed"); | if (!SetupNetworking()) return InitError("Initializing networking failed"); | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
if (!GetBoolArg("-sysperms", false)) { | if (!gArgs.GetBoolArg("-sysperms", false)) { | ||||
umask(077); | umask(077); | ||||
} | } | ||||
// Clean shutdown on SIGTERM | // Clean shutdown on SIGTERM | ||||
struct sigaction sa; | struct sigaction sa; | ||||
sa.sa_handler = HandleSIGTERM; | sa.sa_handler = HandleSIGTERM; | ||||
sigemptyset(&sa.sa_mask); | sigemptyset(&sa.sa_mask); | ||||
sa.sa_flags = 0; | sa.sa_flags = 0; | ||||
Show All 19 Lines | |||||
bool AppInitParameterInteraction(Config &config) { | bool AppInitParameterInteraction(Config &config) { | ||||
const CChainParams &chainparams = Params(); | const CChainParams &chainparams = Params(); | ||||
// Step 2: parameter interactions | // Step 2: parameter interactions | ||||
// also see: InitParameterInteraction() | // also see: InitParameterInteraction() | ||||
// if using block pruning, then disallow txindex | // if using block pruning, then disallow txindex | ||||
if (GetArg("-prune", 0)) { | if (gArgs.GetArg("-prune", 0)) { | ||||
if (GetBoolArg("-txindex", DEFAULT_TXINDEX)) | if (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) | ||||
return InitError(_("Prune mode is incompatible with -txindex.")); | return InitError(_("Prune mode is incompatible with -txindex.")); | ||||
} | } | ||||
// if space reserved for high priority transactions is misconfigured | // if space reserved for high priority transactions is misconfigured | ||||
// stop program execution and warn the user with a proper error message | // stop program execution and warn the user with a proper error message | ||||
const int64_t blkprio = | const int64_t blkprio = gArgs.GetArg("-blockprioritypercentage", | ||||
GetArg("-blockprioritypercentage", DEFAULT_BLOCK_PRIORITY_PERCENTAGE); | DEFAULT_BLOCK_PRIORITY_PERCENTAGE); | ||||
if (!config.SetBlockPriorityPercentage(blkprio)) { | if (!config.SetBlockPriorityPercentage(blkprio)) { | ||||
return InitError(_("Block priority percentage has to belong to the " | return InitError(_("Block priority percentage has to belong to the " | ||||
"[0..100] interval.")); | "[0..100] interval.")); | ||||
} | } | ||||
// Make sure enough file descriptors are available | // Make sure enough file descriptors are available | ||||
int nBind = std::max( | int nBind = std::max( | ||||
(gArgs.IsArgSet("-bind") ? gArgs.GetArgs("-bind").size() : 0) + | (gArgs.IsArgSet("-bind") ? gArgs.GetArgs("-bind").size() : 0) + | ||||
(gArgs.IsArgSet("-whitebind") ? gArgs.GetArgs("-whitebind").size() | (gArgs.IsArgSet("-whitebind") ? gArgs.GetArgs("-whitebind").size() | ||||
: 0), | : 0), | ||||
size_t(1)); | size_t(1)); | ||||
nUserMaxConnections = | nUserMaxConnections = | ||||
GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS); | gArgs.GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS); | ||||
nMaxConnections = std::max(nUserMaxConnections, 0); | nMaxConnections = std::max(nUserMaxConnections, 0); | ||||
// Trim requested connection counts, to fit into system limitations | // Trim requested connection counts, to fit into system limitations | ||||
nMaxConnections = | nMaxConnections = | ||||
std::max(std::min(nMaxConnections, | std::max(std::min(nMaxConnections, | ||||
(int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS - | (int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS - | ||||
MAX_ADDNODE_CONNECTIONS)), | MAX_ADDNODE_CONNECTIONS)), | ||||
0); | 0); | ||||
Show All 38 Lines | if (gArgs.IsArgSet("-debugexclude")) { | ||||
InitWarning(strprintf(_("Unsupported logging category %s=%s."), | InitWarning(strprintf(_("Unsupported logging category %s=%s."), | ||||
"-debugexclude", cat)); | "-debugexclude", cat)); | ||||
} | } | ||||
logCategories &= ~flag; | logCategories &= ~flag; | ||||
} | } | ||||
} | } | ||||
// Check for -debugnet | // Check for -debugnet | ||||
if (GetBoolArg("-debugnet", false)) | if (gArgs.GetBoolArg("-debugnet", false)) | ||||
InitWarning( | InitWarning( | ||||
_("Unsupported argument -debugnet ignored, use -debug=net.")); | _("Unsupported argument -debugnet ignored, use -debug=net.")); | ||||
// Check for -socks - as this is a privacy risk to continue, exit here | // Check for -socks - as this is a privacy risk to continue, exit here | ||||
if (IsArgSet("-socks")) | if (gArgs.IsArgSet("-socks")) | ||||
return InitError( | return InitError( | ||||
_("Unsupported argument -socks found. Setting SOCKS version isn't " | _("Unsupported argument -socks found. Setting SOCKS version isn't " | ||||
"possible anymore, only SOCKS5 proxies are supported.")); | "possible anymore, only SOCKS5 proxies are supported.")); | ||||
// Check for -tor - as this is a privacy risk to continue, exit here | // Check for -tor - as this is a privacy risk to continue, exit here | ||||
if (GetBoolArg("-tor", false)) | if (gArgs.GetBoolArg("-tor", false)) | ||||
return InitError(_("Unsupported argument -tor found, use -onion.")); | return InitError(_("Unsupported argument -tor found, use -onion.")); | ||||
if (GetBoolArg("-benchmark", false)) | if (gArgs.GetBoolArg("-benchmark", false)) | ||||
InitWarning( | InitWarning( | ||||
_("Unsupported argument -benchmark ignored, use -debug=bench.")); | _("Unsupported argument -benchmark ignored, use -debug=bench.")); | ||||
if (GetBoolArg("-whitelistalwaysrelay", false)) | if (gArgs.GetBoolArg("-whitelistalwaysrelay", false)) | ||||
InitWarning(_("Unsupported argument -whitelistalwaysrelay ignored, use " | InitWarning(_("Unsupported argument -whitelistalwaysrelay ignored, use " | ||||
"-whitelistrelay and/or -whitelistforcerelay.")); | "-whitelistrelay and/or -whitelistforcerelay.")); | ||||
if (IsArgSet("-blockminsize")) | if (gArgs.IsArgSet("-blockminsize")) | ||||
InitWarning("Unsupported argument -blockminsize ignored."); | InitWarning("Unsupported argument -blockminsize ignored."); | ||||
// Checkmempool and checkblockindex default to true in regtest mode | // Checkmempool and checkblockindex default to true in regtest mode | ||||
int ratio = std::min<int>( | int ratio = std::min<int>( | ||||
std::max<int>(GetArg("-checkmempool", | std::max<int>( | ||||
gArgs.GetArg("-checkmempool", | |||||
chainparams.DefaultConsistencyChecks() ? 1 : 0), | chainparams.DefaultConsistencyChecks() ? 1 : 0), | ||||
0), | 0), | ||||
1000000); | 1000000); | ||||
if (ratio != 0) { | if (ratio != 0) { | ||||
mempool.setSanityCheck(1.0 / ratio); | mempool.setSanityCheck(1.0 / ratio); | ||||
} | } | ||||
fCheckBlockIndex = | fCheckBlockIndex = gArgs.GetBoolArg("-checkblockindex", | ||||
GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks()); | chainparams.DefaultConsistencyChecks()); | ||||
fCheckpointsEnabled = | fCheckpointsEnabled = | ||||
GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED); | gArgs.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED); | ||||
hashAssumeValid = uint256S( | hashAssumeValid = uint256S( | ||||
GetArg("-assumevalid", | gArgs.GetArg("-assumevalid", | ||||
chainparams.GetConsensus().defaultAssumeValid.GetHex())); | chainparams.GetConsensus().defaultAssumeValid.GetHex())); | ||||
if (!hashAssumeValid.IsNull()) | if (!hashAssumeValid.IsNull()) | ||||
LogPrintf("Assuming ancestors of block %s have valid signatures.\n", | LogPrintf("Assuming ancestors of block %s have valid signatures.\n", | ||||
hashAssumeValid.GetHex()); | hashAssumeValid.GetHex()); | ||||
else | else | ||||
LogPrintf("Validating signatures for all blocks.\n"); | LogPrintf("Validating signatures for all blocks.\n"); | ||||
// mempool limits | // mempool limits | ||||
int64_t nMempoolSizeMax = | int64_t nMempoolSizeMax = | ||||
GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000; | gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000; | ||||
int64_t nMempoolSizeMin = | int64_t nMempoolSizeMin = | ||||
GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000 * | gArgs.GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * | ||||
40; | 1000 * 40; | ||||
if (nMempoolSizeMax < 0 || nMempoolSizeMax < nMempoolSizeMin) | if (nMempoolSizeMax < 0 || nMempoolSizeMax < nMempoolSizeMin) | ||||
return InitError(strprintf(_("-maxmempool must be at least %d MB"), | return InitError(strprintf(_("-maxmempool must be at least %d MB"), | ||||
std::ceil(nMempoolSizeMin / 1000000.0))); | std::ceil(nMempoolSizeMin / 1000000.0))); | ||||
// Incremental relay fee sets the minimimum feerate increase necessary for | // Incremental relay fee sets the minimimum feerate increase necessary for | ||||
// BIP 125 replacement in the mempool and the amount the mempool min fee | // BIP 125 replacement in the mempool and the amount the mempool min fee | ||||
// increases above the feerate of txs evicted due to mempool limiting. | // increases above the feerate of txs evicted due to mempool limiting. | ||||
if (IsArgSet("-incrementalrelayfee")) { | if (gArgs.IsArgSet("-incrementalrelayfee")) { | ||||
Amount n(0); | Amount n(0); | ||||
if (!ParseMoney(GetArg("-incrementalrelayfee", ""), n)) | if (!ParseMoney(gArgs.GetArg("-incrementalrelayfee", ""), n)) | ||||
return InitError(AmountErrMsg("incrementalrelayfee", | return InitError( | ||||
GetArg("-incrementalrelayfee", ""))); | AmountErrMsg("incrementalrelayfee", | ||||
gArgs.GetArg("-incrementalrelayfee", ""))); | |||||
incrementalRelayFee = CFeeRate(n); | incrementalRelayFee = CFeeRate(n); | ||||
} | } | ||||
// -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency | // -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency | ||||
nScriptCheckThreads = GetArg("-par", DEFAULT_SCRIPTCHECK_THREADS); | nScriptCheckThreads = gArgs.GetArg("-par", DEFAULT_SCRIPTCHECK_THREADS); | ||||
if (nScriptCheckThreads <= 0) nScriptCheckThreads += GetNumCores(); | if (nScriptCheckThreads <= 0) nScriptCheckThreads += GetNumCores(); | ||||
if (nScriptCheckThreads <= 1) | if (nScriptCheckThreads <= 1) | ||||
nScriptCheckThreads = 0; | nScriptCheckThreads = 0; | ||||
else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS) | else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS) | ||||
nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS; | nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS; | ||||
// Configure excessive block size. | // Configure excessive block size. | ||||
const uint64_t nProposedExcessiveBlockSize = | const uint64_t nProposedExcessiveBlockSize = | ||||
GetArg("-excessiveblocksize", DEFAULT_MAX_BLOCK_SIZE); | gArgs.GetArg("-excessiveblocksize", DEFAULT_MAX_BLOCK_SIZE); | ||||
if (!config.SetMaxBlockSize(nProposedExcessiveBlockSize)) { | if (!config.SetMaxBlockSize(nProposedExcessiveBlockSize)) { | ||||
return InitError( | return InitError( | ||||
_("Excessive block size must be > 1,000,000 bytes (1MB)")); | _("Excessive block size must be > 1,000,000 bytes (1MB)")); | ||||
} | } | ||||
// Check blockmaxsize does not exceed maximum accepted block size. | // Check blockmaxsize does not exceed maximum accepted block size. | ||||
const uint64_t nProposedMaxGeneratedBlockSize = | const uint64_t nProposedMaxGeneratedBlockSize = | ||||
GetArg("-blockmaxsize", DEFAULT_MAX_GENERATED_BLOCK_SIZE); | gArgs.GetArg("-blockmaxsize", DEFAULT_MAX_GENERATED_BLOCK_SIZE); | ||||
if (nProposedMaxGeneratedBlockSize > config.GetMaxBlockSize()) { | if (nProposedMaxGeneratedBlockSize > config.GetMaxBlockSize()) { | ||||
auto msg = _("Max generated block size (blockmaxsize) cannot exceed " | auto msg = _("Max generated block size (blockmaxsize) cannot exceed " | ||||
"the excessive block size (excessiveblocksize)"); | "the excessive block size (excessiveblocksize)"); | ||||
return InitError(msg); | return InitError(msg); | ||||
} | } | ||||
// block pruning; get the amount of disk space (in MiB) to allot for block & | // block pruning; get the amount of disk space (in MiB) to allot for block & | ||||
// undo files | // undo files | ||||
int64_t nPruneArg = GetArg("-prune", 0); | int64_t nPruneArg = gArgs.GetArg("-prune", 0); | ||||
if (nPruneArg < 0) { | if (nPruneArg < 0) { | ||||
return InitError( | return InitError( | ||||
_("Prune cannot be configured with a negative value.")); | _("Prune cannot be configured with a negative value.")); | ||||
} | } | ||||
nPruneTarget = (uint64_t)nPruneArg * 1024 * 1024; | nPruneTarget = (uint64_t)nPruneArg * 1024 * 1024; | ||||
if (nPruneArg == 1) { // manual pruning: -prune=1 | if (nPruneArg == 1) { // manual pruning: -prune=1 | ||||
LogPrintf("Block pruning enabled. Use RPC call " | LogPrintf("Block pruning enabled. Use RPC call " | ||||
"pruneblockchain(height) to manually prune block and undo " | "pruneblockchain(height) to manually prune block and undo " | ||||
Show All 14 Lines | bool AppInitParameterInteraction(Config &config) { | ||||
} | } | ||||
RegisterAllRPCCommands(tableRPC); | RegisterAllRPCCommands(tableRPC); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
RegisterWalletRPCCommands(tableRPC); | RegisterWalletRPCCommands(tableRPC); | ||||
RegisterDumpRPCCommands(tableRPC); | RegisterDumpRPCCommands(tableRPC); | ||||
#endif | #endif | ||||
nConnectTimeout = GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT); | nConnectTimeout = gArgs.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT); | ||||
if (nConnectTimeout <= 0) nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; | if (nConnectTimeout <= 0) nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; | ||||
// Fee-per-kilobyte amount considered the same as "free". If you are mining, | // Fee-per-kilobyte amount considered the same as "free". If you are mining, | ||||
// be careful setting this: if you set it to zero then a transaction spammer | // be careful setting this: if you set it to zero then a transaction spammer | ||||
// can cheaply fill blocks using 1-satoshi-fee transactions. It should be | // can cheaply fill blocks using 1-satoshi-fee transactions. It should be | ||||
// set above the real cost to you of processing a transaction. | // set above the real cost to you of processing a transaction. | ||||
if (IsArgSet("-minrelaytxfee")) { | if (gArgs.IsArgSet("-minrelaytxfee")) { | ||||
Amount n(0); | Amount n(0); | ||||
auto parsed = ParseMoney(GetArg("-minrelaytxfee", ""), n); | auto parsed = ParseMoney(gArgs.GetArg("-minrelaytxfee", ""), n); | ||||
if (!parsed || Amount(0) == n) | if (!parsed || Amount(0) == n) | ||||
return InitError( | return InitError(AmountErrMsg("minrelaytxfee", | ||||
AmountErrMsg("minrelaytxfee", GetArg("-minrelaytxfee", ""))); | gArgs.GetArg("-minrelaytxfee", ""))); | ||||
// High fee check is done afterward in CWallet::ParameterInteraction() | // High fee check is done afterward in CWallet::ParameterInteraction() | ||||
::minRelayTxFee = CFeeRate(n); | ::minRelayTxFee = CFeeRate(n); | ||||
} else if (incrementalRelayFee > ::minRelayTxFee) { | } else if (incrementalRelayFee > ::minRelayTxFee) { | ||||
// Allow only setting incrementalRelayFee to control both | // Allow only setting incrementalRelayFee to control both | ||||
::minRelayTxFee = incrementalRelayFee; | ::minRelayTxFee = incrementalRelayFee; | ||||
LogPrintf( | LogPrintf( | ||||
"Increasing minrelaytxfee to %s to match incrementalrelayfee\n", | "Increasing minrelaytxfee to %s to match incrementalrelayfee\n", | ||||
::minRelayTxFee.ToString()); | ::minRelayTxFee.ToString()); | ||||
} | } | ||||
// Sanity check argument for min fee for including tx in block | // Sanity check argument for min fee for including tx in block | ||||
// TODO: Harmonize which arguments need sanity checking and where that | // TODO: Harmonize which arguments need sanity checking and where that | ||||
// happens. | // happens. | ||||
if (IsArgSet("-blockmintxfee")) { | if (gArgs.IsArgSet("-blockmintxfee")) { | ||||
Amount n(0); | Amount n(0); | ||||
if (!ParseMoney(GetArg("-blockmintxfee", ""), n)) | if (!ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n)) | ||||
return InitError( | return InitError(AmountErrMsg("blockmintxfee", | ||||
AmountErrMsg("blockmintxfee", GetArg("-blockmintxfee", ""))); | gArgs.GetArg("-blockmintxfee", ""))); | ||||
} | } | ||||
// Feerate used to define dust. Shouldn't be changed lightly as old | // Feerate used to define dust. Shouldn't be changed lightly as old | ||||
// implementations may inadvertently create non-standard transactions. | // implementations may inadvertently create non-standard transactions. | ||||
if (IsArgSet("-dustrelayfee")) { | if (gArgs.IsArgSet("-dustrelayfee")) { | ||||
Amount n(0); | Amount n(0); | ||||
auto parsed = ParseMoney(GetArg("-dustrelayfee", ""), n); | auto parsed = ParseMoney(gArgs.GetArg("-dustrelayfee", ""), n); | ||||
if (!parsed || Amount(0) == n) | if (!parsed || Amount(0) == n) | ||||
return InitError( | return InitError(AmountErrMsg("dustrelayfee", | ||||
AmountErrMsg("dustrelayfee", GetArg("-dustrelayfee", ""))); | gArgs.GetArg("-dustrelayfee", ""))); | ||||
dustRelayFee = CFeeRate(n); | dustRelayFee = CFeeRate(n); | ||||
} | } | ||||
fRequireStandard = | fRequireStandard = | ||||
!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 = GetArg("-bytespersigop", nBytesPerSigOp); | nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
if (!CWallet::ParameterInteraction()) return false; | if (!CWallet::ParameterInteraction()) return false; | ||||
#endif | #endif | ||||
fIsBareMultisigStd = | fIsBareMultisigStd = | ||||
GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); | gArgs.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); | ||||
fAcceptDatacarrier = GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); | fAcceptDatacarrier = | ||||
nMaxDatacarrierBytes = GetArg("-datacarriersize", nMaxDatacarrierBytes); | gArgs.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); | ||||
nMaxDatacarrierBytes = | |||||
gArgs.GetArg("-datacarriersize", nMaxDatacarrierBytes); | |||||
// Option to startup with mocktime set (used for regression testing): | // Option to startup with mocktime set (used for regression testing): | ||||
SetMockTime(GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op | SetMockTime(gArgs.GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op | ||||
if (GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS)) | if (gArgs.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS)) | ||||
nLocalServices = ServiceFlags(nLocalServices | NODE_BLOOM); | nLocalServices = ServiceFlags(nLocalServices | NODE_BLOOM); | ||||
// Signal Bitcoin Cash support. | // Signal Bitcoin Cash support. | ||||
// TODO: remove some time after the hardfork when no longer needed | // TODO: remove some time after the hardfork when no longer needed | ||||
// to differentiate the network nodes. | // to differentiate the network nodes. | ||||
nLocalServices = ServiceFlags(nLocalServices | NODE_BITCOIN_CASH); | nLocalServices = ServiceFlags(nLocalServices | NODE_BITCOIN_CASH); | ||||
nMaxTipAge = GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE); | nMaxTipAge = gArgs.GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE); | ||||
if (gArgs.IsArgSet("-bip9params")) { | if (gArgs.IsArgSet("-bip9params")) { | ||||
// Allow overriding BIP9 parameters for testing | // Allow overriding BIP9 parameters for testing | ||||
if (!chainparams.MineBlocksOnDemand()) { | if (!chainparams.MineBlocksOnDemand()) { | ||||
return InitError( | return InitError( | ||||
"BIP9 parameters may only be overridden on regtest."); | "BIP9 parameters may only be overridden on regtest."); | ||||
} | } | ||||
for (const std::string &strDeployment : gArgs.GetArgs("-bip9params")) { | for (const std::string &strDeployment : gArgs.GetArgs("-bip9params")) { | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | bool AppInitMain(Config &config, boost::thread_group &threadGroup, | ||||
if (!LockDataDirectory(false)) { | if (!LockDataDirectory(false)) { | ||||
// Detailed error printed inside LockDataDirectory | // Detailed error printed inside LockDataDirectory | ||||
return false; | return false; | ||||
} | } | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
CreatePidFile(GetPidFile(), getpid()); | CreatePidFile(GetPidFile(), getpid()); | ||||
#endif | #endif | ||||
if (GetBoolArg("-shrinkdebugfile", logCategories != BCLog::NONE)) { | if (gArgs.GetBoolArg("-shrinkdebugfile", logCategories != BCLog::NONE)) { | ||||
// Do this first since it both loads a bunch of debug.log into memory, | // Do this first since it both loads a bunch of debug.log into memory, | ||||
// and because this needs to happen before any other debug.log printing. | // and because this needs to happen before any other debug.log printing. | ||||
ShrinkDebugFile(); | ShrinkDebugFile(); | ||||
} | } | ||||
if (fPrintToDebugLog) { | if (fPrintToDebugLog) { | ||||
OpenDebugLog(); | OpenDebugLog(); | ||||
} | } | ||||
if (!fLogTimestamps) { | if (!fLogTimestamps) { | ||||
LogPrintf("Startup time: %s\n", | LogPrintf("Startup time: %s\n", | ||||
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime())); | DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime())); | ||||
} | } | ||||
LogPrintf("Default data directory %s\n", GetDefaultDataDir().string()); | LogPrintf("Default data directory %s\n", GetDefaultDataDir().string()); | ||||
LogPrintf("Using data directory %s\n", GetDataDir().string()); | LogPrintf("Using data directory %s\n", GetDataDir().string()); | ||||
LogPrintf("Using config file %s\n", | LogPrintf( | ||||
GetConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME)).string()); | "Using config file %s\n", | ||||
GetConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME)).string()); | |||||
LogPrintf("Using at most %i automatic connections (%i file descriptors " | LogPrintf("Using at most %i automatic connections (%i file descriptors " | ||||
"available)\n", | "available)\n", | ||||
nMaxConnections, nFD); | nMaxConnections, nFD); | ||||
InitSignatureCache(); | InitSignatureCache(); | ||||
InitScriptExecutionCache(); | InitScriptExecutionCache(); | ||||
LogPrintf("Using %u threads for script verification\n", | LogPrintf("Using %u threads for script verification\n", | ||||
Show All 10 Lines | #endif | ||||
threadGroup.create_thread(boost::bind(&TraceThread<CScheduler::Function>, | threadGroup.create_thread(boost::bind(&TraceThread<CScheduler::Function>, | ||||
"scheduler", serviceLoop)); | "scheduler", serviceLoop)); | ||||
/* Start the RPC server already. It will be started in "warmup" mode | /* Start the RPC server already. It will be started in "warmup" mode | ||||
* and not really process calls already (but it will signify connections | * and not really process calls already (but it will signify connections | ||||
* that the server is there and will be ready later). Warmup mode will | * that the server is there and will be ready later). Warmup mode will | ||||
* be disabled when initialisation is finished. | * be disabled when initialisation is finished. | ||||
*/ | */ | ||||
if (GetBoolArg("-server", false)) { | if (gArgs.GetBoolArg("-server", false)) { | ||||
uiInterface.InitMessage.connect(SetRPCWarmupStatus); | uiInterface.InitMessage.connect(SetRPCWarmupStatus); | ||||
if (!AppInitServers(config, threadGroup)) { | if (!AppInitServers(config, 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.")); | ||||
} | } | ||||
} | } | ||||
int64_t nStart; | int64_t nStart; | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if (gArgs.IsArgSet("-whitelist")) { | ||||
LookupSubNet(net.c_str(), subnet); | LookupSubNet(net.c_str(), subnet); | ||||
if (!subnet.IsValid()) | if (!subnet.IsValid()) | ||||
return InitError(strprintf( | return InitError(strprintf( | ||||
_("Invalid netmask specified in -whitelist: '%s'"), net)); | _("Invalid netmask specified in -whitelist: '%s'"), net)); | ||||
connman.AddWhitelistedRange(subnet); | connman.AddWhitelistedRange(subnet); | ||||
} | } | ||||
} | } | ||||
bool proxyRandomize = GetBoolArg("-proxyrandomize", DEFAULT_PROXYRANDOMIZE); | bool proxyRandomize = | ||||
gArgs.GetBoolArg("-proxyrandomize", DEFAULT_PROXYRANDOMIZE); | |||||
// -proxy sets a proxy for all outgoing network traffic | // -proxy sets a proxy for all outgoing network traffic | ||||
// -noproxy (or -proxy=0) as well as the empty string can be used to not set | // -noproxy (or -proxy=0) as well as the empty string can be used to not set | ||||
// a proxy, this is the default | // a proxy, this is the default | ||||
std::string proxyArg = GetArg("-proxy", ""); | std::string proxyArg = gArgs.GetArg("-proxy", ""); | ||||
SetLimited(NET_TOR); | SetLimited(NET_TOR); | ||||
if (proxyArg != "" && proxyArg != "0") { | if (proxyArg != "" && proxyArg != "0") { | ||||
CService resolved(LookupNumeric(proxyArg.c_str(), 9050)); | CService resolved(LookupNumeric(proxyArg.c_str(), 9050)); | ||||
proxyType addrProxy = proxyType(resolved, proxyRandomize); | proxyType addrProxy = proxyType(resolved, proxyRandomize); | ||||
if (!addrProxy.IsValid()) { | if (!addrProxy.IsValid()) { | ||||
return InitError( | return InitError( | ||||
strprintf(_("Invalid -proxy address: '%s'"), proxyArg)); | strprintf(_("Invalid -proxy address: '%s'"), proxyArg)); | ||||
} | } | ||||
SetProxy(NET_IPV4, addrProxy); | SetProxy(NET_IPV4, addrProxy); | ||||
SetProxy(NET_IPV6, addrProxy); | SetProxy(NET_IPV6, addrProxy); | ||||
SetProxy(NET_TOR, addrProxy); | SetProxy(NET_TOR, addrProxy); | ||||
SetNameProxy(addrProxy); | SetNameProxy(addrProxy); | ||||
SetLimited(NET_TOR, false); // by default, -proxy sets onion as | SetLimited(NET_TOR, false); // by default, -proxy sets onion as | ||||
// reachable, unless -noonion later | // reachable, unless -noonion later | ||||
} | } | ||||
// -onion can be used to set only a proxy for .onion, or override normal | // -onion can be used to set only a proxy for .onion, or override normal | ||||
// proxy for .onion addresses. | // proxy for .onion addresses. | ||||
// -noonion (or -onion=0) disables connecting to .onion entirely. An empty | // -noonion (or -onion=0) disables connecting to .onion entirely. An empty | ||||
// string is used to not override the onion proxy (in which case it defaults | // string is used to not override the onion proxy (in which case it defaults | ||||
// to -proxy set above, or none) | // to -proxy set above, or none) | ||||
std::string onionArg = GetArg("-onion", ""); | std::string onionArg = gArgs.GetArg("-onion", ""); | ||||
if (onionArg != "") { | if (onionArg != "") { | ||||
if (onionArg == "0") { // Handle -noonion/-onion=0 | if (onionArg == "0") { // Handle -noonion/-onion=0 | ||||
SetLimited(NET_TOR); // set onions as unreachable | SetLimited(NET_TOR); // set onions as unreachable | ||||
} else { | } else { | ||||
CService resolved(LookupNumeric(onionArg.c_str(), 9050)); | CService resolved(LookupNumeric(onionArg.c_str(), 9050)); | ||||
proxyType addrOnion = proxyType(resolved, proxyRandomize); | proxyType addrOnion = proxyType(resolved, proxyRandomize); | ||||
if (!addrOnion.IsValid()) { | if (!addrOnion.IsValid()) { | ||||
return InitError( | return InitError( | ||||
strprintf(_("Invalid -onion address: '%s'"), onionArg)); | strprintf(_("Invalid -onion address: '%s'"), onionArg)); | ||||
} | } | ||||
SetProxy(NET_TOR, addrOnion); | SetProxy(NET_TOR, addrOnion); | ||||
SetLimited(NET_TOR, false); | SetLimited(NET_TOR, false); | ||||
} | } | ||||
} | } | ||||
// see Step 2: parameter interactions for more information about these | // see Step 2: parameter interactions for more information about these | ||||
fListen = GetBoolArg("-listen", DEFAULT_LISTEN); | fListen = gArgs.GetBoolArg("-listen", DEFAULT_LISTEN); | ||||
fDiscover = GetBoolArg("-discover", true); | fDiscover = gArgs.GetBoolArg("-discover", true); | ||||
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP); | fNameLookup = gArgs.GetBoolArg("-dns", DEFAULT_NAME_LOOKUP); | ||||
fRelayTxes = !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY); | fRelayTxes = !gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY); | ||||
if (fListen) { | if (fListen) { | ||||
bool fBound = false; | bool fBound = false; | ||||
if (gArgs.IsArgSet("-bind")) { | if (gArgs.IsArgSet("-bind")) { | ||||
for (const std::string &strBind : gArgs.GetArgs("-bind")) { | for (const std::string &strBind : gArgs.GetArgs("-bind")) { | ||||
CService addrBind; | CService addrBind; | ||||
if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), | if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), | ||||
false)) { | false)) { | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | #if ENABLE_ZMQ | ||||
if (pzmqNotificationInterface) { | if (pzmqNotificationInterface) { | ||||
RegisterValidationInterface(pzmqNotificationInterface); | RegisterValidationInterface(pzmqNotificationInterface); | ||||
} | } | ||||
#endif | #endif | ||||
// unlimited unless -maxuploadtarget is set | // unlimited unless -maxuploadtarget is set | ||||
uint64_t nMaxOutboundLimit = 0; | uint64_t nMaxOutboundLimit = 0; | ||||
uint64_t nMaxOutboundTimeframe = MAX_UPLOAD_TIMEFRAME; | uint64_t nMaxOutboundTimeframe = MAX_UPLOAD_TIMEFRAME; | ||||
if (IsArgSet("-maxuploadtarget")) { | if (gArgs.IsArgSet("-maxuploadtarget")) { | ||||
nMaxOutboundLimit = | nMaxOutboundLimit = | ||||
GetArg("-maxuploadtarget", DEFAULT_MAX_UPLOAD_TARGET) * 1024 * 1024; | gArgs.GetArg("-maxuploadtarget", DEFAULT_MAX_UPLOAD_TARGET) * 1024 * | ||||
1024; | |||||
} | } | ||||
// Step 7: load block chain | // Step 7: load block chain | ||||
fReindex = GetBoolArg("-reindex", false); | fReindex = gArgs.GetBoolArg("-reindex", false); | ||||
bool fReindexChainState = GetBoolArg("-reindex-chainstate", false); | bool fReindexChainState = gArgs.GetBoolArg("-reindex-chainstate", false); | ||||
// cache size calculations | // cache size calculations | ||||
int64_t nTotalCache = (GetArg("-dbcache", nDefaultDbCache) << 20); | int64_t nTotalCache = (gArgs.GetArg("-dbcache", nDefaultDbCache) << 20); | ||||
// total cache cannot be less than nMinDbCache | // total cache cannot be less than nMinDbCache | ||||
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); | nTotalCache = std::max(nTotalCache, nMinDbCache << 20); | ||||
// total cache cannot be greater than nMaxDbcache | // total cache cannot be greater than nMaxDbcache | ||||
nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); | nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); | ||||
int64_t nBlockTreeDBCache = nTotalCache / 8; | int64_t nBlockTreeDBCache = nTotalCache / 8; | ||||
nBlockTreeDBCache = std::min(nBlockTreeDBCache, | nBlockTreeDBCache = std::min(nBlockTreeDBCache, | ||||
(GetBoolArg("-txindex", DEFAULT_TXINDEX) | (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX) | ||||
? nMaxBlockDBAndTxIndexCache | ? nMaxBlockDBAndTxIndexCache | ||||
: nMaxBlockDBCache) | : nMaxBlockDBCache) | ||||
<< 20); | << 20); | ||||
nTotalCache -= nBlockTreeDBCache; | nTotalCache -= nBlockTreeDBCache; | ||||
// use 25%-50% of the remainder for disk cache | // use 25%-50% of the remainder for disk cache | ||||
int64_t nCoinDBCache = | int64_t nCoinDBCache = | ||||
std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); | std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); | ||||
// cap total coins db cache | // cap total coins db cache | ||||
nCoinDBCache = std::min(nCoinDBCache, nMaxCoinsDBCache << 20); | nCoinDBCache = std::min(nCoinDBCache, nMaxCoinsDBCache << 20); | ||||
nTotalCache -= nCoinDBCache; | nTotalCache -= nCoinDBCache; | ||||
// the rest goes to in-memory cache | // the rest goes to in-memory cache | ||||
nCoinCacheUsage = nTotalCache; | nCoinCacheUsage = nTotalCache; | ||||
int64_t nMempoolSizeMax = | int64_t nMempoolSizeMax = | ||||
GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000; | gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000; | ||||
LogPrintf("Cache configuration:\n"); | LogPrintf("Cache configuration:\n"); | ||||
LogPrintf("* Using %.1fMiB for block index database\n", | LogPrintf("* Using %.1fMiB for block index database\n", | ||||
nBlockTreeDBCache * (1.0 / 1024 / 1024)); | nBlockTreeDBCache * (1.0 / 1024 / 1024)); | ||||
LogPrintf("* Using %.1fMiB for chain state database\n", | LogPrintf("* Using %.1fMiB for chain state database\n", | ||||
nCoinDBCache * (1.0 / 1024 / 1024)); | nCoinDBCache * (1.0 / 1024 / 1024)); | ||||
LogPrintf("* Using %.1fMiB for in-memory UTXO set (plus up to %.1fMiB of " | LogPrintf("* Using %.1fMiB for in-memory UTXO set (plus up to %.1fMiB of " | ||||
"unused mempool space)\n", | "unused mempool space)\n", | ||||
nCoinCacheUsage * (1.0 / 1024 / 1024), | nCoinCacheUsage * (1.0 / 1024 / 1024), | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | while (!fLoaded && !fRequestShutdown) { | ||||
// Initialize the block index (no-op if non-empty database was | // Initialize the block index (no-op if non-empty database was | ||||
// already loaded) | // already loaded) | ||||
if (!InitBlockIndex(config)) { | if (!InitBlockIndex(config)) { | ||||
strLoadError = _("Error initializing block database"); | strLoadError = _("Error initializing block database"); | ||||
break; | break; | ||||
} | } | ||||
// Check for changed -txindex state | // Check for changed -txindex state | ||||
if (fTxIndex != GetBoolArg("-txindex", DEFAULT_TXINDEX)) { | if (fTxIndex != gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) { | ||||
strLoadError = _("You need to rebuild the database using " | strLoadError = _("You need to rebuild the database using " | ||||
"-reindex-chainstate to change -txindex"); | "-reindex-chainstate to change -txindex"); | ||||
break; | break; | ||||
} | } | ||||
// Check for changed -prune state. What we are concerned about | // Check for changed -prune state. What we are concerned about | ||||
// is a user who has pruned blocks in the past, but is now | // is a user who has pruned blocks in the past, but is now | ||||
// trying to run unpruned. | // trying to run unpruned. | ||||
Show All 22 Lines | while (!fLoaded && !fRequestShutdown) { | ||||
"pre-fork state. You will need to " | "pre-fork state. You will need to " | ||||
"redownload the blockchain"); | "redownload the blockchain"); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
uiInterface.InitMessage(_("Verifying blocks...")); | uiInterface.InitMessage(_("Verifying blocks...")); | ||||
if (fHavePruned && | if (fHavePruned && | ||||
GetArg("-checkblocks", DEFAULT_CHECKBLOCKS) > | gArgs.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS) > | ||||
MIN_BLOCKS_TO_KEEP) { | MIN_BLOCKS_TO_KEEP) { | ||||
LogPrintf("Prune: pruned datadir may not have more than %d " | LogPrintf("Prune: pruned datadir may not have more than %d " | ||||
"blocks; only checking available blocks", | "blocks; only checking available blocks", | ||||
MIN_BLOCKS_TO_KEEP); | MIN_BLOCKS_TO_KEEP); | ||||
} | } | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CBlockIndex *tip = chainActive.Tip(); | CBlockIndex *tip = chainActive.Tip(); | ||||
RPCNotifyBlockChange(true, tip); | RPCNotifyBlockChange(true, tip); | ||||
if (tip && tip->nTime > GetAdjustedTime() + 2 * 60 * 60) { | if (tip && tip->nTime > GetAdjustedTime() + 2 * 60 * 60) { | ||||
strLoadError = | strLoadError = | ||||
_("The block database contains a block which " | _("The block database contains a block which " | ||||
"appears to be from the future. " | "appears to be from the future. " | ||||
"This may be due to your computer's date and " | "This may be due to your computer's date and " | ||||
"time being set incorrectly. " | "time being set incorrectly. " | ||||
"Only rebuild the block database if you are sure " | "Only rebuild the block database if you are sure " | ||||
"that your computer's date and time are correct"); | "that your computer's date and time are correct"); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (!CVerifyDB().VerifyDB( | if (!CVerifyDB().VerifyDB( | ||||
config, pcoinsdbview, | config, pcoinsdbview, | ||||
GetArg("-checklevel", DEFAULT_CHECKLEVEL), | gArgs.GetArg("-checklevel", DEFAULT_CHECKLEVEL), | ||||
GetArg("-checkblocks", DEFAULT_CHECKBLOCKS))) { | gArgs.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS))) { | ||||
strLoadError = _("Corrupted block database detected"); | strLoadError = _("Corrupted block database detected"); | ||||
break; | break; | ||||
} | } | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
LogPrintf("%s\n", e.what()); | LogPrintf("%s\n", e.what()); | ||||
strLoadError = _("Error opening block database"); | strLoadError = _("Error opening block database"); | ||||
break; | break; | ||||
} | } | ||||
Show All 40 Lines | CAutoFile est_filein(fsbridge::fopen(est_path, "rb"), SER_DISK, | ||||
CLIENT_VERSION); | CLIENT_VERSION); | ||||
// Allowed to fail as this file IS missing on first startup. | // Allowed to fail as this file IS missing on first startup. | ||||
if (!est_filein.IsNull()) mempool.ReadFeeEstimates(est_filein); | if (!est_filein.IsNull()) mempool.ReadFeeEstimates(est_filein); | ||||
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( | ||||
GetBoolArg("-usecashaddr", GetAdjustedTime() > 1515900000)); | gArgs.GetBoolArg("-usecashaddr", GetAdjustedTime() > 1515900000)); | ||||
// Step 8: load wallet | // Step 8: load wallet | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
if (!CWallet::InitLoadWallet()) return false; | if (!CWallet::InitLoadWallet()) return false; | ||||
#else | #else | ||||
LogPrintf("No wallet support compiled in!\n"); | LogPrintf("No wallet support compiled in!\n"); | ||||
#endif | #endif | ||||
Show All 20 Lines | #endif | ||||
// fHaveGenesis directly. | // fHaveGenesis directly. | ||||
// No locking, as this happens before any background thread is started. | // No locking, as this happens before any background thread is started. | ||||
if (chainActive.Tip() == nullptr) { | if (chainActive.Tip() == nullptr) { | ||||
uiInterface.NotifyBlockTip.connect(BlockNotifyGenesisWait); | uiInterface.NotifyBlockTip.connect(BlockNotifyGenesisWait); | ||||
} else { | } else { | ||||
fHaveGenesis = true; | fHaveGenesis = true; | ||||
} | } | ||||
if (IsArgSet("-blocknotify")) { | if (gArgs.IsArgSet("-blocknotify")) { | ||||
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); | uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); | ||||
} | } | ||||
std::vector<fs::path> vImportFiles; | std::vector<fs::path> vImportFiles; | ||||
if (gArgs.IsArgSet("-loadblock")) { | if (gArgs.IsArgSet("-loadblock")) { | ||||
for (const std::string &strFile : gArgs.GetArgs("-loadblock")) { | for (const std::string &strFile : gArgs.GetArgs("-loadblock")) { | ||||
vImportFiles.push_back(strFile); | vImportFiles.push_back(strFile); | ||||
} | } | ||||
Show All 11 Lines | // Wait for genesis block to be processed | ||||
uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait); | uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait); | ||||
} | } | ||||
// Step 11: start node | // Step 11: start node | ||||
//// debug print | //// debug print | ||||
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size()); | LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size()); | ||||
LogPrintf("nBestHeight = %d\n", chainActive.Height()); | LogPrintf("nBestHeight = %d\n", chainActive.Height()); | ||||
if (GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION)) { | if (gArgs.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION)) { | ||||
StartTorControl(threadGroup, scheduler); | StartTorControl(threadGroup, scheduler); | ||||
} | } | ||||
Discover(threadGroup); | Discover(threadGroup); | ||||
// Map ports with UPnP | // Map ports with UPnP | ||||
MapPort(GetBoolArg("-upnp", DEFAULT_UPNP)); | MapPort(gArgs.GetBoolArg("-upnp", DEFAULT_UPNP)); | ||||
std::string strNodeError; | std::string strNodeError; | ||||
CConnman::Options connOptions; | CConnman::Options connOptions; | ||||
connOptions.nLocalServices = nLocalServices; | connOptions.nLocalServices = nLocalServices; | ||||
connOptions.nRelevantServices = nRelevantServices; | connOptions.nRelevantServices = nRelevantServices; | ||||
connOptions.nMaxConnections = nMaxConnections; | connOptions.nMaxConnections = nMaxConnections; | ||||
connOptions.nMaxOutbound = | connOptions.nMaxOutbound = | ||||
std::min(MAX_OUTBOUND_CONNECTIONS, connOptions.nMaxConnections); | std::min(MAX_OUTBOUND_CONNECTIONS, connOptions.nMaxConnections); | ||||
connOptions.nMaxAddnode = MAX_ADDNODE_CONNECTIONS; | connOptions.nMaxAddnode = MAX_ADDNODE_CONNECTIONS; | ||||
connOptions.nMaxFeeler = 1; | connOptions.nMaxFeeler = 1; | ||||
connOptions.nBestHeight = chainActive.Height(); | connOptions.nBestHeight = chainActive.Height(); | ||||
connOptions.uiInterface = &uiInterface; | connOptions.uiInterface = &uiInterface; | ||||
connOptions.nSendBufferMaxSize = | connOptions.nSendBufferMaxSize = | ||||
1000 * GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER); | 1000 * gArgs.GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER); | ||||
connOptions.nReceiveFloodSize = | connOptions.nReceiveFloodSize = | ||||
1000 * GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER); | 1000 * gArgs.GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER); | ||||
connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe; | connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe; | ||||
connOptions.nMaxOutboundLimit = nMaxOutboundLimit; | connOptions.nMaxOutboundLimit = nMaxOutboundLimit; | ||||
if (!connman.Start(scheduler, strNodeError, connOptions)) { | if (!connman.Start(scheduler, strNodeError, connOptions)) { | ||||
return InitError(strNodeError); | return InitError(strNodeError); | ||||
} | } | ||||
Show All 13 Lines |