From e518ef43afcf6e0ec2a2eb688fe8244558b10eeb Mon Sep 17 00:00:00 2001 From: random-zebra Date: Thu, 12 Mar 2020 16:50:36 +0100 Subject: [PATCH] Merge #1375: [Init] Do parameter interaction before creating the UI model 9182b9007559fa6ae945b1e13984dc1971572c28 Initialize logging before we do parameter interaction (Jonas Schnelli) dec078739aca63be8dc7c6e2fbb8267c2dfa86c3 [QT] Call inits parameter interaction before we create the options model (Jonas Schnelli) 18480ce73994d9326b27a0ff7a034e71ec5f0dce Refactor parameter interaction, call it before AppInit2() (Jonas Schnelli) Pull request description: Backport of https://github.com/bitcoin/bitcoin/pull/6780 Currently optionsModel(QT) parameters interaction overwrites/dominates initial and depending parameter settings. This PR would factor out init's parameter interaction and call it before AppInit2(). ACKs for top commit: furszy: ACK 9182b90 random-zebra: ACK rebase 9182b9007559fa6ae945b1e13984dc1971572c28 and merging... Tree-SHA512: f01c9b6603452d59c3fa7df8b8f85998b9c716fd3209f80fc6d4591035c995ad577b217d1d7ffd7f642d16fe130ee922ba0394870ec391b8e972587022962611 --- src/init.cpp | 59 ++++++++++++++++++++++++++++--------------------- src/init.h | 4 ++++ src/pivxd.cpp | 3 +++ src/qt/pivx.cpp | 10 +++++++++ 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index e5cf104907968e..38ff6152f3dcdb 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -842,34 +842,22 @@ bool AppInitBasicSetup() return true; } -/** Initialize pivx. - * @pre Parameters should be parsed and config file should be read. - */ -bool AppInit2() +// Parameter interaction based on rules +void InitParameterInteraction() { - // ********************************************************* Step 1: setup - if (!AppInitBasicSetup()) - return false; - - // ********************************************************* Step 2: parameter interactions - // Set this early so that parameter interactions go to console - fPrintToConsole = GetBoolArg("-printtoconsole", false); - fLogTimestamps = GetBoolArg("-logtimestamps", true); - fLogIPs = GetBoolArg("-logips", false); - if (mapArgs.count("-bind") || mapArgs.count("-whitebind")) { // when specifying an explicit binding address, you want to listen on it // even when -connect or -proxy is specified if (SoftSetBoolArg("-listen", true)) - LogPrintf("AppInit2 : parameter interaction: -bind or -whitebind set -> setting -listen=1\n"); + LogPrintf("%s : parameter interaction: -bind or -whitebind set -> setting -listen=1\n", __func__); } if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) { // when only connecting to trusted nodes, do not seed via DNS, or listen by default if (SoftSetBoolArg("-dnsseed", false)) - LogPrintf("AppInit2 : parameter interaction: -connect set -> setting -dnsseed=0\n"); + LogPrintf("%s : parameter interaction: -connect set -> setting -dnsseed=0\n", __func__); if (SoftSetBoolArg("-listen", false)) - LogPrintf("AppInit2 : parameter interaction: -connect set -> setting -listen=0\n"); + LogPrintf("%s : parameter interaction: -connect set -> setting -listen=0\n", __func__); } if (mapArgs.count("-proxy")) { @@ -882,42 +870,63 @@ bool AppInit2() LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__); // to protect privacy, do not discover addresses by default if (SoftSetBoolArg("-discover", false)) - LogPrintf("AppInit2 : parameter interaction: -proxy set -> setting -discover=0\n"); + LogPrintf("%s : parameter interaction: -proxy set -> setting -discover=0\n", __func__); } if (!GetBoolArg("-listen", true)) { // do not map ports or try to retrieve public IP when not listening (pointless) if (SoftSetBoolArg("-upnp", false)) - LogPrintf("AppInit2 : parameter interaction: -listen=0 -> setting -upnp=0\n"); + LogPrintf("%s : parameter interaction: -listen=0 -> setting -upnp=0\n", __func__); if (SoftSetBoolArg("-discover", false)) - LogPrintf("AppInit2 : parameter interaction: -listen=0 -> setting -discover=0\n"); + LogPrintf("%s : parameter interaction: -listen=0 -> setting -discover=0\n", __func__); if (SoftSetBoolArg("-listenonion", false)) - LogPrintf("AppInit2 : parameter interaction: -listen=0 -> setting -listenonion=0\n"); + LogPrintf("%s : parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__); } if (mapArgs.count("-externalip")) { // if an explicit public IP is specified, do not try to find others if (SoftSetBoolArg("-discover", false)) - LogPrintf("AppInit2 : parameter interaction: -externalip set -> setting -discover=0\n"); + LogPrintf("%s : parameter interaction: -externalip set -> setting -discover=0\n", __func__); } if (GetBoolArg("-salvagewallet", false)) { // Rewrite just private keys: rescan to find transactions if (SoftSetBoolArg("-rescan", true)) - LogPrintf("AppInit2 : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n"); + LogPrintf("%s : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__); } // -zapwallettx implies a rescan if (GetBoolArg("-zapwallettxes", false)) { if (SoftSetBoolArg("-rescan", true)) - LogPrintf("AppInit2 : parameter interaction: -zapwallettxes= -> setting -rescan=1\n"); + LogPrintf("%s : parameter interaction: -zapwallettxes= -> setting -rescan=1\n", __func__); } if (!GetBoolArg("-enableswifttx", fEnableSwiftTX)) { if (SoftSetArg("-swifttxdepth", "0")) - LogPrintf("AppInit2 : parameter interaction: -enableswifttx=false -> setting -nSwiftTXDepth=0\n"); + LogPrintf("%s : parameter interaction: -enableswifttx=false -> setting -nSwiftTXDepth=0\n", __func__); } +} +void InitLogging() +{ + 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("PIVX version %s (%s)\n", FormatFullVersion(), CLIENT_DATE); +} + +/** Initialize pivx. + * @pre Parameters should be parsed and config file should be read. + */ +bool AppInit2() +{ + // ********************************************************* Step 1: setup + if (!AppInitBasicSetup()) + return false; + + // ********************************************************* Step 2: parameter interactions // Make sure enough file descriptors are available int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1); nMaxConnections = GetArg("-maxconnections", 125); diff --git a/src/init.h b/src/init.h index c84f574f035def..ff71d849aaaed9 100644 --- a/src/init.h +++ b/src/init.h @@ -27,6 +27,10 @@ bool ShutdownRequested(); void Interrupt(); void Shutdown(); void PrepareShutdown(); +//!Initialize the logging infrastructure +void InitLogging(); +//!Parameter interaction: change current parameters depending on various rules +void InitParameterInteraction(); bool AppInit2(); /** Initialize PIVX core: Basic context setup. diff --git a/src/pivxd.cpp b/src/pivxd.cpp index 9e4d1e8cfeda91..5f76f7c3598847 100644 --- a/src/pivxd.cpp +++ b/src/pivxd.cpp @@ -140,6 +140,9 @@ bool AppInit(int argc, char* argv[]) #endif SoftSetBoolArg("-server", true); + // Set this early so that parameter interactions go to console + InitLogging(); + InitParameterInteraction(); fRet = AppInit2(); } catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInit()"); diff --git a/src/qt/pivx.cpp b/src/qt/pivx.cpp index 126d8b214ff463..3e10b4da182059 100644 --- a/src/qt/pivx.cpp +++ b/src/qt/pivx.cpp @@ -184,6 +184,8 @@ class BitcoinApplication : public QApplication /// Create payment server void createPaymentServer(); #endif + /// parameter interaction/setup based on rules + void parameterSetup(); /// Create options model void createOptionsModel(); /// Create main window @@ -411,6 +413,12 @@ void BitcoinApplication::startThread() coreThread->start(); } +void BitcoinApplication::parameterSetup() +{ + InitLogging(); + InitParameterInteraction(); +} + void BitcoinApplication::requestInitialize() { qDebug() << __func__ << ": Requesting initialize"; @@ -639,6 +647,8 @@ int main(int argc, char* argv[]) #endif // Install qDebug() message handler to route to debug.log qInstallMessageHandler(DebugMessageHandler); + // Allow parameter interaction before we create the options model + app.parameterSetup(); // Load GUI settings from QSettings app.createOptionsModel();