Skip to content

Commit 2a94cd6

Browse files
committed
Merge pull request #6780
a46f87f Initialize logging before we do parameter interaction (Jonas Schnelli) df66147 Move -blocksonly parameter interaction to the new ParameterInteraction() function (Jonas Schnelli) 68354e7 [QT] Call inits parameter interaction before we create the options model (Jonas Schnelli) 411b05a Refactor parameter interaction, call it before AppInit2() (Jonas Schnelli)
2 parents 5ca149a + a46f87f commit 2a94cd6

File tree

4 files changed

+102
-67
lines changed

4 files changed

+102
-67
lines changed

src/bitcoind.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ bool AppInit(int argc, char* argv[])
151151
#endif
152152
SoftSetBoolArg("-server", true);
153153

154+
// Set this early so that parameter interactions go to console
155+
InitLogging();
156+
InitParameterInteraction();
154157
fRet = AppInit2(threadGroup, scheduler);
155158
}
156159
catch (const std::exception& e) {

src/init.cpp

Lines changed: 85 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,91 @@ bool AppInitServers(boost::thread_group& threadGroup)
682682
return true;
683683
}
684684

685+
// Parameter interaction based on rules
686+
void InitParameterInteraction()
687+
{
688+
// when specifying an explicit binding address, you want to listen on it
689+
// even when -connect or -proxy is specified
690+
if (mapArgs.count("-bind")) {
691+
if (SoftSetBoolArg("-listen", true))
692+
LogPrintf("%s: parameter interaction: -bind set -> setting -listen=1\n", __func__);
693+
}
694+
if (mapArgs.count("-whitebind")) {
695+
if (SoftSetBoolArg("-listen", true))
696+
LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__);
697+
}
698+
699+
if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) {
700+
// when only connecting to trusted nodes, do not seed via DNS, or listen by default
701+
if (SoftSetBoolArg("-dnsseed", false))
702+
LogPrintf("%s: parameter interaction: -connect set -> setting -dnsseed=0\n", __func__);
703+
if (SoftSetBoolArg("-listen", false))
704+
LogPrintf("%s: parameter interaction: -connect set -> setting -listen=0\n", __func__);
705+
}
706+
707+
if (mapArgs.count("-proxy")) {
708+
// to protect privacy, do not listen by default if a default proxy server is specified
709+
if (SoftSetBoolArg("-listen", false))
710+
LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
711+
// to protect privacy, do not use UPNP when a proxy is set. The user may still specify -listen=1
712+
// to listen locally, so don't rely on this happening through -listen below.
713+
if (SoftSetBoolArg("-upnp", false))
714+
LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__);
715+
// to protect privacy, do not discover addresses by default
716+
if (SoftSetBoolArg("-discover", false))
717+
LogPrintf("%s: parameter interaction: -proxy set -> setting -discover=0\n", __func__);
718+
}
719+
720+
if (!GetBoolArg("-listen", DEFAULT_LISTEN)) {
721+
// do not map ports or try to retrieve public IP when not listening (pointless)
722+
if (SoftSetBoolArg("-upnp", false))
723+
LogPrintf("%s: parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
724+
if (SoftSetBoolArg("-discover", false))
725+
LogPrintf("%s: parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
726+
if (SoftSetBoolArg("-listenonion", false))
727+
LogPrintf("%s: parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__);
728+
}
729+
730+
if (mapArgs.count("-externalip")) {
731+
// if an explicit public IP is specified, do not try to find others
732+
if (SoftSetBoolArg("-discover", false))
733+
LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
734+
}
735+
736+
if (GetBoolArg("-salvagewallet", false)) {
737+
// Rewrite just private keys: rescan to find transactions
738+
if (SoftSetBoolArg("-rescan", true))
739+
LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
740+
}
741+
742+
// -zapwallettx implies a rescan
743+
if (GetBoolArg("-zapwallettxes", false)) {
744+
if (SoftSetBoolArg("-rescan", true))
745+
LogPrintf("%s: parameter interaction: -zapwallettxes=<mode> -> setting -rescan=1\n", __func__);
746+
}
747+
748+
// disable walletbroadcast and whitelistalwaysrelay in blocksonly mode
749+
if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {
750+
if (SoftSetBoolArg("-whitelistalwaysrelay", false))
751+
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistalwaysrelay=0\n", __func__);
752+
#ifdef ENABLE_WALLET
753+
if (SoftSetBoolArg("-walletbroadcast", false))
754+
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
755+
#endif
756+
}
757+
}
758+
759+
void InitLogging()
760+
{
761+
fPrintToConsole = GetBoolArg("-printtoconsole", false);
762+
fLogTimestamps = GetBoolArg("-logtimestamps", true);
763+
fLogTimeMicros = GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
764+
fLogIPs = GetBoolArg("-logips", false);
765+
766+
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
767+
LogPrintf("Bitcoin version %s (%s)\n", FormatFullVersion(), CLIENT_DATE);
768+
}
769+
685770
/** Initialize bitcoin.
686771
* @pre Parameters should be parsed and config file should be read.
687772
*/
@@ -746,74 +831,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
746831
// ********************************************************* Step 2: parameter interactions
747832
const CChainParams& chainparams = Params();
748833

749-
// Set this early so that parameter interactions go to console
750-
fPrintToConsole = GetBoolArg("-printtoconsole", false);
751-
fLogTimestamps = GetBoolArg("-logtimestamps", true);
752-
fLogTimeMicros = GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
753-
fLogIPs = GetBoolArg("-logips", false);
754-
755-
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
756-
LogPrintf("Bitcoin version %s (%s)\n", FormatFullVersion(), CLIENT_DATE);
757-
758-
// when specifying an explicit binding address, you want to listen on it
759-
// even when -connect or -proxy is specified
760-
if (mapArgs.count("-bind")) {
761-
if (SoftSetBoolArg("-listen", true))
762-
LogPrintf("%s: parameter interaction: -bind set -> setting -listen=1\n", __func__);
763-
}
764-
if (mapArgs.count("-whitebind")) {
765-
if (SoftSetBoolArg("-listen", true))
766-
LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__);
767-
}
768-
769-
if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) {
770-
// when only connecting to trusted nodes, do not seed via DNS, or listen by default
771-
if (SoftSetBoolArg("-dnsseed", false))
772-
LogPrintf("%s: parameter interaction: -connect set -> setting -dnsseed=0\n", __func__);
773-
if (SoftSetBoolArg("-listen", false))
774-
LogPrintf("%s: parameter interaction: -connect set -> setting -listen=0\n", __func__);
775-
}
776-
777-
if (mapArgs.count("-proxy")) {
778-
// to protect privacy, do not listen by default if a default proxy server is specified
779-
if (SoftSetBoolArg("-listen", false))
780-
LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
781-
// to protect privacy, do not use UPNP when a proxy is set. The user may still specify -listen=1
782-
// to listen locally, so don't rely on this happening through -listen below.
783-
if (SoftSetBoolArg("-upnp", false))
784-
LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__);
785-
// to protect privacy, do not discover addresses by default
786-
if (SoftSetBoolArg("-discover", false))
787-
LogPrintf("%s: parameter interaction: -proxy set -> setting -discover=0\n", __func__);
788-
}
789-
790-
if (!GetBoolArg("-listen", DEFAULT_LISTEN)) {
791-
// do not map ports or try to retrieve public IP when not listening (pointless)
792-
if (SoftSetBoolArg("-upnp", false))
793-
LogPrintf("%s: parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
794-
if (SoftSetBoolArg("-discover", false))
795-
LogPrintf("%s: parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
796-
if (SoftSetBoolArg("-listenonion", false))
797-
LogPrintf("%s: parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__);
798-
}
799-
800-
if (mapArgs.count("-externalip")) {
801-
// if an explicit public IP is specified, do not try to find others
802-
if (SoftSetBoolArg("-discover", false))
803-
LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
804-
}
805-
806-
if (GetBoolArg("-salvagewallet", false)) {
807-
// Rewrite just private keys: rescan to find transactions
808-
if (SoftSetBoolArg("-rescan", true))
809-
LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
810-
}
811834

812-
// -zapwallettx implies a rescan
813-
if (GetBoolArg("-zapwallettxes", false)) {
814-
if (SoftSetBoolArg("-rescan", true))
815-
LogPrintf("%s: parameter interaction: -zapwallettxes=<mode> -> setting -rescan=1\n", __func__);
816-
}
817835

818836
// if using block pruning, then disable txindex
819837
if (GetArg("-prune", 0)) {

src/init.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ bool ShutdownRequested();
2323
/** Interrupt threads */
2424
void Interrupt(boost::thread_group& threadGroup);
2525
void Shutdown();
26+
//!Initialize the logging infrastructure
27+
void InitLogging();
28+
//!Parameter interaction: change current parameters depending on various rules
29+
void InitParameterInteraction();
2630
bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler);
2731

2832
/** The help message mode determines what help message to show */

src/qt/bitcoin.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ class BitcoinApplication: public QApplication
201201
/// Create payment server
202202
void createPaymentServer();
203203
#endif
204+
/// parameter interaction/setup based on rules
205+
void parameterSetup();
204206
/// Create options model
205207
void createOptionsModel(bool resetSettings);
206208
/// Create main window
@@ -397,6 +399,12 @@ void BitcoinApplication::startThread()
397399
coreThread->start();
398400
}
399401

402+
void BitcoinApplication::parameterSetup()
403+
{
404+
InitLogging();
405+
InitParameterInteraction();
406+
}
407+
400408
void BitcoinApplication::requestInitialize()
401409
{
402410
qDebug() << __func__ << ": Requesting initialize";
@@ -644,6 +652,8 @@ int main(int argc, char *argv[])
644652
// Install qDebug() message handler to route to debug.log
645653
qInstallMessageHandler(DebugMessageHandler);
646654
#endif
655+
// Allow parameter interaction before we create the options model
656+
app.parameterSetup();
647657
// Load GUI settings from QSettings
648658
app.createOptionsModel(mapArgs.count("-resetguisettings") != 0);
649659

0 commit comments

Comments
 (0)