LCOV - code coverage report
Current view: top level - src - init.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 956 1150 83.1 %
Date: 2022-04-21 14:51:19 Functions: 28 32 87.5 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 392 508 77.2 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
#       2                 :            : // Copyright (c) 2009-2021 The Bitcoin Core developers
#       3                 :            : // Distributed under the MIT software license, see the accompanying
#       4                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#       5                 :            : 
#       6                 :            : #if defined(HAVE_CONFIG_H)
#       7                 :            : #include <config/bitcoin-config.h>
#       8                 :            : #endif
#       9                 :            : 
#      10                 :            : #include <init.h>
#      11                 :            : 
#      12                 :            : #include <addrman.h>
#      13                 :            : #include <banman.h>
#      14                 :            : #include <blockfilter.h>
#      15                 :            : #include <chain.h>
#      16                 :            : #include <chainparams.h>
#      17                 :            : #include <compat/sanity.h>
#      18                 :            : #include <consensus/amount.h>
#      19                 :            : #include <deploymentstatus.h>
#      20                 :            : #include <fs.h>
#      21                 :            : #include <hash.h>
#      22                 :            : #include <httprpc.h>
#      23                 :            : #include <httpserver.h>
#      24                 :            : #include <index/blockfilterindex.h>
#      25                 :            : #include <index/coinstatsindex.h>
#      26                 :            : #include <index/txindex.h>
#      27                 :            : #include <init/common.h>
#      28                 :            : #include <interfaces/chain.h>
#      29                 :            : #include <interfaces/init.h>
#      30                 :            : #include <interfaces/node.h>
#      31                 :            : #include <mapport.h>
#      32                 :            : #include <net.h>
#      33                 :            : #include <net_permissions.h>
#      34                 :            : #include <net_processing.h>
#      35                 :            : #include <netbase.h>
#      36                 :            : #include <node/blockstorage.h>
#      37                 :            : #include <node/caches.h>
#      38                 :            : #include <node/chainstate.h>
#      39                 :            : #include <node/context.h>
#      40                 :            : #include <node/miner.h>
#      41                 :            : #include <node/ui_interface.h>
#      42                 :            : #include <policy/feerate.h>
#      43                 :            : #include <policy/fees.h>
#      44                 :            : #include <policy/policy.h>
#      45                 :            : #include <policy/settings.h>
#      46                 :            : #include <protocol.h>
#      47                 :            : #include <rpc/blockchain.h>
#      48                 :            : #include <rpc/register.h>
#      49                 :            : #include <rpc/server.h>
#      50                 :            : #include <rpc/util.h>
#      51                 :            : #include <scheduler.h>
#      52                 :            : #include <script/sigcache.h>
#      53                 :            : #include <script/standard.h>
#      54                 :            : #include <shutdown.h>
#      55                 :            : #include <sync.h>
#      56                 :            : #include <timedata.h>
#      57                 :            : #include <torcontrol.h>
#      58                 :            : #include <txdb.h>
#      59                 :            : #include <txmempool.h>
#      60                 :            : #include <txorphanage.h>
#      61                 :            : #include <util/asmap.h>
#      62                 :            : #include <util/check.h>
#      63                 :            : #include <util/moneystr.h>
#      64                 :            : #include <util/strencodings.h>
#      65                 :            : #include <util/string.h>
#      66                 :            : #include <util/syscall_sandbox.h>
#      67                 :            : #include <util/system.h>
#      68                 :            : #include <util/thread.h>
#      69                 :            : #include <util/threadnames.h>
#      70                 :            : #include <util/translation.h>
#      71                 :            : #include <validation.h>
#      72                 :            : #include <validationinterface.h>
#      73                 :            : #include <walletinitinterface.h>
#      74                 :            : 
#      75                 :            : #include <condition_variable>
#      76                 :            : #include <cstdint>
#      77                 :            : #include <cstdio>
#      78                 :            : #include <fstream>
#      79                 :            : #include <functional>
#      80                 :            : #include <set>
#      81                 :            : #include <string>
#      82                 :            : #include <thread>
#      83                 :            : #include <vector>
#      84                 :            : 
#      85                 :            : #ifndef WIN32
#      86                 :            : #include <attributes.h>
#      87                 :            : #include <cerrno>
#      88                 :            : #include <signal.h>
#      89                 :            : #include <sys/stat.h>
#      90                 :            : #endif
#      91                 :            : 
#      92                 :            : #include <boost/algorithm/string/replace.hpp>
#      93                 :            : #include <boost/signals2/signal.hpp>
#      94                 :            : 
#      95                 :            : #if ENABLE_ZMQ
#      96                 :            : #include <zmq/zmqabstractnotifier.h>
#      97                 :            : #include <zmq/zmqnotificationinterface.h>
#      98                 :            : #include <zmq/zmqrpc.h>
#      99                 :            : #endif
#     100                 :            : 
#     101                 :            : using node::CacheSizes;
#     102                 :            : using node::CalculateCacheSizes;
#     103                 :            : using node::ChainstateLoadVerifyError;
#     104                 :            : using node::ChainstateLoadingError;
#     105                 :            : using node::CleanupBlockRevFiles;
#     106                 :            : using node::DEFAULT_PRINTPRIORITY;
#     107                 :            : using node::DEFAULT_STOPAFTERBLOCKIMPORT;
#     108                 :            : using node::LoadChainstate;
#     109                 :            : using node::NodeContext;
#     110                 :            : using node::ThreadImport;
#     111                 :            : using node::VerifyLoadedChainstate;
#     112                 :            : using node::fHavePruned;
#     113                 :            : using node::fPruneMode;
#     114                 :            : using node::fReindex;
#     115                 :            : using node::nPruneTarget;
#     116                 :            : 
#     117                 :            : static const bool DEFAULT_PROXYRANDOMIZE = true;
#     118                 :            : static const bool DEFAULT_REST_ENABLE = false;
#     119                 :            : 
#     120                 :            : #ifdef WIN32
#     121                 :            : // Win32 LevelDB doesn't use filedescriptors, and the ones used for
#     122                 :            : // accessing block files don't count towards the fd_set size limit
#     123                 :            : // anyway.
#     124                 :            : #define MIN_CORE_FILEDESCRIPTORS 0
#     125                 :            : #else
#     126                 :       6540 : #define MIN_CORE_FILEDESCRIPTORS 150
#     127                 :            : #endif
#     128                 :            : 
#     129                 :            : static const char* DEFAULT_ASMAP_FILENAME="ip_asn.map";
#     130                 :            : 
#     131                 :            : /**
#     132                 :            :  * The PID file facilities.
#     133                 :            :  */
#     134                 :            : static const char* BITCOIN_PID_FILENAME = "bitcoind.pid";
#     135                 :            : 
#     136                 :            : static fs::path GetPidFile(const ArgsManager& args)
#     137                 :       1588 : {
#     138                 :       1588 :     return AbsPathForConfigVal(args.GetPathArg("-pid", BITCOIN_PID_FILENAME));
#     139                 :       1588 : }
#     140                 :            : 
#     141                 :            : [[nodiscard]] static bool CreatePidFile(const ArgsManager& args)
#     142                 :        794 : {
#     143                 :        794 :     std::ofstream file{GetPidFile(args)};
#     144         [ +  - ]:        794 :     if (file) {
#     145                 :            : #ifdef WIN32
#     146                 :            :         tfm::format(file, "%d\n", GetCurrentProcessId());
#     147                 :            : #else
#     148                 :        794 :         tfm::format(file, "%d\n", getpid());
#     149                 :        794 : #endif
#     150                 :        794 :         return true;
#     151                 :        794 :     } else {
#     152                 :          0 :         return InitError(strprintf(_("Unable to create the PID file '%s': %s"), fs::PathToString(GetPidFile(args)), std::strerror(errno)));
#     153                 :          0 :     }
#     154                 :        794 : }
#     155                 :            : 
#     156                 :            : //////////////////////////////////////////////////////////////////////////////
#     157                 :            : //
#     158                 :            : // Shutdown
#     159                 :            : //
#     160                 :            : 
#     161                 :            : //
#     162                 :            : // Thread management and startup/shutdown:
#     163                 :            : //
#     164                 :            : // The network-processing threads are all part of a thread group
#     165                 :            : // created by AppInit() or the Qt main() function.
#     166                 :            : //
#     167                 :            : // A clean exit happens when StartShutdown() or the SIGTERM
#     168                 :            : // signal handler sets ShutdownRequested(), which makes main thread's
#     169                 :            : // WaitForShutdown() interrupts the thread group.
#     170                 :            : // And then, WaitForShutdown() makes all other on-going threads
#     171                 :            : // in the thread group join the main thread.
#     172                 :            : // Shutdown() is then called to clean up database connections, and stop other
#     173                 :            : // threads that should only be stopped after the main network-processing
#     174                 :            : // threads have exited.
#     175                 :            : //
#     176                 :            : // Shutdown for Qt is very similar, only it uses a QTimer to detect
#     177                 :            : // ShutdownRequested() getting set, and then does the normal Qt
#     178                 :            : // shutdown thing.
#     179                 :            : //
#     180                 :            : 
#     181                 :            : void Interrupt(NodeContext& node)
#     182                 :        794 : {
#     183                 :        794 :     InterruptHTTPServer();
#     184                 :        794 :     InterruptHTTPRPC();
#     185                 :        794 :     InterruptRPC();
#     186                 :        794 :     InterruptREST();
#     187                 :        794 :     InterruptTorControl();
#     188                 :        794 :     InterruptMapPort();
#     189         [ +  + ]:        794 :     if (node.connman)
#     190                 :        757 :         node.connman->Interrupt();
#     191         [ +  + ]:        794 :     if (g_txindex) {
#     192                 :         19 :         g_txindex->Interrupt();
#     193                 :         19 :     }
#     194                 :        794 :     ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Interrupt(); });
#     195         [ +  + ]:        794 :     if (g_coin_stats_index) {
#     196                 :         13 :         g_coin_stats_index->Interrupt();
#     197                 :         13 :     }
#     198                 :        794 : }
#     199                 :            : 
#     200                 :            : void Shutdown(NodeContext& node)
#     201                 :        794 : {
#     202                 :        794 :     static Mutex g_shutdown_mutex;
#     203                 :        794 :     TRY_LOCK(g_shutdown_mutex, lock_shutdown);
#     204         [ -  + ]:        794 :     if (!lock_shutdown) return;
#     205                 :        794 :     LogPrintf("%s: In progress...\n", __func__);
#     206                 :        794 :     Assert(node.args);
#     207                 :            : 
#     208                 :            :     /// Note: Shutdown() must be able to handle cases in which initialization failed part of the way,
#     209                 :            :     /// for example if the data directory was found to be locked.
#     210                 :            :     /// Be sure that anything that writes files or flushes caches only does this if the respective
#     211                 :            :     /// module was initialized.
#     212                 :        794 :     util::ThreadRename("shutoff");
#     213         [ +  + ]:        794 :     if (node.mempool) node.mempool->AddTransactionsUpdated(1);
#     214                 :            : 
#     215                 :        794 :     StopHTTPRPC();
#     216                 :        794 :     StopREST();
#     217                 :        794 :     StopRPC();
#     218                 :        794 :     StopHTTPServer();
#     219         [ +  + ]:        794 :     for (const auto& client : node.chain_clients) {
#     220                 :        788 :         client->flush();
#     221                 :        788 :     }
#     222                 :        794 :     StopMapPort();
#     223                 :            : 
#     224                 :            :     // Because these depend on each-other, we make sure that neither can be
#     225                 :            :     // using the other before destroying them.
#     226         [ +  + ]:        794 :     if (node.peerman) UnregisterValidationInterface(node.peerman.get());
#     227         [ +  + ]:        794 :     if (node.connman) node.connman->Stop();
#     228                 :            : 
#     229                 :        794 :     StopTorControl();
#     230                 :            : 
#     231                 :            :     // After everything has been shut down, but before things get flushed, stop the
#     232                 :            :     // CScheduler/checkqueue, scheduler and load block thread.
#     233         [ +  + ]:        794 :     if (node.scheduler) node.scheduler->stop();
#     234 [ +  + ][ +  + ]:        794 :     if (node.chainman && node.chainman->m_load_block.joinable()) node.chainman->m_load_block.join();
#     235                 :        794 :     StopScriptCheckWorkerThreads();
#     236                 :            : 
#     237                 :            :     // After the threads that potentially access these pointers have been stopped,
#     238                 :            :     // destruct and reset all to nullptr.
#     239                 :        794 :     node.peerman.reset();
#     240                 :        794 :     node.connman.reset();
#     241                 :        794 :     node.banman.reset();
#     242                 :        794 :     node.addrman.reset();
#     243                 :            : 
#     244 [ +  + ][ +  + ]:        794 :     if (node.mempool && node.mempool->IsLoaded() && node.args->GetBoolArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
#         [ +  + ][ +  + ]
#     245                 :        715 :         DumpMempool(*node.mempool);
#     246                 :        715 :     }
#     247                 :            : 
#     248                 :            :     // Drop transactions we were still watching, and record fee estimations.
#     249         [ +  + ]:        794 :     if (node.fee_estimator) node.fee_estimator->Flush();
#     250                 :            : 
#     251                 :            :     // FlushStateToDisk generates a ChainStateFlushed callback, which we should avoid missing
#     252         [ +  + ]:        794 :     if (node.chainman) {
#     253                 :        757 :         LOCK(cs_main);
#     254         [ +  + ]:        757 :         for (CChainState* chainstate : node.chainman->GetAll()) {
#     255         [ +  + ]:        739 :             if (chainstate->CanFlushToDisk()) {
#     256                 :        733 :                 chainstate->ForceFlushStateToDisk();
#     257                 :        733 :             }
#     258                 :        739 :         }
#     259                 :        757 :     }
#     260                 :            : 
#     261                 :            :     // After there are no more peers/RPC left to give us new data which may generate
#     262                 :            :     // CValidationInterface callbacks, flush them...
#     263                 :        794 :     GetMainSignals().FlushBackgroundCallbacks();
#     264                 :            : 
#     265                 :            :     // Stop and delete all indexes only after flushing background callbacks.
#     266         [ +  + ]:        794 :     if (g_txindex) {
#     267                 :         19 :         g_txindex->Stop();
#     268                 :         19 :         g_txindex.reset();
#     269                 :         19 :     }
#     270         [ +  + ]:        794 :     if (g_coin_stats_index) {
#     271                 :         13 :         g_coin_stats_index->Stop();
#     272                 :         13 :         g_coin_stats_index.reset();
#     273                 :         13 :     }
#     274                 :        794 :     ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); });
#     275                 :        794 :     DestroyAllBlockFilterIndexes();
#     276                 :            : 
#     277                 :            :     // Any future callbacks will be dropped. This should absolutely be safe - if
#     278                 :            :     // missing a callback results in an unrecoverable situation, unclean shutdown
#     279                 :            :     // would too. The only reason to do the above flushes is to let the wallet catch
#     280                 :            :     // up with our current chain to avoid any strange pruning edge cases and make
#     281                 :            :     // next startup faster by avoiding rescan.
#     282                 :            : 
#     283         [ +  + ]:        794 :     if (node.chainman) {
#     284                 :        757 :         LOCK(cs_main);
#     285         [ +  + ]:        757 :         for (CChainState* chainstate : node.chainman->GetAll()) {
#     286         [ +  + ]:        739 :             if (chainstate->CanFlushToDisk()) {
#     287                 :        733 :                 chainstate->ForceFlushStateToDisk();
#     288                 :        733 :                 chainstate->ResetCoinsViews();
#     289                 :        733 :             }
#     290                 :        739 :         }
#     291                 :        757 :     }
#     292         [ +  + ]:        794 :     for (const auto& client : node.chain_clients) {
#     293                 :        788 :         client->stop();
#     294                 :        788 :     }
#     295                 :            : 
#     296                 :            : #if ENABLE_ZMQ
#     297                 :            :     if (g_zmq_notification_interface) {
#     298                 :            :         UnregisterValidationInterface(g_zmq_notification_interface);
#     299                 :            :         delete g_zmq_notification_interface;
#     300                 :            :         g_zmq_notification_interface = nullptr;
#     301                 :            :     }
#     302                 :            : #endif
#     303                 :            : 
#     304                 :        794 :     node.chain_clients.clear();
#     305                 :        794 :     UnregisterAllValidationInterfaces();
#     306                 :        794 :     GetMainSignals().UnregisterBackgroundSignalScheduler();
#     307                 :        794 :     init::UnsetGlobals();
#     308                 :        794 :     node.mempool.reset();
#     309                 :        794 :     node.fee_estimator.reset();
#     310                 :        794 :     node.chainman.reset();
#     311                 :        794 :     node.scheduler.reset();
#     312                 :            : 
#     313                 :        794 :     try {
#     314         [ -  + ]:        794 :         if (!fs::remove(GetPidFile(*node.args))) {
#     315                 :          0 :             LogPrintf("%s: Unable to remove PID file: File does not exist\n", __func__);
#     316                 :          0 :         }
#     317                 :        794 :     } catch (const fs::filesystem_error& e) {
#     318                 :          0 :         LogPrintf("%s: Unable to remove PID file: %s\n", __func__, fsbridge::get_filesystem_error_message(e));
#     319                 :          0 :     }
#     320                 :            : 
#     321                 :        794 :     LogPrintf("%s: done\n", __func__);
#     322                 :        794 : }
#     323                 :            : 
#     324                 :            : /**
#     325                 :            :  * Signal handlers are very limited in what they are allowed to do.
#     326                 :            :  * The execution context the handler is invoked in is not guaranteed,
#     327                 :            :  * so we restrict handler operations to just touching variables:
#     328                 :            :  */
#     329                 :            : #ifndef WIN32
#     330                 :            : static void HandleSIGTERM(int)
#     331                 :         21 : {
#     332                 :         21 :     StartShutdown();
#     333                 :         21 : }
#     334                 :            : 
#     335                 :            : static void HandleSIGHUP(int)
#     336                 :          0 : {
#     337                 :          0 :     LogInstance().m_reopen_file = true;
#     338                 :          0 : }
#     339                 :            : #else
#     340                 :            : static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType)
#     341                 :            : {
#     342                 :            :     StartShutdown();
#     343                 :            :     Sleep(INFINITE);
#     344                 :            :     return true;
#     345                 :            : }
#     346                 :            : #endif
#     347                 :            : 
#     348                 :            : #ifndef WIN32
#     349                 :            : static void registerSignalHandler(int signal, void(*handler)(int))
#     350                 :       2406 : {
#     351                 :       2406 :     struct sigaction sa;
#     352                 :       2406 :     sa.sa_handler = handler;
#     353                 :       2406 :     sigemptyset(&sa.sa_mask);
#     354                 :       2406 :     sa.sa_flags = 0;
#     355                 :       2406 :     sigaction(signal, &sa, nullptr);
#     356                 :       2406 : }
#     357                 :            : #endif
#     358                 :            : 
#     359                 :            : static boost::signals2::connection rpc_notify_block_change_connection;
#     360                 :            : static void OnRPCStarted()
#     361                 :        789 : {
#     362                 :        789 :     rpc_notify_block_change_connection = uiInterface.NotifyBlockTip_connect(std::bind(RPCNotifyBlockChange, std::placeholders::_2));
#     363                 :        789 : }
#     364                 :            : 
#     365                 :            : static void OnRPCStopped()
#     366                 :        789 : {
#     367                 :        789 :     rpc_notify_block_change_connection.disconnect();
#     368                 :        789 :     RPCNotifyBlockChange(nullptr);
#     369                 :        789 :     g_best_block_cv.notify_all();
#     370         [ +  - ]:        789 :     LogPrint(BCLog::RPC, "RPC stopped.\n");
#     371                 :        789 : }
#     372                 :            : 
#     373                 :            : void SetupServerArgs(ArgsManager& argsman)
#     374                 :       1662 : {
#     375                 :       1662 :     SetupHelpOptions(argsman);
#     376                 :       1662 :     argsman.AddArg("-help-debug", "Print help message with debugging options and exit", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); // server-only for now
#     377                 :            : 
#     378                 :       1662 :     init::AddLoggingArgs(argsman);
#     379                 :            : 
#     380                 :       1662 :     const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
#     381                 :       1662 :     const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
#     382                 :       1662 :     const auto signetBaseParams = CreateBaseChainParams(CBaseChainParams::SIGNET);
#     383                 :       1662 :     const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST);
#     384                 :       1662 :     const auto defaultChainParams = CreateChainParams(argsman, CBaseChainParams::MAIN);
#     385                 :       1662 :     const auto testnetChainParams = CreateChainParams(argsman, CBaseChainParams::TESTNET);
#     386                 :       1662 :     const auto signetChainParams = CreateChainParams(argsman, CBaseChainParams::SIGNET);
#     387                 :       1662 :     const auto regtestChainParams = CreateChainParams(argsman, CBaseChainParams::REGTEST);
#     388                 :            : 
#     389                 :            :     // Hidden Options
#     390                 :       1662 :     std::vector<std::string> hidden_args = {
#     391                 :       1662 :         "-dbcrashratio", "-forcecompactdb",
#     392                 :            :         // GUI args. These will be overwritten by SetupUIArgs for the GUI
#     393                 :       1662 :         "-choosedatadir", "-lang=<lang>", "-min", "-resetguisettings", "-splash", "-uiplatform"};
#     394                 :            : 
#     395                 :       1662 :     argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     396                 :       1662 : #if HAVE_SYSTEM
#     397                 :       1662 :     argsman.AddArg("-alertnotify=<cmd>", "Execute command when an alert is raised (%s in cmd is replaced by message)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     398                 :       1662 : #endif
#     399                 :       1662 :     argsman.AddArg("-assumevalid=<hex>", strprintf("If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: %s, testnet: %s, signet: %s)", defaultChainParams->GetConsensus().defaultAssumeValid.GetHex(), testnetChainParams->GetConsensus().defaultAssumeValid.GetHex(), signetChainParams->GetConsensus().defaultAssumeValid.GetHex()), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     400                 :       1662 :     argsman.AddArg("-blocksdir=<dir>", "Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     401                 :       1662 :     argsman.AddArg("-fastprune", "Use smaller block files and lower minimum prune height for testing purposes", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     402                 :       1662 : #if HAVE_SYSTEM
#     403                 :       1662 :     argsman.AddArg("-blocknotify=<cmd>", "Execute command when the best block changes (%s in cmd is replaced by block hash)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     404                 :       1662 : #endif
#     405                 :       1662 :     argsman.AddArg("-blockreconstructionextratxn=<n>", strprintf("Extra transactions to keep in memory for compact block reconstructions (default: %u)", DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     406                 :       1662 :     argsman.AddArg("-blocksonly", strprintf("Whether to reject transactions from network peers. Automatic broadcast and rebroadcast of any transactions from inbound peers is disabled, unless the peer has the 'forcerelay' permission. RPC transactions are not affected. (default: %u)", DEFAULT_BLOCKSONLY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     407                 :       1662 :     argsman.AddArg("-coinstatsindex", strprintf("Maintain coinstats index used by the gettxoutsetinfo RPC (default: %u)", DEFAULT_COINSTATSINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     408                 :       1662 :     argsman.AddArg("-conf=<file>", strprintf("Specify path to read-only configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     409                 :       1662 :     argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     410                 :       1662 :     argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
#     411                 :       1662 :     argsman.AddArg("-dbcache=<n>", strprintf("Maximum database cache size <n> MiB (%d to %d, default: %d). In addition, unused mempool memory is shared for this cache (see -maxmempool).", nMinDbCache, nMaxDbCache, nDefaultDbCache), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     412                 :       1662 :     argsman.AddArg("-includeconf=<file>", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     413                 :       1662 :     argsman.AddArg("-loadblock=<file>", "Imports blocks from external file on startup", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     414                 :       1662 :     argsman.AddArg("-maxmempool=<n>", strprintf("Keep the transaction memory pool below <n> megabytes (default: %u)", DEFAULT_MAX_MEMPOOL_SIZE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     415                 :       1662 :     argsman.AddArg("-maxorphantx=<n>", strprintf("Keep at most <n> unconnectable transactions in memory (default: %u)", DEFAULT_MAX_ORPHAN_TRANSACTIONS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     416                 :       1662 :     argsman.AddArg("-mempoolexpiry=<n>", strprintf("Do not keep transactions in the mempool longer than <n> hours (default: %u)", DEFAULT_MEMPOOL_EXPIRY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     417                 :       1662 :     argsman.AddArg("-minimumchainwork=<hex>", strprintf("Minimum work assumed to exist on a valid chain in hex (default: %s, testnet: %s, signet: %s)", defaultChainParams->GetConsensus().nMinimumChainWork.GetHex(), testnetChainParams->GetConsensus().nMinimumChainWork.GetHex(), signetChainParams->GetConsensus().nMinimumChainWork.GetHex()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
#     418                 :       1662 :     argsman.AddArg("-par=<n>", strprintf("Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)",
#     419                 :       1662 :         -GetNumCores(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     420                 :       1662 :     argsman.AddArg("-persistmempool", strprintf("Whether to save the mempool on shutdown and load on restart (default: %u)", DEFAULT_PERSIST_MEMPOOL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     421                 :       1662 :     argsman.AddArg("-pid=<file>", strprintf("Specify pid file. Relative paths will be prefixed by a net-specific datadir location. (default: %s)", BITCOIN_PID_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     422                 :       1662 :     argsman.AddArg("-prune=<n>", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks, and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex and -coinstatsindex. "
#     423                 :       1662 :             "Warning: Reverting this setting requires re-downloading the entire blockchain. "
#     424                 :       1662 :             "(default: 0 = disable pruning blocks, 1 = allow manual pruning via RPC, >=%u = automatically prune block files to stay under the specified target size in MiB)", MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     425                 :       1662 :     argsman.AddArg("-reindex", "Rebuild chain state and block index from the blk*.dat files on disk", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     426                 :       1662 :     argsman.AddArg("-reindex-chainstate", "Rebuild chain state from the currently indexed blocks. When in pruning mode or if blocks on disk might be corrupted, use full -reindex instead.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     427                 :       1662 :     argsman.AddArg("-settings=<file>", strprintf("Specify path to dynamic settings data file. Can be disabled with -nosettings. File is written at runtime and not meant to be edited by users (use %s instead for custom settings). Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME, BITCOIN_SETTINGS_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     428                 :       1662 : #if HAVE_SYSTEM
#     429                 :       1662 :     argsman.AddArg("-startupnotify=<cmd>", "Execute command on startup.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     430                 :       1662 : #endif
#     431                 :       1662 : #ifndef WIN32
#     432                 :       1662 :     argsman.AddArg("-sysperms", "Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     433                 :            : #else
#     434                 :            :     hidden_args.emplace_back("-sysperms");
#     435                 :            : #endif
#     436                 :       1662 :     argsman.AddArg("-txindex", strprintf("Maintain a full transaction index, used by the getrawtransaction rpc call (default: %u)", DEFAULT_TXINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     437                 :       1662 :     argsman.AddArg("-blockfilterindex=<type>",
#     438                 :       1662 :                  strprintf("Maintain an index of compact filters by block (default: %s, values: %s).", DEFAULT_BLOCKFILTERINDEX, ListBlockFilterTypes()) +
#     439                 :       1662 :                  " If <type> is not supplied or if <type> = 1, indexes for all known types are enabled.",
#     440                 :       1662 :                  ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     441                 :            : 
#     442                 :       1662 :     argsman.AddArg("-addnode=<ip>", strprintf("Add a node to connect to and attempt to keep the connection open (see the addnode RPC help for more info). This option can be specified multiple times to add multiple nodes; connections are limited to %u at a time and are counted separately from the -maxconnections limit.", MAX_ADDNODE_CONNECTIONS), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::CONNECTION);
#     443                 :       1662 :     argsman.AddArg("-asmap=<file>", strprintf("Specify asn mapping used for bucketing of the peers (default: %s). Relative paths will be prefixed by the net-specific datadir location.", DEFAULT_ASMAP_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     444                 :       1662 :     argsman.AddArg("-bantime=<n>", strprintf("Default duration (in seconds) of manually configured bans (default: %u)", DEFAULT_MISBEHAVING_BANTIME), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     445                 :       1662 :     argsman.AddArg("-bind=<addr>[:<port>][=onion]", strprintf("Bind to given address and always listen on it (default: 0.0.0.0). Use [host]:port notation for IPv6. Append =onion to tag any incoming connections to that address and port as incoming Tor connections (default: 127.0.0.1:%u=onion, testnet: 127.0.0.1:%u=onion, signet: 127.0.0.1:%u=onion, regtest: 127.0.0.1:%u=onion)", defaultBaseParams->OnionServiceTargetPort(), testnetBaseParams->OnionServiceTargetPort(), signetBaseParams->OnionServiceTargetPort(), regtestBaseParams->OnionServiceTargetPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::CONNECTION);
#     446                 :       1662 :     argsman.AddArg("-cjdnsreachable", "If set, then this host is configured for CJDNS (connecting to fc00::/8 addresses would lead us to the CJDNS network, see doc/cjdns.md) (default: 0)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     447                 :       1662 :     argsman.AddArg("-connect=<ip>", "Connect only to the specified node; -noconnect disables automatic connections (the rules for this peer are the same as for -addnode). This option can be specified multiple times to connect to multiple nodes.", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::CONNECTION);
#     448                 :       1662 :     argsman.AddArg("-discover", "Discover own IP addresses (default: 1 when listening and no -externalip or -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     449                 :       1662 :     argsman.AddArg("-dns", strprintf("Allow DNS lookups for -addnode, -seednode and -connect (default: %u)", DEFAULT_NAME_LOOKUP), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     450                 :       1662 :     argsman.AddArg("-dnsseed", strprintf("Query for peer addresses via DNS lookup, if low on addresses (default: %u unless -connect used)", DEFAULT_DNSSEED), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     451                 :       1662 :     argsman.AddArg("-externalip=<ip>", "Specify your own public address", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     452                 :       1662 :     argsman.AddArg("-fixedseeds", strprintf("Allow fixed seeds if DNS seeds don't provide peers (default: %u)", DEFAULT_FIXEDSEEDS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     453                 :       1662 :     argsman.AddArg("-forcednsseed", strprintf("Always query for peer addresses via DNS lookup (default: %u)", DEFAULT_FORCEDNSSEED), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     454                 :       1662 :     argsman.AddArg("-listen", "Accept connections from outside (default: 1 if no -proxy or -connect)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     455                 :       1662 :     argsman.AddArg("-listenonion", strprintf("Automatically create Tor onion service (default: %d)", DEFAULT_LISTEN_ONION), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     456                 :       1662 :     argsman.AddArg("-maxconnections=<n>", strprintf("Maintain at most <n> connections to peers (default: %u). This limit does not apply to connections manually added via -addnode or the addnode RPC, which have a separate limit of %u.", DEFAULT_MAX_PEER_CONNECTIONS, MAX_ADDNODE_CONNECTIONS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     457                 :       1662 :     argsman.AddArg("-maxreceivebuffer=<n>", strprintf("Maximum per-connection receive buffer, <n>*1000 bytes (default: %u)", DEFAULT_MAXRECEIVEBUFFER), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     458                 :       1662 :     argsman.AddArg("-maxsendbuffer=<n>", strprintf("Maximum per-connection send buffer, <n>*1000 bytes (default: %u)", DEFAULT_MAXSENDBUFFER), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     459                 :       1662 :     argsman.AddArg("-maxtimeadjustment", strprintf("Maximum allowed median peer time offset adjustment. Local perspective of time may be influenced by outbound peers forward or backward by this amount (default: %u seconds).", DEFAULT_MAX_TIME_ADJUSTMENT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     460                 :       1662 :     argsman.AddArg("-maxuploadtarget=<n>", strprintf("Tries to keep outbound traffic under the given target per 24h. Limit does not apply to peers with 'download' permission or blocks created within past week. 0 = no limit (default: %s). Optional suffix units [k|K|m|M|g|G|t|T] (default: M). Lowercase is 1000 base while uppercase is 1024 base", DEFAULT_MAX_UPLOAD_TARGET), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     461                 :       1662 :     argsman.AddArg("-onion=<ip:port>", "Use separate SOCKS5 proxy to reach peers via Tor onion services, set -noonion to disable (default: -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     462                 :       1662 :     argsman.AddArg("-i2psam=<ip:port>", "I2P SAM proxy to reach I2P peers and accept I2P connections (default: none)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     463                 :       1662 :     argsman.AddArg("-i2pacceptincoming", "If set and -i2psam is also set then incoming I2P connections are accepted via the SAM proxy. If this is not set but -i2psam is set then only outgoing connections will be made to the I2P network. Ignored if -i2psam is not set. Listening for incoming I2P connections is done through the SAM proxy, not by binding to a local address and port (default: 1)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     464                 :       1662 :     argsman.AddArg("-onlynet=<net>", "Make automatic outbound connections only to network <net> (" + Join(GetNetworkNames(), ", ") + "). Inbound and manual connections are not affected by this option. It can be specified multiple times to allow multiple networks.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     465                 :       1662 :     argsman.AddArg("-peerbloomfilters", strprintf("Support filtering of blocks and transaction with bloom filters (default: %u)", DEFAULT_PEERBLOOMFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     466                 :       1662 :     argsman.AddArg("-peerblockfilters", strprintf("Serve compact block filters to peers per BIP 157 (default: %u)", DEFAULT_PEERBLOCKFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     467                 :       1662 :     argsman.AddArg("-permitbaremultisig", strprintf("Relay non-P2SH multisig (default: %u)", DEFAULT_PERMIT_BAREMULTISIG), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     468                 :            :     // TODO: remove the sentence "Nodes not using ... incoming connections." once the changes from
#     469                 :            :     // https://github.com/bitcoin/bitcoin/pull/23542 have become widespread.
#     470                 :       1662 :     argsman.AddArg("-port=<port>", strprintf("Listen for connections on <port>. Nodes not using the default ports (default: %u, testnet: %u, signet: %u, regtest: %u) are unlikely to get incoming connections. Not relevant for I2P (see doc/i2p.md).", defaultChainParams->GetDefaultPort(), testnetChainParams->GetDefaultPort(), signetChainParams->GetDefaultPort(), regtestChainParams->GetDefaultPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::CONNECTION);
#     471                 :       1662 :     argsman.AddArg("-proxy=<ip:port>", "Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     472                 :       1662 :     argsman.AddArg("-proxyrandomize", strprintf("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)", DEFAULT_PROXYRANDOMIZE), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     473                 :       1662 :     argsman.AddArg("-seednode=<ip>", "Connect to a node to retrieve peer addresses, and disconnect. This option can be specified multiple times to connect to multiple nodes.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     474                 :       1662 :     argsman.AddArg("-networkactive", "Enable all P2P network activity (default: 1). Can be changed by the setnetworkactive RPC command", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     475                 :       1662 :     argsman.AddArg("-timeout=<n>", strprintf("Specify socket connection timeout in milliseconds. If an initial attempt to connect is unsuccessful after this amount of time, drop it (minimum: 1, default: %d)", DEFAULT_CONNECT_TIMEOUT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     476                 :       1662 :     argsman.AddArg("-peertimeout=<n>", strprintf("Specify a p2p connection timeout delay in seconds. After connecting to a peer, wait this amount of time before considering disconnection based on inactivity (minimum: 1, default: %d)", DEFAULT_PEER_CONNECT_TIMEOUT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CONNECTION);
#     477                 :       1662 :     argsman.AddArg("-torcontrol=<ip>:<port>", strprintf("Tor control port to use if onion listening enabled (default: %s)", DEFAULT_TOR_CONTROL), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     478                 :       1662 :     argsman.AddArg("-torpassword=<pass>", "Tor control port password (default: empty)", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::CONNECTION);
#     479                 :       1662 : #ifdef USE_UPNP
#     480                 :            : #if USE_UPNP
#     481                 :            :     argsman.AddArg("-upnp", "Use UPnP to map the listening port (default: 1 when listening and no -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     482                 :            : #else
#     483                 :       1662 :     argsman.AddArg("-upnp", strprintf("Use UPnP to map the listening port (default: %u)", 0), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     484                 :       1662 : #endif
#     485                 :            : #else
#     486                 :            :     hidden_args.emplace_back("-upnp");
#     487                 :            : #endif
#     488                 :       1662 : #ifdef USE_NATPMP
#     489                 :       1662 :     argsman.AddArg("-natpmp", strprintf("Use NAT-PMP to map the listening port (default: %s)", DEFAULT_NATPMP ? "1 when listening and no -proxy" : "0"), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     490                 :            : #else
#     491                 :            :     hidden_args.emplace_back("-natpmp");
#     492                 :            : #endif // USE_NATPMP
#     493                 :       1662 :     argsman.AddArg("-whitebind=<[permissions@]addr>", "Bind to the given address and add permission flags to the peers connecting to it. "
#     494                 :       1662 :         "Use [host]:port notation for IPv6. Allowed permissions: " + Join(NET_PERMISSIONS_DOC, ", ") + ". "
#     495                 :       1662 :         "Specify multiple permissions separated by commas (default: download,noban,mempool,relay). Can be specified multiple times.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     496                 :            : 
#     497                 :       1662 :     argsman.AddArg("-whitelist=<[permissions@]IP address or network>", "Add permission flags to the peers connecting from the given IP address (e.g. 1.2.3.4) or "
#     498                 :       1662 :         "CIDR-notated network (e.g. 1.2.3.0/24). Uses the same permissions as "
#     499                 :       1662 :         "-whitebind. Can be specified multiple times." , ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#     500                 :            : 
#     501                 :       1662 :     g_wallet_init_interface.AddWalletOptions(argsman);
#     502                 :            : 
#     503                 :            : #if ENABLE_ZMQ
#     504                 :            :     argsman.AddArg("-zmqpubhashblock=<address>", "Enable publish hash block in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
#     505                 :            :     argsman.AddArg("-zmqpubhashtx=<address>", "Enable publish hash transaction in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
#     506                 :            :     argsman.AddArg("-zmqpubrawblock=<address>", "Enable publish raw block in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
#     507                 :            :     argsman.AddArg("-zmqpubrawtx=<address>", "Enable publish raw transaction in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
#     508                 :            :     argsman.AddArg("-zmqpubsequence=<address>", "Enable publish hash block and tx sequence in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
#     509                 :            :     argsman.AddArg("-zmqpubhashblockhwm=<n>", strprintf("Set publish hash block outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
#     510                 :            :     argsman.AddArg("-zmqpubhashtxhwm=<n>", strprintf("Set publish hash transaction outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
#     511                 :            :     argsman.AddArg("-zmqpubrawblockhwm=<n>", strprintf("Set publish raw block outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
#     512                 :            :     argsman.AddArg("-zmqpubrawtxhwm=<n>", strprintf("Set publish raw transaction outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
#     513                 :            :     argsman.AddArg("-zmqpubsequencehwm=<n>", strprintf("Set publish hash sequence message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
#     514                 :            : #else
#     515                 :       1662 :     hidden_args.emplace_back("-zmqpubhashblock=<address>");
#     516                 :       1662 :     hidden_args.emplace_back("-zmqpubhashtx=<address>");
#     517                 :       1662 :     hidden_args.emplace_back("-zmqpubrawblock=<address>");
#     518                 :       1662 :     hidden_args.emplace_back("-zmqpubrawtx=<address>");
#     519                 :       1662 :     hidden_args.emplace_back("-zmqpubsequence=<n>");
#     520                 :       1662 :     hidden_args.emplace_back("-zmqpubhashblockhwm=<n>");
#     521                 :       1662 :     hidden_args.emplace_back("-zmqpubhashtxhwm=<n>");
#     522                 :       1662 :     hidden_args.emplace_back("-zmqpubrawblockhwm=<n>");
#     523                 :       1662 :     hidden_args.emplace_back("-zmqpubrawtxhwm=<n>");
#     524                 :       1662 :     hidden_args.emplace_back("-zmqpubsequencehwm=<n>");
#     525                 :       1662 : #endif
#     526                 :            : 
#     527                 :       1662 :     argsman.AddArg("-checkblocks=<n>", strprintf("How many blocks to check at startup (default: %u, 0 = all)", DEFAULT_CHECKBLOCKS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     528                 :       1662 :     argsman.AddArg("-checklevel=<n>", strprintf("How thorough the block verification of -checkblocks is: %s (0-4, default: %u)", Join(CHECKLEVEL_DOC, ", "), DEFAULT_CHECKLEVEL), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     529                 :       1662 :     argsman.AddArg("-checkblockindex", strprintf("Do a consistency check for the block tree, chainstate, and other validation data structures occasionally. (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     530                 :       1662 :     argsman.AddArg("-checkaddrman=<n>", strprintf("Run addrman consistency checks every <n> operations. Use 0 to disable. (default: %u)", DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     531                 :       1662 :     argsman.AddArg("-checkmempool=<n>", strprintf("Run mempool consistency checks every <n> transactions. Use 0 to disable. (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     532                 :       1662 :     argsman.AddArg("-checkpoints", strprintf("Enable rejection of any forks from the known historical chain until block %s (default: %u)", defaultChainParams->Checkpoints().GetHeight(), DEFAULT_CHECKPOINTS_ENABLED), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     533                 :       1662 :     argsman.AddArg("-deprecatedrpc=<method>", "Allows deprecated RPC method(s) to be used", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     534                 :       1662 :     argsman.AddArg("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", DEFAULT_STOPAFTERBLOCKIMPORT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     535                 :       1662 :     argsman.AddArg("-stopatheight", strprintf("Stop running after reaching the given height in the main chain (default: %u)", DEFAULT_STOPATHEIGHT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     536                 :       1662 :     argsman.AddArg("-limitancestorcount=<n>", strprintf("Do not accept transactions if number of in-mempool ancestors is <n> or more (default: %u)", DEFAULT_ANCESTOR_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     537                 :       1662 :     argsman.AddArg("-limitancestorsize=<n>", strprintf("Do not accept transactions whose size with all in-mempool ancestors exceeds <n> kilobytes (default: %u)", DEFAULT_ANCESTOR_SIZE_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     538                 :       1662 :     argsman.AddArg("-limitdescendantcount=<n>", strprintf("Do not accept transactions if any ancestor would have <n> or more in-mempool descendants (default: %u)", DEFAULT_DESCENDANT_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     539                 :       1662 :     argsman.AddArg("-limitdescendantsize=<n>", strprintf("Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     540                 :       1662 :     argsman.AddArg("-addrmantest", "Allows to test address relay on localhost", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     541                 :       1662 :     argsman.AddArg("-capturemessages", "Capture all P2P messages to disk", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     542                 :       1662 :     argsman.AddArg("-mocktime=<n>", "Replace actual time with " + UNIX_EPOCH_TIME + " (default: 0)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     543                 :       1662 :     argsman.AddArg("-maxsigcachesize=<n>", strprintf("Limit sum of signature cache and script execution cache sizes to <n> MiB (default: %u)", DEFAULT_MAX_SIG_CACHE_SIZE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     544                 :       1662 :     argsman.AddArg("-maxtipage=<n>", strprintf("Maximum tip age in seconds to consider node in initial block download (default: %u)", DEFAULT_MAX_TIP_AGE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     545                 :       1662 :     argsman.AddArg("-printpriority", strprintf("Log transaction fee rate in " + CURRENCY_UNIT + "/kvB when mining blocks (default: %u)", DEFAULT_PRINTPRIORITY), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
#     546                 :       1662 :     argsman.AddArg("-uacomment=<cmt>", "Append comment to the user agent string", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
#     547                 :            : 
#     548                 :       1662 :     SetupChainParamsBaseOptions(argsman);
#     549                 :            : 
#     550                 :       1662 :     argsman.AddArg("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", !testnetChainParams->RequireStandard()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::NODE_RELAY);
#     551                 :       1662 :     argsman.AddArg("-incrementalrelayfee=<amt>", strprintf("Fee rate (in %s/kvB) used to define cost of relay, used for mempool limiting and BIP 125 replacement. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_INCREMENTAL_RELAY_FEE)), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::NODE_RELAY);
#     552                 :       1662 :     argsman.AddArg("-dustrelayfee=<amt>", strprintf("Fee rate (in %s/kvB) used to define dust, the value of an output such that it will cost more than its value in fees at this fee rate to spend it. (default: %s)", CURRENCY_UNIT, FormatMoney(DUST_RELAY_TX_FEE)), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::NODE_RELAY);
#     553                 :       1662 :     argsman.AddArg("-bytespersigop", strprintf("Equivalent bytes per sigop in transactions for relay and mining (default: %u)", DEFAULT_BYTES_PER_SIGOP), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
#     554                 :       1662 :     argsman.AddArg("-datacarrier", strprintf("Relay and mine data carrier transactions (default: %u)", DEFAULT_ACCEPT_DATACARRIER), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
#     555                 :       1662 :     argsman.AddArg("-datacarriersize", strprintf("Maximum size of data in data carrier transactions we relay and mine (default: %u)", MAX_OP_RETURN_RELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
#     556                 :       1662 :     argsman.AddArg("-minrelaytxfee=<amt>", strprintf("Fees (in %s/kvB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s)",
#     557                 :       1662 :         CURRENCY_UNIT, FormatMoney(DEFAULT_MIN_RELAY_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
#     558                 :       1662 :     argsman.AddArg("-whitelistforcerelay", strprintf("Add 'forcerelay' permission to whitelisted inbound peers with default permissions. This will relay transactions even if the transactions were already in the mempool. (default: %d)", DEFAULT_WHITELISTFORCERELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
#     559                 :       1662 :     argsman.AddArg("-whitelistrelay", strprintf("Add 'relay' permission to whitelisted inbound peers with default permissions. This will accept relayed transactions even when not relaying transactions (default: %d)", DEFAULT_WHITELISTRELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
#     560                 :            : 
#     561                 :            : 
#     562                 :       1662 :     argsman.AddArg("-blockmaxweight=<n>", strprintf("Set maximum BIP141 block weight (default: %d)", DEFAULT_BLOCK_MAX_WEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
#     563                 :       1662 :     argsman.AddArg("-blockmintxfee=<amt>", strprintf("Set lowest fee rate (in %s/kvB) for transactions to be included in block creation. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_BLOCK_MIN_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
#     564                 :       1662 :     argsman.AddArg("-blockversion=<n>", "Override block version to test forking scenarios", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::BLOCK_CREATION);
#     565                 :            : 
#     566                 :       1662 :     argsman.AddArg("-rest", strprintf("Accept public REST requests (default: %u)", DEFAULT_REST_ENABLE), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
#     567                 :       1662 :     argsman.AddArg("-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", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
#     568                 :       1662 :     argsman.AddArg("-rpcauth=<userpw>", "Username and HMAC-SHA-256 hashed password for JSON-RPC connections. The field <userpw> comes in the format: <USERNAME>:<SALT>$<HASH>. A canonical python script is included in share/rpcauth. The client then connects normally using the rpcuser=<USERNAME>/rpcpassword=<PASSWORD> pair of arguments. This option can be specified multiple times", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
#     569                 :       1662 :     argsman.AddArg("-rpcbind=<addr>[:port]", "Bind to given address to listen for JSON-RPC connections. Do not expose the RPC server to untrusted networks such as the public internet! This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
#     570                 :       1662 :     argsman.AddArg("-rpccookiefile=<loc>", "Location of the auth cookie. Relative paths will be prefixed by a net-specific datadir location. (default: data dir)", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
#     571                 :       1662 :     argsman.AddArg("-rpcpassword=<pw>", "Password for JSON-RPC connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
#     572                 :       1662 :     argsman.AddArg("-rpcport=<port>", strprintf("Listen for JSON-RPC connections on <port> (default: %u, testnet: %u, signet: %u, regtest: %u)", defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort(), signetBaseParams->RPCPort(), regtestBaseParams->RPCPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC);
#     573                 :       1662 :     argsman.AddArg("-rpcserialversion", strprintf("Sets the serialization of raw transaction or block hex returned in non-verbose mode, non-segwit(0) or segwit(1) (default: %d)", DEFAULT_RPC_SERIALIZE_VERSION), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
#     574                 :       1662 :     argsman.AddArg("-rpcservertimeout=<n>", strprintf("Timeout during HTTP requests (default: %d)", DEFAULT_HTTP_SERVER_TIMEOUT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC);
#     575                 :       1662 :     argsman.AddArg("-rpcthreads=<n>", strprintf("Set the number of threads to service RPC calls (default: %d)", DEFAULT_HTTP_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
#     576                 :       1662 :     argsman.AddArg("-rpcuser=<user>", "Username for JSON-RPC connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
#     577                 :       1662 :     argsman.AddArg("-rpcwhitelist=<whitelist>", "Set a whitelist to filter incoming RPC calls for a specific user. The field <whitelist> comes in the format: <USERNAME>:<rpc 1>,<rpc 2>,...,<rpc n>. If multiple whitelists are set for a given user, they are set-intersected. See -rpcwhitelistdefault documentation for information on default whitelist behavior.", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
#     578                 :       1662 :     argsman.AddArg("-rpcwhitelistdefault", "Sets default behavior for rpc whitelisting. Unless rpcwhitelistdefault is set to 0, if any -rpcwhitelist is set, the rpc server acts as if all rpc users are subject to empty-unless-otherwise-specified whitelists. If rpcwhitelistdefault is set to 1 and no -rpcwhitelist is set, rpc server acts as if all rpc users are subject to empty whitelists.", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
#     579                 :       1662 :     argsman.AddArg("-rpcworkqueue=<n>", strprintf("Set the depth of the work queue to service RPC calls (default: %d)", DEFAULT_HTTP_WORKQUEUE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC);
#     580                 :       1662 :     argsman.AddArg("-server", "Accept command line and JSON-RPC commands", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
#     581                 :            : 
#     582                 :       1662 : #if HAVE_DECL_FORK
#     583                 :       1662 :     argsman.AddArg("-daemon", strprintf("Run in the background as a daemon and accept commands (default: %d)", DEFAULT_DAEMON), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     584                 :       1662 :     argsman.AddArg("-daemonwait", strprintf("Wait for initialization to be finished before exiting. This implies -daemon (default: %d)", DEFAULT_DAEMONWAIT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     585                 :            : #else
#     586                 :            :     hidden_args.emplace_back("-daemon");
#     587                 :            :     hidden_args.emplace_back("-daemonwait");
#     588                 :            : #endif
#     589                 :            : 
#     590                 :            : #if defined(USE_SYSCALL_SANDBOX)
#     591                 :            :     argsman.AddArg("-sandbox=<mode>", "Use the experimental syscall sandbox in the specified mode (-sandbox=log-and-abort or -sandbox=abort). Allow only expected syscalls to be used by bitcoind. Note that this is an experimental new feature that may cause bitcoind to exit or crash unexpectedly: use with caution. In the \"log-and-abort\" mode the invocation of an unexpected syscall results in a debug handler being invoked which will log the incident and terminate the program (without executing the unexpected syscall). In the \"abort\" mode the invocation of an unexpected syscall results in the entire process being killed immediately by the kernel without executing the unexpected syscall.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#     592                 :            : #endif // USE_SYSCALL_SANDBOX
#     593                 :            : 
#     594                 :            :     // Add the hidden options
#     595                 :       1662 :     argsman.AddHiddenArgs(hidden_args);
#     596                 :       1662 : }
#     597                 :            : 
#     598                 :            : static bool fHaveGenesis = false;
#     599                 :            : static Mutex g_genesis_wait_mutex;
#     600                 :            : static std::condition_variable g_genesis_wait_cv;
#     601                 :            : 
#     602                 :            : static void BlockNotifyGenesisWait(const CBlockIndex* pBlockIndex)
#     603                 :        268 : {
#     604         [ +  - ]:        268 :     if (pBlockIndex != nullptr) {
#     605                 :        268 :         {
#     606                 :        268 :             LOCK(g_genesis_wait_mutex);
#     607                 :        268 :             fHaveGenesis = true;
#     608                 :        268 :         }
#     609                 :        268 :         g_genesis_wait_cv.notify_all();
#     610                 :        268 :     }
#     611                 :        268 : }
#     612                 :            : 
#     613                 :            : #if HAVE_SYSTEM
#     614                 :            : static void StartupNotify(const ArgsManager& args)
#     615                 :        719 : {
#     616                 :        719 :     std::string cmd = args.GetArg("-startupnotify", "");
#     617         [ +  + ]:        719 :     if (!cmd.empty()) {
#     618                 :          1 :         std::thread t(runCommand, cmd);
#     619                 :          1 :         t.detach(); // thread runs free
#     620                 :          1 :     }
#     621                 :        719 : }
#     622                 :            : #endif
#     623                 :            : 
#     624                 :            : static bool AppInitServers(NodeContext& node)
#     625                 :        789 : {
#     626                 :        789 :     const ArgsManager& args = *Assert(node.args);
#     627                 :        789 :     RPCServer::OnStarted(&OnRPCStarted);
#     628                 :        789 :     RPCServer::OnStopped(&OnRPCStopped);
#     629         [ -  + ]:        789 :     if (!InitHTTPServer())
#     630                 :          0 :         return false;
#     631                 :        789 :     StartRPC();
#     632                 :        789 :     node.rpc_interruption_point = RpcInterruptionPoint;
#     633         [ +  + ]:        789 :     if (!StartHTTPRPC(&node))
#     634                 :          3 :         return false;
#     635         [ +  + ]:        786 :     if (args.GetBoolArg("-rest", DEFAULT_REST_ENABLE)) StartREST(&node);
#     636                 :        786 :     StartHTTPServer();
#     637                 :        786 :     return true;
#     638                 :        789 : }
#     639                 :            : 
#     640                 :            : // Parameter interaction based on rules
#     641                 :            : void InitParameterInteraction(ArgsManager& args)
#     642                 :        808 : {
#     643                 :            :     // when specifying an explicit binding address, you want to listen on it
#     644                 :            :     // even when -connect or -proxy is specified
#     645         [ +  + ]:        808 :     if (args.IsArgSet("-bind")) {
#     646         [ +  + ]:        797 :         if (args.SoftSetBoolArg("-listen", true))
#     647                 :        792 :             LogPrintf("%s: parameter interaction: -bind set -> setting -listen=1\n", __func__);
#     648                 :        797 :     }
#     649         [ +  + ]:        808 :     if (args.IsArgSet("-whitebind")) {
#     650         [ +  + ]:          2 :         if (args.SoftSetBoolArg("-listen", true))
#     651                 :          1 :             LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__);
#     652                 :          2 :     }
#     653                 :            : 
#     654         [ +  + ]:        808 :     if (args.IsArgSet("-connect")) {
#     655                 :            :         // when only connecting to trusted nodes, do not seed via DNS, or listen by default
#     656         [ -  + ]:        781 :         if (args.SoftSetBoolArg("-dnsseed", false))
#     657                 :          0 :             LogPrintf("%s: parameter interaction: -connect set -> setting -dnsseed=0\n", __func__);
#     658         [ +  + ]:        781 :         if (args.SoftSetBoolArg("-listen", false))
#     659                 :          3 :             LogPrintf("%s: parameter interaction: -connect set -> setting -listen=0\n", __func__);
#     660                 :        781 :     }
#     661                 :            : 
#     662                 :        808 :     std::string proxy_arg = args.GetArg("-proxy", "");
#     663 [ +  + ][ +  - ]:        808 :     if (proxy_arg != "" && proxy_arg != "0") {
#     664                 :            :         // to protect privacy, do not listen by default if a default proxy server is specified
#     665         [ -  + ]:          9 :         if (args.SoftSetBoolArg("-listen", false))
#     666                 :          0 :             LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
#     667                 :            :         // to protect privacy, do not map ports when a proxy is set. The user may still specify -listen=1
#     668                 :            :         // to listen locally, so don't rely on this happening through -listen below.
#     669         [ -  + ]:          9 :         if (args.SoftSetBoolArg("-upnp", false))
#     670                 :          0 :             LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__);
#     671         [ -  + ]:          9 :         if (args.SoftSetBoolArg("-natpmp", false)) {
#     672                 :          0 :             LogPrintf("%s: parameter interaction: -proxy set -> setting -natpmp=0\n", __func__);
#     673                 :          0 :         }
#     674                 :            :         // to protect privacy, do not discover addresses by default
#     675         [ -  + ]:          9 :         if (args.SoftSetBoolArg("-discover", false))
#     676                 :          0 :             LogPrintf("%s: parameter interaction: -proxy set -> setting -discover=0\n", __func__);
#     677                 :          9 :     }
#     678                 :            : 
#     679         [ +  + ]:        808 :     if (!args.GetBoolArg("-listen", DEFAULT_LISTEN)) {
#     680                 :            :         // do not map ports or try to retrieve public IP when not listening (pointless)
#     681         [ -  + ]:         10 :         if (args.SoftSetBoolArg("-upnp", false))
#     682                 :          0 :             LogPrintf("%s: parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
#     683         [ -  + ]:         10 :         if (args.SoftSetBoolArg("-natpmp", false)) {
#     684                 :          0 :             LogPrintf("%s: parameter interaction: -listen=0 -> setting -natpmp=0\n", __func__);
#     685                 :          0 :         }
#     686         [ -  + ]:         10 :         if (args.SoftSetBoolArg("-discover", false))
#     687                 :          0 :             LogPrintf("%s: parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
#     688         [ +  + ]:         10 :         if (args.SoftSetBoolArg("-listenonion", false))
#     689                 :          1 :             LogPrintf("%s: parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__);
#     690         [ +  + ]:         10 :         if (args.SoftSetBoolArg("-i2pacceptincoming", false)) {
#     691                 :          4 :             LogPrintf("%s: parameter interaction: -listen=0 -> setting -i2pacceptincoming=0\n", __func__);
#     692                 :          4 :         }
#     693                 :         10 :     }
#     694                 :            : 
#     695         [ -  + ]:        808 :     if (args.IsArgSet("-externalip")) {
#     696                 :            :         // if an explicit public IP is specified, do not try to find others
#     697         [ #  # ]:          0 :         if (args.SoftSetBoolArg("-discover", false))
#     698                 :          0 :             LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
#     699                 :          0 :     }
#     700                 :            : 
#     701                 :            :     // disable whitelistrelay in blocksonly mode
#     702         [ +  + ]:        808 :     if (args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {
#     703         [ +  - ]:          6 :         if (args.SoftSetBoolArg("-whitelistrelay", false))
#     704                 :          6 :             LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistrelay=0\n", __func__);
#     705                 :          6 :     }
#     706                 :            : 
#     707                 :            :     // Forcing relay from whitelisted hosts implies we will accept relays from them in the first place.
#     708         [ +  + ]:        808 :     if (args.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
#     709         [ +  - ]:          3 :         if (args.SoftSetBoolArg("-whitelistrelay", true))
#     710                 :          3 :             LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n", __func__);
#     711                 :          3 :     }
#     712                 :        808 : }
#     713                 :            : 
#     714                 :            : /**
#     715                 :            :  * Initialize global loggers.
#     716                 :            :  *
#     717                 :            :  * Note that this is called very early in the process lifetime, so you should be
#     718                 :            :  * careful about what global state you rely on here.
#     719                 :            :  */
#     720                 :            : void InitLogging(const ArgsManager& args)
#     721                 :       1639 : {
#     722                 :       1639 :     init::SetLoggingOptions(args);
#     723                 :       1639 :     init::LogPackageVersion();
#     724                 :       1639 : }
#     725                 :            : 
#     726                 :            : namespace { // Variables internal to initialization process only
#     727                 :            : 
#     728                 :            : int nMaxConnections;
#     729                 :            : int nUserMaxConnections;
#     730                 :            : int nFD;
#     731                 :            : ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK | NODE_NETWORK_LIMITED | NODE_WITNESS);
#     732                 :            : int64_t peer_connect_timeout;
#     733                 :            : std::set<BlockFilterType> g_enabled_filter_types;
#     734                 :            : 
#     735                 :            : } // namespace
#     736                 :            : 
#     737                 :            : [[noreturn]] static void new_handler_terminate()
#     738                 :          0 : {
#     739                 :            :     // Rather than throwing std::bad-alloc if allocation fails, terminate
#     740                 :            :     // immediately to (try to) avoid chain corruption.
#     741                 :            :     // Since LogPrintf may itself allocate memory, set the handler directly
#     742                 :            :     // to terminate first.
#     743                 :          0 :     std::set_new_handler(std::terminate);
#     744                 :          0 :     LogPrintf("Error: Out of memory. Terminating.\n");
#     745                 :            : 
#     746                 :            :     // The log was successful, terminate now.
#     747                 :          0 :     std::terminate();
#     748                 :          0 : };
#     749                 :            : 
#     750                 :            : bool AppInitBasicSetup(const ArgsManager& args)
#     751                 :        802 : {
#     752                 :            :     // ********************************************************* Step 1: setup
#     753                 :            : #ifdef _MSC_VER
#     754                 :            :     // Turn off Microsoft heap dump noise
#     755                 :            :     _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
#     756                 :            :     _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, 0));
#     757                 :            :     // Disable confusing "helpful" text message on abort, Ctrl-C
#     758                 :            :     _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
#     759                 :            : #endif
#     760                 :            : #ifdef WIN32
#     761                 :            :     // Enable heap terminate-on-corruption
#     762                 :            :     HeapSetInformation(nullptr, HeapEnableTerminationOnCorruption, nullptr, 0);
#     763                 :            : #endif
#     764         [ -  + ]:        802 :     if (!InitShutdownState()) {
#     765                 :          0 :         return InitError(Untranslated("Initializing wait-for-shutdown state failed."));
#     766                 :          0 :     }
#     767                 :            : 
#     768         [ -  + ]:        802 :     if (!SetupNetworking()) {
#     769                 :          0 :         return InitError(Untranslated("Initializing networking failed."));
#     770                 :          0 :     }
#     771                 :            : 
#     772                 :        802 : #ifndef WIN32
#     773         [ +  - ]:        802 :     if (!args.GetBoolArg("-sysperms", false)) {
#     774                 :        802 :         umask(077);
#     775                 :        802 :     }
#     776                 :            : 
#     777                 :            :     // Clean shutdown on SIGTERM
#     778                 :        802 :     registerSignalHandler(SIGTERM, HandleSIGTERM);
#     779                 :        802 :     registerSignalHandler(SIGINT, HandleSIGTERM);
#     780                 :            : 
#     781                 :            :     // Reopen debug.log on SIGHUP
#     782                 :        802 :     registerSignalHandler(SIGHUP, HandleSIGHUP);
#     783                 :            : 
#     784                 :            :     // Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
#     785                 :        802 :     signal(SIGPIPE, SIG_IGN);
#     786                 :            : #else
#     787                 :            :     SetConsoleCtrlHandler(consoleCtrlHandler, true);
#     788                 :            : #endif
#     789                 :            : 
#     790                 :        802 :     std::set_new_handler(new_handler_terminate);
#     791                 :            : 
#     792                 :        802 :     return true;
#     793                 :        802 : }
#     794                 :            : 
#     795                 :            : bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandbox)
#     796                 :       1640 : {
#     797                 :       1640 :     const CChainParams& chainparams = Params();
#     798                 :            :     // ********************************************************* Step 2: parameter interactions
#     799                 :            : 
#     800                 :            :     // also see: InitParameterInteraction()
#     801                 :            : 
#     802                 :            :     // Error if network-specific options (-addnode, -connect, etc) are
#     803                 :            :     // specified in default section of config file, but not overridden
#     804                 :            :     // on the command line or in this network's section of the config file.
#     805                 :       1640 :     std::string network = args.GetChainName();
#     806         [ +  + ]:       1640 :     if (network == CBaseChainParams::SIGNET) {
#     807                 :          9 :         LogPrintf("Signet derived magic (message start): %s\n", HexStr(chainparams.MessageStart()));
#     808                 :          9 :     }
#     809                 :       1640 :     bilingual_str errors;
#     810         [ +  + ]:       1640 :     for (const auto& arg : args.GetUnsuitableSectionOnlyArgs()) {
#     811                 :          1 :         errors += strprintf(_("Config setting for %s only applied on %s network when in [%s] section.") + Untranslated("\n"), arg, network, network);
#     812                 :          1 :     }
#     813                 :            : 
#     814         [ +  + ]:       1640 :     if (!errors.empty()) {
#     815                 :          1 :         return InitError(errors);
#     816                 :          1 :     }
#     817                 :            : 
#     818                 :            :     // Warn if unrecognized section name are present in the config file.
#     819                 :       1639 :     bilingual_str warnings;
#     820         [ +  + ]:       1639 :     for (const auto& section : args.GetUnrecognizedSections()) {
#     821                 :          2 :         warnings += strprintf(Untranslated("%s:%i ") + _("Section [%s] is not recognized.") + Untranslated("\n"), section.m_file, section.m_line, section.m_name);
#     822                 :          2 :     }
#     823                 :            : 
#     824         [ +  + ]:       1639 :     if (!warnings.empty()) {
#     825                 :          1 :         InitWarning(warnings);
#     826                 :          1 :     }
#     827                 :            : 
#     828         [ +  + ]:       1639 :     if (!fs::is_directory(gArgs.GetBlocksDirPath())) {
#     829                 :          1 :         return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), args.GetArg("-blocksdir", "")));
#     830                 :          1 :     }
#     831                 :            : 
#     832                 :            :     // parse and validate enabled filter types
#     833                 :       1638 :     std::string blockfilterindex_value = args.GetArg("-blockfilterindex", DEFAULT_BLOCKFILTERINDEX);
#     834 [ +  + ][ +  + ]:       1638 :     if (blockfilterindex_value == "" || blockfilterindex_value == "1") {
#     835                 :         33 :         g_enabled_filter_types = AllBlockFilterTypes();
#     836         [ -  + ]:       1605 :     } else if (blockfilterindex_value != "0") {
#     837                 :          0 :         const std::vector<std::string> names = args.GetArgs("-blockfilterindex");
#     838         [ #  # ]:          0 :         for (const auto& name : names) {
#     839                 :          0 :             BlockFilterType filter_type;
#     840         [ #  # ]:          0 :             if (!BlockFilterTypeByName(name, filter_type)) {
#     841                 :          0 :                 return InitError(strprintf(_("Unknown -blockfilterindex value %s."), name));
#     842                 :          0 :             }
#     843                 :          0 :             g_enabled_filter_types.insert(filter_type);
#     844                 :          0 :         }
#     845                 :          0 :     }
#     846                 :            : 
#     847                 :            :     // Signal NODE_COMPACT_FILTERS if peerblockfilters and basic filters index are both enabled.
#     848         [ +  + ]:       1638 :     if (args.GetBoolArg("-peerblockfilters", DEFAULT_PEERBLOCKFILTERS)) {
#     849         [ +  + ]:          2 :         if (g_enabled_filter_types.count(BlockFilterType::BASIC) != 1) {
#     850                 :          1 :             return InitError(_("Cannot set -peerblockfilters without -blockfilterindex."));
#     851                 :          1 :         }
#     852                 :            : 
#     853                 :          1 :         nLocalServices = ServiceFlags(nLocalServices | NODE_COMPACT_FILTERS);
#     854                 :          1 :     }
#     855                 :            : 
#     856         [ +  + ]:       1637 :     if (args.GetIntArg("-prune", 0)) {
#     857         [ -  + ]:         11 :         if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX))
#     858                 :          0 :             return InitError(_("Prune mode is incompatible with -txindex."));
#     859         [ -  + ]:         11 :         if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX))
#     860                 :          0 :             return InitError(_("Prune mode is incompatible with -coinstatsindex."));
#     861         [ -  + ]:         11 :         if (args.GetBoolArg("-reindex-chainstate", false)) {
#     862                 :          0 :             return InitError(_("Prune mode is incompatible with -reindex-chainstate. Use full -reindex instead."));
#     863                 :          0 :         }
#     864                 :         11 :     }
#     865                 :            : 
#     866                 :            :     // If -forcednsseed is set to true, ensure -dnsseed has not been set to false
#     867 [ +  + ][ +  + ]:       1637 :     if (args.GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED) && !args.GetBoolArg("-dnsseed", DEFAULT_DNSSEED)){
#                 [ +  + ]
#     868                 :          2 :         return InitError(_("Cannot set -forcednsseed to true when setting -dnsseed to false."));
#     869                 :          2 :     }
#     870                 :            : 
#     871                 :            :     // -bind and -whitebind can't be set when not listening
#     872                 :       1635 :     size_t nUserBind = args.GetArgs("-bind").size() + args.GetArgs("-whitebind").size();
#     873 [ +  + ][ -  + ]:       1635 :     if (nUserBind != 0 && !args.GetBoolArg("-listen", DEFAULT_LISTEN)) {
#                 [ -  + ]
#     874                 :          0 :         return InitError(Untranslated("Cannot set -bind or -whitebind together with -listen=0"));
#     875                 :          0 :     }
#     876                 :            : 
#     877                 :            :     // if listen=0, then disallow listenonion=1
#     878 [ +  + ][ -  + ]:       1635 :     if (!args.GetBoolArg("-listen", DEFAULT_LISTEN) && args.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION)) {
#                 [ -  + ]
#     879                 :          0 :         return InitError(Untranslated("Cannot set -listen=0 together with -listenonion=1"));
#     880                 :          0 :     }
#     881                 :            : 
#     882                 :            :     // Make sure enough file descriptors are available
#     883                 :       1635 :     int nBind = std::max(nUserBind, size_t(1));
#     884                 :       1635 :     nUserMaxConnections = args.GetIntArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS);
#     885                 :       1635 :     nMaxConnections = std::max(nUserMaxConnections, 0);
#     886                 :            : 
#     887                 :       1635 :     nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS + nBind + NUM_FDS_MESSAGE_CAPTURE);
#     888                 :            : 
#     889                 :            : #ifdef USE_POLL
#     890                 :            :     int fd_max = nFD;
#     891                 :            : #else
#     892                 :       1635 :     int fd_max = FD_SETSIZE;
#     893                 :       1635 : #endif
#     894                 :            :     // Trim requested connection counts, to fit into system limitations
#     895                 :            :     // <int> in std::min<int>(...) to work around FreeBSD compilation issue described in #2695
#     896                 :       1635 :     nMaxConnections = std::max(std::min<int>(nMaxConnections, fd_max - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE), 0);
#     897         [ -  + ]:       1635 :     if (nFD < MIN_CORE_FILEDESCRIPTORS)
#     898                 :          0 :         return InitError(_("Not enough file descriptors available."));
#     899                 :       1635 :     nMaxConnections = std::min(nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE, nMaxConnections);
#     900                 :            : 
#     901         [ -  + ]:       1635 :     if (nMaxConnections < nUserMaxConnections)
#     902                 :          0 :         InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), nUserMaxConnections, nMaxConnections));
#     903                 :            : 
#     904                 :            :     // ********************************************************* Step 3: parameter-to-internal-flags
#     905                 :       1635 :     init::SetLoggingCategories(args);
#     906                 :            : 
#     907                 :       1635 :     fCheckBlockIndex = args.GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
#     908                 :       1635 :     fCheckpointsEnabled = args.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED);
#     909                 :            : 
#     910                 :       1635 :     hashAssumeValid = uint256S(args.GetArg("-assumevalid", chainparams.GetConsensus().defaultAssumeValid.GetHex()));
#     911         [ +  + ]:       1635 :     if (!hashAssumeValid.IsNull())
#     912                 :        744 :         LogPrintf("Assuming ancestors of block %s have valid signatures.\n", hashAssumeValid.GetHex());
#     913                 :        891 :     else
#     914                 :        891 :         LogPrintf("Validating signatures for all blocks.\n");
#     915                 :            : 
#     916         [ +  + ]:       1635 :     if (args.IsArgSet("-minimumchainwork")) {
#     917                 :          3 :         const std::string minChainWorkStr = args.GetArg("-minimumchainwork", "");
#     918         [ -  + ]:          3 :         if (!IsHexNumber(minChainWorkStr)) {
#     919                 :          0 :             return InitError(strprintf(Untranslated("Invalid non-hex (%s) minimum chain work value specified"), minChainWorkStr));
#     920                 :          0 :         }
#     921                 :          3 :         nMinimumChainWork = UintToArith256(uint256S(minChainWorkStr));
#     922                 :       1632 :     } else {
#     923                 :       1632 :         nMinimumChainWork = UintToArith256(chainparams.GetConsensus().nMinimumChainWork);
#     924                 :       1632 :     }
#     925                 :       1635 :     LogPrintf("Setting nMinimumChainWork=%s\n", nMinimumChainWork.GetHex());
#     926         [ -  + ]:       1635 :     if (nMinimumChainWork < UintToArith256(chainparams.GetConsensus().nMinimumChainWork)) {
#     927                 :          0 :         LogPrintf("Warning: nMinimumChainWork set below default value of %s\n", chainparams.GetConsensus().nMinimumChainWork.GetHex());
#     928                 :          0 :     }
#     929                 :            : 
#     930                 :            :     // mempool limits
#     931                 :       1635 :     int64_t nMempoolSizeMax = args.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
#     932                 :       1635 :     int64_t nMempoolSizeMin = args.GetIntArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000 * 40;
#     933 [ -  + ][ -  + ]:       1635 :     if (nMempoolSizeMax < 0 || nMempoolSizeMax < nMempoolSizeMin)
#     934                 :          0 :         return InitError(strprintf(_("-maxmempool must be at least %d MB"), std::ceil(nMempoolSizeMin / 1000000.0)));
#     935                 :            :     // incremental relay fee sets the minimum feerate increase necessary for BIP 125 replacement in the mempool
#     936                 :            :     // and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
#     937         [ -  + ]:       1635 :     if (args.IsArgSet("-incrementalrelayfee")) {
#     938         [ #  # ]:          0 :         if (std::optional<CAmount> inc_relay_fee = ParseMoney(args.GetArg("-incrementalrelayfee", ""))) {
#     939                 :          0 :             ::incrementalRelayFee = CFeeRate{inc_relay_fee.value()};
#     940                 :          0 :         } else {
#     941                 :          0 :             return InitError(AmountErrMsg("incrementalrelayfee", args.GetArg("-incrementalrelayfee", "")));
#     942                 :          0 :         }
#     943                 :          0 :     }
#     944                 :            : 
#     945                 :            :     // block pruning; get the amount of disk space (in MiB) to allot for block & undo files
#     946                 :       1635 :     int64_t nPruneArg = args.GetIntArg("-prune", 0);
#     947         [ -  + ]:       1635 :     if (nPruneArg < 0) {
#     948                 :          0 :         return InitError(_("Prune cannot be configured with a negative value."));
#     949                 :          0 :     }
#     950                 :       1635 :     nPruneTarget = (uint64_t) nPruneArg * 1024 * 1024;
#     951         [ +  + ]:       1635 :     if (nPruneArg == 1) {  // manual pruning: -prune=1
#     952                 :          9 :         LogPrintf("Block pruning enabled.  Use RPC call pruneblockchain(height) to manually prune block and undo files.\n");
#     953                 :          9 :         nPruneTarget = std::numeric_limits<uint64_t>::max();
#     954                 :          9 :         fPruneMode = true;
#     955         [ +  + ]:       1626 :     } else if (nPruneTarget) {
#     956         [ -  + ]:          2 :         if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
#     957                 :          0 :             return InitError(strprintf(_("Prune configured below the minimum of %d MiB.  Please use a higher number."), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024));
#     958                 :          0 :         }
#     959                 :          2 :         LogPrintf("Prune configured to target %u MiB on disk for block and undo files.\n", nPruneTarget / 1024 / 1024);
#     960                 :          2 :         fPruneMode = true;
#     961                 :          2 :     }
#     962                 :            : 
#     963                 :       1635 :     nConnectTimeout = args.GetIntArg("-timeout", DEFAULT_CONNECT_TIMEOUT);
#     964         [ -  + ]:       1635 :     if (nConnectTimeout <= 0) {
#     965                 :          0 :         nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
#     966                 :          0 :     }
#     967                 :            : 
#     968                 :       1635 :     peer_connect_timeout = args.GetIntArg("-peertimeout", DEFAULT_PEER_CONNECT_TIMEOUT);
#     969         [ -  + ]:       1635 :     if (peer_connect_timeout <= 0) {
#     970                 :          0 :         return InitError(Untranslated("peertimeout cannot be configured with a negative value."));
#     971                 :          0 :     }
#     972                 :            : 
#     973         [ +  + ]:       1635 :     if (args.IsArgSet("-minrelaytxfee")) {
#     974         [ +  - ]:         20 :         if (std::optional<CAmount> min_relay_fee = ParseMoney(args.GetArg("-minrelaytxfee", ""))) {
#     975                 :            :             // High fee check is done afterward in CWallet::Create()
#     976                 :         20 :             ::minRelayTxFee = CFeeRate{min_relay_fee.value()};
#     977                 :         20 :         } else {
#     978                 :          0 :             return InitError(AmountErrMsg("minrelaytxfee", args.GetArg("-minrelaytxfee", "")));
#     979                 :          0 :         }
#     980         [ -  + ]:       1615 :     } else if (incrementalRelayFee > ::minRelayTxFee) {
#     981                 :            :         // Allow only setting incrementalRelayFee to control both
#     982                 :          0 :         ::minRelayTxFee = incrementalRelayFee;
#     983                 :          0 :         LogPrintf("Increasing minrelaytxfee to %s to match incrementalrelayfee\n",::minRelayTxFee.ToString());
#     984                 :          0 :     }
#     985                 :            : 
#     986                 :            :     // Sanity check argument for min fee for including tx in block
#     987                 :            :     // TODO: Harmonize which arguments need sanity checking and where that happens
#     988         [ -  + ]:       1635 :     if (args.IsArgSet("-blockmintxfee")) {
#     989         [ #  # ]:          0 :         if (!ParseMoney(args.GetArg("-blockmintxfee", ""))) {
#     990                 :          0 :             return InitError(AmountErrMsg("blockmintxfee", args.GetArg("-blockmintxfee", "")));
#     991                 :          0 :         }
#     992                 :          0 :     }
#     993                 :            : 
#     994                 :            :     // Feerate used to define dust.  Shouldn't be changed lightly as old
#     995                 :            :     // implementations may inadvertently create non-standard transactions
#     996         [ -  + ]:       1635 :     if (args.IsArgSet("-dustrelayfee")) {
#     997         [ #  # ]:          0 :         if (std::optional<CAmount> parsed = ParseMoney(args.GetArg("-dustrelayfee", ""))) {
#     998                 :          0 :             dustRelayFee = CFeeRate{parsed.value()};
#     999                 :          0 :         } else {
#    1000                 :          0 :             return InitError(AmountErrMsg("dustrelayfee", args.GetArg("-dustrelayfee", "")));
#    1001                 :          0 :         }
#    1002                 :          0 :     }
#    1003                 :            : 
#    1004                 :       1635 :     fRequireStandard = !args.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
#    1005 [ +  + ][ +  + ]:       1635 :     if (!chainparams.IsTestChain() && !fRequireStandard) {
#    1006                 :          1 :         return InitError(strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.NetworkIDString()));
#    1007                 :          1 :     }
#    1008                 :       1634 :     nBytesPerSigOp = args.GetIntArg("-bytespersigop", nBytesPerSigOp);
#    1009                 :            : 
#    1010         [ -  + ]:       1634 :     if (!g_wallet_init_interface.ParameterInteraction()) return false;
#    1011                 :            : 
#    1012                 :       1634 :     fIsBareMultisigStd = args.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
#    1013                 :       1634 :     fAcceptDatacarrier = args.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER);
#    1014                 :       1634 :     nMaxDatacarrierBytes = args.GetIntArg("-datacarriersize", nMaxDatacarrierBytes);
#    1015                 :            : 
#    1016                 :            :     // Option to startup with mocktime set (used for regression testing):
#    1017                 :       1634 :     SetMockTime(args.GetIntArg("-mocktime", 0)); // SetMockTime(0) is a no-op
#    1018                 :            : 
#    1019         [ +  + ]:       1634 :     if (args.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS))
#    1020                 :          1 :         nLocalServices = ServiceFlags(nLocalServices | NODE_BLOOM);
#    1021                 :            : 
#    1022         [ -  + ]:       1634 :     if (args.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) < 0)
#    1023                 :          0 :         return InitError(Untranslated("rpcserialversion must be non-negative."));
#    1024                 :            : 
#    1025         [ -  + ]:       1634 :     if (args.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) > 1)
#    1026                 :          0 :         return InitError(Untranslated("Unknown rpcserialversion requested."));
#    1027                 :            : 
#    1028                 :       1634 :     nMaxTipAge = args.GetIntArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
#    1029                 :            : 
#    1030 [ +  + ][ +  + ]:       1634 :     if (args.IsArgSet("-proxy") && args.GetArg("-proxy", "").empty()) {
#                 [ +  + ]
#    1031                 :          1 :         return InitError(_("No proxy server specified. Use -proxy=<ip> or -proxy=<ip:port>."));
#    1032                 :          1 :     }
#    1033                 :            : 
#    1034                 :            : #if defined(USE_SYSCALL_SANDBOX)
#    1035                 :            :     if (args.IsArgSet("-sandbox") && !args.IsArgNegated("-sandbox")) {
#    1036                 :            :         const std::string sandbox_arg{args.GetArg("-sandbox", "")};
#    1037                 :            :         bool log_syscall_violation_before_terminating{false};
#    1038                 :            :         if (sandbox_arg == "log-and-abort") {
#    1039                 :            :             log_syscall_violation_before_terminating = true;
#    1040                 :            :         } else if (sandbox_arg == "abort") {
#    1041                 :            :             // log_syscall_violation_before_terminating is false by default.
#    1042                 :            :         } else {
#    1043                 :            :             return InitError(Untranslated("Unknown syscall sandbox mode (-sandbox=<mode>). Available modes are \"log-and-abort\" and \"abort\"."));
#    1044                 :            :         }
#    1045                 :            :         // execve(...) is not allowed by the syscall sandbox.
#    1046                 :            :         const std::vector<std::string> features_using_execve{
#    1047                 :            :             "-alertnotify",
#    1048                 :            :             "-blocknotify",
#    1049                 :            :             "-signer",
#    1050                 :            :             "-startupnotify",
#    1051                 :            :             "-walletnotify",
#    1052                 :            :         };
#    1053                 :            :         for (const std::string& feature_using_execve : features_using_execve) {
#    1054                 :            :             if (!args.GetArg(feature_using_execve, "").empty()) {
#    1055                 :            :                 return InitError(Untranslated(strprintf("The experimental syscall sandbox feature (-sandbox=<mode>) is incompatible with %s (which uses execve).", feature_using_execve)));
#    1056                 :            :             }
#    1057                 :            :         }
#    1058                 :            :         if (!SetupSyscallSandbox(log_syscall_violation_before_terminating)) {
#    1059                 :            :             return InitError(Untranslated("Installation of the syscall sandbox failed."));
#    1060                 :            :         }
#    1061                 :            :         if (use_syscall_sandbox) {
#    1062                 :            :             SetSyscallSandboxPolicy(SyscallSandboxPolicy::INITIALIZATION);
#    1063                 :            :         }
#    1064                 :            :         LogPrintf("Experimental syscall sandbox enabled (-sandbox=%s): bitcoind will terminate if an unexpected (not allowlisted) syscall is invoked.\n", sandbox_arg);
#    1065                 :            :     }
#    1066                 :            : #endif // USE_SYSCALL_SANDBOX
#    1067                 :            : 
#    1068                 :       1633 :     return true;
#    1069                 :       1634 : }
#    1070                 :            : 
#    1071                 :            : static bool LockDataDirectory(bool probeOnly)
#    1072                 :       1589 : {
#    1073                 :            :     // Make sure only a single Bitcoin process is using the data directory.
#    1074                 :       1589 :     fs::path datadir = gArgs.GetDataDirNet();
#    1075         [ -  + ]:       1589 :     if (!DirIsWritable(datadir)) {
#    1076                 :          0 :         return InitError(strprintf(_("Cannot write to data directory '%s'; check permissions."), fs::PathToString(datadir)));
#    1077                 :          0 :     }
#    1078         [ +  + ]:       1589 :     if (!LockDirectory(datadir, ".lock", probeOnly)) {
#    1079                 :          1 :         return InitError(strprintf(_("Cannot obtain a lock on data directory %s. %s is probably already running."), fs::PathToString(datadir), PACKAGE_NAME));
#    1080                 :          1 :     }
#    1081                 :       1588 :     return true;
#    1082                 :       1589 : }
#    1083                 :            : 
#    1084                 :            : bool AppInitSanityChecks()
#    1085                 :        795 : {
#    1086                 :            :     // ********************************************************* Step 4: sanity checks
#    1087                 :            : 
#    1088                 :        795 :     init::SetGlobals();
#    1089                 :            : 
#    1090         [ -  + ]:        795 :     if (!init::SanityChecks()) {
#    1091                 :          0 :         return InitError(strprintf(_("Initialization sanity check failed. %s is shutting down."), PACKAGE_NAME));
#    1092                 :          0 :     }
#    1093                 :            : 
#    1094                 :            :     // Probe the data directory lock to give an early error message, if possible
#    1095                 :            :     // We cannot hold the data directory lock here, as the forking for daemon() hasn't yet happened,
#    1096                 :            :     // and a fork will cause weird behavior to it.
#    1097                 :        795 :     return LockDataDirectory(true);
#    1098                 :        795 : }
#    1099                 :            : 
#    1100                 :            : bool AppInitLockDataDirectory()
#    1101                 :        794 : {
#    1102                 :            :     // After daemonization get the data directory lock again and hold on to it until exit
#    1103                 :            :     // This creates a slight window for a race condition to happen, however this condition is harmless: it
#    1104                 :            :     // will at most make us exit without printing a message to console.
#    1105         [ -  + ]:        794 :     if (!LockDataDirectory(false)) {
#    1106                 :            :         // Detailed error printed inside LockDataDirectory
#    1107                 :          0 :         return false;
#    1108                 :          0 :     }
#    1109                 :        794 :     return true;
#    1110                 :        794 : }
#    1111                 :            : 
#    1112                 :            : bool AppInitInterfaces(NodeContext& node)
#    1113                 :        794 : {
#    1114                 :        794 :     node.chain = node.init->makeChain();
#    1115                 :        794 :     return true;
#    1116                 :        794 : }
#    1117                 :            : 
#    1118                 :            : bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
#    1119                 :        794 : {
#    1120                 :        794 :     const ArgsManager& args = *Assert(node.args);
#    1121                 :        794 :     const CChainParams& chainparams = Params();
#    1122                 :            : 
#    1123                 :        794 :     auto opt_max_upload = ParseByteUnits(args.GetArg("-maxuploadtarget", DEFAULT_MAX_UPLOAD_TARGET), ByteUnit::M);
#    1124         [ -  + ]:        794 :     if (!opt_max_upload) {
#    1125                 :          0 :         return InitError(strprintf(_("Unable to parse -maxuploadtarget: '%s'"), args.GetArg("-maxuploadtarget", "")));
#    1126                 :          0 :     }
#    1127                 :            : 
#    1128                 :            :     // ********************************************************* Step 4a: application initialization
#    1129         [ -  + ]:        794 :     if (!CreatePidFile(args)) {
#    1130                 :            :         // Detailed error printed inside CreatePidFile().
#    1131                 :          0 :         return false;
#    1132                 :          0 :     }
#    1133         [ +  + ]:        794 :     if (!init::StartLogging(args)) {
#    1134                 :            :         // Detailed error printed inside StartLogging().
#    1135                 :          2 :         return false;
#    1136                 :          2 :     }
#    1137                 :            : 
#    1138                 :        792 :     LogPrintf("Using at most %i automatic connections (%i file descriptors available)\n", nMaxConnections, nFD);
#    1139                 :            : 
#    1140                 :            :     // Warn about relative -datadir path.
#    1141 [ -  + ][ +  - ]:        792 :     if (args.IsArgSet("-datadir") && !args.GetPathArg("-datadir").is_absolute()) {
#                 [ -  + ]
#    1142                 :          0 :         LogPrintf("Warning: relative datadir option '%s' specified, which will be interpreted relative to the " /* Continued */
#    1143                 :          0 :                   "current working directory '%s'. This is fragile, because if bitcoin is started in the future "
#    1144                 :          0 :                   "from a different location, it will be unable to locate the current data files. There could "
#    1145                 :          0 :                   "also be data loss if bitcoin is started while in a temporary directory.\n",
#    1146                 :          0 :                   args.GetArg("-datadir", ""), fs::PathToString(fs::current_path()));
#    1147                 :          0 :     }
#    1148                 :            : 
#    1149                 :        792 :     InitSignatureCache();
#    1150                 :        792 :     InitScriptExecutionCache();
#    1151                 :            : 
#    1152                 :        792 :     int script_threads = args.GetIntArg("-par", DEFAULT_SCRIPTCHECK_THREADS);
#    1153         [ +  + ]:        792 :     if (script_threads <= 0) {
#    1154                 :            :         // -par=0 means autodetect (number of cores - 1 script threads)
#    1155                 :            :         // -par=-n means "leave n cores free" (number of cores - n - 1 script threads)
#    1156                 :        784 :         script_threads += GetNumCores();
#    1157                 :        784 :     }
#    1158                 :            : 
#    1159                 :            :     // Subtract 1 because the main thread counts towards the par threads
#    1160                 :        792 :     script_threads = std::max(script_threads - 1, 0);
#    1161                 :            : 
#    1162                 :            :     // Number of script-checking threads <= MAX_SCRIPTCHECK_THREADS
#    1163                 :        792 :     script_threads = std::min(script_threads, MAX_SCRIPTCHECK_THREADS);
#    1164                 :            : 
#    1165                 :        792 :     LogPrintf("Script verification uses %d additional threads\n", script_threads);
#    1166         [ +  + ]:        792 :     if (script_threads >= 1) {
#    1167                 :        784 :         g_parallel_script_checks = true;
#    1168                 :        784 :         StartScriptCheckWorkerThreads(script_threads);
#    1169                 :        784 :     }
#    1170                 :            : 
#    1171                 :        792 :     assert(!node.scheduler);
#    1172                 :          0 :     node.scheduler = std::make_unique<CScheduler>();
#    1173                 :            : 
#    1174                 :            :     // Start the lightweight task scheduler thread
#    1175                 :        792 :     node.scheduler->m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { node.scheduler->serviceQueue(); });
#    1176                 :            : 
#    1177                 :            :     // Gather some entropy once per minute.
#    1178                 :        792 :     node.scheduler->scheduleEvery([]{
#    1179                 :         94 :         RandAddPeriodic();
#    1180                 :         94 :     }, std::chrono::minutes{1});
#    1181                 :            : 
#    1182                 :        792 :     GetMainSignals().RegisterBackgroundSignalScheduler(*node.scheduler);
#    1183                 :            : 
#    1184                 :            :     // Create client interfaces for wallets that are supposed to be loaded
#    1185                 :            :     // according to -wallet and -disablewallet options. This only constructs
#    1186                 :            :     // the interfaces, it doesn't load wallet data. Wallets actually get loaded
#    1187                 :            :     // when load() and start() interface methods are called below.
#    1188                 :        792 :     g_wallet_init_interface.Construct(node);
#    1189                 :        792 :     uiInterface.InitWallet();
#    1190                 :            : 
#    1191                 :            :     /* Register RPC commands regardless of -server setting so they will be
#    1192                 :            :      * available in the GUI RPC console even if external calls are disabled.
#    1193                 :            :      */
#    1194                 :        792 :     RegisterAllCoreRPCCommands(tableRPC);
#    1195         [ +  + ]:        792 :     for (const auto& client : node.chain_clients) {
#    1196                 :        788 :         client->registerRpcs();
#    1197                 :        788 :     }
#    1198                 :            : #if ENABLE_ZMQ
#    1199                 :            :     RegisterZMQRPCCommands(tableRPC);
#    1200                 :            : #endif
#    1201                 :            : 
#    1202                 :            :     /* Start the RPC server already.  It will be started in "warmup" mode
#    1203                 :            :      * and not really process calls already (but it will signify connections
#    1204                 :            :      * that the server is there and will be ready later).  Warmup mode will
#    1205                 :            :      * be disabled when initialisation is finished.
#    1206                 :            :      */
#    1207         [ +  + ]:        792 :     if (args.GetBoolArg("-server", false)) {
#    1208                 :        789 :         uiInterface.InitMessage_connect(SetRPCWarmupStatus);
#    1209         [ +  + ]:        789 :         if (!AppInitServers(node))
#    1210                 :          3 :             return InitError(_("Unable to start HTTP server. See debug log for details."));
#    1211                 :        789 :     }
#    1212                 :            : 
#    1213                 :            :     // ********************************************************* Step 5: verify wallet database integrity
#    1214         [ +  + ]:        789 :     for (const auto& client : node.chain_clients) {
#    1215         [ +  + ]:        785 :         if (!client->verify()) {
#    1216                 :         23 :             return false;
#    1217                 :         23 :         }
#    1218                 :        785 :     }
#    1219                 :            : 
#    1220                 :            :     // ********************************************************* Step 6: network initialization
#    1221                 :            :     // Note that we absolutely cannot open any actual connections
#    1222                 :            :     // until the very end ("start node") as the UTXO/block state
#    1223                 :            :     // is not yet setup and may end up being set up twice if we
#    1224                 :            :     // need to reindex later.
#    1225                 :            : 
#    1226                 :        766 :     fListen = args.GetBoolArg("-listen", DEFAULT_LISTEN);
#    1227                 :        766 :     fDiscover = args.GetBoolArg("-discover", true);
#    1228                 :        766 :     const bool ignores_incoming_txs{args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)};
#    1229                 :            : 
#    1230                 :        766 :     {
#    1231                 :            :         // Initialize addrman
#    1232                 :        766 :         assert(!node.addrman);
#    1233                 :            : 
#    1234                 :            :         // Read asmap file if configured
#    1235                 :          0 :         std::vector<bool> asmap;
#    1236         [ +  + ]:        766 :         if (args.IsArgSet("-asmap")) {
#    1237                 :          8 :             fs::path asmap_path = args.GetPathArg("-asmap", DEFAULT_ASMAP_FILENAME);
#    1238         [ +  + ]:          8 :             if (!asmap_path.is_absolute()) {
#    1239                 :          7 :                 asmap_path = gArgs.GetDataDirNet() / asmap_path;
#    1240                 :          7 :             }
#    1241         [ +  + ]:          8 :             if (!fs::exists(asmap_path)) {
#    1242                 :          1 :                 InitError(strprintf(_("Could not find asmap file %s"), fs::quoted(fs::PathToString(asmap_path))));
#    1243                 :          1 :                 return false;
#    1244                 :          1 :             }
#    1245                 :          7 :             asmap = DecodeAsmap(asmap_path);
#    1246         [ +  + ]:          7 :             if (asmap.size() == 0) {
#    1247                 :          1 :                 InitError(strprintf(_("Could not parse asmap file %s"), fs::quoted(fs::PathToString(asmap_path))));
#    1248                 :          1 :                 return false;
#    1249                 :          1 :             }
#    1250                 :          6 :             const uint256 asmap_version = SerializeHash(asmap);
#    1251                 :          6 :             LogPrintf("Using asmap version %s for IP bucketing\n", asmap_version.ToString());
#    1252                 :        758 :         } else {
#    1253                 :        758 :             LogPrintf("Using /16 prefix for IP bucketing\n");
#    1254                 :        758 :         }
#    1255                 :            : 
#    1256                 :        764 :         uiInterface.InitMessage(_("Loading P2P addresses…").translated);
#    1257         [ +  + ]:        764 :         if (const auto error{LoadAddrman(asmap, args, node.addrman)}) {
#    1258                 :          7 :             return InitError(*error);
#    1259                 :          7 :         }
#    1260                 :        764 :     }
#    1261                 :            : 
#    1262                 :        757 :     assert(!node.banman);
#    1263                 :          0 :     node.banman = std::make_unique<BanMan>(gArgs.GetDataDirNet() / "banlist", &uiInterface, args.GetIntArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
#    1264                 :        757 :     assert(!node.connman);
#    1265                 :          0 :     node.connman = std::make_unique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), *node.addrman, args.GetBoolArg("-networkactive", true));
#    1266                 :            : 
#    1267                 :        757 :     assert(!node.fee_estimator);
#    1268                 :            :     // Don't initialize fee estimation with old data if we don't relay transactions,
#    1269                 :            :     // as they would never get updated.
#    1270         [ +  + ]:        757 :     if (!ignores_incoming_txs) node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
#    1271                 :            : 
#    1272                 :        757 :     assert(!node.mempool);
#    1273         [ +  + ]:        757 :     int check_ratio = std::min<int>(std::max<int>(args.GetIntArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0), 1000000);
#    1274                 :        757 :     node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), check_ratio);
#    1275                 :            : 
#    1276                 :        757 :     assert(!node.chainman);
#    1277                 :          0 :     node.chainman = std::make_unique<ChainstateManager>();
#    1278                 :        757 :     ChainstateManager& chainman = *node.chainman;
#    1279                 :            : 
#    1280                 :        757 :     assert(!node.peerman);
#    1281                 :          0 :     node.peerman = PeerManager::make(chainparams, *node.connman, *node.addrman, node.banman.get(),
#    1282                 :        757 :                                      chainman, *node.mempool, ignores_incoming_txs);
#    1283                 :        757 :     RegisterValidationInterface(node.peerman.get());
#    1284                 :            : 
#    1285                 :            :     // sanitize comments per BIP-0014, format user agent and check total size
#    1286                 :        757 :     std::vector<std::string> uacomments;
#    1287         [ +  + ]:        771 :     for (const std::string& cmt : args.GetArgs("-uacomment")) {
#    1288         [ +  + ]:        771 :         if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT))
#    1289                 :          6 :             return InitError(strprintf(_("User Agent comment (%s) contains unsafe characters."), cmt));
#    1290                 :        765 :         uacomments.push_back(cmt);
#    1291                 :        765 :     }
#    1292                 :        751 :     strSubVersion = FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, uacomments);
#    1293         [ +  + ]:        751 :     if (strSubVersion.size() > MAX_SUBVERSION_LENGTH) {
#    1294                 :          1 :         return InitError(strprintf(_("Total length of network version string (%i) exceeds maximum length (%i). Reduce the number or size of uacomments."),
#    1295                 :          1 :             strSubVersion.size(), MAX_SUBVERSION_LENGTH));
#    1296                 :          1 :     }
#    1297                 :            : 
#    1298         [ +  + ]:        750 :     if (args.IsArgSet("-onlynet")) {
#    1299                 :          3 :         std::set<enum Network> nets;
#    1300         [ +  + ]:          3 :         for (const std::string& snet : args.GetArgs("-onlynet")) {
#    1301                 :          3 :             enum Network net = ParseNetwork(snet);
#    1302         [ -  + ]:          3 :             if (net == NET_UNROUTABLE)
#    1303                 :          0 :                 return InitError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet));
#    1304                 :          3 :             nets.insert(net);
#    1305                 :          3 :         }
#    1306         [ +  + ]:         24 :         for (int n = 0; n < NET_MAX; n++) {
#    1307                 :         21 :             enum Network net = (enum Network)n;
#    1308                 :         21 :             assert(IsReachable(net));
#    1309         [ +  + ]:         21 :             if (!nets.count(net))
#    1310                 :         18 :                 SetReachable(net, false);
#    1311                 :         21 :         }
#    1312                 :          3 :     }
#    1313                 :            : 
#    1314         [ +  + ]:        750 :     if (!args.IsArgSet("-cjdnsreachable")) {
#    1315                 :        749 :         SetReachable(NET_CJDNS, false);
#    1316                 :        749 :     }
#    1317                 :            :     // Now IsReachable(NET_CJDNS) is true if:
#    1318                 :            :     // 1. -cjdnsreachable is given and
#    1319                 :            :     // 2.1. -onlynet is not given or
#    1320                 :            :     // 2.2. -onlynet=cjdns is given
#    1321                 :            : 
#    1322                 :            :     // Check for host lookup allowed before parsing any network related parameters
#    1323                 :        750 :     fNameLookup = args.GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
#    1324                 :            : 
#    1325                 :        750 :     Proxy onion_proxy;
#    1326                 :            : 
#    1327                 :        750 :     bool proxyRandomize = args.GetBoolArg("-proxyrandomize", DEFAULT_PROXYRANDOMIZE);
#    1328                 :            :     // -proxy sets a proxy for all outgoing network traffic
#    1329                 :            :     // -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
#    1330                 :        750 :     std::string proxyArg = args.GetArg("-proxy", "");
#    1331 [ +  + ][ +  - ]:        750 :     if (proxyArg != "" && proxyArg != "0") {
#    1332                 :          8 :         CService proxyAddr;
#    1333         [ +  + ]:          8 :         if (!Lookup(proxyArg, proxyAddr, 9050, fNameLookup)) {
#    1334                 :          1 :             return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
#    1335                 :          1 :         }
#    1336                 :            : 
#    1337                 :          7 :         Proxy addrProxy = Proxy(proxyAddr, proxyRandomize);
#    1338         [ -  + ]:          7 :         if (!addrProxy.IsValid())
#    1339                 :          0 :             return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
#    1340                 :            : 
#    1341                 :          7 :         SetProxy(NET_IPV4, addrProxy);
#    1342                 :          7 :         SetProxy(NET_IPV6, addrProxy);
#    1343                 :          7 :         SetProxy(NET_CJDNS, addrProxy);
#    1344                 :          7 :         SetNameProxy(addrProxy);
#    1345                 :          7 :         onion_proxy = addrProxy;
#    1346                 :          7 :     }
#    1347                 :            : 
#    1348                 :            :     // -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
#    1349                 :            :     // -noonion (or -onion=0) disables connecting to .onion entirely
#    1350                 :            :     // An empty string is used to not override the onion proxy (in which case it defaults to -proxy set above, or none)
#    1351                 :        749 :     std::string onionArg = args.GetArg("-onion", "");
#    1352         [ +  + ]:        749 :     if (onionArg != "") {
#    1353         [ +  + ]:          5 :         if (onionArg == "0") { // Handle -noonion/-onion=0
#    1354                 :          3 :             onion_proxy = Proxy{};
#    1355                 :          3 :         } else {
#    1356                 :          2 :             CService addr;
#    1357 [ +  + ][ +  + ]:          2 :             if (!Lookup(onionArg, addr, 9050, fNameLookup) || !addr.IsValid()) {
#                 [ -  + ]
#    1358                 :          1 :                 return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
#    1359                 :          1 :             }
#    1360                 :          1 :             onion_proxy = Proxy{addr, proxyRandomize};
#    1361                 :          1 :         }
#    1362                 :          5 :     }
#    1363                 :            : 
#    1364         [ +  + ]:        748 :     if (onion_proxy.IsValid()) {
#    1365                 :          6 :         SetProxy(NET_ONION, onion_proxy);
#    1366                 :        742 :     } else {
#    1367 [ +  + ][ +  + ]:        742 :         if (args.IsArgSet("-onlynet") && IsReachable(NET_ONION)) {
#                 [ +  - ]
#    1368                 :          3 :             return InitError(
#    1369                 :          3 :                 _("Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
#    1370                 :          3 :                   "reaching the Tor network is not provided (no -proxy= and no -onion= given) or "
#    1371                 :          3 :                   "it is explicitly forbidden (-onion=0)"));
#    1372                 :          3 :         }
#    1373                 :        739 :         SetReachable(NET_ONION, false);
#    1374                 :        739 :     }
#    1375                 :            : 
#    1376         [ -  + ]:        745 :     for (const std::string& strAddr : args.GetArgs("-externalip")) {
#    1377                 :          0 :         CService addrLocal;
#    1378 [ #  # ][ #  # ]:          0 :         if (Lookup(strAddr, addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())
#                 [ #  # ]
#    1379                 :          0 :             AddLocal(addrLocal, LOCAL_MANUAL);
#    1380                 :          0 :         else
#    1381                 :          0 :             return InitError(ResolveErrMsg("externalip", strAddr));
#    1382                 :          0 :     }
#    1383                 :            : 
#    1384                 :            : #if ENABLE_ZMQ
#    1385                 :            :     g_zmq_notification_interface = CZMQNotificationInterface::Create();
#    1386                 :            : 
#    1387                 :            :     if (g_zmq_notification_interface) {
#    1388                 :            :         RegisterValidationInterface(g_zmq_notification_interface);
#    1389                 :            :     }
#    1390                 :            : #endif
#    1391                 :            : 
#    1392                 :            :     // ********************************************************* Step 7: load block chain
#    1393                 :            : 
#    1394                 :        745 :     fReindex = args.GetBoolArg("-reindex", false);
#    1395                 :        745 :     bool fReindexChainState = args.GetBoolArg("-reindex-chainstate", false);
#    1396                 :            : 
#    1397                 :            :     // cache size calculations
#    1398                 :        745 :     CacheSizes cache_sizes = CalculateCacheSizes(args, g_enabled_filter_types.size());
#    1399                 :            : 
#    1400                 :        745 :     int64_t nMempoolSizeMax = args.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
#    1401                 :        745 :     LogPrintf("Cache configuration:\n");
#    1402                 :        745 :     LogPrintf("* Using %.1f MiB for block index database\n", cache_sizes.block_tree_db * (1.0 / 1024 / 1024));
#    1403         [ +  + ]:        745 :     if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
#    1404                 :         33 :         LogPrintf("* Using %.1f MiB for transaction index database\n", cache_sizes.tx_index * (1.0 / 1024 / 1024));
#    1405                 :         33 :     }
#    1406         [ +  + ]:        745 :     for (BlockFilterType filter_type : g_enabled_filter_types) {
#    1407                 :         33 :         LogPrintf("* Using %.1f MiB for %s block filter index database\n",
#    1408                 :         33 :                   cache_sizes.filter_index * (1.0 / 1024 / 1024), BlockFilterTypeName(filter_type));
#    1409                 :         33 :     }
#    1410                 :        745 :     LogPrintf("* Using %.1f MiB for chain state database\n", cache_sizes.coins_db * (1.0 / 1024 / 1024));
#    1411                 :        745 :     LogPrintf("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)\n", cache_sizes.coins * (1.0 / 1024 / 1024), nMempoolSizeMax * (1.0 / 1024 / 1024));
#    1412                 :            : 
#    1413                 :        745 :     bool fLoaded = false;
#    1414 [ +  + ][ +  + ]:       1478 :     while (!fLoaded && !ShutdownRequested()) {
#    1415                 :        739 :         const bool fReset = fReindex;
#    1416                 :        739 :         bilingual_str strLoadError;
#    1417                 :            : 
#    1418                 :        739 :         uiInterface.InitMessage(_("Loading block index…").translated);
#    1419                 :        739 :         const int64_t load_block_index_start_time = GetTimeMillis();
#    1420                 :        739 :         std::optional<ChainstateLoadingError> maybe_load_error;
#    1421                 :        739 :         try {
#    1422                 :        739 :             maybe_load_error = LoadChainstate(fReset,
#    1423                 :        739 :                                               chainman,
#    1424                 :        739 :                                               Assert(node.mempool.get()),
#    1425                 :        739 :                                               fPruneMode,
#    1426                 :        739 :                                               chainparams.GetConsensus(),
#    1427                 :        739 :                                               fReindexChainState,
#    1428                 :        739 :                                               cache_sizes.block_tree_db,
#    1429                 :        739 :                                               cache_sizes.coins_db,
#    1430                 :        739 :                                               cache_sizes.coins,
#    1431                 :        739 :                                               /*block_tree_db_in_memory=*/false,
#    1432                 :        739 :                                               /*coins_db_in_memory=*/false,
#    1433                 :        739 :                                               /*shutdown_requested=*/ShutdownRequested,
#    1434                 :        739 :                                               /*coins_error_cb=*/[]() {
#    1435                 :          0 :                                                   uiInterface.ThreadSafeMessageBox(
#    1436                 :          0 :                                                                                    _("Error reading from database, shutting down."),
#    1437                 :          0 :                                                                                    "", CClientUIInterface::MSG_ERROR);
#    1438                 :          0 :                                               });
#    1439                 :        739 :         } catch (const std::exception& e) {
#    1440                 :          2 :             LogPrintf("%s\n", e.what());
#    1441                 :          2 :             maybe_load_error = ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
#    1442                 :          2 :         }
#    1443         [ +  + ]:        739 :         if (maybe_load_error.has_value()) {
#    1444         [ -  + ]:          7 :             switch (maybe_load_error.value()) {
#    1445         [ +  + ]:          1 :             case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:
#    1446                 :          1 :                 strLoadError = _("Error loading block database");
#    1447                 :          1 :                 break;
#    1448         [ -  + ]:          0 :             case ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK:
#    1449                 :            :                 // If the loaded chain has a wrong genesis, bail out immediately
#    1450                 :            :                 // (we're likely using a testnet datadir, or the other way around).
#    1451                 :          0 :                 return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
#    1452         [ -  + ]:          0 :             case ChainstateLoadingError::ERROR_PRUNED_NEEDS_REINDEX:
#    1453                 :          0 :                 strLoadError = _("You need to rebuild the database using -reindex to go back to unpruned mode.  This will redownload the entire blockchain");
#    1454                 :          0 :                 break;
#    1455         [ -  + ]:          0 :             case ChainstateLoadingError::ERROR_LOAD_GENESIS_BLOCK_FAILED:
#    1456                 :          0 :                 strLoadError = _("Error initializing block database");
#    1457                 :          0 :                 break;
#    1458         [ -  + ]:          0 :             case ChainstateLoadingError::ERROR_CHAINSTATE_UPGRADE_FAILED:
#    1459                 :          0 :                 return InitError(_("Unsupported chainstate database format found. "
#    1460                 :          0 :                                    "Please restart with -reindex-chainstate. This will "
#    1461                 :          0 :                                    "rebuild the chainstate database."));
#    1462         [ -  + ]:          0 :             case ChainstateLoadingError::ERROR_REPLAYBLOCKS_FAILED:
#    1463                 :          0 :                 strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.");
#    1464                 :          0 :                 break;
#    1465         [ -  + ]:          0 :             case ChainstateLoadingError::ERROR_LOADCHAINTIP_FAILED:
#    1466                 :          0 :                 strLoadError = _("Error initializing block database");
#    1467                 :          0 :                 break;
#    1468         [ +  + ]:          2 :             case ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED:
#    1469                 :          2 :                 strLoadError = _("Error opening block database");
#    1470                 :          2 :                 break;
#    1471         [ +  + ]:          1 :             case ChainstateLoadingError::ERROR_BLOCKS_WITNESS_INSUFFICIENTLY_VALIDATED:
#    1472                 :          1 :                 strLoadError = strprintf(_("Witness data for blocks after height %d requires validation. Please restart with -reindex."),
#    1473                 :          1 :                                          chainparams.GetConsensus().SegwitHeight);
#    1474                 :          1 :                 break;
#    1475         [ +  + ]:          3 :             case ChainstateLoadingError::SHUTDOWN_PROBED:
#    1476                 :          3 :                 break;
#    1477                 :          7 :             }
#    1478                 :        732 :         } else {
#    1479                 :        732 :             std::optional<ChainstateLoadVerifyError> maybe_verify_error;
#    1480                 :        732 :             try {
#    1481                 :        732 :                 uiInterface.InitMessage(_("Verifying blocks…").translated);
#    1482                 :        732 :                 auto check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
#    1483 [ +  + ][ -  + ]:        732 :                 if (fHavePruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
#    1484                 :          0 :                     LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n",
#    1485                 :          0 :                               MIN_BLOCKS_TO_KEEP);
#    1486                 :          0 :                 }
#    1487                 :        732 :                 maybe_verify_error = VerifyLoadedChainstate(chainman,
#    1488                 :        732 :                                                             fReset,
#    1489                 :        732 :                                                             fReindexChainState,
#    1490                 :        732 :                                                             chainparams.GetConsensus(),
#    1491                 :        732 :                                                             check_blocks,
#    1492                 :        732 :                                                             args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL),
#    1493                 :        732 :                                                             /*get_unix_time_seconds=*/static_cast<int64_t(*)()>(GetTime));
#    1494                 :        732 :             } catch (const std::exception& e) {
#    1495                 :          0 :                 LogPrintf("%s\n", e.what());
#    1496                 :          0 :                 maybe_verify_error = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE;
#    1497                 :          0 :             }
#    1498         [ +  + ]:        732 :             if (maybe_verify_error.has_value()) {
#    1499         [ -  + ]:          2 :                 switch (maybe_verify_error.value()) {
#    1500         [ +  + ]:          1 :                 case ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE:
#    1501                 :          1 :                     strLoadError = _("The block database contains a block which appears to be from the future. "
#    1502                 :          1 :                                      "This may be due to your computer's date and time being set incorrectly. "
#    1503                 :          1 :                                      "Only rebuild the block database if you are sure that your computer's date and time are correct");
#    1504                 :          1 :                     break;
#    1505         [ +  + ]:          1 :                 case ChainstateLoadVerifyError::ERROR_CORRUPTED_BLOCK_DB:
#    1506                 :          1 :                     strLoadError = _("Corrupted block database detected");
#    1507                 :          1 :                     break;
#    1508         [ -  + ]:          0 :                 case ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE:
#    1509                 :          0 :                     strLoadError = _("Error opening block database");
#    1510                 :          0 :                     break;
#    1511                 :          2 :                 }
#    1512                 :        730 :             } else {
#    1513                 :        730 :                 fLoaded = true;
#    1514                 :        730 :                 LogPrintf(" block index %15dms\n", GetTimeMillis() - load_block_index_start_time);
#    1515                 :        730 :             }
#    1516                 :        732 :         }
#    1517                 :            : 
#    1518 [ +  + ][ +  + ]:        739 :         if (!fLoaded && !ShutdownRequested()) {
#    1519                 :            :             // first suggest a reindex
#    1520         [ +  - ]:          6 :             if (!fReset) {
#    1521                 :          6 :                 bool fRet = uiInterface.ThreadSafeQuestion(
#    1522                 :          6 :                     strLoadError + Untranslated(".\n\n") + _("Do you want to rebuild the block database now?"),
#    1523                 :          6 :                     strLoadError.original + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
#    1524                 :          6 :                     "", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
#    1525         [ -  + ]:          6 :                 if (fRet) {
#    1526                 :          0 :                     fReindex = true;
#    1527                 :          0 :                     AbortShutdown();
#    1528                 :          6 :                 } else {
#    1529                 :          6 :                     LogPrintf("Aborted block database rebuild. Exiting.\n");
#    1530                 :          6 :                     return false;
#    1531                 :          6 :                 }
#    1532                 :          6 :             } else {
#    1533                 :          0 :                 return InitError(strLoadError);
#    1534                 :          0 :             }
#    1535                 :          6 :         }
#    1536                 :        739 :     }
#    1537                 :            : 
#    1538                 :            :     // As LoadBlockIndex can take several minutes, it's possible the user
#    1539                 :            :     // requested to kill the GUI during the last operation. If so, exit.
#    1540                 :            :     // As the program has not fully started yet, Shutdown() is possibly overkill.
#    1541         [ +  + ]:        739 :     if (ShutdownRequested()) {
#    1542                 :         11 :         LogPrintf("Shutdown requested. Exiting.\n");
#    1543                 :         11 :         return false;
#    1544                 :         11 :     }
#    1545                 :            : 
#    1546                 :            :     // ********************************************************* Step 8: start indexers
#    1547         [ +  + ]:        728 :     if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
#    1548         [ -  + ]:         19 :         if (const auto error{WITH_LOCK(cs_main, return CheckLegacyTxindex(*Assert(chainman.m_blockman.m_block_tree_db)))}) {
#    1549                 :          0 :             return InitError(*error);
#    1550                 :          0 :         }
#    1551                 :            : 
#    1552                 :         19 :         g_txindex = std::make_unique<TxIndex>(cache_sizes.tx_index, false, fReindex);
#    1553         [ -  + ]:         19 :         if (!g_txindex->Start(chainman.ActiveChainstate())) {
#    1554                 :          0 :             return false;
#    1555                 :          0 :         }
#    1556                 :         19 :     }
#    1557                 :            : 
#    1558         [ +  + ]:        728 :     for (const auto& filter_type : g_enabled_filter_types) {
#    1559                 :         19 :         InitBlockFilterIndex(filter_type, cache_sizes.filter_index, false, fReindex);
#    1560         [ +  + ]:         19 :         if (!GetBlockFilterIndex(filter_type)->Start(chainman.ActiveChainstate())) {
#    1561                 :          1 :             return false;
#    1562                 :          1 :         }
#    1563                 :         19 :     }
#    1564                 :            : 
#    1565         [ +  + ]:        727 :     if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
#    1566                 :         13 :         g_coin_stats_index = std::make_unique<CoinStatsIndex>(/* cache size */ 0, false, fReindex);
#    1567         [ -  + ]:         13 :         if (!g_coin_stats_index->Start(chainman.ActiveChainstate())) {
#    1568                 :          0 :             return false;
#    1569                 :          0 :         }
#    1570                 :         13 :     }
#    1571                 :            : 
#    1572                 :            :     // ********************************************************* Step 9: load wallet
#    1573         [ +  + ]:        727 :     for (const auto& client : node.chain_clients) {
#    1574         [ +  + ]:        723 :         if (!client->load()) {
#    1575                 :          2 :             return false;
#    1576                 :          2 :         }
#    1577                 :        723 :     }
#    1578                 :            : 
#    1579                 :            :     // ********************************************************* Step 10: data directory maintenance
#    1580                 :            : 
#    1581                 :            :     // if pruning, unset the service bit and perform the initial blockstore prune
#    1582                 :            :     // after any wallet rescanning has taken place.
#    1583         [ +  + ]:        725 :     if (fPruneMode) {
#    1584                 :         10 :         LogPrintf("Unsetting NODE_NETWORK on prune mode\n");
#    1585                 :         10 :         nLocalServices = ServiceFlags(nLocalServices & ~NODE_NETWORK);
#    1586         [ +  + ]:         10 :         if (!fReindex) {
#    1587                 :          9 :             LOCK(cs_main);
#    1588         [ +  + ]:          9 :             for (CChainState* chainstate : chainman.GetAll()) {
#    1589                 :          9 :                 uiInterface.InitMessage(_("Pruning blockstore…").translated);
#    1590                 :          9 :                 chainstate->PruneAndFlush();
#    1591                 :          9 :             }
#    1592                 :          9 :         }
#    1593                 :         10 :     }
#    1594                 :            : 
#    1595                 :            :     // ********************************************************* Step 11: import blocks
#    1596                 :            : 
#    1597         [ -  + ]:        725 :     if (!CheckDiskSpace(gArgs.GetDataDirNet())) {
#    1598                 :          0 :         InitError(strprintf(_("Error: Disk space is low for %s"), fs::quoted(fs::PathToString(gArgs.GetDataDirNet()))));
#    1599                 :          0 :         return false;
#    1600                 :          0 :     }
#    1601         [ -  + ]:        725 :     if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) {
#    1602                 :          0 :         InitError(strprintf(_("Error: Disk space is low for %s"), fs::quoted(fs::PathToString(gArgs.GetBlocksDirPath()))));
#    1603                 :          0 :         return false;
#    1604                 :          0 :     }
#    1605                 :            : 
#    1606                 :            :     // Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
#    1607                 :            :     // No locking, as this happens before any background thread is started.
#    1608                 :        725 :     boost::signals2::connection block_notify_genesis_wait_connection;
#    1609         [ +  + ]:        725 :     if (chainman.ActiveChain().Tip() == nullptr) {
#    1610                 :        268 :         block_notify_genesis_wait_connection = uiInterface.NotifyBlockTip_connect(std::bind(BlockNotifyGenesisWait, std::placeholders::_2));
#    1611                 :        457 :     } else {
#    1612                 :        457 :         fHaveGenesis = true;
#    1613                 :        457 :     }
#    1614                 :            : 
#    1615                 :        725 : #if HAVE_SYSTEM
#    1616                 :        725 :     const std::string block_notify = args.GetArg("-blocknotify", "");
#    1617         [ +  + ]:        725 :     if (!block_notify.empty()) {
#    1618                 :        113 :         uiInterface.NotifyBlockTip_connect([block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
#    1619 [ +  + ][ -  + ]:        113 :             if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) return;
#    1620                 :        112 :             std::string command = block_notify;
#    1621                 :        112 :             boost::replace_all(command, "%s", pBlockIndex->GetBlockHash().GetHex());
#    1622                 :        112 :             std::thread t(runCommand, command);
#    1623                 :        112 :             t.detach(); // thread runs free
#    1624                 :        112 :         });
#    1625                 :          1 :     }
#    1626                 :        725 : #endif
#    1627                 :            : 
#    1628                 :        725 :     std::vector<fs::path> vImportFiles;
#    1629         [ +  + ]:        725 :     for (const std::string& strFile : args.GetArgs("-loadblock")) {
#    1630                 :          1 :         vImportFiles.push_back(fs::PathFromString(strFile));
#    1631                 :          1 :     }
#    1632                 :            : 
#    1633                 :        725 :     chainman.m_load_block = std::thread(&util::TraceThread, "loadblk", [=, &chainman, &args] {
#    1634                 :        725 :         ThreadImport(chainman, vImportFiles, args);
#    1635                 :        725 :     });
#    1636                 :            : 
#    1637                 :            :     // Wait for genesis block to be processed
#    1638                 :        725 :     {
#    1639                 :        725 :         WAIT_LOCK(g_genesis_wait_mutex, lock);
#    1640                 :            :         // We previously could hang here if StartShutdown() is called prior to
#    1641                 :            :         // ThreadImport getting started, so instead we just wait on a timer to
#    1642                 :            :         // check ShutdownRequested() regularly.
#    1643 [ +  + ][ +  - ]:        993 :         while (!fHaveGenesis && !ShutdownRequested()) {
#    1644                 :        268 :             g_genesis_wait_cv.wait_for(lock, std::chrono::milliseconds(500));
#    1645                 :        268 :         }
#    1646                 :        725 :         block_notify_genesis_wait_connection.disconnect();
#    1647                 :        725 :     }
#    1648                 :            : 
#    1649         [ +  + ]:        725 :     if (ShutdownRequested()) {
#    1650                 :          2 :         return false;
#    1651                 :          2 :     }
#    1652                 :            : 
#    1653                 :            :     // ********************************************************* Step 12: start node
#    1654                 :            : 
#    1655                 :        723 :     int chain_active_height;
#    1656                 :            : 
#    1657                 :            :     //// debug print
#    1658                 :        723 :     {
#    1659                 :        723 :         LOCK(cs_main);
#    1660                 :        723 :         LogPrintf("block tree size = %u\n", chainman.BlockIndex().size());
#    1661                 :        723 :         chain_active_height = chainman.ActiveChain().Height();
#    1662         [ +  + ]:        723 :         if (tip_info) {
#    1663                 :          1 :             tip_info->block_height = chain_active_height;
#    1664         [ +  - ]:          1 :             tip_info->block_time = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockTime() : Params().GenesisBlock().GetBlockTime();
#    1665                 :          1 :             tip_info->verification_progress = GuessVerificationProgress(Params().TxData(), chainman.ActiveChain().Tip());
#    1666                 :          1 :         }
#    1667 [ +  + ][ +  - ]:        723 :         if (tip_info && ::pindexBestHeader) {
#    1668                 :          1 :             tip_info->header_height = ::pindexBestHeader->nHeight;
#    1669                 :          1 :             tip_info->header_time = ::pindexBestHeader->GetBlockTime();
#    1670                 :          1 :         }
#    1671                 :        723 :     }
#    1672                 :        723 :     LogPrintf("nBestHeight = %d\n", chain_active_height);
#    1673         [ +  - ]:        723 :     if (node.peerman) node.peerman->SetBestHeight(chain_active_height);
#    1674                 :            : 
#    1675                 :            :     // Map ports with UPnP or NAT-PMP.
#    1676                 :        723 :     StartMapPort(args.GetBoolArg("-upnp", DEFAULT_UPNP), gArgs.GetBoolArg("-natpmp", DEFAULT_NATPMP));
#    1677                 :            : 
#    1678                 :        723 :     CConnman::Options connOptions;
#    1679                 :        723 :     connOptions.nLocalServices = nLocalServices;
#    1680                 :        723 :     connOptions.nMaxConnections = nMaxConnections;
#    1681                 :        723 :     connOptions.m_max_outbound_full_relay = std::min(MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, connOptions.nMaxConnections);
#    1682                 :        723 :     connOptions.m_max_outbound_block_relay = std::min(MAX_BLOCK_RELAY_ONLY_CONNECTIONS, connOptions.nMaxConnections-connOptions.m_max_outbound_full_relay);
#    1683                 :        723 :     connOptions.nMaxAddnode = MAX_ADDNODE_CONNECTIONS;
#    1684                 :        723 :     connOptions.nMaxFeeler = MAX_FEELER_CONNECTIONS;
#    1685                 :        723 :     connOptions.uiInterface = &uiInterface;
#    1686                 :        723 :     connOptions.m_banman = node.banman.get();
#    1687                 :        723 :     connOptions.m_msgproc = node.peerman.get();
#    1688                 :        723 :     connOptions.nSendBufferMaxSize = 1000 * args.GetIntArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
#    1689                 :        723 :     connOptions.nReceiveFloodSize = 1000 * args.GetIntArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);
#    1690                 :        723 :     connOptions.m_added_nodes = args.GetArgs("-addnode");
#    1691                 :        723 :     connOptions.nMaxOutboundLimit = *opt_max_upload;
#    1692                 :        723 :     connOptions.m_peer_connect_timeout = peer_connect_timeout;
#    1693                 :            : 
#    1694                 :            :     // Port to bind to if `-bind=addr` is provided without a `:port` suffix.
#    1695                 :        723 :     const uint16_t default_bind_port =
#    1696                 :        723 :         static_cast<uint16_t>(args.GetIntArg("-port", Params().GetDefaultPort()));
#    1697                 :            : 
#    1698                 :        723 :     const auto BadPortWarning = [](const char* prefix, uint16_t port) {
#    1699                 :          0 :         return strprintf(_("%s request to listen on port %u. This port is considered \"bad\" and "
#    1700                 :          0 :                            "thus it is unlikely that any Bitcoin Core peers connect to it. See "
#    1701                 :          0 :                            "doc/p2p-bad-ports.md for details and a full list."),
#    1702                 :          0 :                          prefix,
#    1703                 :          0 :                          port);
#    1704                 :          0 :     };
#    1705                 :            : 
#    1706         [ +  + ]:        723 :     for (const std::string& bind_arg : args.GetArgs("-bind")) {
#    1707                 :        720 :         CService bind_addr;
#    1708                 :        720 :         const size_t index = bind_arg.rfind('=');
#    1709         [ +  - ]:        720 :         if (index == std::string::npos) {
#    1710         [ +  - ]:        720 :             if (Lookup(bind_arg, bind_addr, default_bind_port, /*fAllowLookup=*/false)) {
#    1711                 :        720 :                 connOptions.vBinds.push_back(bind_addr);
#    1712         [ -  + ]:        720 :                 if (IsBadPort(bind_addr.GetPort())) {
#    1713                 :          0 :                     InitWarning(BadPortWarning("-bind", bind_addr.GetPort()));
#    1714                 :          0 :                 }
#    1715                 :        720 :                 continue;
#    1716                 :        720 :             }
#    1717                 :        720 :         } else {
#    1718                 :          0 :             const std::string network_type = bind_arg.substr(index + 1);
#    1719         [ #  # ]:          0 :             if (network_type == "onion") {
#    1720                 :          0 :                 const std::string truncated_bind_arg = bind_arg.substr(0, index);
#    1721         [ #  # ]:          0 :                 if (Lookup(truncated_bind_arg, bind_addr, BaseParams().OnionServiceTargetPort(), false)) {
#    1722                 :          0 :                     connOptions.onion_binds.push_back(bind_addr);
#    1723                 :          0 :                     continue;
#    1724                 :          0 :                 }
#    1725                 :          0 :             }
#    1726                 :          0 :         }
#    1727                 :          0 :         return InitError(ResolveErrMsg("bind", bind_arg));
#    1728                 :        720 :     }
#    1729                 :            : 
#    1730         [ +  + ]:        723 :     for (const std::string& strBind : args.GetArgs("-whitebind")) {
#    1731                 :          2 :         NetWhitebindPermissions whitebind;
#    1732                 :          2 :         bilingual_str error;
#    1733         [ +  + ]:          2 :         if (!NetWhitebindPermissions::TryParse(strBind, whitebind, error)) return InitError(error);
#    1734                 :          1 :         connOptions.vWhiteBinds.push_back(whitebind);
#    1735                 :          1 :     }
#    1736                 :            : 
#    1737                 :            :     // If the user did not specify -bind= or -whitebind= then we bind
#    1738                 :            :     // on any address - 0.0.0.0 (IPv4) and :: (IPv6).
#    1739 [ +  + ][ +  + ]:        722 :     connOptions.bind_on_any = args.GetArgs("-bind").empty() && args.GetArgs("-whitebind").empty();
#    1740                 :            : 
#    1741                 :            :     // Emit a warning if a bad port is given to -port= but only if -bind and -whitebind are not
#    1742                 :            :     // given, because if they are, then -port= is ignored.
#    1743 [ +  + ][ +  + ]:        722 :     if (connOptions.bind_on_any && args.IsArgSet("-port")) {
#                 [ +  + ]
#    1744                 :          1 :         const uint16_t port_arg = args.GetIntArg("-port", 0);
#    1745         [ -  + ]:          1 :         if (IsBadPort(port_arg)) {
#    1746                 :          0 :             InitWarning(BadPortWarning("-port", port_arg));
#    1747                 :          0 :         }
#    1748                 :          1 :     }
#    1749                 :            : 
#    1750                 :        722 :     CService onion_service_target;
#    1751         [ -  + ]:        722 :     if (!connOptions.onion_binds.empty()) {
#    1752                 :          0 :         onion_service_target = connOptions.onion_binds.front();
#    1753                 :        722 :     } else {
#    1754                 :        722 :         onion_service_target = DefaultOnionServiceTarget();
#    1755                 :        722 :         connOptions.onion_binds.push_back(onion_service_target);
#    1756                 :        722 :     }
#    1757                 :            : 
#    1758         [ -  + ]:        722 :     if (args.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION)) {
#    1759         [ #  # ]:          0 :         if (connOptions.onion_binds.size() > 1) {
#    1760                 :          0 :             InitWarning(strprintf(_("More than one onion bind address is provided. Using %s "
#    1761                 :          0 :                                     "for the automatically created Tor onion service."),
#    1762                 :          0 :                                   onion_service_target.ToStringIPPort()));
#    1763                 :          0 :         }
#    1764                 :          0 :         StartTorControl(onion_service_target);
#    1765                 :          0 :     }
#    1766                 :            : 
#    1767         [ +  + ]:        722 :     if (connOptions.bind_on_any) {
#    1768                 :            :         // Only add all IP addresses of the machine if we would be listening on
#    1769                 :            :         // any address - 0.0.0.0 (IPv4) and :: (IPv6).
#    1770                 :          2 :         Discover();
#    1771                 :          2 :     }
#    1772                 :            : 
#    1773         [ +  + ]:        722 :     for (const auto& net : args.GetArgs("-whitelist")) {
#    1774                 :        106 :         NetWhitelistPermissions subnet;
#    1775                 :        106 :         bilingual_str error;
#    1776         [ +  + ]:        106 :         if (!NetWhitelistPermissions::TryParse(net, subnet, error)) return InitError(error);
#    1777                 :        104 :         connOptions.vWhitelistedRange.push_back(subnet);
#    1778                 :        104 :     }
#    1779                 :            : 
#    1780                 :        720 :     connOptions.vSeedNodes = args.GetArgs("-seednode");
#    1781                 :            : 
#    1782                 :            :     // Initiate outbound connections unless connect=0
#    1783                 :        720 :     connOptions.m_use_addrman_outgoing = !args.IsArgSet("-connect");
#    1784         [ +  + ]:        720 :     if (!connOptions.m_use_addrman_outgoing) {
#    1785                 :        701 :         const auto connect = args.GetArgs("-connect");
#    1786 [ +  + ][ +  + ]:        701 :         if (connect.size() != 1 || connect[0] != "0") {
#    1787                 :          3 :             connOptions.m_specified_outgoing = connect;
#    1788                 :          3 :         }
#    1789                 :        701 :     }
#    1790                 :            : 
#    1791                 :        720 :     const std::string& i2psam_arg = args.GetArg("-i2psam", "");
#    1792         [ +  + ]:        720 :     if (!i2psam_arg.empty()) {
#    1793                 :          5 :         CService addr;
#    1794 [ +  + ][ +  + ]:          5 :         if (!Lookup(i2psam_arg, addr, 7656, fNameLookup) || !addr.IsValid()) {
#                 [ -  + ]
#    1795                 :          1 :             return InitError(strprintf(_("Invalid -i2psam address or hostname: '%s'"), i2psam_arg));
#    1796                 :          1 :         }
#    1797                 :          4 :         SetProxy(NET_I2P, Proxy{addr});
#    1798                 :        715 :     } else {
#    1799                 :        715 :         SetReachable(NET_I2P, false);
#    1800                 :        715 :     }
#    1801                 :            : 
#    1802                 :        719 :     connOptions.m_i2p_accept_incoming = args.GetBoolArg("-i2pacceptincoming", true);
#    1803                 :            : 
#    1804         [ -  + ]:        719 :     if (!node.connman->Start(*node.scheduler, connOptions)) {
#    1805                 :          0 :         return false;
#    1806                 :          0 :     }
#    1807                 :            : 
#    1808                 :            :     // ********************************************************* Step 13: finished
#    1809                 :            : 
#    1810                 :            :     // At this point, the RPC is "started", but still in warmup, which means it
#    1811                 :            :     // cannot yet be called. Before we make it callable, we need to make sure
#    1812                 :            :     // that the RPC's view of the best block is valid and consistent with
#    1813                 :            :     // ChainstateManager's ActiveTip.
#    1814                 :            :     //
#    1815                 :            :     // If we do not do this, RPC's view of the best block will be height=0 and
#    1816                 :            :     // hash=0x0. This will lead to erroroneous responses for things like
#    1817                 :            :     // waitforblockheight.
#    1818                 :        719 :     RPCNotifyBlockChange(chainman.ActiveTip());
#    1819                 :        719 :     SetRPCWarmupFinished();
#    1820                 :            : 
#    1821                 :        719 :     uiInterface.InitMessage(_("Done loading").translated);
#    1822                 :            : 
#    1823         [ +  + ]:        719 :     for (const auto& client : node.chain_clients) {
#    1824                 :        715 :         client->start(*node.scheduler);
#    1825                 :        715 :     }
#    1826                 :            : 
#    1827                 :        719 :     BanMan* banman = node.banman.get();
#    1828                 :        719 :     node.scheduler->scheduleEvery([banman]{
#    1829                 :          3 :         banman->DumpBanlist();
#    1830                 :          3 :     }, DUMP_BANS_INTERVAL);
#    1831                 :            : 
#    1832         [ +  - ]:        719 :     if (node.peerman) node.peerman->StartScheduledTasks(*node.scheduler);
#    1833                 :            : 
#    1834                 :        719 : #if HAVE_SYSTEM
#    1835                 :        719 :     StartupNotify(args);
#    1836                 :        719 : #endif
#    1837                 :            : 
#    1838                 :        719 :     return true;
#    1839                 :        719 : }

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a