Initial merge
This commit is contained in:
324
src/init.cpp
324
src/init.cpp
@@ -11,9 +11,14 @@
|
||||
#include "crypto/common.h"
|
||||
#include "addrman.h"
|
||||
#include "amount.h"
|
||||
#ifdef ENABLE_MINING
|
||||
#include "base58.h"
|
||||
#endif
|
||||
#include "checkpoints.h"
|
||||
#include "compat/sanity.h"
|
||||
#include "consensus/validation.h"
|
||||
#include "httpserver.h"
|
||||
#include "httprpc.h"
|
||||
#include "key.h"
|
||||
#include "main.h"
|
||||
#include "metrics.h"
|
||||
@@ -23,6 +28,7 @@
|
||||
#include "script/standard.h"
|
||||
#include "scheduler.h"
|
||||
#include "txdb.h"
|
||||
#include "torcontrol.h"
|
||||
#include "ui_interface.h"
|
||||
#include "util.h"
|
||||
#include "utilmoneystr.h"
|
||||
@@ -31,7 +37,6 @@
|
||||
#include "wallet/wallet.h"
|
||||
#include "wallet/walletdb.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -50,6 +55,10 @@
|
||||
|
||||
#include "libsnark/common/profiling.hpp"
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
#include "zmq/zmqnotificationinterface.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern void ThreadSendAlert();
|
||||
@@ -61,6 +70,10 @@ CWallet* pwalletMain = NULL;
|
||||
#endif
|
||||
bool fFeeEstimatesInitialized = false;
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
static CZMQNotificationInterface* pzmqNotificationInterface = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
// Win32 LevelDB doesn't use file descriptors, and the ones used for
|
||||
// accessing block files don't count towards the fd_set size limit
|
||||
@@ -90,7 +103,7 @@ CClientUIInterface uiInterface; // Declared but not defined in ui_interface.h
|
||||
// Thread management and startup/shutdown:
|
||||
//
|
||||
// The network-processing threads are all part of a thread group
|
||||
// created by AppInit() or the Qt main() function.
|
||||
// created by AppInit().
|
||||
//
|
||||
// A clean exit happens when StartShutdown() or the SIGTERM
|
||||
// signal handler sets fRequestShutdown, which triggers
|
||||
@@ -106,10 +119,6 @@ CClientUIInterface uiInterface; // Declared but not defined in ui_interface.h
|
||||
// before adding any threads to the threadGroup, so .join_all() returns
|
||||
// immediately and the parent exits from main().
|
||||
//
|
||||
// Shutdown for Qt is very similar, only it uses a QTimer to detect
|
||||
// fRequestShutdown getting set, and then does the normal Qt
|
||||
// shutdown thing.
|
||||
//
|
||||
|
||||
std::atomic<bool> fRequestShutdown(false);
|
||||
|
||||
@@ -145,6 +154,16 @@ public:
|
||||
static CCoinsViewDB *pcoinsdbview = NULL;
|
||||
static CCoinsViewErrorCatcher *pcoinscatcher = NULL;
|
||||
|
||||
void Interrupt(boost::thread_group& threadGroup)
|
||||
{
|
||||
InterruptHTTPServer();
|
||||
InterruptHTTPRPC();
|
||||
InterruptRPC();
|
||||
InterruptREST();
|
||||
InterruptTorControl();
|
||||
threadGroup.interrupt_all();
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
LogPrintf("%s: In progress...\n", __func__);
|
||||
@@ -159,13 +178,24 @@ void Shutdown()
|
||||
/// module was initialized.
|
||||
RenameThread("zcash-shutoff");
|
||||
mempool.AddTransactionsUpdated(1);
|
||||
StopRPCThreads();
|
||||
|
||||
StopHTTPRPC();
|
||||
StopREST();
|
||||
StopRPC();
|
||||
StopHTTPServer();
|
||||
#ifdef ENABLE_WALLET
|
||||
if (pwalletMain)
|
||||
pwalletMain->Flush(false);
|
||||
#endif
|
||||
#ifdef ENABLE_MINING
|
||||
#ifdef ENABLE_WALLET
|
||||
GenerateBitcoins(false, NULL, 0);
|
||||
#else
|
||||
GenerateBitcoins(false, 0);
|
||||
#endif
|
||||
#endif
|
||||
StopNode();
|
||||
StopTorControl();
|
||||
UnregisterNodeSignals(GetNodeSignals());
|
||||
|
||||
if (fFeeEstimatesInitialized)
|
||||
@@ -197,6 +227,15 @@ void Shutdown()
|
||||
if (pwalletMain)
|
||||
pwalletMain->Flush(true);
|
||||
#endif
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
if (pzmqNotificationInterface) {
|
||||
UnregisterValidationInterface(pzmqNotificationInterface);
|
||||
delete pzmqNotificationInterface;
|
||||
pzmqNotificationInterface = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
try {
|
||||
boost::filesystem::remove(GetPidFile());
|
||||
@@ -319,7 +358,8 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-externalip=<ip>", _("Specify your own public address"));
|
||||
strUsage += HelpMessageOpt("-forcednsseed", strprintf(_("Always query for peer addresses via DNS lookup (default: %u)"), 0));
|
||||
strUsage += HelpMessageOpt("-listen", _("Accept connections from outside (default: 1 if no -proxy or -connect)"));
|
||||
strUsage += HelpMessageOpt("-maxconnections=<n>", strprintf(_("Maintain at most <n> connections to peers (default: %u)"), 125));
|
||||
strUsage += HelpMessageOpt("-listenonion", strprintf(_("Automatically create Tor hidden service (default: %d)"), DEFAULT_LISTEN_ONION));
|
||||
strUsage += HelpMessageOpt("-maxconnections=<n>", strprintf(_("Maintain at most <n> connections to peers (default: %u)"), DEFAULT_MAX_PEER_CONNECTIONS));
|
||||
strUsage += HelpMessageOpt("-maxreceivebuffer=<n>", strprintf(_("Maximum per-connection receive buffer, <n>*1000 bytes (default: %u)"), 5000));
|
||||
strUsage += HelpMessageOpt("-maxsendbuffer=<n>", strprintf(_("Maximum per-connection send buffer, <n>*1000 bytes (default: %u)"), 1000));
|
||||
strUsage += HelpMessageOpt("-onion=<ip:port>", strprintf(_("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: %s)"), "-proxy"));
|
||||
@@ -330,9 +370,11 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-proxyrandomize", strprintf(_("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)"), 1));
|
||||
strUsage += HelpMessageOpt("-seednode=<ip>", _("Connect to a node to retrieve peer addresses, and disconnect"));
|
||||
strUsage += HelpMessageOpt("-timeout=<n>", strprintf(_("Specify connection timeout in milliseconds (minimum: 1, default: %d)"), DEFAULT_CONNECT_TIMEOUT));
|
||||
strUsage += HelpMessageOpt("-torcontrol=<ip>:<port>", strprintf(_("Tor control port to use if onion listening enabled (default: %s)"), DEFAULT_TOR_CONTROL));
|
||||
strUsage += HelpMessageOpt("-torpassword=<pass>", _("Tor control port password (default: empty)"));
|
||||
#ifdef USE_UPNP
|
||||
#if USE_UPNP
|
||||
strUsage += HelpMessageOpt("-upnp", _("Use UPnP to map the listening port (default: 1 when listening)"));
|
||||
strUsage += HelpMessageOpt("-upnp", _("Use UPnP to map the listening port (default: 1 when listening and no -proxy)"));
|
||||
#else
|
||||
strUsage += HelpMessageOpt("-upnp", strprintf(_("Use UPnP to map the listening port (default: %u)"), 0));
|
||||
#endif
|
||||
@@ -362,13 +404,20 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-walletnotify=<cmd>", _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)"));
|
||||
strUsage += HelpMessageOpt("-zapwallettxes=<mode>", _("Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup") +
|
||||
" " + _("(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)"));
|
||||
|
||||
#endif
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
strUsage += HelpMessageGroup(_("ZeroMQ notification options:"));
|
||||
strUsage += HelpMessageOpt("-zmqpubhashblock=<address>", _("Enable publish hash block in <address>"));
|
||||
strUsage += HelpMessageOpt("-zmqpubhashtx=<address>", _("Enable publish hash transaction in <address>"));
|
||||
strUsage += HelpMessageOpt("-zmqpubrawblock=<address>", _("Enable publish raw block in <address>"));
|
||||
strUsage += HelpMessageOpt("-zmqpubrawtx=<address>", _("Enable publish raw transaction in <address>"));
|
||||
#endif
|
||||
|
||||
strUsage += HelpMessageGroup(_("Debugging/Testing options:"));
|
||||
if (showDebug)
|
||||
{
|
||||
strUsage += HelpMessageOpt("-checkpoints", strprintf("Only accept block chain matching built-in checkpoints (default: %u)", 1));
|
||||
strUsage += HelpMessageOpt("-checkpoints", strprintf("Disable expensive verification for known chain history (default: %u)", 1));
|
||||
strUsage += HelpMessageOpt("-dblogsize=<n>", strprintf("Flush database activity from memory pool to disk log every <n> megabytes (default: %u)", 100));
|
||||
strUsage += HelpMessageOpt("-disablesafemode", strprintf("Disable safemode, override a real safe mode event (default: %u)", 0));
|
||||
strUsage += HelpMessageOpt("-testsafemode", strprintf("Force safe mode (default: %u)", 0));
|
||||
@@ -377,17 +426,11 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-flushwallet", strprintf("Run a thread to flush wallet periodically (default: %u)", 1));
|
||||
strUsage += HelpMessageOpt("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", 0));
|
||||
}
|
||||
string debugCategories = "addrman, alert, bench, coindb, db, estimatefee, lock, mempool, net, partitioncheck, pow, proxy, prune, "
|
||||
"rand, reindex, rpc, selectcoins, zrpc, zrpcunsafe"; // Don't translate these and qt below
|
||||
if (mode == HMM_BITCOIN_QT)
|
||||
debugCategories += ", qt";
|
||||
string debugCategories = "addrman, alert, bench, coindb, db, estimatefee, http, libevent, lock, mempool, net, partitioncheck, pow, proxy, prune, "
|
||||
"rand, reindex, rpc, selectcoins, tor, zmq, zrpc, zrpcunsafe (implies zrpc)"; // Don't translate these
|
||||
strUsage += HelpMessageOpt("-debug=<category>", strprintf(_("Output debugging information (default: %u, supplying <category> is optional)"), 0) + ". " +
|
||||
_("If <category> is not supplied or if <category> = 1, output all debugging information.") + " " + _("<category> can be:") + " " + debugCategories + ".");
|
||||
#ifdef ENABLE_WALLET
|
||||
strUsage += HelpMessageOpt("-gen", strprintf(_("Generate coins (default: %u)"), 0));
|
||||
strUsage += HelpMessageOpt("-genproclimit=<n>", strprintf(_("Set the number of threads for coin generation if enabled (-1 = all cores, default: %d)"), 1));
|
||||
strUsage += HelpMessageOpt("-equihashsolver=<name>", _("Specify the Equihash solver to be used if enabled (default: \"default\")"));
|
||||
#endif
|
||||
strUsage += HelpMessageOpt("-experimentalfeatures", _("Enable use of experimental features"));
|
||||
strUsage += HelpMessageOpt("-help-debug", _("Show all debugging options (usage: --help -help-debug)"));
|
||||
strUsage += HelpMessageOpt("-logips", strprintf(_("Include IP addresses in debug output (default: %u)"), 0));
|
||||
strUsage += HelpMessageOpt("-logtimestamps", strprintf(_("Prepend debug output with timestamp (default: %u)"), 1));
|
||||
@@ -417,6 +460,24 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-blockminsize=<n>", strprintf(_("Set minimum block size in bytes (default: %u)"), 0));
|
||||
strUsage += HelpMessageOpt("-blockmaxsize=<n>", strprintf(_("Set maximum block size in bytes (default: %d)"), DEFAULT_BLOCK_MAX_SIZE));
|
||||
strUsage += HelpMessageOpt("-blockprioritysize=<n>", strprintf(_("Set maximum size of high-priority/low-fee transactions in bytes (default: %d)"), DEFAULT_BLOCK_PRIORITY_SIZE));
|
||||
if (GetBoolArg("-help-debug", false))
|
||||
strUsage += HelpMessageOpt("-blockversion=<n>", strprintf("Override block version to test forking scenarios (default: %d)", (int)CBlock::CURRENT_VERSION));
|
||||
|
||||
#ifdef ENABLE_MINING
|
||||
strUsage += HelpMessageGroup(_("Mining options:"));
|
||||
strUsage += HelpMessageOpt("-gen", strprintf(_("Generate coins (default: %u)"), 0));
|
||||
strUsage += HelpMessageOpt("-genproclimit=<n>", strprintf(_("Set the number of threads for coin generation if enabled (-1 = all cores, default: %d)"), 1));
|
||||
strUsage += HelpMessageOpt("-equihashsolver=<name>", _("Specify the Equihash solver to be used if enabled (default: \"default\")"));
|
||||
strUsage += HelpMessageOpt("-mineraddress=<addr>", _("Send mined coins to a specific single address"));
|
||||
strUsage += HelpMessageOpt("-minetolocalwallet", strprintf(
|
||||
_("Require that mined blocks use a coinbase address in the local wallet (default: %u)"),
|
||||
#ifdef ENABLE_WALLET
|
||||
1
|
||||
#else
|
||||
0
|
||||
#endif
|
||||
));
|
||||
#endif
|
||||
|
||||
strUsage += HelpMessageGroup(_("RPC server options:"));
|
||||
strUsage += HelpMessageOpt("-server", _("Accept command line and JSON-RPC commands"));
|
||||
@@ -426,33 +487,16 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
|
||||
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Listen for JSON-RPC connections on <port> (default: %u or testnet: %u)"), 8232, 18232));
|
||||
strUsage += HelpMessageOpt("-rpcallowip=<ip>", _("Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times"));
|
||||
strUsage += HelpMessageOpt("-rpcthreads=<n>", strprintf(_("Set the number of threads to service RPC calls (default: %d)"), 4));
|
||||
|
||||
// TODO #1856: Re-enable support for persistent connections.
|
||||
// Disabled to avoid rpc deadlock #1680, until we backport upstream changes which replace boost::asio with libevent, or another solution is implemented.
|
||||
//strUsage += HelpMessageOpt("-rpckeepalive", strprintf(_("RPC support for HTTP persistent connections (default: %d)"), 1));
|
||||
strUsage += HelpMessageOpt("-rpcthreads=<n>", strprintf(_("Set the number of threads to service RPC calls (default: %d)"), DEFAULT_HTTP_THREADS));
|
||||
if (showDebug) {
|
||||
strUsage += HelpMessageOpt("-rpcworkqueue=<n>", strprintf("Set the depth of the work queue to service RPC calls (default: %d)", DEFAULT_HTTP_WORKQUEUE));
|
||||
strUsage += HelpMessageOpt("-rpcservertimeout=<n>", strprintf("Timeout during HTTP requests (default: %d)", DEFAULT_HTTP_SERVER_TIMEOUT));
|
||||
}
|
||||
|
||||
// Disabled until we can lock notes and also tune performance of libsnark which by default uses multiple threads
|
||||
//strUsage += HelpMessageOpt("-rpcasyncthreads=<n>", strprintf(_("Set the number of threads to service Async RPC calls (default: %d)"), 1));
|
||||
|
||||
strUsage += HelpMessageGroup(_("RPC SSL options: (see the Bitcoin Wiki for SSL setup instructions)"));
|
||||
strUsage += HelpMessageOpt("-rpcssl", _("Use OpenSSL (https) for JSON-RPC connections"));
|
||||
strUsage += HelpMessageOpt("-rpcsslcertificatechainfile=<file.cert>", strprintf(_("Server certificate file (default: %s)"), "server.cert"));
|
||||
strUsage += HelpMessageOpt("-rpcsslprivatekeyfile=<file.pem>", strprintf(_("Server private key (default: %s)"), "server.pem"));
|
||||
strUsage += HelpMessageOpt("-rpcsslciphers=<ciphers>", strprintf(_("Acceptable ciphers (default: %s)"), "TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH"));
|
||||
|
||||
if (mode == HMM_BITCOIN_QT)
|
||||
{
|
||||
strUsage += HelpMessageGroup(_("UI Options:"));
|
||||
if (showDebug) {
|
||||
strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", "Allow self signed root certificates (default: 0)");
|
||||
}
|
||||
strUsage += HelpMessageOpt("-choosedatadir", _("Choose data directory on startup (default: 0)"));
|
||||
strUsage += HelpMessageOpt("-lang=<lang>", _("Set language, for example \"de_DE\" (default: system locale)"));
|
||||
strUsage += HelpMessageOpt("-min", _("Start minimized"));
|
||||
strUsage += HelpMessageOpt("-rootcertificates=<file>", _("Set SSL root certificates for payment request (default: -system-)"));
|
||||
strUsage += HelpMessageOpt("-splash", _("Show splash screen on startup (default: 1)"));
|
||||
} else if (mode == HMM_BITCOIND) {
|
||||
if (mode == HMM_BITCOIND) {
|
||||
strUsage += HelpMessageGroup(_("Metrics Options (only if -daemon and -printtoconsole are not set):"));
|
||||
strUsage += HelpMessageOpt("-showmetrics", _("Show metrics on stdout (default: 1 if running in a console, 0 otherwise)"));
|
||||
strUsage += HelpMessageOpt("-metricsui", _("Set to 1 for a persistent metrics screen, 0 for sequential metrics output (default: 1 if running in a console, 0 otherwise)"));
|
||||
@@ -570,7 +614,7 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
|
||||
}
|
||||
|
||||
// -loadblock=
|
||||
BOOST_FOREACH(boost::filesystem::path &path, vImportFiles) {
|
||||
BOOST_FOREACH(const boost::filesystem::path& path, vImportFiles) {
|
||||
FILE *file = fopen(path.string().c_str(), "rb");
|
||||
if (file) {
|
||||
CImportingNow imp;
|
||||
@@ -638,6 +682,23 @@ static void ZC_LoadParams()
|
||||
pzcashParams->setProvingKeyPath(pk_path.string());
|
||||
}
|
||||
|
||||
bool AppInitServers(boost::thread_group& threadGroup)
|
||||
{
|
||||
RPCServer::OnStopped(&OnRPCStopped);
|
||||
RPCServer::OnPreCommand(&OnRPCPreCommand);
|
||||
if (!InitHTTPServer())
|
||||
return false;
|
||||
if (!StartRPC())
|
||||
return false;
|
||||
if (!StartHTTPRPC())
|
||||
return false;
|
||||
if (GetBoolArg("-rest", false) && !StartREST())
|
||||
return false;
|
||||
if (!StartHTTPServer(threadGroup))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Initialize bitcoin.
|
||||
* @pre Parameters should be parsed and config file should be read.
|
||||
*/
|
||||
@@ -667,17 +728,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
typedef BOOL (WINAPI *PSETPROCDEPPOL)(DWORD);
|
||||
PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy");
|
||||
if (setProcDEPPol != NULL) setProcDEPPol(PROCESS_DEP_ENABLE);
|
||||
|
||||
// Initialize Windows Sockets
|
||||
WSADATA wsadata;
|
||||
int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
|
||||
if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
|
||||
{
|
||||
return InitError(strprintf("Error: Winsock library failed to start (WSAStartup returned error %d)", ret));
|
||||
}
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
|
||||
if (!SetupNetworking())
|
||||
return InitError("Error: Initializing networking failed");
|
||||
|
||||
#ifndef WIN32
|
||||
if (GetBoolArg("-sysperms", false)) {
|
||||
#ifdef ENABLE_WALLET
|
||||
if (!GetBoolArg("-disablewallet", false))
|
||||
@@ -702,20 +758,31 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
sa_hup.sa_flags = 0;
|
||||
sigaction(SIGHUP, &sa_hup, NULL);
|
||||
|
||||
#if defined (__SVR4) && defined (__sun)
|
||||
// ignore SIGPIPE on Solaris
|
||||
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// ********************************************************* Step 2: parameter interactions
|
||||
const CChainParams& chainparams = Params();
|
||||
|
||||
// Set this early so that experimental features are correctly enabled/disabled
|
||||
fExperimentalMode = GetBoolArg("-experimentalfeatures", false);
|
||||
|
||||
// Fail early if user has set experimental options without the global flag
|
||||
if (!fExperimentalMode) {
|
||||
if (mapArgs.count("-developerencryptwallet")) {
|
||||
return InitError(_("Wallet encryption requires -experimentalfeatures."));
|
||||
}
|
||||
}
|
||||
|
||||
// Set this early so that parameter interactions go to console
|
||||
fPrintToConsole = GetBoolArg("-printtoconsole", false);
|
||||
fLogTimestamps = GetBoolArg("-logtimestamps", true);
|
||||
fLogIPs = GetBoolArg("-logips", false);
|
||||
|
||||
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
|
||||
LogPrintf("Zcash version %s (%s)\n", FormatFullVersion(), CLIENT_DATE);
|
||||
|
||||
// when specifying an explicit binding address, you want to listen on it
|
||||
// even when -connect or -proxy is specified
|
||||
if (mapArgs.count("-bind")) {
|
||||
@@ -754,6 +821,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
LogPrintf("%s: parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
|
||||
if (SoftSetBoolArg("-discover", false))
|
||||
LogPrintf("%s: parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
|
||||
if (SoftSetBoolArg("-listenonion", false))
|
||||
LogPrintf("%s: parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__);
|
||||
}
|
||||
|
||||
if (mapArgs.count("-externalip")) {
|
||||
@@ -776,7 +845,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
|
||||
// Make sure enough file descriptors are available
|
||||
int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1);
|
||||
nMaxConnections = GetArg("-maxconnections", 125);
|
||||
nMaxConnections = GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS);
|
||||
nMaxConnections = std::max(std::min(nMaxConnections, (int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS)), 0);
|
||||
int nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS);
|
||||
if (nFD < MIN_CORE_FILEDESCRIPTORS)
|
||||
@@ -807,6 +876,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
if (GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), string("0")) != categories.end())
|
||||
fDebug = false;
|
||||
|
||||
// Special case: if debug=zrpcunsafe, implies debug=zrpc, so add it to debug categories
|
||||
if (find(categories.begin(), categories.end(), string("zrpcunsafe")) != categories.end()) {
|
||||
if (find(categories.begin(), categories.end(), string("zrpc")) == categories.end()) {
|
||||
LogPrintf("%s: parameter interaction: setting -debug=zrpcunsafe -> -debug=zrpc\n", __func__);
|
||||
vector<string>& v = mapMultiArgs["-debug"];
|
||||
v.push_back("zrpc");
|
||||
}
|
||||
}
|
||||
|
||||
// Check for -debugnet
|
||||
if (GetBoolArg("-debugnet", false))
|
||||
InitWarning(_("Warning: Unsupported argument -debugnet ignored, use -debug=net."));
|
||||
@@ -922,6 +1000,20 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
|
||||
fAlerts = GetBoolArg("-alerts", DEFAULT_ALERTS);
|
||||
|
||||
// Option to startup with mocktime set (used for regression testing):
|
||||
SetMockTime(GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op
|
||||
|
||||
#ifdef ENABLE_MINING
|
||||
if (mapArgs.count("-mineraddress")) {
|
||||
CBitcoinAddress addr;
|
||||
if (!addr.SetString(mapArgs["-mineraddress"])) {
|
||||
return InitError(strprintf(
|
||||
_("Invalid address for -mineraddress=<addr>: '%s' (must be a transparent address)"),
|
||||
mapArgs["-mineraddress"]));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
|
||||
|
||||
// Initialize libsodium
|
||||
@@ -962,6 +1054,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
ShrinkDebugFile();
|
||||
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
|
||||
LogPrintf("Komodo version %s (%s)\n", FormatFullVersion(), CLIENT_DATE);
|
||||
|
||||
if (fPrintToDebugLog)
|
||||
OpenDebugLog();
|
||||
LogPrintf("Using OpenSSL version %s\n", SSLeay_version(SSLEAY_VERSION));
|
||||
#ifdef ENABLE_WALLET
|
||||
LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0));
|
||||
@@ -1011,9 +1106,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
if (fServer)
|
||||
{
|
||||
uiInterface.InitMessage.connect(SetRPCWarmupStatus);
|
||||
RPCServer::OnStopped(&OnRPCStopped);
|
||||
RPCServer::OnPreCommand(&OnRPCPreCommand);
|
||||
StartRPCThreads();
|
||||
if (!AppInitServers(threadGroup))
|
||||
return InitError(_("Unable to start HTTP server. See debug log for details."));
|
||||
}
|
||||
|
||||
int64_t nStart;
|
||||
@@ -1026,15 +1120,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
|
||||
std::string warningString;
|
||||
std::string errorString;
|
||||
|
||||
|
||||
if (!CWallet::Verify(strWalletFile, warningString, errorString))
|
||||
return false;
|
||||
|
||||
|
||||
if (!warningString.empty())
|
||||
InitWarning(warningString);
|
||||
if (!errorString.empty())
|
||||
return InitError(warningString);
|
||||
|
||||
|
||||
} // (!fDisableWallet)
|
||||
#endif // ENABLE_WALLET
|
||||
// ********************************************************* Step 6: network initialization
|
||||
@@ -1043,7 +1137,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
|
||||
if (mapArgs.count("-onlynet")) {
|
||||
std::set<enum Network> nets;
|
||||
BOOST_FOREACH(std::string snet, mapMultiArgs["-onlynet"]) {
|
||||
BOOST_FOREACH(const std::string& snet, mapMultiArgs["-onlynet"]) {
|
||||
enum Network net = ParseNetwork(snet);
|
||||
if (net == NET_UNROUTABLE)
|
||||
return InitError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet));
|
||||
@@ -1065,31 +1159,37 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
}
|
||||
}
|
||||
|
||||
proxyType addrProxy;
|
||||
bool fProxy = false;
|
||||
if (mapArgs.count("-proxy")) {
|
||||
addrProxy = proxyType(CService(mapArgs["-proxy"], 9050), GetBoolArg("-proxyrandomize", true));
|
||||
bool proxyRandomize = GetBoolArg("-proxyrandomize", true);
|
||||
// -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 a proxy, this is the default
|
||||
std::string proxyArg = GetArg("-proxy", "");
|
||||
SetLimited(NET_TOR);
|
||||
if (proxyArg != "" && proxyArg != "0") {
|
||||
proxyType addrProxy = proxyType(CService(proxyArg, 9050), proxyRandomize);
|
||||
if (!addrProxy.IsValid())
|
||||
return InitError(strprintf(_("Invalid -proxy address: '%s'"), mapArgs["-proxy"]));
|
||||
return InitError(strprintf(_("Invalid -proxy address: '%s'"), proxyArg));
|
||||
|
||||
SetProxy(NET_IPV4, addrProxy);
|
||||
SetProxy(NET_IPV6, addrProxy);
|
||||
SetProxy(NET_TOR, addrProxy);
|
||||
SetNameProxy(addrProxy);
|
||||
fProxy = true;
|
||||
SetLimited(NET_TOR, false); // by default, -proxy sets onion as reachable, unless -noonion later
|
||||
}
|
||||
|
||||
// -onion can override normal proxy, -noonion disables connecting to .onion entirely
|
||||
if (!(mapArgs.count("-onion") && mapArgs["-onion"] == "0") &&
|
||||
(fProxy || mapArgs.count("-onion"))) {
|
||||
proxyType addrOnion;
|
||||
if (!mapArgs.count("-onion"))
|
||||
addrOnion = addrProxy;
|
||||
else
|
||||
addrOnion = proxyType(CService(mapArgs["-onion"], 9050), GetBoolArg("-proxyrandomize", true));
|
||||
if (!addrOnion.IsValid())
|
||||
return InitError(strprintf(_("Invalid -onion address: '%s'"), mapArgs["-onion"]));
|
||||
SetProxy(NET_TOR, addrOnion);
|
||||
SetReachable(NET_TOR);
|
||||
// -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
|
||||
// -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 to -proxy set above, or none)
|
||||
std::string onionArg = GetArg("-onion", "");
|
||||
if (onionArg != "") {
|
||||
if (onionArg == "0") { // Handle -noonion/-onion=0
|
||||
SetLimited(NET_TOR); // set onions as unreachable
|
||||
} else {
|
||||
proxyType addrOnion = proxyType(CService(onionArg, 9050), proxyRandomize);
|
||||
if (!addrOnion.IsValid())
|
||||
return InitError(strprintf(_("Invalid -onion address: '%s'"), onionArg));
|
||||
SetProxy(NET_TOR, addrOnion);
|
||||
SetLimited(NET_TOR, false);
|
||||
}
|
||||
}
|
||||
|
||||
// see Step 2: parameter interactions for more information about these
|
||||
@@ -1100,13 +1200,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
bool fBound = false;
|
||||
if (fListen) {
|
||||
if (mapArgs.count("-bind") || mapArgs.count("-whitebind")) {
|
||||
BOOST_FOREACH(std::string strBind, mapMultiArgs["-bind"]) {
|
||||
BOOST_FOREACH(const std::string& strBind, mapMultiArgs["-bind"]) {
|
||||
CService addrBind;
|
||||
if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false))
|
||||
return InitError(strprintf(_("Cannot resolve -bind address: '%s'"), strBind));
|
||||
fBound |= Bind(addrBind, (BF_EXPLICIT | BF_REPORT_ERROR));
|
||||
}
|
||||
BOOST_FOREACH(std::string strBind, mapMultiArgs["-whitebind"]) {
|
||||
BOOST_FOREACH(const std::string& strBind, mapMultiArgs["-whitebind"]) {
|
||||
CService addrBind;
|
||||
if (!Lookup(strBind.c_str(), addrBind, 0, false))
|
||||
return InitError(strprintf(_("Cannot resolve -whitebind address: '%s'"), strBind));
|
||||
@@ -1126,7 +1226,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
}
|
||||
|
||||
if (mapArgs.count("-externalip")) {
|
||||
BOOST_FOREACH(string strAddr, mapMultiArgs["-externalip"]) {
|
||||
BOOST_FOREACH(const std::string& strAddr, mapMultiArgs["-externalip"]) {
|
||||
CService addrLocal(strAddr, GetListenPort(), fNameLookup);
|
||||
if (!addrLocal.IsValid())
|
||||
return InitError(strprintf(_("Cannot resolve -externalip address: '%s'"), strAddr));
|
||||
@@ -1134,9 +1234,17 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"])
|
||||
BOOST_FOREACH(const std::string& strDest, mapMultiArgs["-seednode"])
|
||||
AddOneShot(strDest);
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
pzmqNotificationInterface = CZMQNotificationInterface::CreateWithArguments(mapArgs);
|
||||
|
||||
if (pzmqNotificationInterface) {
|
||||
RegisterValidationInterface(pzmqNotificationInterface);
|
||||
}
|
||||
#endif
|
||||
|
||||
// ********************************************************* Step 7: load block chain
|
||||
|
||||
fReindex = GetBoolArg("-reindex", false);
|
||||
@@ -1371,8 +1479,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
if (fFirstRun)
|
||||
{
|
||||
// Create new keyUser and set as default key
|
||||
RandAddSeedPerfmon();
|
||||
|
||||
CPubKey newDefaultKey;
|
||||
if (pwalletMain->GetKeyFromPool(newDefaultKey)) {
|
||||
pwalletMain->SetDefaultKey(newDefaultKey);
|
||||
@@ -1444,6 +1550,33 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
LogPrintf("No wallet support compiled in!\n");
|
||||
#endif // !ENABLE_WALLET
|
||||
|
||||
#ifdef ENABLE_MINING
|
||||
#ifndef ENABLE_WALLET
|
||||
if (GetBoolArg("-minetolocalwallet", false)) {
|
||||
return InitError(_("Zcash was not built with wallet support. Set -minetolocalwallet=0 to use -mineraddress, or rebuild Zcash with wallet support."));
|
||||
}
|
||||
if (GetArg("-mineraddress", "").empty() && GetBoolArg("-gen", false)) {
|
||||
return InitError(_("Zcash was not built with wallet support. Set -mineraddress, or rebuild Zcash with wallet support."));
|
||||
}
|
||||
#endif // !ENABLE_WALLET
|
||||
|
||||
if (mapArgs.count("-mineraddress")) {
|
||||
#ifdef ENABLE_WALLET
|
||||
bool minerAddressInLocalWallet = false;
|
||||
if (pwalletMain) {
|
||||
// Address has alreday been validated
|
||||
CBitcoinAddress addr(mapArgs["-mineraddress"]);
|
||||
CKeyID keyID;
|
||||
addr.GetKeyID(keyID);
|
||||
minerAddressInLocalWallet = pwalletMain->HaveKey(keyID);
|
||||
}
|
||||
if (GetBoolArg("-minetolocalwallet", true) && !minerAddressInLocalWallet) {
|
||||
return InitError(_("-mineraddress is not in the local wallet. Either use a local address, or set -minetolocalwallet=0"));
|
||||
}
|
||||
#endif // ENABLE_WALLET
|
||||
}
|
||||
#endif // ENABLE_MINING
|
||||
|
||||
// ********************************************************* Step 9: data directory maintenance
|
||||
|
||||
// if pruning, unset the service bit and perform the initial blockstore prune
|
||||
@@ -1472,7 +1605,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
std::vector<boost::filesystem::path> vImportFiles;
|
||||
if (mapArgs.count("-loadblock"))
|
||||
{
|
||||
BOOST_FOREACH(string strFile, mapMultiArgs["-loadblock"])
|
||||
BOOST_FOREACH(const std::string& strFile, mapMultiArgs["-loadblock"])
|
||||
vImportFiles.push_back(strFile);
|
||||
}
|
||||
threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles));
|
||||
@@ -1490,8 +1623,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
if (!strErrors.str().empty())
|
||||
return InitError(strErrors.str());
|
||||
|
||||
RandAddSeedPerfmon();
|
||||
|
||||
//// debug print
|
||||
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size());
|
||||
LogPrintf("nBestHeight = %d\n", chainActive.Height());
|
||||
@@ -1501,6 +1632,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
LogPrintf("mapAddressBook.size() = %u\n", pwalletMain ? pwalletMain->mapAddressBook.size() : 0);
|
||||
#endif
|
||||
|
||||
if (GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION))
|
||||
StartTorControl(threadGroup, scheduler);
|
||||
|
||||
StartNode(threadGroup, scheduler);
|
||||
|
||||
// Monitor the chain, and alert if we get blocks much quicker or slower than expected
|
||||
@@ -1509,10 +1643,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
boost::ref(cs_main), boost::cref(pindexBestHeader), nPowTargetSpacing);
|
||||
scheduler.scheduleEvery(f, nPowTargetSpacing);
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
#ifdef ENABLE_MINING
|
||||
// Generate coins in the background
|
||||
if (pwalletMain)
|
||||
#ifdef ENABLE_WALLET
|
||||
if (pwalletMain || !GetArg("-mineraddress", "").empty())
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1));
|
||||
#else
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", 1));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// ********************************************************* Step 11: finished
|
||||
|
||||
Reference in New Issue
Block a user