Line data Source code
1 : // Copyright (c) 2009-2010 Satoshi Nakamoto
2 : // Copyright (c) 2009-2021 The Bitcoin Core developers
3 : // Copyright (c) 2014-2026 The Dash Core developers
4 : // Distributed under the MIT software license, see the accompanying
5 : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 :
7 : #if defined(HAVE_CONFIG_H)
8 : #include <config/bitcoin-config.h>
9 : #endif
10 :
11 : #include <init.h>
12 :
13 : #include <addrman.h>
14 : #include <banman.h>
15 : #include <base58.h>
16 : #include <blockfilter.h>
17 : #include <chain.h>
18 : #include <chainparams.h>
19 : #include <context.h>
20 : #include <consensus/amount.h>
21 : #include <deploymentstatus.h>
22 : #include <fs.h>
23 : #include <hash.h>
24 : #include <httpserver.h>
25 : #include <httprpc.h>
26 : #include <chainlock/chainlock.h>
27 : #include <chainlock/handler.h>
28 : #include <init/common.h>
29 : #include <interfaces/chain.h>
30 : #include <index/addressindex.h>
31 : #include <index/blockfilterindex.h>
32 : #include <index/coinstatsindex.h>
33 : #include <index/spentindex.h>
34 : #include <index/timestampindex.h>
35 : #include <index/txindex.h>
36 : #include <interfaces/init.h>
37 : #include <interfaces/node.h>
38 : #include <interfaces/wallet.h>
39 : #include <kernel/coinstats.h>
40 : #include <mapport.h>
41 : #include <node/miner.h>
42 : #include <net.h>
43 : #include <net_permissions.h>
44 : #include <net_processing.h>
45 : #include <netbase.h>
46 : #include <netgroup.h>
47 : #include <node/blockstorage.h>
48 : #include <node/caches.h>
49 : #include <node/chainstate.h>
50 : #include <node/context.h>
51 : #include <node/interface_ui.h>
52 : #include <node/sync_manager.h>
53 : #include <node/txreconciliation.h>
54 : #include <policy/feerate.h>
55 : #include <policy/fees.h>
56 : #include <policy/policy.h>
57 : #include <policy/settings.h>
58 : #include <rpc/blockchain.h>
59 : #include <rpc/register.h>
60 : #include <rpc/server.h>
61 : #include <rpc/util.h>
62 : #include <scheduler.h>
63 : #include <script/sigcache.h>
64 : #include <script/standard.h>
65 : #include <shutdown.h>
66 : #include <sync.h>
67 : #include <timedata.h>
68 : #include <torcontrol.h>
69 : #include <txdb.h>
70 : #include <txmempool.h>
71 : #include <util/asmap.h>
72 : #include <util/error.h>
73 : #include <util/moneystr.h>
74 : #include <util/strencodings.h>
75 : #include <util/string.h>
76 : #include <util/syserror.h>
77 : #include <util/system.h>
78 : #include <util/thread.h>
79 : #include <util/threadnames.h>
80 : #include <util/translation.h>
81 : #include <validation.h>
82 : #include <validationinterface.h>
83 : #include <walletinitinterface.h>
84 :
85 : #include <active/context.h>
86 : #include <active/masternode.h>
87 : #include <bls/bls.h>
88 : #include <coinjoin/coinjoin.h>
89 : #include <coinjoin/server.h>
90 : #include <coinjoin/walletman.h>
91 : #include <dsnotificationinterface.h>
92 : #include <evo/chainhelper.h>
93 : #include <evo/deterministicmns.h>
94 : #include <evo/evodb.h>
95 : #include <evo/specialtxman.h>
96 : #include <flat-database.h>
97 : #include <governance/governance.h>
98 : #include <governance/net_governance.h>
99 : #include <instantsend/instantsend.h>
100 : #include <instantsend/net_instantsend.h>
101 : #include <llmq/context.h>
102 : #include <llmq/dkgsessionmgr.h>
103 : #include <llmq/signing.h>
104 : #include <llmq/net_dkg.h>
105 : #include <llmq/net_quorum.h>
106 : #include <llmq/net_signing.h>
107 : #include <llmq/observer.h>
108 : #include <llmq/options.h>
109 : #include <masternode/meta.h>
110 : #include <masternode/sync.h>
111 : #include <masternode/utils.h>
112 : #include <messagesigner.h>
113 : #include <netfulfilledman.h>
114 : #include <spork.h>
115 : #include <stats/client.h>
116 :
117 : #ifdef ENABLE_WALLET
118 : #include <coinjoin/client.h>
119 : #include <coinjoin/options.h>
120 : #endif // ENABLE_WALLET
121 :
122 : #include <algorithm>
123 : #include <condition_variable>
124 : #include <cstdint>
125 : #include <cstdio>
126 : #include <fstream>
127 : #include <functional>
128 : #include <set>
129 : #include <memory>
130 : #include <optional>
131 : #include <string>
132 : #include <thread>
133 : #include <vector>
134 :
135 : #ifndef WIN32
136 : #include <cerrno>
137 : #include <signal.h>
138 : #include <sys/stat.h>
139 : #endif
140 :
141 : #include <boost/signals2/signal.hpp>
142 :
143 : #if ENABLE_ZMQ
144 : #include <zmq/zmqabstractnotifier.h>
145 : #include <zmq/zmqnotificationinterface.h>
146 : #include <zmq/zmqrpc.h>
147 : #endif
148 :
149 : using kernel::CoinStatsHashType;
150 :
151 : using node::CacheSizes;
152 : using node::CalculateCacheSizes;
153 : using node::ChainstateLoadingError;
154 : using node::ChainstateLoadVerifyError;
155 : using node::DashChainstateSetupClose;
156 : using node::DEFAULT_PRINTPRIORITY;
157 : using node::DEFAULT_STOPAFTERBLOCKIMPORT;
158 : using node::LoadChainstate;
159 : using node::NodeContext;
160 : using node::ThreadImport;
161 : using node::VerifyLoadedChainstate;
162 : using node::fPruneMode;
163 : using node::fReindex;
164 : using node::nPruneTarget;
165 : #ifdef ENABLE_WALLET
166 : using wallet::DEFAULT_DISABLE_WALLET;
167 : #endif // ENABLE_WALLET
168 :
169 : static constexpr bool DEFAULT_PROXYRANDOMIZE{true};
170 : static constexpr bool DEFAULT_REST_ENABLE{false};
171 : static constexpr bool DEFAULT_I2P_ACCEPT_INCOMING{true};
172 :
173 : #ifdef WIN32
174 : // Win32 LevelDB doesn't use filedescriptors, and the ones used for
175 : // accessing block files don't count towards the fd_set size limit
176 : // anyway.
177 : #define MIN_CORE_FILEDESCRIPTORS 0
178 : #else
179 : #define MIN_CORE_FILEDESCRIPTORS 150
180 : #endif
181 :
182 : static const char* DEFAULT_ASMAP_FILENAME="ip_asn.map";
183 : /**
184 : * The PID file facilities.
185 : */
186 : static const char* BITCOIN_PID_FILENAME = "dashd.pid";
187 :
188 0 : static fs::path GetPidFile(const ArgsManager& args)
189 : {
190 0 : return AbsPathForConfigVal(args.GetPathArg("-pid", BITCOIN_PID_FILENAME));
191 0 : }
192 :
193 0 : [[nodiscard]] static bool CreatePidFile(const ArgsManager& args)
194 : {
195 0 : std::ofstream file{GetPidFile(args)};
196 0 : if (file) {
197 : #ifdef WIN32
198 : tfm::format(file, "%d\n", GetCurrentProcessId());
199 : #else
200 0 : tfm::format(file, "%d\n", getpid());
201 : #endif
202 0 : return true;
203 : } else {
204 0 : return InitError(strprintf(_("Unable to create the PID file '%s': %s"), fs::PathToString(GetPidFile(args)), SysErrorString(errno)));
205 : }
206 0 : }
207 :
208 : //////////////////////////////////////////////////////////////////////////////
209 : //
210 : // Shutdown
211 : //
212 :
213 : //
214 : // Thread management and startup/shutdown:
215 : //
216 : // The network-processing threads are all part of a thread group
217 : // created by AppInit() or the Qt main() function.
218 : //
219 : // A clean exit happens when StartShutdown() or the SIGTERM
220 : // signal handler sets ShutdownRequested(), which makes main thread's
221 : // WaitForShutdown() interrupts the thread group.
222 : // And then, WaitForShutdown() makes all other on-going threads
223 : // in the thread group join the main thread.
224 : // Shutdown() is then called to clean up database connections, and stop other
225 : // threads that should only be stopped after the main network-processing
226 : // threads have exited.
227 : //
228 : // Shutdown for Qt is very similar, only it uses a QTimer to detect
229 : // ShutdownRequested() getting set, and then does the normal Qt
230 : // shutdown thing.
231 : //
232 :
233 : #if HAVE_SYSTEM
234 0 : static void ShutdownNotify(const ArgsManager& args)
235 : {
236 0 : std::vector<std::thread> threads;
237 0 : for (const auto& cmd : args.GetArgs("-shutdownnotify")) {
238 0 : threads.emplace_back(runCommand, cmd);
239 : }
240 0 : for (auto& t : threads) {
241 0 : t.join();
242 : }
243 0 : }
244 : #endif
245 :
246 0 : void Interrupt(NodeContext& node)
247 : {
248 : #if HAVE_SYSTEM
249 0 : ShutdownNotify(*node.args);
250 : #endif
251 0 : InterruptHTTPServer();
252 0 : InterruptHTTPRPC();
253 0 : InterruptRPC();
254 0 : InterruptREST();
255 0 : InterruptTorControl();
256 0 : if (node.peerman) {
257 0 : node.peerman->InterruptHandlers();
258 0 : }
259 0 : InterruptMapPort();
260 0 : if (node.connman)
261 0 : node.connman->Interrupt();
262 0 : if (g_txindex) {
263 0 : g_txindex->Interrupt();
264 0 : }
265 0 : if (g_addressindex) {
266 0 : g_addressindex->Interrupt();
267 0 : }
268 0 : if (g_timestampindex) {
269 0 : g_timestampindex->Interrupt();
270 0 : }
271 0 : if (g_spentindex) {
272 0 : g_spentindex->Interrupt();
273 0 : }
274 0 : ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Interrupt(); });
275 0 : if (g_coin_stats_index) {
276 0 : g_coin_stats_index->Interrupt();
277 0 : }
278 0 : }
279 :
280 : /** Preparing steps before shutting down or restarting the wallet */
281 0 : void PrepareShutdown(NodeContext& node)
282 : {
283 0 : static Mutex g_shutdown_mutex;
284 0 : TRY_LOCK(g_shutdown_mutex, lock_shutdown);
285 0 : if (!lock_shutdown) return;
286 0 : LogPrintf("%s: In progress...\n", __func__);
287 0 : Assert(node.args);
288 :
289 : /// Note: Shutdown() must be able to handle cases in which initialization failed part of the way,
290 : /// for example if the data directory was found to be locked.
291 : /// Be sure that anything that writes files or flushes caches only does this if the respective
292 : /// module was initialized.
293 0 : util::ThreadRename("shutoff");
294 0 : if (node.mempool) node.mempool->AddTransactionsUpdated(1);
295 :
296 0 : StopHTTPRPC();
297 0 : StopREST();
298 0 : StopRPC();
299 0 : StopHTTPServer();
300 :
301 0 : if (node.active_ctx) node.active_ctx->Stop();
302 0 : if (node.clhandler) node.clhandler->Stop();
303 0 : if (node.peerman) node.peerman->StopHandlers();
304 :
305 :
306 0 : for (const auto& client : node.chain_clients) {
307 0 : client->flush();
308 : }
309 0 : StopMapPort();
310 :
311 : // Because these depend on each-other, we make sure that neither can be
312 : // using the other before destroying them.
313 0 : if (node.clhandler) UnregisterValidationInterface(node.clhandler.get());
314 0 : if (node.peerman) UnregisterValidationInterface(node.peerman.get());
315 0 : if (node.connman) node.connman->Stop();
316 :
317 0 : StopTorControl();
318 :
319 : // After everything has been shut down, but before things get flushed, stop the
320 : // CScheduler/checkqueue, threadGroup and load block thread.
321 0 : if (node.scheduler) node.scheduler->stop();
322 0 : if (node.chainman && node.chainman->m_load_block.joinable()) node.chainman->m_load_block.join();
323 0 : StopScriptCheckWorkerThreads();
324 :
325 : // After there are no more peers/RPC left to give us new data which may generate
326 : // CValidationInterface callbacks, flush them...
327 0 : GetMainSignals().FlushBackgroundCallbacks();
328 :
329 : // After the threads that potentially access these pointers have been stopped,
330 : // destruct and reset all to nullptr.
331 0 : node.peerman.reset();
332 0 : node.connman.reset();
333 0 : node.banman.reset();
334 0 : node.addrman.reset();
335 0 : node.netgroupman.reset();
336 0 : ::g_stats_client.reset();
337 :
338 0 : if (node.mempool && node.mempool->IsLoaded() && node.args->GetBoolArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
339 0 : DumpMempool(*node.mempool);
340 0 : }
341 :
342 : // Drop transactions we were still watching, and record fee estimations.
343 0 : if (node.fee_estimator) node.fee_estimator->Flush();
344 :
345 : // FlushStateToDisk generates a ChainStateFlushed callback, which we should avoid missing
346 0 : if (node.chainman) {
347 0 : LOCK(cs_main);
348 0 : for (CChainState* chainstate : node.chainman->GetAll()) {
349 0 : if (chainstate->CanFlushToDisk()) {
350 0 : chainstate->ForceFlushStateToDisk();
351 0 : }
352 : }
353 0 : }
354 :
355 : // After there are no more peers/RPC left to give us new data which may generate
356 : // CValidationInterface callbacks, flush them...
357 0 : GetMainSignals().FlushBackgroundCallbacks();
358 :
359 0 : if (node.observer_ctx) {
360 0 : UnregisterValidationInterface(node.observer_ctx.get());
361 0 : }
362 :
363 0 : if (node.active_ctx) {
364 0 : UnregisterValidationInterface(node.active_ctx.get());
365 0 : }
366 :
367 0 : if (node.cj_walletman) {
368 0 : UnregisterValidationInterface(node.cj_walletman.get());
369 0 : }
370 :
371 0 : if (g_ds_notification_interface) {
372 0 : UnregisterValidationInterface(g_ds_notification_interface.get());
373 0 : g_ds_notification_interface.reset();
374 0 : }
375 :
376 : // After all scheduled tasks have been flushed, destroy pointers
377 : // and reset all to nullptr.
378 0 : node.observer_ctx.reset();
379 0 : node.active_ctx.reset();
380 0 : node.govman.reset();
381 0 : node.mn_sync.reset();
382 0 : node.sporkman.reset();
383 0 : node.netfulfilledman.reset();
384 0 : node.mn_metaman.reset();
385 :
386 : // Stop and delete all indexes only after flushing background callbacks.
387 0 : if (g_txindex) {
388 0 : g_txindex->Stop();
389 0 : g_txindex.reset();
390 0 : }
391 0 : if (g_addressindex) {
392 0 : g_addressindex->Stop();
393 0 : g_addressindex.reset();
394 0 : }
395 0 : if (g_timestampindex) {
396 0 : g_timestampindex->Stop();
397 0 : g_timestampindex.reset();
398 0 : }
399 0 : if (g_spentindex) {
400 0 : g_spentindex->Stop();
401 0 : g_spentindex.reset();
402 0 : }
403 0 : if (g_coin_stats_index) {
404 0 : g_coin_stats_index->Stop();
405 0 : g_coin_stats_index.reset();
406 0 : }
407 0 : ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); });
408 0 : DestroyAllBlockFilterIndexes();
409 :
410 : // Any future callbacks will be dropped. This should absolutely be safe - if
411 : // missing a callback results in an unrecoverable situation, unclean shutdown
412 : // would too. The only reason to do the above flushes is to let the wallet catch
413 : // up with our current chain to avoid any strange pruning edge cases and make
414 : // next startup faster by avoiding rescan.
415 :
416 0 : if (node.chainman) {
417 0 : LOCK(cs_main);
418 0 : for (CChainState* chainstate : node.chainman->GetAll()) {
419 0 : if (chainstate->CanFlushToDisk()) {
420 0 : chainstate->ForceFlushStateToDisk();
421 0 : chainstate->ResetCoinsViews();
422 0 : }
423 : }
424 0 : DashChainstateSetupClose(node.chain_helper, node.dmnman, node.llmq_ctx,
425 0 : Assert(node.mempool.get()));
426 0 : node.evodb.reset();
427 0 : }
428 0 : for (const auto& client : node.chain_clients) {
429 0 : client->stop();
430 : }
431 :
432 : #if ENABLE_ZMQ
433 : if (g_zmq_notification_interface) {
434 : UnregisterValidationInterface(g_zmq_notification_interface.get());
435 : g_zmq_notification_interface.reset();
436 : }
437 : #endif
438 :
439 0 : node.chain_clients.clear();
440 :
441 : // After all wallets are removed, destroy all CoinJoin objects
442 : // and reset them to nullptr
443 0 : node.cj_walletman.reset();
444 0 : node.dstxman.reset();
445 :
446 0 : UnregisterAllValidationInterfaces();
447 0 : GetMainSignals().UnregisterBackgroundSignalScheduler();
448 :
449 : // We need to manually release our directory locks if we are expected to restart
450 : // because the replacement instance will start before this instance stops and the
451 : // global context won't be torn down in time to release the locks automatically.
452 0 : if (RestartRequested()) {
453 0 : ReleaseDirectoryLocks();
454 0 : }
455 0 : }
456 :
457 : /**
458 : * Shutdown is split into 2 parts:
459 : * Part 1: shut down everything but the main wallet instance (done in PrepareShutdown() )
460 : * Part 2: delete wallet instance
461 : *
462 : * In case of a restart PrepareShutdown() was already called before, but this method here gets
463 : * called implicitly when the parent object is deleted. In this case we have to skip the
464 : * PrepareShutdown() part because it was already executed and just delete the wallet instance.
465 : */
466 0 : void Shutdown(NodeContext& node)
467 : {
468 : // Shutdown part 1: prepare shutdown
469 0 : if(!RestartRequested()) {
470 0 : PrepareShutdown(node);
471 0 : }
472 : // Shutdown part 2: delete wallet instance
473 0 : init::UnsetGlobals();
474 0 : node.mempool.reset();
475 0 : node.fee_estimator.reset();
476 0 : node.chainman.reset();
477 0 : node.scheduler.reset();
478 :
479 : try {
480 0 : if (!fs::remove(GetPidFile(*node.args))) {
481 0 : LogPrintf("%s: Unable to remove PID file: File does not exist\n", __func__);
482 0 : }
483 0 : } catch (const fs::filesystem_error& e) {
484 0 : LogPrintf("%s: Unable to remove PID file: %s\n", __func__, fsbridge::get_filesystem_error_message(e));
485 0 : }
486 :
487 0 : LogPrintf("%s: done\n", __func__);
488 0 : }
489 :
490 : /**
491 : * Signal handlers are very limited in what they are allowed to do.
492 : * The execution context the handler is invoked in is not guaranteed,
493 : * so we restrict handler operations to just touching variables:
494 : */
495 : #ifndef WIN32
496 0 : static void HandleSIGTERM(int)
497 : {
498 0 : StartShutdown();
499 0 : }
500 :
501 0 : static void HandleSIGHUP(int)
502 : {
503 0 : LogInstance().m_reopen_file = true;
504 0 : }
505 : #else
506 : static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType)
507 : {
508 : StartShutdown();
509 : Sleep(INFINITE);
510 : return true;
511 : }
512 : #endif
513 :
514 : #ifndef WIN32
515 0 : static void registerSignalHandler(int signal, void(*handler)(int))
516 : {
517 : struct sigaction sa;
518 0 : sa.sa_handler = handler;
519 0 : sigemptyset(&sa.sa_mask);
520 0 : sa.sa_flags = 0;
521 0 : sigaction(signal, &sa, nullptr);
522 0 : }
523 : #endif
524 :
525 146 : static boost::signals2::connection rpc_notify_block_change_connection;
526 0 : static void OnRPCStarted()
527 : {
528 0 : rpc_notify_block_change_connection = uiInterface.NotifyBlockTip_connect(std::bind(RPCNotifyBlockChange, std::placeholders::_2));
529 0 : }
530 :
531 0 : static void OnRPCStopped()
532 : {
533 0 : rpc_notify_block_change_connection.disconnect();
534 0 : RPCNotifyBlockChange(nullptr);
535 0 : g_best_block_cv.notify_all();
536 0 : LogPrint(BCLog::RPC, "RPC stopped.\n");
537 0 : }
538 :
539 627 : void SetupServerArgs(ArgsManager& argsman)
540 : {
541 627 : SetupHelpOptions(argsman);
542 627 : argsman.AddArg("-help-debug", "Print help message with debugging options and exit", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
543 :
544 627 : init::AddLoggingArgs(argsman);
545 :
546 627 : const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
547 627 : const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
548 627 : const auto devnetBaseParams = CreateBaseChainParams(CBaseChainParams::DEVNET);
549 627 : const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST);
550 627 : const auto defaultChainParams = CreateChainParams(argsman, CBaseChainParams::MAIN);
551 627 : const auto testnetChainParams = CreateChainParams(argsman, CBaseChainParams::TESTNET);
552 627 : const auto devnetChainParams = CreateChainParams(argsman, CBaseChainParams::DEVNET);
553 627 : const auto regtestChainParams = CreateChainParams(argsman, CBaseChainParams::REGTEST);
554 :
555 : // Hidden Options
556 627 : std::vector<std::string> hidden_args = {"-dbcrashratio", "-forcecompactdb", "-printcrashinfo",
557 : // GUI args. These will be overwritten by SetupUIArgs for the GUI
558 627 : "-choosedatadir", "-lang=<lang>", "-min", "-resetguisettings", "-splash", "-uiplatform"};
559 :
560 :
561 : // Set all of the args and their help
562 : // When adding new options to the categories, please keep and ensure alphabetical ordering.
563 : #if HAVE_SYSTEM
564 627 : argsman.AddArg("-alertnotify=<cmd>", "Execute command when an alert is raised (%s in cmd is replaced by message)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
565 : #endif
566 627 : 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, devnet: %s)", defaultChainParams->GetConsensus().defaultAssumeValid.GetHex(), testnetChainParams->GetConsensus().defaultAssumeValid.GetHex(), devnetChainParams->GetConsensus().defaultAssumeValid.GetHex()), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
567 627 : argsman.AddArg("-blocksdir=<dir>", "Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
568 627 : argsman.AddArg("-fastprune", "Use smaller block files and lower minimum prune height for testing purposes", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
569 627 : argsman.AddArg("-tinyblk", "Use smaller block files for testing purposes", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
570 : #if HAVE_SYSTEM
571 627 : argsman.AddArg("-blocknotify=<cmd>", "Execute command when the best block changes (%s in cmd is replaced by block hash)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
572 : #endif
573 627 : 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);
574 627 : 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);
575 : #if HAVE_SYSTEM
576 627 : argsman.AddArg("-chainlocknotify=<cmd>", "Execute command when the best chainlock changes (%s in cmd is replaced by chainlocked block hash)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
577 : #endif
578 627 : argsman.AddArg("-coinstatsindex", strprintf("Maintain coinstats index used by the gettxoutsetinfo RPC (default: %u)", DEFAULT_COINSTATSINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
579 627 : argsman.AddArg("-conf=<file>", strprintf("Specify path to read-only configuration file. Relative paths will be prefixed by datadir location (only useable from command line, not configuration file) (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
580 627 : argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
581 627 : argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
582 627 : 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);
583 627 : 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);
584 627 : argsman.AddArg("-loadblock=<file>", "Imports blocks from external file on startup", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
585 627 : argsman.AddArg("-maxmempool=<n>", strprintf("Keep the transaction memory pool below <n> megabytes (default: %u)", DEFAULT_MAX_MEMPOOL_SIZE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
586 627 : argsman.AddArg("-maxorphantxsize=<n>", strprintf("Maximum total size of all orphan transactions in megabytes (default: %u)", DEFAULT_MAX_ORPHAN_TRANSACTIONS_SIZE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
587 627 : argsman.AddArg("-maxrecsigsage=<n>", strprintf("Number of seconds to keep LLMQ recovery sigs (default: %u)", llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
588 627 : 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);
589 627 : argsman.AddArg("-minimumchainwork=<hex>", strprintf("Minimum work assumed to exist on a valid chain in hex (default: %s, testnet: %s, devnet: %s)", defaultChainParams->GetConsensus().nMinimumChainWork.GetHex(), testnetChainParams->GetConsensus().nMinimumChainWork.GetHex(), devnetChainParams->GetConsensus().nMinimumChainWork.GetHex()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
590 1254 : 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)",
591 627 : -GetNumCores(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
592 1254 : argsman.AddArg("-parbls=<n>", strprintf("Set the number of BLS verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)",
593 627 : -GetNumCores(), llmq::MAX_BLSCHECK_THREADS, llmq::DEFAULT_BLSCHECK_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
594 627 : 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);
595 627 : 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);
596 627 : 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, -addressindex, -spentindex, -rescan and -disablegovernance=false. "
597 : "Warning: Reverting this setting requires re-downloading the entire blockchain. "
598 627 : "(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);
599 627 : 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);
600 627 : argsman.AddArg("-syncmempool", strprintf("Sync mempool from other nodes on start (default: %u)", DEFAULT_SYNC_MEMPOOL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
601 : #if HAVE_SYSTEM
602 627 : argsman.AddArg("-startupnotify=<cmd>", "Execute command on startup.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
603 627 : argsman.AddArg("-shutdownnotify=<cmd>", "Execute command immediately before beginning shutdown. The need for shutdown may be urgent, so be careful not to delay it long (if the command doesn't require interaction with the server, consider having it fork into the background).", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
604 : #endif
605 627 : argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
606 :
607 627 : argsman.AddArg("-addressindex", strprintf("Maintain a full address index, used to query for the balance, txids and unspent outputs for addresses (default: %u)", DEFAULT_ADDRESSINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::INDEXING);
608 627 : argsman.AddArg("-reindex", "Rebuild chain state and block index from the blk*.dat files on disk. This will also rebuild active optional indexes.", ArgsManager::ALLOW_ANY, OptionsCategory::INDEXING);
609 627 : 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. Deactivate all optional indexes before running this.", ArgsManager::ALLOW_ANY, OptionsCategory::INDEXING);
610 627 : argsman.AddArg("-spentindex", strprintf("Maintain a full spent index, used to query the spending txid and input index for an outpoint (default: %u)", DEFAULT_SPENTINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::INDEXING);
611 627 : argsman.AddArg("-timestampindex", strprintf("Maintain a timestamp index for block hashes, used to query blocks hashes by a range of timestamps (default: %u)", DEFAULT_TIMESTAMPINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::INDEXING);
612 627 : argsman.AddArg("-txindex", strprintf("Maintain a full transaction index, used by the getrawtransaction rpc call (default: %u)", DEFAULT_TXINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::INDEXING);
613 1254 : argsman.AddArg("-blockfilterindex=<type>",
614 627 : strprintf("Maintain an index of compact filters by block (default: %s, values: %s).", DEFAULT_BLOCKFILTERINDEX, ListBlockFilterTypes()) +
615 627 : " If <type> is not supplied or if <type> = 1, indexes for all known types are enabled." +
616 : " Automatically enabled for masternodes with value 'basic'.",
617 627 : ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
618 :
619 627 : 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);
620 627 : 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);
621 627 : argsman.AddArg("-allowprivatenet", strprintf("Allow RFC1918 addresses to be relayed and connected to (default: %u)", DEFAULT_ALLOWPRIVATENET), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
622 627 : argsman.AddArg("-bantime=<n>", strprintf("Default duration (in seconds) of manually configured bans (default: %u)", DEFAULT_MISBEHAVING_BANTIME), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
623 627 : 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, devnet: 127.0.0.1:%u=onion, regtest: 127.0.0.1:%u=onion)", defaultBaseParams->OnionServiceTargetPort(), testnetBaseParams->OnionServiceTargetPort(), devnetBaseParams->OnionServiceTargetPort(), regtestBaseParams->OnionServiceTargetPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::CONNECTION);
624 627 : 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);
625 627 : 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);
626 627 : argsman.AddArg("-discover", "Discover own IP addresses (default: 1 when listening and no -externalip or -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
627 627 : argsman.AddArg("-dns", strprintf("Allow DNS lookups for -addnode, -seednode and -connect (default: %u)", DEFAULT_NAME_LOOKUP), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
628 627 : argsman.AddArg("-dnsseed", strprintf("Query for peer addresses via DNS lookup, if low on addresses (default: %u unless -connect used or -maxconnections=0)", DEFAULT_DNSSEED), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
629 627 : argsman.AddArg("-externalip=<ip>", "Specify your own public address", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
630 627 : argsman.AddArg("-fixedseeds", strprintf("Allow fixed seeds if DNS seeds don't provide peers (default: %u)", DEFAULT_FIXEDSEEDS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
631 627 : argsman.AddArg("-forcednsseed", strprintf("Always query for peer addresses via DNS lookup (default: %u)", DEFAULT_FORCEDNSSEED), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
632 627 : argsman.AddArg("-listen", strprintf("Accept connections from outside (default: %u if no -proxy, -connect or -maxconnections=0)", DEFAULT_LISTEN), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
633 627 : argsman.AddArg("-listenonion", strprintf("Automatically create Tor onion service (default: %d)", DEFAULT_LISTEN_ONION), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
634 627 : argsman.AddArg("-maxconnections=<n>", strprintf("Maintain at most <n> connections to peers (temporary service connections excluded) (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);
635 627 : argsman.AddArg("-maxreceivebuffer=<n>", strprintf("Maximum per-connection receive buffer, <n>*1000 bytes (default: %u)", DEFAULT_MAXRECEIVEBUFFER), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
636 627 : argsman.AddArg("-maxsendbuffer=<n>", strprintf("Maximum per-connection memory usage for the send buffer, <n>*1000 bytes (default: %u)", DEFAULT_MAXSENDBUFFER), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
637 627 : 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);
638 627 : 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);
639 : #if HAVE_SOCKADDR_UN
640 627 : argsman.AddArg("-onion=<ip:port|path>", "Use separate SOCKS5 proxy to reach peers via Tor onion services, set -noonion to disable (default: -proxy). May be a local file path prefixed with 'unix:'.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
641 : #else
642 : 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);
643 : #endif
644 627 : argsman.AddArg("-i2psam=<ip:port>", "I2P SAM proxy to reach I2P peers and accept I2P connections (default: none)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
645 627 : argsman.AddArg("-i2pacceptincoming", strprintf("Whether to accept inbound I2P connections (default: %i). Ignored if -i2psam is not set. Listening for inbound I2P connections is done through the SAM proxy, not by binding to a local address and port.", DEFAULT_I2P_ACCEPT_INCOMING), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
646 627 : 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);
647 627 : argsman.AddArg("-v2transport", strprintf("Support v2 transport (default: %u)", DEFAULT_V2_TRANSPORT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
648 627 : argsman.AddArg("-peerblockfilters", strprintf("Serve compact block filters to peers per BIP 157 (default: %u, automatically enabled for masternodes)", DEFAULT_PEERBLOCKFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
649 627 : argsman.AddArg("-peerbloomfilters", strprintf("Support filtering of blocks and transaction with bloom filters (default: %u)", DEFAULT_PEERBLOOMFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
650 627 : argsman.AddArg("-txreconciliation", strprintf("Enable transaction reconciliations per BIP 330 (default: %d)", DEFAULT_TXRECONCILIATION_ENABLE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CONNECTION);
651 627 : 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, OptionsCategory::CONNECTION);
652 : // TODO: remove the sentence "Nodes not using ... incoming connections." once the changes from
653 : // https://github.com/bitcoin/bitcoin/pull/23542 have become widespread.
654 627 : argsman.AddArg("-port=<port>", strprintf("Listen for connections on <port>. Nodes not using the default ports (default: %u, testnet: %u, devnet: %u, regtest: %u) are unlikely to get incoming connections. Not relevant for I2P (see doc/i2p.md).", defaultChainParams->GetDefaultPort(), testnetChainParams->GetDefaultPort(), devnetChainParams->GetDefaultPort(), regtestChainParams->GetDefaultPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::CONNECTION);
655 : #if HAVE_SOCKADDR_UN
656 627 : argsman.AddArg("-proxy=<ip:port|path>", "Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled). May be a local file path prefixed with 'unix:' if the proxy supports it.", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_ELISION, OptionsCategory::CONNECTION);
657 : #else
658 : argsman.AddArg("-proxy=<ip:port>", "Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled)", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_ELISION, OptionsCategory::CONNECTION);
659 : #endif
660 627 : argsman.AddArg("-proxyrandomize", strprintf("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)", DEFAULT_PROXYRANDOMIZE), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
661 627 : 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);
662 627 : argsman.AddArg("-socketevents=<mode>", "Socket events mode, which must be one of 'select', 'poll', 'epoll' or 'kqueue', depending on your system (default: Linux - 'epoll', FreeBSD/Apple - 'kqueue', Windows - 'select')", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
663 627 : argsman.AddArg("-networkactive", "Enable all P2P network activity (default: 1). Can be changed by the setnetworkactive RPC command", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
664 627 : 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);
665 627 : argsman.AddArg("-torcontrol=<ip>:<port>", strprintf("Tor control host and port to use if onion listening enabled (default: %s). If no port is specified, the default port of %i will be used.", DEFAULT_TOR_CONTROL, DEFAULT_TOR_CONTROL_PORT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
666 627 : argsman.AddArg("-torpassword=<pass>", "Tor control port password (default: empty)", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::CONNECTION);
667 : #ifdef USE_UPNP
668 : argsman.AddArg("-upnp", strprintf("Use UPnP to map the listening port (default: %u)", DEFAULT_UPNP), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
669 : #else
670 627 : hidden_args.emplace_back("-upnp");
671 : #endif
672 : #ifdef USE_NATPMP
673 : argsman.AddArg("-natpmp", strprintf("Use NAT-PMP to map the listening port (default: %u)", DEFAULT_NATPMP), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
674 : #else
675 627 : hidden_args.emplace_back("-natpmp");
676 : #endif // USE_NATPMP
677 1254 : argsman.AddArg("-whitebind=<[permissions@]addr>", "Bind to the given address and add permission flags to the peers connecting to it. "
678 627 : "Use [host]:port notation for IPv6. Allowed permissions: " + Join(NET_PERMISSIONS_DOC, ", ") + ". "
679 627 : "Specify multiple permissions separated by commas (default: download,noban,mempool,relay). Can be specified multiple times.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
680 :
681 627 : 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 "
682 : "CIDR-notated network (e.g. 1.2.3.0/24). Uses the same permissions as "
683 627 : "-whitebind. Can be specified multiple times." , ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
684 :
685 627 : g_wallet_init_interface.AddWalletOptions(argsman);
686 :
687 : #if ENABLE_ZMQ
688 : argsman.AddArg("-zmqpubhashblock=<address>", "Enable publish hash block in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
689 : argsman.AddArg("-zmqpubhashchainlock=<address>", "Enable publish hash block (locked via ChainLocks) in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
690 : argsman.AddArg("-zmqpubhashgovernanceobject=<address>", "Enable publish hash of governance objects (like proposals) in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
691 : argsman.AddArg("-zmqpubhashgovernancevote=<address>", "Enable publish hash of governance votes in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
692 : argsman.AddArg("-zmqpubhashinstantsenddoublespend=<address>", "Enable publish transaction hashes of attempted InstantSend double spend in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
693 : argsman.AddArg("-zmqpubhashrecoveredsig=<address>", "Enable publish message hash of recovered signatures (recovered by LLMQs) in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
694 : argsman.AddArg("-zmqpubhashtx=<address>", "Enable publish hash transaction in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
695 : argsman.AddArg("-zmqpubhashtxlock=<address>", "Enable publish hash transaction (locked via InstantSend) in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
696 : argsman.AddArg("-zmqpubrawblock=<address>", "Enable publish raw block in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
697 : argsman.AddArg("-zmqpubrawchainlock=<address>", "Enable publish raw block (locked via ChainLocks) in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
698 : argsman.AddArg("-zmqpubrawchainlocksig=<address>", "Enable publish raw block (locked via ChainLocks) and CLSIG message in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
699 : argsman.AddArg("-zmqpubrawgovernancevote=<address>", "Enable publish raw governance objects (like proposals) in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
700 : argsman.AddArg("-zmqpubrawgovernanceobject=<address>", "Enable publish raw governance votes in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
701 : argsman.AddArg("-zmqpubrawinstantsenddoublespend=<address>", "Enable publish raw transactions of attempted InstantSend double spend in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
702 : argsman.AddArg("-zmqpubrawrecoveredsig=<address>", "Enable publish raw recovered signatures (recovered by LLMQs) in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
703 : argsman.AddArg("-zmqpubrawtx=<address>", "Enable publish raw transaction in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
704 : argsman.AddArg("-zmqpubrawtxlock=<address>", "Enable publish raw transaction (locked via InstantSend) in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
705 : argsman.AddArg("-zmqpubrawtxlocksig=<address>", "Enable publish raw transaction (locked via InstantSend) and ISLOCK in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
706 : argsman.AddArg("-zmqpubsequence=<address>", "Enable publish hash block and tx sequence in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
707 : 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);
708 : argsman.AddArg("-zmqpubhashchainlockhwm=<n>", strprintf("Set publish hash chain lock outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
709 : argsman.AddArg("-zmqpubhashgovernanceobjecthwm=<n>", strprintf("Set publish hash governance object outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
710 : argsman.AddArg("-zmqpubhashgovernancevotehwm=<n>", strprintf("Set publish hash governance vote outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
711 : argsman.AddArg("-zmqpubhashinstantsenddoublespendhwm=<n>", strprintf("Set publish hash InstantSend double spend outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
712 : argsman.AddArg("-zmqpubhashrecoveredsighwm=<n>", strprintf("Set publish hash recovered signature outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
713 : 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);
714 : argsman.AddArg("-zmqpubhashtxlockhwm=<n>", strprintf("Set publish hash transaction lock outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
715 : 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);
716 : argsman.AddArg("-zmqpubrawchainlockhwm=<n>", strprintf("Set publish raw chain lock outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
717 : argsman.AddArg("-zmqpubrawchainlocksighwm=<n>", strprintf("Set publish raw chain lock signature outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
718 : argsman.AddArg("-zmqpubrawgovernanceobjecthwm=<n>", strprintf("Set publish raw governance object outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
719 : argsman.AddArg("-zmqpubrawgovernancevotehwm=<n>", strprintf("Set publish raw governance vote outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
720 : argsman.AddArg("-zmqpubrawinstantsenddoublespendhwm=<n>", strprintf("Set publish raw InstantSend double spend outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
721 : argsman.AddArg("-zmqpubrawrecoveredsighwm=<n>", strprintf("Set publish raw recovered signature outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
722 : 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);
723 : argsman.AddArg("-zmqpubrawtxlockhwm=<n>", strprintf("Set publish raw transaction lock outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
724 : argsman.AddArg("-zmqpubrawtxlocksighwm=<n>", strprintf("Set publish raw transaction lock signature outbound message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
725 : argsman.AddArg("-zmqpubsequencehwm=<n>", strprintf("Set publish hash sequence message high water mark (default: %d)", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM), ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
726 : #else
727 627 : hidden_args.emplace_back("-zmqpubhashblock=<address>");
728 627 : hidden_args.emplace_back("-zmqpubhashchainlock=<address>");
729 627 : hidden_args.emplace_back("-zmqpubhashgovernanceobject=<address>");
730 627 : hidden_args.emplace_back("-zmqpubhashgovernancevote=<address>");
731 627 : hidden_args.emplace_back("-zmqpubhashinstantsenddoublespend=<address>");
732 627 : hidden_args.emplace_back("-zmqpubhashrecoveredsig=<address>");
733 627 : hidden_args.emplace_back("-zmqpubhashtx=<address>");
734 627 : hidden_args.emplace_back("-zmqpubhashtxlock=<address>");
735 627 : hidden_args.emplace_back("-zmqpubrawblock=<address>");
736 627 : hidden_args.emplace_back("-zmqpubrawchainlock=<address>");
737 627 : hidden_args.emplace_back("-zmqpubrawchainlocksig=<address>");
738 627 : hidden_args.emplace_back("-zmqpubrawgovernancevote=<address>");
739 627 : hidden_args.emplace_back("-zmqpubrawgovernanceobject=<address>");
740 627 : hidden_args.emplace_back("-zmqpubrawinstantsenddoublespend=<address>");
741 627 : hidden_args.emplace_back("-zmqpubrawrecoveredsig=<address>");
742 627 : hidden_args.emplace_back("-zmqpubrawtx=<address>");
743 627 : hidden_args.emplace_back("-zmqpubrawtxlock=<address>");
744 627 : hidden_args.emplace_back("-zmqpubrawtxlocksig=<address>");
745 627 : hidden_args.emplace_back("-zmqpubsequence=<n>");
746 627 : hidden_args.emplace_back("-zmqpubhashblockhwm=<n>");
747 627 : hidden_args.emplace_back("-zmqpubhashchainlockhwm=<n>");
748 627 : hidden_args.emplace_back("-zmqpubhashgovernanceobjecthwm=<n>");
749 627 : hidden_args.emplace_back("-zmqpubhashgovernancevotehwm=<n>");
750 627 : hidden_args.emplace_back("-zmqpubhashinstantsenddoublespendhwm=<n>");
751 627 : hidden_args.emplace_back("-zmqpubhashrecoveredsighwm=<n>");
752 627 : hidden_args.emplace_back("-zmqpubhashtxhwm=<n>");
753 627 : hidden_args.emplace_back("-zmqpubhashtxlockhwm=<n>");
754 627 : hidden_args.emplace_back("-zmqpubrawblockhwm=<n>");
755 627 : hidden_args.emplace_back("-zmqpubrawchainlockhwm=<n>");
756 627 : hidden_args.emplace_back("-zmqpubrawchainlocksighwm=<n>");
757 627 : hidden_args.emplace_back("-zmqpubrawgovernanceobjecthwm=<n>");
758 627 : hidden_args.emplace_back("-zmqpubrawgovernancevotehwm=<n>");
759 627 : hidden_args.emplace_back("-zmqpubrawinstantsenddoublespendhwm=<n>");
760 627 : hidden_args.emplace_back("-zmqpubrawrecoveredsighwm=<n>");
761 627 : hidden_args.emplace_back("-zmqpubrawtxhwm=<n>");
762 627 : hidden_args.emplace_back("-zmqpubrawtxlockhwm=<n>");
763 627 : hidden_args.emplace_back("-zmqpubrawtxlocksighwm=<n>");
764 627 : hidden_args.emplace_back("-zmqpubsequencehwm=<n>");
765 : #endif
766 :
767 627 : argsman.AddArg("-checkblockindex", strprintf("Do a consistency check for the block tree, and occasionally. (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
768 627 : 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);
769 627 : 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);
770 627 : 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);
771 627 : 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);
772 627 : 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);
773 627 : argsman.AddArg("-deprecatedrpc=<method>", "Allows deprecated RPC method(s) to be used", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
774 627 : argsman.AddArg("-forceevodbrepair", "Force evodb masternode list diff verification and repair on startup, even if already repaired (default: 0)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
775 627 : 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);
776 627 : 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);
777 627 : 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);
778 627 : 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);
779 627 : argsman.AddArg("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", DEFAULT_STOPAFTERBLOCKIMPORT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
780 627 : 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);
781 627 : argsman.AddArg("-watchquorums=<n>", strprintf("Watch and validate quorum communication (default: %u)", llmq::DEFAULT_WATCH_QUORUMS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
782 627 : argsman.AddArg("-capturemessages", "Capture all P2P messages to disk", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
783 627 : argsman.AddArg("-disablegovernance", strprintf("Disable governance validation (0-1, default: %u)", 0), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
784 627 : 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);
785 627 : 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);
786 627 : argsman.AddArg("-mocktime=<n>", "Replace actual time with " + UNIX_EPOCH_TIME + " (default: 0)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
787 627 : argsman.AddArg("-minsporkkeys=<n>", "Overrides minimum spork signers to change spork value. Only useful for regtest and devnet. Using this on mainnet or testnet will ban you.", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
788 627 : argsman.AddArg("-printpriority", strprintf("Log transaction fee per kB when mining blocks (default: %u)", DEFAULT_PRINTPRIORITY), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
789 627 : argsman.AddArg("-pushversion", "Protocol version to report to other nodes", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
790 627 : argsman.AddArg("-sporkaddr=<dashaddress>", "Override spork address. Only useful for regtest and devnet. Using this on mainnet or testnet will ban you.", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
791 627 : argsman.AddArg("-sporkkey=<privatekey>", "Set the private key to be used for signing spork messages.", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::DEBUG_TEST);
792 627 : argsman.AddArg("-uacomment=<cmt>", "Append comment to the user agent string", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
793 :
794 627 : SetupChainParamsOptions(argsman);
795 :
796 627 : argsman.AddArg("-llmq-data-recovery=<n>", strprintf("Enable automated quorum data recovery (default: %u)", llmq::DEFAULT_ENABLE_QUORUM_DATA_RECOVERY), ArgsManager::ALLOW_ANY, OptionsCategory::MASTERNODE);
797 627 : argsman.AddArg("-llmq-qvvec-sync=<quorum_name>:<mode>", strprintf("Defines from which LLMQ type the masternode should sync quorum verification vectors. Can be used multiple times with different LLMQ types. <mode>: %d (sync always from all quorums of the type defined by <quorum_name>), %d (sync from all quorums of the type defined by <quorum_name> if a member of any of the quorums)", (int32_t)llmq::QvvecSyncMode::Always, (int32_t)llmq::QvvecSyncMode::OnlyIfTypeMember), ArgsManager::ALLOW_ANY, OptionsCategory::MASTERNODE);
798 627 : argsman.AddArg("-masternodeblsprivkey=<hex>", "Set the masternode BLS private key and enable the client to act as a masternode", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::MASTERNODE);
799 627 : argsman.AddArg("-deprecated-platform-user=<user>", "Set the username for the \"platform user\", a restricted user intended to be used by Dash Platform, to the specified username.", ArgsManager::ALLOW_ANY, OptionsCategory::MASTERNODE);
800 :
801 627 : 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);
802 627 : argsman.AddArg("-dustrelayfee=<amt>", strprintf("Fee rate (in %s/kB) 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);
803 627 : argsman.AddArg("-incrementalrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to define cost of relay, used for mempool limiting. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_INCREMENTAL_RELAY_FEE)), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::NODE_RELAY);
804 627 : 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);
805 627 : argsman.AddArg("-datacarrier", strprintf("Relay and mine data carrier transactions (default: %u)", DEFAULT_ACCEPT_DATACARRIER), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
806 1254 : argsman.AddArg("-datacarriersize",
807 627 : strprintf("Relay and mine transactions whose data-carrying raw scriptPubKey "
808 : "is of this size or less (default: %u)",
809 : MAX_OP_RETURN_RELAY),
810 627 : ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
811 627 : argsman.AddArg("-permitbaremultisig", strprintf("Relay non-P2SH multisig (default: %u)", DEFAULT_PERMIT_BAREMULTISIG), ArgsManager::ALLOW_ANY,
812 627 : OptionsCategory::NODE_RELAY);
813 1254 : argsman.AddArg("-minrelaytxfee=<amt>", strprintf("Fees (in %s/kB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s)",
814 1254 : CURRENCY_UNIT, FormatMoney(DEFAULT_MIN_RELAY_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
815 627 : 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);
816 627 : 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);
817 :
818 627 : argsman.AddArg("-blockmaxsize=<n>", strprintf("Set maximum block size in bytes (default: %d)", DEFAULT_BLOCK_MAX_SIZE), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
819 627 : argsman.AddArg("-blockmintxfee=<amt>", strprintf("Set lowest fee rate (in %s/kB) for transactions to be included in block creation. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_BLOCK_MIN_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
820 627 : argsman.AddArg("-blockversion=<n>", "Override block version to test forking scenarios", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::BLOCK_CREATION);
821 :
822 627 : argsman.AddArg("-rest", strprintf("Accept public REST requests (default: %u)", DEFAULT_REST_ENABLE), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
823 627 : argsman.AddArg("-rpcallowip=<ip>", "Allow JSON-RPC connections from specified source. Valid values 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), a network/CIDR (e.g. 1.2.3.4/24), all ipv4 (0.0.0.0/0), or all ipv6 (::/0). This option can be specified multiple times", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
824 627 : 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/rpcuser. 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);
825 627 : 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, or if -rpcallowip has been specified, 0.0.0.0 and :: i.e., all addresses)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC);
826 627 : argsman.AddArg("-rpcdoccheck", strprintf("Throw a non-fatal error at runtime if the documentation for an RPC is incorrect (default: %u)", DEFAULT_RPC_DOC_CHECK), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC);
827 627 : 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);
828 627 : argsman.AddArg("-rpcexternaluser=<users>", "List of comma-separated usernames for JSON-RPC external connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
829 627 : argsman.AddArg("-rpcexternalworkqueue=<n>", strprintf("Set the depth of the work queue to service external RPC calls (default: %d)", DEFAULT_HTTP_WORKQUEUE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC);
830 627 : argsman.AddArg("-rpcpassword=<pw>", "Password for JSON-RPC connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
831 627 : argsman.AddArg("-rpcport=<port>", strprintf("Listen for JSON-RPC connections on <port> (default: %u, testnet: %u, devnet: %u, regtest: %u)", defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort(), devnetBaseParams->RPCPort(), regtestBaseParams->RPCPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC);
832 627 : argsman.AddArg("-rpcservertimeout=<n>", strprintf("Timeout during HTTP requests (default: %d)", DEFAULT_HTTP_SERVER_TIMEOUT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC);
833 627 : argsman.AddArg("-rpcthreads=<n>", strprintf("Set the number of threads to service RPC calls (default: %d)", DEFAULT_HTTP_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
834 627 : argsman.AddArg("-rpcuser=<user>", "Username for JSON-RPC connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
835 627 : 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);
836 627 : 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);
837 627 : 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);
838 627 : argsman.AddArg("-server", "Accept command line and JSON-RPC commands", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
839 :
840 627 : argsman.AddArg("-statsbatchsize=<bytes>", strprintf("Specify the size of each batch of stats messages (default: %d)", DEFAULT_STATSD_BATCH_SIZE), ArgsManager::ALLOW_ANY, OptionsCategory::STATSD);
841 627 : argsman.AddArg("-statsduration=<ms>", strprintf("Specify the number of milliseconds between stats messages (default: %d)", DEFAULT_STATSD_DURATION), ArgsManager::ALLOW_ANY, OptionsCategory::STATSD);
842 627 : argsman.AddArg("-statshost=<ip>", strprintf("Specify statsd host (default: %s)", DEFAULT_STATSD_HOST), ArgsManager::ALLOW_ANY, OptionsCategory::STATSD);
843 627 : hidden_args.emplace_back("-statsport");
844 627 : argsman.AddArg("-statsperiod=<seconds>", strprintf("Specify the number of seconds between periodic measurements (default: %d)", DEFAULT_STATSD_PERIOD), ArgsManager::ALLOW_ANY, OptionsCategory::STATSD);
845 627 : argsman.AddArg("-statsprefix=<string>", strprintf("Specify an optional string prepended to every stats key (default: %s)", DEFAULT_STATSD_PREFIX), ArgsManager::ALLOW_ANY, OptionsCategory::STATSD);
846 627 : argsman.AddArg("-statssuffix=<string>", strprintf("Specify an optional string appended to every stats key (default: %s)", DEFAULT_STATSD_SUFFIX), ArgsManager::ALLOW_ANY, OptionsCategory::STATSD);
847 : #if HAVE_DECL_FORK
848 627 : argsman.AddArg("-daemon", strprintf("Run in the background as a daemon and accept commands (default: %d)", DEFAULT_DAEMON), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
849 627 : argsman.AddArg("-daemonwait", strprintf("Wait for initialization to be finished before exiting. This implies -daemon (default: %d)", DEFAULT_DAEMONWAIT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
850 : #else
851 : hidden_args.emplace_back("-daemon");
852 : hidden_args.emplace_back("-daemonwait");
853 : #endif
854 :
855 : // Add the hidden options
856 627 : argsman.AddHiddenArgs(hidden_args);
857 627 : }
858 :
859 : static bool fHaveGenesis = false;
860 : static GlobalMutex g_genesis_wait_mutex;
861 : static std::condition_variable g_genesis_wait_cv;
862 :
863 0 : static void BlockNotifyGenesisWait(const CBlockIndex* pBlockIndex)
864 : {
865 0 : if (pBlockIndex != nullptr) {
866 : {
867 0 : LOCK(g_genesis_wait_mutex);
868 0 : fHaveGenesis = true;
869 0 : }
870 0 : g_genesis_wait_cv.notify_all();
871 0 : }
872 0 : }
873 :
874 : #if HAVE_SYSTEM
875 0 : static void StartupNotify(const ArgsManager& args)
876 : {
877 0 : std::string cmd = args.GetArg("-startupnotify", "");
878 0 : if (!cmd.empty()) {
879 0 : std::thread t(runCommand, cmd);
880 0 : t.detach(); // thread runs free
881 0 : }
882 0 : }
883 : #endif
884 :
885 0 : static void PeriodicStats(NodeContext& node)
886 : {
887 0 : assert(::g_stats_client->active());
888 0 : const ArgsManager& args = *Assert(node.args);
889 0 : ChainstateManager& chainman = *Assert(node.chainman);
890 0 : const CTxMemPool& mempool = *Assert(node.mempool);
891 0 : const llmq::CInstantSendManager& isman = *Assert(node.llmq_ctx->isman);
892 0 : chainman.ActiveChainstate().ForceFlushStateToDisk();
893 0 : const auto maybe_stats = WITH_LOCK(::cs_main, return GetUTXOStats(&chainman.ActiveChainstate().CoinsDB(), chainman.m_blockman, /*hash_type=*/CoinStatsHashType::NONE, node.rpc_interruption_point, chainman.ActiveChain().Tip(), /*index_requested=*/true));
894 0 : if (maybe_stats.has_value()) {
895 0 : ::g_stats_client->gauge("utxoset.tx", maybe_stats->nTransactions, 1.0f);
896 0 : ::g_stats_client->gauge("utxoset.txOutputs", maybe_stats->nTransactionOutputs, 1.0f);
897 0 : ::g_stats_client->gauge("utxoset.dbSizeBytes", maybe_stats->nDiskSize, 1.0f);
898 0 : ::g_stats_client->gauge("utxoset.blockHeight", maybe_stats->nHeight, 1.0f);
899 0 : if (maybe_stats->total_amount.has_value()) {
900 0 : ::g_stats_client->gauge("utxoset.totalAmount", (double)maybe_stats->total_amount.value() / (double)COIN, 1.0f);
901 0 : }
902 0 : } else {
903 : // something went wrong
904 0 : LogPrintf("%s: GetUTXOStats failed\n", __func__);
905 : }
906 :
907 0 : CBlockIndex *tip = chainman.ActiveChain().Tip();
908 0 : double nNetworkHashPS = [&]() {
909 : // Short version of GetNetworkHashPS(120, -1);
910 0 : CBlockIndex *pindex = tip;
911 0 : int64_t minTime = pindex->GetBlockTime();
912 0 : int64_t maxTime = minTime;
913 0 : for (int i = 0; i < 120 && pindex->pprev != nullptr; i++) {
914 0 : pindex = pindex->pprev;
915 0 : int64_t time = pindex->GetBlockTime();
916 0 : minTime = std::min(time, minTime);
917 0 : maxTime = std::max(time, maxTime);
918 0 : }
919 0 : if (minTime == maxTime) return 0.0;
920 0 : arith_uint256 workDiff = tip->nChainWork - pindex->nChainWork;
921 0 : int64_t timeDiff = maxTime - minTime;
922 0 : return workDiff.getdouble() / timeDiff;
923 0 : }();
924 :
925 0 : if (nNetworkHashPS > 0.0) {
926 0 : ::g_stats_client->gaugeDouble("network.hashesPerSecond", nNetworkHashPS);
927 0 : ::g_stats_client->gaugeDouble("network.terahashesPerSecond", nNetworkHashPS / 1e12);
928 0 : ::g_stats_client->gaugeDouble("network.petahashesPerSecond", nNetworkHashPS / 1e15);
929 0 : ::g_stats_client->gaugeDouble("network.exahashesPerSecond", nNetworkHashPS / 1e18);
930 0 : }
931 : // No need for cs_main, we never use null tip here
932 0 : ::g_stats_client->gaugeDouble("network.difficulty", (double)GetDifficulty(tip));
933 :
934 0 : ::g_stats_client->gauge("transactions.txCacheSize", WITH_LOCK(cs_main, return chainman.ActiveChainstate().CoinsTip().GetCacheSize()), 1.0f);
935 0 : ::g_stats_client->gauge("transactions.totalTransactions", tip->nChainTx, 1.0f);
936 :
937 : {
938 0 : LOCK(mempool.cs);
939 0 : ::g_stats_client->gauge("transactions.mempool.totalTransactions", mempool.size(), 1.0f);
940 0 : ::g_stats_client->gauge("transactions.mempool.totalTxBytes", (int64_t) mempool.GetTotalTxSize(), 1.0f);
941 0 : ::g_stats_client->gauge("transactions.mempool.memoryUsageBytes", (int64_t) mempool.DynamicMemoryUsage(), 1.0f);
942 0 : ::g_stats_client->gauge("transactions.mempool.minFeePerKb", mempool.GetMinFee(args.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK(), 1.0f);
943 0 : }
944 0 : ::g_stats_client->gauge("transactions.mempool.lockedTransactions", isman.GetInstantSendLockCount(), 1.0f);
945 0 : }
946 :
947 0 : static bool AppInitServers(NodeContext& node)
948 : {
949 0 : const ArgsManager& args = *Assert(node.args);
950 0 : RPCServer::OnStarted(&OnRPCStarted);
951 0 : RPCServer::OnStopped(&OnRPCStopped);
952 0 : if (!InitHTTPServer())
953 0 : return false;
954 0 : StartRPC();
955 0 : node.rpc_interruption_point = RpcInterruptionPoint;
956 0 : if (!StartHTTPRPC(node))
957 0 : return false;
958 0 : if (args.GetBoolArg("-rest", DEFAULT_REST_ENABLE)) StartREST(node);
959 0 : StartHTTPServer();
960 0 : return true;
961 0 : }
962 :
963 : // Parameter interaction based on rules
964 0 : void InitParameterInteraction(ArgsManager& args)
965 : {
966 : // when specifying an explicit binding address, you want to listen on it
967 : // even when -connect or -proxy is specified
968 0 : if (args.IsArgSet("-bind")) {
969 0 : if (args.SoftSetBoolArg("-listen", true))
970 0 : LogPrintf("%s: parameter interaction: -bind set -> setting -listen=1\n", __func__);
971 0 : }
972 0 : if (args.IsArgSet("-whitebind")) {
973 0 : if (args.SoftSetBoolArg("-listen", true))
974 0 : LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__);
975 0 : }
976 :
977 0 : if (args.IsArgSet("-connect") || args.GetIntArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS) <= 0) {
978 : // when only connecting to trusted nodes, do not seed via DNS, or listen by default
979 0 : if (args.SoftSetBoolArg("-dnsseed", false))
980 0 : LogPrintf("%s: parameter interaction: -connect or -maxconnections=0 set -> setting -dnsseed=0\n", __func__);
981 0 : if (args.SoftSetBoolArg("-listen", false))
982 0 : LogPrintf("%s: parameter interaction: -connect or -maxconnections=0 set -> setting -listen=0\n", __func__);
983 0 : }
984 :
985 0 : std::string proxy_arg = args.GetArg("-proxy", "");
986 0 : if (proxy_arg != "" && proxy_arg != "0") {
987 : // to protect privacy, do not listen by default if a default proxy server is specified
988 0 : if (args.SoftSetBoolArg("-listen", false))
989 0 : LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
990 : // to protect privacy, do not map ports when a proxy is set. The user may still specify -listen=1
991 : // to listen locally, so don't rely on this happening through -listen below.
992 0 : if (args.SoftSetBoolArg("-upnp", false))
993 0 : LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__);
994 0 : if (args.SoftSetBoolArg("-natpmp", false))
995 0 : LogPrintf("%s: parameter interaction: -proxy set -> setting -natpmp=0\n", __func__);
996 : // to protect privacy, do not discover addresses by default
997 0 : if (args.SoftSetBoolArg("-discover", false))
998 0 : LogPrintf("%s: parameter interaction: -proxy set -> setting -discover=0\n", __func__);
999 0 : }
1000 :
1001 0 : if (!args.GetBoolArg("-listen", DEFAULT_LISTEN)) {
1002 : // do not map ports or try to retrieve public IP when not listening (pointless)
1003 0 : if (args.SoftSetBoolArg("-upnp", false))
1004 0 : LogPrintf("%s: parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
1005 0 : if (args.SoftSetBoolArg("-natpmp", false))
1006 0 : LogPrintf("%s: parameter interaction: -listen=0 -> setting -natpmp=0\n", __func__);
1007 0 : if (args.SoftSetBoolArg("-discover", false))
1008 0 : LogPrintf("%s: parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
1009 0 : if (args.SoftSetBoolArg("-listenonion", false))
1010 0 : LogPrintf("%s: parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__);
1011 0 : if (args.SoftSetBoolArg("-i2pacceptincoming", false)) {
1012 0 : LogPrintf("%s: parameter interaction: -listen=0 -> setting -i2pacceptincoming=0\n", __func__);
1013 0 : }
1014 0 : }
1015 :
1016 0 : if (args.IsArgSet("-externalip")) {
1017 : // if an explicit public IP is specified, do not try to find others
1018 0 : if (args.SoftSetBoolArg("-discover", false))
1019 0 : LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
1020 0 : }
1021 :
1022 : // disable whitelistrelay in blocksonly mode
1023 0 : if (args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {
1024 0 : if (args.SoftSetBoolArg("-whitelistrelay", false))
1025 0 : LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistrelay=0\n", __func__);
1026 0 : }
1027 :
1028 : // Forcing relay from whitelisted hosts implies we will accept relays from them in the first place.
1029 0 : if (args.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
1030 0 : if (args.SoftSetBoolArg("-whitelistrelay", true))
1031 0 : LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n", __func__);
1032 0 : }
1033 :
1034 0 : if (args.IsArgSet("-onlynet")) {
1035 0 : const auto onlynets = args.GetArgs("-onlynet");
1036 0 : bool clearnet_reachable = std::any_of(onlynets.begin(), onlynets.end(), [](const auto& net) {
1037 0 : const auto n = ParseNetwork(net);
1038 0 : return n == NET_IPV4 || n == NET_IPV6;
1039 : });
1040 0 : if (!clearnet_reachable && args.SoftSetBoolArg("-dnsseed", false)) {
1041 0 : LogPrintf("%s: parameter interaction: -onlynet excludes IPv4 and IPv6 -> setting -dnsseed=0\n", __func__);
1042 0 : }
1043 0 : }
1044 :
1045 0 : int64_t nPruneArg = args.GetIntArg("-prune", 0);
1046 0 : if (nPruneArg > 0) {
1047 0 : if (args.SoftSetBoolArg("-disablegovernance", true)) {
1048 0 : LogPrintf("%s: parameter interaction: -prune=%d -> setting -disablegovernance=true\n", __func__, nPruneArg);
1049 0 : }
1050 0 : if (args.SoftSetBoolArg("-txindex", false)) {
1051 0 : LogPrintf("%s: parameter interaction: -prune=%d -> setting -txindex=false\n", __func__, nPruneArg);
1052 0 : }
1053 0 : }
1054 :
1055 0 : if (args.IsArgSet("-masternodeblsprivkey")) {
1056 0 : if (args.SoftSetBoolArg("-disablewallet", true)) {
1057 0 : LogPrintf("%s: parameter interaction: -masternodeblsprivkey set -> setting -disablewallet=1\n", __func__);
1058 0 : }
1059 : // Enable block filters for masternodes to improve network services
1060 0 : if (args.SoftSetBoolArg("-peerblockfilters", true)) {
1061 0 : LogPrintf("%s: parameter interaction: -masternodeblsprivkey set -> setting -peerblockfilters=1\n", __func__);
1062 0 : }
1063 0 : if (args.SoftSetArg("-blockfilterindex", "basic")) {
1064 0 : LogPrintf("%s: parameter interaction: -masternodeblsprivkey set -> setting -blockfilterindex=basic\n", __func__);
1065 0 : }
1066 0 : }
1067 0 : }
1068 :
1069 : /**
1070 : * Initialize global loggers.
1071 : *
1072 : * Note that this is called very early in the process lifetime, so you should be
1073 : * careful about what global state you rely on here.
1074 : */
1075 627 : void InitLogging(const ArgsManager& args)
1076 : {
1077 627 : init::SetLoggingOptions(args);
1078 627 : init::LogPackageVersion();
1079 627 : }
1080 :
1081 : namespace { // Variables internal to initialization process only
1082 :
1083 : int nMaxConnections;
1084 : int nUserMaxConnections;
1085 : int nFD;
1086 : ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK_LIMITED | NODE_HEADERS_COMPRESSED);
1087 : int64_t peer_connect_timeout;
1088 146 : std::set<BlockFilterType> g_enabled_filter_types;
1089 :
1090 : } // namespace
1091 :
1092 0 : [[noreturn]] static void new_handler_terminate()
1093 : {
1094 : // Rather than throwing std::bad-alloc if allocation fails, terminate
1095 : // immediately to (try to) avoid chain corruption.
1096 : // Since LogPrintf may itself allocate memory, set the handler directly
1097 : // to terminate first.
1098 0 : std::set_new_handler(std::terminate);
1099 0 : LogPrintf("Error: Out of memory. Terminating.\n");
1100 :
1101 : // The log was successful, terminate now.
1102 0 : std::terminate();
1103 0 : };
1104 :
1105 0 : bool AppInitBasicSetup(const ArgsManager& args)
1106 : {
1107 : // ********************************************************* Step 1: setup
1108 : #ifdef _MSC_VER
1109 : // Turn off Microsoft heap dump noise
1110 : _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
1111 : _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, 0));
1112 : // Disable confusing "helpful" text message on abort, Ctrl-C
1113 : _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
1114 : #endif
1115 : #ifdef WIN32
1116 : // Enable heap terminate-on-corruption
1117 : HeapSetInformation(nullptr, HeapEnableTerminationOnCorruption, nullptr, 0);
1118 : #endif
1119 0 : if (!InitShutdownState()) {
1120 0 : return InitError(Untranslated("Initializing wait-for-shutdown state failed."));
1121 : }
1122 :
1123 0 : if (!SetupNetworking()) {
1124 0 : return InitError(Untranslated("Initializing networking failed."));
1125 : }
1126 :
1127 : #ifndef WIN32
1128 : // Clean shutdown on SIGTERM
1129 0 : registerSignalHandler(SIGTERM, HandleSIGTERM);
1130 0 : registerSignalHandler(SIGINT, HandleSIGTERM);
1131 :
1132 : // Reopen debug.log on SIGHUP
1133 0 : registerSignalHandler(SIGHUP, HandleSIGHUP);
1134 :
1135 : // Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
1136 0 : signal(SIGPIPE, SIG_IGN);
1137 : #else
1138 : SetConsoleCtrlHandler(consoleCtrlHandler, true);
1139 : #endif
1140 :
1141 0 : std::set_new_handler(new_handler_terminate);
1142 :
1143 0 : return true;
1144 0 : }
1145 :
1146 627 : bool AppInitParameterInteraction(const ArgsManager& args)
1147 : {
1148 627 : const CChainParams& chainparams = Params();
1149 : // ********************************************************* Step 2: parameter interactions
1150 :
1151 : // also see: InitParameterInteraction()
1152 :
1153 : // Error if network-specific options (-addnode, -connect, etc) are
1154 : // specified in default section of config file, but not overridden
1155 : // on the command line or in this network's section of the config file.
1156 627 : std::string network = args.GetChainName();
1157 627 : bilingual_str errors;
1158 627 : for (const auto& arg : args.GetUnsuitableSectionOnlyArgs()) {
1159 0 : errors += strprintf(_("Config setting for %s only applied on %s network when in [%s] section.") + Untranslated("\n"), arg, network, network);
1160 : }
1161 :
1162 627 : if (!errors.empty()) {
1163 0 : return InitError(errors);
1164 : }
1165 :
1166 : // Warn if unrecognized section name are present in the config file.
1167 627 : bilingual_str warnings;
1168 627 : for (const auto& section : args.GetUnrecognizedSections()) {
1169 0 : warnings += strprintf(Untranslated("%s:%i ") + _("Section [%s] is not recognized.") + Untranslated("\n"), section.m_file, section.m_line, section.m_name);
1170 : }
1171 :
1172 627 : if (!warnings.empty()) {
1173 0 : InitWarning(warnings);
1174 0 : }
1175 :
1176 627 : if (!fs::is_directory(gArgs.GetBlocksDirPath())) {
1177 0 : return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), args.GetArg("-blocksdir", "")));
1178 : }
1179 :
1180 : // parse and validate enabled filter types
1181 627 : std::string blockfilterindex_value = args.GetArg("-blockfilterindex", DEFAULT_BLOCKFILTERINDEX);
1182 627 : if (blockfilterindex_value == "" || blockfilterindex_value == "1") {
1183 0 : g_enabled_filter_types = AllBlockFilterTypes();
1184 627 : } else if (blockfilterindex_value != "0") {
1185 0 : const std::vector<std::string> names = args.GetArgs("-blockfilterindex");
1186 0 : for (const auto& name : names) {
1187 : BlockFilterType filter_type;
1188 0 : if (!BlockFilterTypeByName(name, filter_type)) {
1189 0 : return InitError(strprintf(_("Unknown -blockfilterindex value %s."), name));
1190 : }
1191 0 : g_enabled_filter_types.insert(filter_type);
1192 : }
1193 0 : }
1194 :
1195 : // Signal NODE_P2P_V2 if BIP324 v2 transport is enabled.
1196 627 : if (args.GetBoolArg("-v2transport", DEFAULT_V2_TRANSPORT)) {
1197 627 : nLocalServices = ServiceFlags(nLocalServices | NODE_P2P_V2);
1198 627 : }
1199 :
1200 : // Signal NODE_COMPACT_FILTERS if peerblockfilters and basic filters index are both enabled.
1201 627 : if (args.GetBoolArg("-peerblockfilters", DEFAULT_PEERBLOCKFILTERS)) {
1202 0 : if (g_enabled_filter_types.count(BlockFilterType::BASIC_FILTER) != 1) {
1203 0 : return InitError(_("Cannot set -peerblockfilters without -blockfilterindex."));
1204 : }
1205 :
1206 0 : nLocalServices = ServiceFlags(nLocalServices | NODE_COMPACT_FILTERS);
1207 0 : }
1208 :
1209 627 : if (args.GetIntArg("-prune", 0)) {
1210 0 : if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX))
1211 0 : return InitError(_("Prune mode is incompatible with -txindex."));
1212 0 : if (args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX))
1213 0 : return InitError(_("Prune mode is incompatible with -addressindex."));
1214 0 : if (args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX))
1215 0 : return InitError(_("Prune mode is incompatible with -spentindex."));
1216 0 : if (args.GetBoolArg("-reindex-chainstate", false)) {
1217 0 : return InitError(_("Prune mode is incompatible with -reindex-chainstate. Use full -reindex instead."));
1218 : }
1219 0 : if (!args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)) {
1220 0 : return InitError(_("Prune mode is incompatible with -disablegovernance=false."));
1221 : }
1222 0 : }
1223 :
1224 627 : if (args.IsArgSet("-devnet")) {
1225 : // Require setting of ports when running devnet
1226 0 : if (args.GetBoolArg("-listen", DEFAULT_LISTEN) && !args.IsArgSet("-port")) {
1227 0 : return InitError(_("-port must be specified when -devnet and -listen are specified"));
1228 : }
1229 0 : if (args.GetBoolArg("-server", false) && !args.IsArgSet("-rpcport")) {
1230 0 : return InitError(_("-rpcport must be specified when -devnet and -server are specified"));
1231 : }
1232 0 : if (args.GetArgs("-devnet").size() > 1) {
1233 0 : return InitError(_("-devnet can only be specified once"));
1234 : }
1235 0 : }
1236 :
1237 627 : fAllowPrivateNet = args.GetBoolArg("-allowprivatenet", DEFAULT_ALLOWPRIVATENET);
1238 :
1239 : // If -forcednsseed is set to true, ensure -dnsseed has not been set to false
1240 627 : if (args.GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED) && !args.GetBoolArg("-dnsseed", DEFAULT_DNSSEED)){
1241 0 : return InitError(_("Cannot set -forcednsseed to true when setting -dnsseed to false."));
1242 : }
1243 :
1244 : // -bind and -whitebind can't be set when not listening
1245 627 : size_t nUserBind = args.GetArgs("-bind").size() + args.GetArgs("-whitebind").size();
1246 627 : if (nUserBind != 0 && !args.GetBoolArg("-listen", DEFAULT_LISTEN)) {
1247 0 : return InitError(Untranslated("Cannot set -bind or -whitebind together with -listen=0"));
1248 : }
1249 :
1250 : // if listen=0, then disallow listenonion=1
1251 627 : if (!args.GetBoolArg("-listen", DEFAULT_LISTEN) && args.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION)) {
1252 0 : return InitError(Untranslated("Cannot set -listen=0 together with -listenonion=1"));
1253 : }
1254 :
1255 : // Make sure enough file descriptors are available
1256 627 : int nBind = std::max(nUserBind, size_t(1));
1257 627 : nUserMaxConnections = args.GetIntArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS);
1258 627 : nMaxConnections = std::max(nUserMaxConnections, 0);
1259 :
1260 627 : nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS + nBind + NUM_FDS_MESSAGE_CAPTURE);
1261 :
1262 : #ifdef USE_POLL
1263 : int fd_max = nFD;
1264 : #else
1265 627 : int fd_max = FD_SETSIZE;
1266 : #endif
1267 : // Trim requested connection counts, to fit into system limitations
1268 : // <int> in std::min<int>(...) to work around FreeBSD compilation issue described in #2695
1269 627 : nMaxConnections = std::max(std::min<int>(nMaxConnections, fd_max - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE), 0);
1270 627 : if (nFD < MIN_CORE_FILEDESCRIPTORS)
1271 0 : return InitError(_("Not enough file descriptors available."));
1272 627 : nMaxConnections = std::min(nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE, nMaxConnections);
1273 :
1274 627 : if (nMaxConnections < nUserMaxConnections)
1275 0 : InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), nUserMaxConnections, nMaxConnections));
1276 :
1277 : // ********************************************************* Step 3: parameter-to-internal-flags
1278 627 : init::SetLoggingCategories(args);
1279 627 : init::SetLoggingLevel(args);
1280 :
1281 627 : fCheckBlockIndex = args.GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
1282 627 : fCheckpointsEnabled = args.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED);
1283 :
1284 627 : hashAssumeValid = uint256S(args.GetArg("-assumevalid", chainparams.GetConsensus().defaultAssumeValid.GetHex()));
1285 627 : if (!hashAssumeValid.IsNull())
1286 526 : LogPrintf("Assuming ancestors of block %s have valid signatures.\n", hashAssumeValid.GetHex());
1287 : else
1288 101 : LogPrintf("Validating signatures for all blocks.\n");
1289 :
1290 627 : if (args.IsArgSet("-minimumchainwork")) {
1291 0 : const std::string minChainWorkStr = args.GetArg("-minimumchainwork", "");
1292 0 : if (!IsHexNumber(minChainWorkStr)) {
1293 0 : return InitError(strprintf(Untranslated("Invalid non-hex (%s) minimum chain work value specified"), minChainWorkStr));
1294 : }
1295 0 : nMinimumChainWork = UintToArith256(uint256S(minChainWorkStr));
1296 0 : } else {
1297 627 : nMinimumChainWork = UintToArith256(chainparams.GetConsensus().nMinimumChainWork);
1298 : }
1299 627 : LogPrintf("Setting nMinimumChainWork=%s\n", nMinimumChainWork.GetHex());
1300 627 : if (nMinimumChainWork < UintToArith256(chainparams.GetConsensus().nMinimumChainWork)) {
1301 0 : LogPrintf("Warning: nMinimumChainWork set below default value of %s\n", chainparams.GetConsensus().nMinimumChainWork.GetHex());
1302 0 : }
1303 :
1304 : // mempool limits
1305 627 : int64_t nMempoolSizeMax = args.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
1306 627 : int64_t nMempoolSizeMin = args.GetIntArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000 * 40;
1307 627 : if (nMempoolSizeMax < 0 || nMempoolSizeMax < nMempoolSizeMin)
1308 0 : return InitError(strprintf(_("-maxmempool must be at least %d MB"), std::ceil(nMempoolSizeMin / 1000000.0)));
1309 : // incremental relay fee sets the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
1310 627 : if (args.IsArgSet("-incrementalrelayfee")) {
1311 0 : if (std::optional<CAmount> inc_relay_fee = ParseMoney(args.GetArg("-incrementalrelayfee", ""))) {
1312 0 : ::incrementalRelayFee = CFeeRate{inc_relay_fee.value()};
1313 0 : } else {
1314 0 : return InitError(AmountErrMsg("incrementalrelayfee", args.GetArg("-incrementalrelayfee", "")));
1315 : }
1316 0 : }
1317 :
1318 : // block pruning; get the amount of disk space (in MiB) to allot for block & undo files
1319 627 : int64_t nPruneArg = args.GetIntArg("-prune", 0);
1320 627 : if (nPruneArg < 0) {
1321 0 : return InitError(_("Prune cannot be configured with a negative value."));
1322 : }
1323 627 : nPruneTarget = (uint64_t) nPruneArg * 1024 * 1024;
1324 627 : if (nPruneArg == 1) { // manual pruning: -prune=1
1325 0 : LogPrintf("Block pruning enabled. Use RPC call pruneblockchain(height) to manually prune block and undo files.\n");
1326 0 : nPruneTarget = std::numeric_limits<uint64_t>::max();
1327 0 : fPruneMode = true;
1328 627 : } else if (nPruneTarget) {
1329 0 : if (args.GetBoolArg("-regtest", false)) {
1330 : // we use 1MB blocks to test this on regtest
1331 0 : if (nPruneTarget < 550 * 1024 * 1024) {
1332 0 : return InitError(strprintf(_("Prune configured below the minimum of %d MiB. Please use a higher number."), 550));
1333 : }
1334 0 : } else {
1335 0 : if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
1336 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));
1337 : }
1338 : }
1339 0 : LogPrintf("Prune configured to target %u MiB on disk for block and undo files.\n", nPruneTarget / 1024 / 1024);
1340 0 : fPruneMode = true;
1341 0 : }
1342 :
1343 627 : nConnectTimeout = args.GetIntArg("-timeout", DEFAULT_CONNECT_TIMEOUT);
1344 627 : if (nConnectTimeout <= 0) {
1345 0 : nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
1346 0 : }
1347 :
1348 627 : peer_connect_timeout = args.GetIntArg("-peertimeout", DEFAULT_PEER_CONNECT_TIMEOUT);
1349 627 : if (peer_connect_timeout <= 0) {
1350 0 : return InitError(Untranslated("peertimeout must be a positive integer."));
1351 : }
1352 :
1353 627 : if (args.IsArgSet("-minrelaytxfee")) {
1354 0 : if (std::optional<CAmount> min_relay_fee = ParseMoney(args.GetArg("-minrelaytxfee", ""))) {
1355 : // High fee check is done afterward in CWallet::Create()
1356 0 : ::minRelayTxFee = CFeeRate{min_relay_fee.value()};
1357 0 : } else {
1358 0 : return InitError(AmountErrMsg("minrelaytxfee", args.GetArg("-minrelaytxfee", "")));
1359 : }
1360 627 : } else if (incrementalRelayFee > ::minRelayTxFee) {
1361 : // Allow only setting incrementalRelayFee to control both
1362 0 : ::minRelayTxFee = incrementalRelayFee;
1363 0 : LogPrintf("Increasing minrelaytxfee to %s to match incrementalrelayfee\n",::minRelayTxFee.ToString());
1364 0 : }
1365 :
1366 : // Sanity check argument for min fee for including tx in block
1367 : // TODO: Harmonize which arguments need sanity checking and where that happens
1368 627 : if (args.IsArgSet("-blockmintxfee")) {
1369 0 : if (!ParseMoney(args.GetArg("-blockmintxfee", ""))) {
1370 0 : return InitError(AmountErrMsg("blockmintxfee", args.GetArg("-blockmintxfee", "")));
1371 : }
1372 0 : }
1373 :
1374 : // Feerate used to define dust. Shouldn't be changed lightly as old
1375 : // implementations may inadvertently create non-standard transactions
1376 627 : if (args.IsArgSet("-dustrelayfee")) {
1377 0 : if (std::optional<CAmount> parsed = ParseMoney(args.GetArg("-dustrelayfee", ""))) {
1378 0 : dustRelayFee = CFeeRate{parsed.value()};
1379 0 : } else {
1380 0 : return InitError(AmountErrMsg("dustrelayfee", args.GetArg("-dustrelayfee", "")));
1381 : }
1382 0 : }
1383 :
1384 627 : fRequireStandard = !args.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
1385 627 : if (!chainparams.IsTestChain() && !fRequireStandard) {
1386 0 : return InitError(strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.NetworkIDString()));
1387 : }
1388 627 : nBytesPerSigOp = args.GetIntArg("-bytespersigop", nBytesPerSigOp);
1389 :
1390 627 : if (!g_wallet_init_interface.ParameterInteraction()) return false;
1391 :
1392 627 : fIsBareMultisigStd = args.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
1393 627 : fAcceptDatacarrier = args.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER);
1394 627 : nMaxDatacarrierBytes = args.GetIntArg("-datacarriersize", nMaxDatacarrierBytes);
1395 :
1396 : // Option to startup with mocktime set (used for regression testing):
1397 627 : SetMockTime(args.GetIntArg("-mocktime", 0)); // SetMockTime(0) is a no-op
1398 :
1399 627 : if (args.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS))
1400 627 : nLocalServices = ServiceFlags(nLocalServices | NODE_BLOOM);
1401 :
1402 627 : nMaxTipAge = args.GetIntArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
1403 :
1404 627 : if (args.GetBoolArg("-reindex-chainstate", false)) {
1405 : // indexes that must be deactivated to prevent index corruption, see #24630
1406 0 : if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
1407 0 : return InitError(_("-reindex-chainstate option is not compatible with -coinstatsindex. Please temporarily disable coinstatsindex while using -reindex-chainstate, or replace -reindex-chainstate with -reindex to fully rebuild all indexes."));
1408 : }
1409 0 : if (g_enabled_filter_types.count(BlockFilterType::BASIC_FILTER)) {
1410 0 : return InitError(_("-reindex-chainstate option is not compatible with -blockfilterindex. Please temporarily disable blockfilterindex while using -reindex-chainstate, or replace -reindex-chainstate with -reindex to fully rebuild all indexes."));
1411 : }
1412 0 : if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
1413 0 : return InitError(_("-reindex-chainstate option is not compatible with -txindex. Please temporarily disable txindex while using -reindex-chainstate, or replace -reindex-chainstate with -reindex to fully rebuild all indexes."));
1414 : }
1415 0 : }
1416 :
1417 : try {
1418 627 : const bool fQuorumVvecRequestsEnabled{llmq::GetEnabledQuorumVvecSyncEntries(args).size() > 0};
1419 627 : if (!args.GetBoolArg("-llmq-data-recovery", llmq::DEFAULT_ENABLE_QUORUM_DATA_RECOVERY) && fQuorumVvecRequestsEnabled) {
1420 0 : InitWarning(Untranslated("-llmq-qvvec-sync set but recovery is disabled due to -llmq-data-recovery=0"));
1421 0 : }
1422 627 : } catch (const std::invalid_argument& e) {
1423 0 : return InitError(Untranslated(e.what()));
1424 0 : }
1425 :
1426 627 : if (args.IsArgSet("-masternodeblsprivkey")) {
1427 0 : if (!args.GetBoolArg("-listen", DEFAULT_LISTEN) && Params().RequireRoutableExternalIP()) {
1428 0 : return InitError(Untranslated("Masternode must accept connections from outside, set -listen=1"));
1429 : }
1430 0 : if (!args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
1431 0 : return InitError(Untranslated("Masternode must have transaction index enabled, set -txindex=1"));
1432 : }
1433 0 : if (!args.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS)) {
1434 0 : return InitError(Untranslated("Masternode must have bloom filters enabled, set -peerbloomfilters=1"));
1435 : }
1436 0 : if (args.GetIntArg("-prune", 0) > 0) {
1437 0 : return InitError(Untranslated("Masternode must have no pruning enabled, set -prune=0"));
1438 : }
1439 0 : if (args.GetIntArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS) < DEFAULT_MAX_PEER_CONNECTIONS) {
1440 0 : return InitError(strprintf(Untranslated("Masternode must be able to handle at least %d connections, set -maxconnections=%d"), DEFAULT_MAX_PEER_CONNECTIONS, DEFAULT_MAX_PEER_CONNECTIONS));
1441 : }
1442 0 : if (args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)) {
1443 0 : return InitError(_("You can not disable governance validation on a masternode."));
1444 : }
1445 0 : }
1446 :
1447 627 : if (args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)) {
1448 0 : InitWarning(_("You are starting with governance validation disabled.") +
1449 0 : (fPruneMode ?
1450 0 : Untranslated(" ") + _("This is expected because you are running a pruned node.") :
1451 0 : Untranslated("")));
1452 0 : }
1453 :
1454 627 : return true;
1455 627 : }
1456 :
1457 0 : static bool LockDataDirectory(bool probeOnly)
1458 : {
1459 : // Make sure only a single Dash Core process is using the data directory.
1460 0 : const fs::path& datadir = gArgs.GetDataDirNet();
1461 0 : if (!DirIsWritable(datadir)) {
1462 0 : return InitError(strprintf(_("Cannot write to data directory '%s'; check permissions."), fs::PathToString(datadir)));
1463 : }
1464 0 : if (!LockDirectory(datadir, ".lock", probeOnly)) {
1465 0 : return InitError(strprintf(_("Cannot obtain a lock on data directory %s. %s is probably already running."), fs::PathToString(datadir), PACKAGE_NAME));
1466 : }
1467 0 : return true;
1468 0 : }
1469 :
1470 0 : bool AppInitSanityChecks()
1471 : {
1472 : // ********************************************************* Step 4: sanity checks
1473 :
1474 0 : init::SetGlobals();
1475 :
1476 0 : if (!init::SanityChecks()) {
1477 0 : return InitError(strprintf(_("Initialization sanity check failed. %s is shutting down."), PACKAGE_NAME));
1478 : }
1479 :
1480 : // Probe the data directory lock to give an early error message, if possible
1481 : // We cannot hold the data directory lock here, as the forking for daemon() hasn't yet happened,
1482 : // and a fork will cause weird behavior to it.
1483 0 : return LockDataDirectory(true);
1484 0 : }
1485 :
1486 0 : bool AppInitLockDataDirectory()
1487 : {
1488 : // After daemonization get the data directory lock again and hold on to it until exit
1489 : // This creates a slight window for a race condition to happen, however this condition is harmless: it
1490 : // will at most make us exit without printing a message to console.
1491 0 : if (!LockDataDirectory(false)) {
1492 : // Detailed error printed inside LockDataDirectory
1493 0 : return false;
1494 : }
1495 0 : return true;
1496 0 : }
1497 :
1498 0 : bool AppInitInterfaces(NodeContext& node)
1499 : {
1500 0 : node.chain = node.init->makeChain();
1501 0 : return true;
1502 : }
1503 :
1504 0 : bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
1505 : {
1506 0 : const ArgsManager& args = *Assert(node.args);
1507 0 : const CChainParams& chainparams = Params();
1508 :
1509 0 : auto opt_max_upload = ParseByteUnits(args.GetArg("-maxuploadtarget", DEFAULT_MAX_UPLOAD_TARGET), ByteUnit::M);
1510 0 : if (!opt_max_upload) {
1511 0 : return InitError(strprintf(_("Unable to parse -maxuploadtarget: '%s'"), args.GetArg("-maxuploadtarget", "")));
1512 : }
1513 :
1514 : // ********************************************************* Step 4a: application initialization
1515 0 : if (!CreatePidFile(args)) {
1516 : // Detailed error printed inside CreatePidFile().
1517 0 : return false;
1518 : }
1519 0 : if (!init::StartLogging(args)) {
1520 : // Detailed error printed inside StartLogging().
1521 0 : return false;
1522 : }
1523 :
1524 0 : LogPrintf("Using at most %i automatic connections (%i file descriptors available)\n", nMaxConnections, nFD);
1525 :
1526 : // Warn about relative -datadir path.
1527 0 : if (args.IsArgSet("-datadir") && !args.GetPathArg("-datadir").is_absolute()) {
1528 0 : LogPrintf("Warning: relative datadir option '%s' specified, which will be interpreted relative to the " /* Continued */
1529 : "current working directory '%s'. This is fragile, because if Dash Core is started in the future "
1530 : "from a different location, it will be unable to locate the current data files. There could "
1531 : "also be data loss if Dash Core is started while in a temporary directory.\n",
1532 : args.GetArg("-datadir", ""), fs::PathToString(fs::current_path()));
1533 0 : }
1534 :
1535 0 : InitSignatureCache();
1536 0 : InitScriptExecutionCache();
1537 :
1538 0 : int script_threads = args.GetIntArg("-par", DEFAULT_SCRIPTCHECK_THREADS);
1539 0 : if (script_threads <= 0) {
1540 : // -par=0 means autodetect (number of cores - 1 script threads)
1541 : // -par=-n means "leave n cores free" (number of cores - n - 1 script threads)
1542 0 : script_threads += GetNumCores();
1543 0 : }
1544 :
1545 : // Subtract 1 because the main thread counts towards the par threads
1546 0 : script_threads = std::max(script_threads - 1, 0);
1547 :
1548 : // Number of script-checking threads <= MAX_SCRIPTCHECK_THREADS
1549 0 : script_threads = std::min(script_threads, MAX_SCRIPTCHECK_THREADS);
1550 :
1551 0 : LogPrintf("Script verification uses %d additional threads\n", script_threads);
1552 0 : if (script_threads >= 1) {
1553 0 : g_parallel_script_checks = true;
1554 0 : StartScriptCheckWorkerThreads(script_threads);
1555 0 : }
1556 :
1557 0 : assert(!node.scheduler);
1558 0 : node.scheduler = std::make_unique<CScheduler>();
1559 :
1560 : // Start the lightweight task scheduler thread
1561 0 : node.scheduler->m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { node.scheduler->serviceQueue(); });
1562 :
1563 : // Gather some entropy once per minute.
1564 0 : node.scheduler->scheduleEvery([]{
1565 0 : RandAddPeriodic();
1566 0 : }, std::chrono::minutes{1});
1567 :
1568 0 : GetMainSignals().RegisterBackgroundSignalScheduler(*node.scheduler);
1569 :
1570 : // Create client interfaces for wallets that are supposed to be loaded
1571 : // according to -wallet and -disablewallet options. This only constructs
1572 : // the interfaces, it doesn't load wallet data. Wallets actually get loaded
1573 : // when load() and start() interface methods are called below.
1574 0 : g_wallet_init_interface.Construct(node);
1575 0 : uiInterface.InitWallet();
1576 :
1577 : /* Register RPC commands regardless of -server setting so they will be
1578 : * available in the GUI RPC console even if external calls are disabled.
1579 : */
1580 0 : RegisterAllCoreRPCCommands(tableRPC);
1581 0 : for (const auto& client : node.chain_clients) {
1582 0 : client->registerRpcs();
1583 : }
1584 : #ifdef ENABLE_WALLET
1585 : // Register non-core wallet-only RPC commands. These are commands that
1586 : // aren't a part of the wallet library but heavily rely on wallet logic.
1587 : // TODO: Move them to chain client interfaces so they can be called
1588 : // with registerRpcs()
1589 0 : if (!args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
1590 0 : for (const auto& commands : {
1591 0 : GetWalletCoinJoinRPCCommands(),
1592 0 : GetWalletEvoRPCCommands(),
1593 0 : GetWalletGovernanceRPCCommands(),
1594 0 : GetWalletMasternodeRPCCommands(),
1595 : }) {
1596 0 : node.wallet_loader->registerOtherRpcs(commands);
1597 : }
1598 0 : }
1599 : #endif // ENABLE_WALLET
1600 :
1601 : #if ENABLE_ZMQ
1602 : RegisterZMQRPCCommands(tableRPC);
1603 : #endif
1604 :
1605 : /* Start the RPC server already. It will be started in "warmup" mode
1606 : * and not really process calls already (but it will signify connections
1607 : * that the server is there and will be ready later). Warmup mode will
1608 : * be disabled when initialisation is finished.
1609 : */
1610 0 : if (args.GetBoolArg("-server", false)) {
1611 0 : uiInterface.InitMessage_connect(SetRPCWarmupStatus);
1612 0 : if (!AppInitServers(node))
1613 0 : return InitError(_("Unable to start HTTP server. See debug log for details."));
1614 0 : }
1615 :
1616 : // ********************************************************* Step 5: verify wallet database integrity
1617 :
1618 0 : g_wallet_init_interface.InitAutoBackup();
1619 0 : for (const auto& client : node.chain_clients) {
1620 0 : if (!client->verify()) {
1621 0 : return false;
1622 : }
1623 : }
1624 :
1625 : // ********************************************************* Step 6: network initialization
1626 : // Note that we absolutely cannot open any actual connections
1627 : // until the very end ("start node") as the UTXO/block state
1628 : // is not yet setup and may end up being set up twice if we
1629 : // need to reindex later.
1630 :
1631 0 : fListen = args.GetBoolArg("-listen", DEFAULT_LISTEN);
1632 0 : fDiscover = args.GetBoolArg("-discover", true);
1633 0 : const bool ignores_incoming_txs{args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)};
1634 :
1635 : {
1636 :
1637 : // Read asmap file if configured
1638 0 : std::vector<bool> asmap;
1639 0 : if (args.IsArgSet("-asmap")) {
1640 0 : fs::path asmap_path = args.GetPathArg("-asmap", DEFAULT_ASMAP_FILENAME);
1641 0 : if (!asmap_path.is_absolute()) {
1642 0 : asmap_path = gArgs.GetDataDirNet() / asmap_path;
1643 0 : }
1644 0 : if (!fs::exists(asmap_path)) {
1645 0 : InitError(strprintf(_("Could not find asmap file %s"), fs::quoted(fs::PathToString(asmap_path))));
1646 0 : return false;
1647 : }
1648 0 : asmap = DecodeAsmap(asmap_path);
1649 0 : if (asmap.size() == 0) {
1650 0 : InitError(strprintf(_("Could not parse asmap file %s"), fs::quoted(fs::PathToString(asmap_path))));
1651 0 : return false;
1652 : }
1653 0 : const uint256 asmap_version = (HashWriter{} << asmap).GetHash();
1654 0 : LogPrintf("Using asmap version %s for IP bucketing\n", asmap_version.ToString());
1655 0 : } else {
1656 0 : LogPrintf("Using /16 prefix for IP bucketing\n");
1657 : }
1658 :
1659 : // Initialize netgroup manager
1660 0 : assert(!node.netgroupman);
1661 0 : node.netgroupman = std::make_unique<NetGroupManager>(std::move(asmap));
1662 :
1663 : // Initialize addrman
1664 0 : assert(!node.addrman);
1665 0 : uiInterface.InitMessage(_("Loading P2P addressesā¦").translated);
1666 0 : auto addrman{LoadAddrman(*node.netgroupman, args)};
1667 0 : if (!addrman) return InitError(util::ErrorString(addrman));
1668 0 : node.addrman = std::move(*addrman);
1669 0 : }
1670 :
1671 0 : std::string sem_str = args.GetArg("-socketevents", DEFAULT_SOCKETEVENTS);
1672 0 : ::g_socket_events_mode = SEMFromString(sem_str);
1673 0 : if (::g_socket_events_mode == SocketEventsMode::Unknown) {
1674 0 : return InitError(strprintf(_("Invalid -socketevents ('%s') specified. Only these modes are supported: %s"), sem_str, GetSupportedSocketEventsStr()));
1675 : }
1676 :
1677 : // We need to initialize g_stats_client early as currently, g_stats_client is called
1678 : // regardless of whether transmitting stats are desirable or not and if
1679 : // g_stats_client isn't present when that attempt is made, the client will crash.
1680 : {
1681 0 : auto stats_client = StatsdClient::make(args);
1682 0 : if (!stats_client) {
1683 0 : return InitError(_("Cannot init Statsd client") + Untranslated(" (") + util::ErrorString(stats_client) + Untranslated(")"));
1684 : }
1685 0 : ::g_stats_client = std::move(*stats_client);
1686 0 : }
1687 :
1688 0 : assert(!node.banman);
1689 0 : node.banman = std::make_unique<BanMan>(gArgs.GetDataDirNet() / "banlist", &uiInterface, args.GetIntArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
1690 0 : assert(!node.connman);
1691 0 : node.connman = std::make_unique<CConnman>(GetRand<uint64_t>(),
1692 0 : GetRand<uint64_t>(),
1693 0 : *node.addrman, *node.netgroupman, args.GetBoolArg("-networkactive", true));
1694 :
1695 0 : assert(!node.fee_estimator);
1696 : // Don't initialize fee estimation with old data if we don't relay transactions,
1697 : // as they would never get updated.
1698 0 : if (!ignores_incoming_txs) node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
1699 :
1700 0 : assert(!node.mn_metaman);
1701 0 : node.mn_metaman = std::make_unique<CMasternodeMetaMan>();
1702 :
1703 0 : assert(!node.netfulfilledman);
1704 0 : node.netfulfilledman = std::make_unique<CNetFulfilledRequestManager>();
1705 :
1706 0 : const bool is_governance_enabled{!args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)};
1707 :
1708 0 : assert(!node.sporkman);
1709 0 : node.sporkman = std::make_unique<CSporkManager>();
1710 0 : node.chainlocks = std::make_unique<chainlock::Chainlocks>(*node.sporkman);
1711 :
1712 0 : std::vector<std::string> vSporkAddresses;
1713 0 : if (args.IsArgSet("-sporkaddr")) {
1714 0 : vSporkAddresses = args.GetArgs("-sporkaddr");
1715 0 : } else {
1716 0 : vSporkAddresses = Params().SporkAddresses();
1717 : }
1718 0 : for (const auto& address: vSporkAddresses) {
1719 0 : if (!node.sporkman->SetSporkAddress(address)) {
1720 0 : return InitError(_("Invalid spork address specified with -sporkaddr"));
1721 : }
1722 : }
1723 :
1724 0 : int minsporkkeys = args.GetIntArg("-minsporkkeys", Params().MinSporkKeys());
1725 0 : if (!node.sporkman->SetMinSporkKeys(minsporkkeys)) {
1726 0 : return InitError(_("Invalid minimum number of spork signers specified with -minsporkkeys"));
1727 : }
1728 :
1729 :
1730 0 : if (args.IsArgSet("-sporkkey")) { // spork priv key
1731 0 : if (!node.sporkman->SetPrivKey(args.GetArg("-sporkkey", ""))) {
1732 0 : return InitError(_("Unable to sign spork message, wrong key?"));
1733 : }
1734 0 : }
1735 :
1736 : // Check port numbers
1737 0 : for (const std::string port_option : {
1738 : "-port",
1739 : "-rpcport",
1740 : }) {
1741 0 : if (args.IsArgSet(port_option)) {
1742 0 : const std::string port = args.GetArg(port_option, "");
1743 : uint16_t n;
1744 0 : if (!ParseUInt16(port, &n) || n == 0) {
1745 0 : return InitError(InvalidPortErrMsg(port_option, port));
1746 : }
1747 0 : }
1748 0 : }
1749 :
1750 0 : for ([[maybe_unused]] const auto& [arg, unix] : std::vector<std::pair<std::string, bool>>{
1751 : // arg name UNIX socket support
1752 0 : {"-i2psam", false},
1753 0 : {"-onion", true},
1754 0 : {"-proxy", true},
1755 0 : {"-rpcbind", false},
1756 0 : {"-torcontrol", false},
1757 0 : {"-whitebind", false},
1758 0 : {"-zmqpubhashblock", true},
1759 0 : {"-zmqpubhashchainlock", true},
1760 0 : {"-zmqpubhashgovernanceobject", true},
1761 0 : {"-zmqpubhashgovernancevote", true},
1762 0 : {"-zmqpubhashinstantsenddoublespend", true},
1763 0 : {"-zmqpubhashrecoveredsig", true},
1764 0 : {"-zmqpubhashtx", true},
1765 0 : {"-zmqpubhashtxlock", true},
1766 0 : {"-zmqpubrawblock", true},
1767 0 : {"-zmqpubrawchainlock", true},
1768 0 : {"-zmqpubrawchainlocksig", true},
1769 0 : {"-zmqpubrawgovernancevote", true},
1770 0 : {"-zmqpubrawgovernanceobject", true},
1771 0 : {"-zmqpubrawinstantsenddoublespend", true},
1772 0 : {"-zmqpubrawrecoveredsig", true},
1773 0 : {"-zmqpubrawtx", true},
1774 0 : {"-zmqpubrawtxlock", true},
1775 0 : {"-zmqpubrawtxlocksig", true},
1776 0 : {"-zmqpubsequence", true},
1777 : }) {
1778 0 : for (const std::string& socket_addr : args.GetArgs(arg)) {
1779 0 : std::string host_out;
1780 0 : uint16_t port_out{0};
1781 0 : if (!SplitHostPort(socket_addr, port_out, host_out)) {
1782 : #if HAVE_SOCKADDR_UN
1783 : // Allow unix domain sockets for some options e.g. unix:/some/file/path
1784 0 : if (!unix || socket_addr.find(ADDR_PREFIX_UNIX) != 0) {
1785 0 : return InitError(InvalidPortErrMsg(arg, socket_addr));
1786 : }
1787 : #else
1788 : return InitError(InvalidPortErrMsg(arg, socket_addr));
1789 : #endif
1790 0 : }
1791 0 : }
1792 : }
1793 :
1794 0 : for (const std::string& socket_addr : args.GetArgs("-bind")) {
1795 0 : std::string host_out;
1796 0 : uint16_t port_out{0};
1797 0 : std::string bind_socket_addr = socket_addr.substr(0, socket_addr.rfind('='));
1798 0 : if (!SplitHostPort(bind_socket_addr, port_out, host_out)) {
1799 0 : return InitError(InvalidPortErrMsg("-bind", socket_addr));
1800 : }
1801 0 : }
1802 :
1803 : // sanitize comments per BIP-0014, format user agent and check total size
1804 0 : std::vector<std::string> uacomments;
1805 :
1806 0 : if (chainparams.NetworkIDString() == CBaseChainParams::DEVNET) {
1807 : // Add devnet name to user agent. This allows to disconnect nodes immediately if they don't belong to our own devnet
1808 0 : uacomments.push_back(strprintf("devnet.%s", args.GetDevNetName()));
1809 0 : }
1810 :
1811 0 : for (const std::string& cmt : args.GetArgs("-uacomment")) {
1812 0 : if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT))
1813 0 : return InitError(strprintf(_("User Agent comment (%s) contains unsafe characters."), cmt));
1814 0 : uacomments.push_back(cmt);
1815 : }
1816 0 : strSubVersion = FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, uacomments);
1817 0 : if (strSubVersion.size() > MAX_SUBVERSION_LENGTH) {
1818 0 : return InitError(strprintf(_("Total length of network version string (%i) exceeds maximum length (%i). Reduce the number or size of uacomments."),
1819 0 : strSubVersion.size(), MAX_SUBVERSION_LENGTH));
1820 : }
1821 :
1822 0 : if (args.IsArgSet("-onlynet")) {
1823 0 : g_reachable_nets.RemoveAll();
1824 0 : for (const std::string& snet : args.GetArgs("-onlynet")) {
1825 0 : enum Network net = ParseNetwork(snet);
1826 0 : if (net == NET_UNROUTABLE)
1827 0 : return InitError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet));
1828 0 : g_reachable_nets.Add(net);
1829 : }
1830 0 : }
1831 :
1832 0 : if (!args.IsArgSet("-cjdnsreachable")) {
1833 0 : if (args.IsArgSet("-onlynet") && g_reachable_nets.Contains(NET_CJDNS)) {
1834 0 : return InitError(
1835 0 : _("Outbound connections restricted to CJDNS (-onlynet=cjdns) but "
1836 : "-cjdnsreachable is not provided"));
1837 : }
1838 0 : g_reachable_nets.Remove(NET_CJDNS);
1839 0 : }
1840 : // Now g_reachable_nets.Contains(NET_CJDNS) is true if:
1841 : // 1. -cjdnsreachable is given and
1842 : // 2.1. -onlynet is not given or
1843 : // 2.2. -onlynet=cjdns is given
1844 :
1845 : // Requesting DNS seeds entails connecting to IPv4/IPv6, which -onlynet options may prohibit:
1846 : // If -dnsseed=1 is explicitly specified, abort. If it's left unspecified by the user, we skip
1847 : // the DNS seeds by adjusting -dnsseed in InitParameterInteraction.
1848 0 : if (args.GetBoolArg("-dnsseed", DEFAULT_DNSSEED) == true && !g_reachable_nets.Contains(NET_IPV4) && !g_reachable_nets.Contains(NET_IPV6)) {
1849 0 : return InitError(strprintf(_("Incompatible options: -dnsseed=1 was explicitly specified, but -onlynet forbids connections to IPv4/IPv6")));
1850 : };
1851 :
1852 : // Check for host lookup allowed before parsing any network related parameters
1853 0 : fNameLookup = args.GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
1854 :
1855 0 : Proxy onion_proxy;
1856 :
1857 0 : bool proxyRandomize = args.GetBoolArg("-proxyrandomize", DEFAULT_PROXYRANDOMIZE);
1858 : // -proxy sets a proxy for all outgoing network traffic
1859 : // -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
1860 0 : std::string proxyArg = args.GetArg("-proxy", "");
1861 0 : if (proxyArg != "" && proxyArg != "0") {
1862 0 : Proxy addrProxy;
1863 0 : if (IsUnixSocketPath(proxyArg)) {
1864 0 : addrProxy = Proxy(proxyArg, proxyRandomize);
1865 0 : } else {
1866 0 : const std::optional<CService> proxyAddr{Lookup(proxyArg, 9050, fNameLookup)};
1867 0 : if (!proxyAddr.has_value()) {
1868 0 : return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
1869 : }
1870 :
1871 0 : addrProxy = Proxy(proxyAddr.value(), proxyRandomize);
1872 0 : }
1873 :
1874 0 : if (!addrProxy.IsValid())
1875 0 : return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
1876 :
1877 0 : SetProxy(NET_IPV4, addrProxy);
1878 0 : SetProxy(NET_IPV6, addrProxy);
1879 0 : SetProxy(NET_CJDNS, addrProxy);
1880 0 : SetNameProxy(addrProxy);
1881 0 : onion_proxy = addrProxy;
1882 0 : }
1883 :
1884 0 : const bool onlynet_used_with_onion{args.IsArgSet("-onlynet") && g_reachable_nets.Contains(NET_ONION)};
1885 :
1886 : // -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
1887 : // -noonion (or -onion=0) disables connecting to .onion entirely
1888 : // An empty string is used to not override the onion proxy (in which case it defaults to -proxy set above, or none)
1889 0 : std::string onionArg = args.GetArg("-onion", "");
1890 0 : if (onionArg != "") {
1891 0 : if (onionArg == "0") { // Handle -noonion/-onion=0
1892 0 : onion_proxy = Proxy{};
1893 0 : if (onlynet_used_with_onion) {
1894 0 : return InitError(
1895 0 : _("Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
1896 : "reaching the Tor network is explicitly forbidden: -onion=0"));
1897 : }
1898 0 : } else {
1899 0 : if (IsUnixSocketPath(onionArg)) {
1900 0 : onion_proxy = Proxy(onionArg, proxyRandomize);
1901 0 : } else {
1902 0 : const std::optional<CService> addr{Lookup(onionArg, 9050, fNameLookup)};
1903 0 : if (!addr.has_value() || !addr->IsValid()) {
1904 0 : return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
1905 : }
1906 :
1907 0 : onion_proxy = Proxy(addr.value(), proxyRandomize);
1908 0 : }
1909 : }
1910 0 : }
1911 :
1912 0 : if (onion_proxy.IsValid()) {
1913 0 : SetProxy(NET_ONION, onion_proxy);
1914 0 : } else {
1915 : // If -listenonion is set, then we will (try to) connect to the Tor control port
1916 : // later from the torcontrol thread and may retrieve the onion proxy from there.
1917 0 : const bool listenonion_disabled{!args.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION)};
1918 0 : if (onlynet_used_with_onion && listenonion_disabled) {
1919 0 : return InitError(
1920 0 : _("Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
1921 : "reaching the Tor network is not provided: none of -proxy, -onion or "
1922 : "-listenonion is given"));
1923 : }
1924 0 : g_reachable_nets.Remove(NET_ONION);
1925 : }
1926 :
1927 0 : for (const std::string& strAddr : args.GetArgs("-externalip")) {
1928 0 : const std::optional<CService> addrLocal{Lookup(strAddr, GetListenPort(), fNameLookup)};
1929 0 : if (addrLocal.has_value() && addrLocal->IsValid())
1930 0 : AddLocal(addrLocal.value(), LOCAL_MANUAL);
1931 : else
1932 0 : return InitError(ResolveErrMsg("externalip", strAddr));
1933 0 : }
1934 :
1935 : #if ENABLE_ZMQ
1936 : g_zmq_notification_interface = CZMQNotificationInterface::Create();
1937 :
1938 : if (g_zmq_notification_interface) {
1939 : RegisterValidationInterface(g_zmq_notification_interface.get());
1940 : }
1941 : #endif
1942 :
1943 : // ********************************************************* Step 7a: Load sporks
1944 :
1945 0 : if (!node.sporkman->LoadCache()) {
1946 0 : auto file_path = fs::PathToString(gArgs.GetDataDirNet() / "sporks.dat");
1947 0 : return InitError(strprintf(_("Failed to load sporks cache from %s"), file_path));
1948 0 : }
1949 :
1950 : // ********************************************************* Step 7b: load block chain
1951 :
1952 0 : fReindex = args.GetBoolArg("-reindex", false);
1953 0 : bool fReindexChainState = args.GetBoolArg("-reindex-chainstate", false);
1954 :
1955 : // cache size calculations
1956 0 : CacheSizes cache_sizes = CalculateCacheSizes(args, g_enabled_filter_types.size());
1957 :
1958 0 : int64_t nMempoolSizeMax = args.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
1959 0 : LogPrintf("Cache configuration:\n");
1960 0 : LogPrintf("* Using %.1f MiB for block index database\n", cache_sizes.block_tree_db * (1.0 / 1024 / 1024));
1961 0 : if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
1962 0 : LogPrintf("* Using %.1f MiB for transaction index database\n", cache_sizes.tx_index * (1.0 / 1024 / 1024));
1963 0 : }
1964 0 : if (args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX)) {
1965 0 : LogPrintf("* Using %.1f MiB for address index database\n", cache_sizes.address_index * (1.0 / 1024 / 1024));
1966 0 : }
1967 0 : if (args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX)) {
1968 0 : LogPrintf("* Using %.1f MiB for timestamp index database\n", cache_sizes.timestamp_index * (1.0 / 1024 / 1024));
1969 0 : }
1970 0 : if (args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX)) {
1971 0 : LogPrintf("* Using %.1f MiB for spent index database\n", cache_sizes.spent_index * (1.0 / 1024 / 1024));
1972 0 : }
1973 0 : for (BlockFilterType filter_type : g_enabled_filter_types) {
1974 0 : LogPrintf("* Using %.1f MiB for %s block filter index database\n",
1975 : cache_sizes.filter_index * (1.0 / 1024 / 1024), BlockFilterTypeName(filter_type));
1976 : }
1977 0 : LogPrintf("* Using %.1f MiB for chain state database\n", cache_sizes.coins_db * (1.0 / 1024 / 1024));
1978 0 : 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));
1979 :
1980 0 : assert(!node.mempool);
1981 0 : assert(!node.chainman);
1982 0 : assert(!node.mn_sync);
1983 0 : const int mempool_check_ratio = std::clamp<int>(args.GetIntArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0, 1000000);
1984 :
1985 0 : for (bool fLoaded = false; !fLoaded && !ShutdownRequested();) {
1986 0 : node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), mempool_check_ratio);
1987 :
1988 0 : node.chainman = std::make_unique<ChainstateManager>(chainparams);
1989 0 : ChainstateManager& chainman = *node.chainman;
1990 :
1991 : /**
1992 : * The manager needs to be constructed regardless of whether governance
1993 : * validation is needed or not.
1994 : *
1995 : * Instead, we decide whether to initialize its database based on whether we
1996 : * need it or not further down and then query if the database is initialized
1997 : * to check if validation is enabled.
1998 : */
1999 0 : node.mn_sync = std::make_unique<CMasternodeSync>(std::make_unique<NodeSyncNotifierImpl>(*node.connman, *node.netfulfilledman));
2000 :
2001 0 : const bool fReset = fReindex;
2002 0 : bilingual_str strLoadError;
2003 :
2004 0 : uiInterface.InitMessage(_("Loading block indexā¦").translated);
2005 0 : const auto load_block_index_start_time{SteadyClock::now()};
2006 0 : std::optional<ChainstateLoadingError> maybe_load_error;
2007 : try {
2008 0 : maybe_load_error = LoadChainstate(fReset,
2009 0 : chainman,
2010 0 : *node.mn_metaman,
2011 0 : *node.sporkman,
2012 0 : *node.chainlocks,
2013 0 : *node.mn_sync,
2014 0 : node.chain_helper,
2015 0 : node.dmnman,
2016 0 : node.evodb,
2017 0 : node.llmq_ctx,
2018 0 : Assert(node.mempool.get()),
2019 0 : args.GetDataDirNet(),
2020 0 : fPruneMode,
2021 0 : chainparams.GetConsensus(),
2022 0 : fReindexChainState,
2023 0 : cache_sizes.block_tree_db,
2024 0 : cache_sizes.coins_db,
2025 0 : cache_sizes.coins,
2026 : /*block_tree_db_in_memory=*/false,
2027 : /*coins_db_in_memory=*/false,
2028 : /*dash_dbs_in_memory=*/false,
2029 0 : /*bls_threads=*/[&args]() -> int8_t {
2030 0 : int8_t threads = args.GetIntArg("-parbls", llmq::DEFAULT_BLSCHECK_THREADS);
2031 0 : if (threads <= 0) {
2032 : // -parbls=0 means autodetect (number of cores - 1 validator threads)
2033 : // -parbls=-n means "leave n cores free" (number of cores - n - 1 validator threads)
2034 0 : threads += GetNumCores();
2035 0 : }
2036 : // Subtract 1 because the main thread counts towards the par threads
2037 0 : return std::clamp<int8_t>(threads - 1, 0, llmq::MAX_BLSCHECK_THREADS);
2038 0 : }(),
2039 0 : llmq::DEFAULT_WORKER_COUNT,
2040 0 : args.GetIntArg("-maxrecsigsage", llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE),
2041 0 : /*shutdown_requested=*/ShutdownRequested,
2042 0 : /*coins_error_cb=*/[]() {
2043 0 : uiInterface.ThreadSafeMessageBox(
2044 0 : _("Error reading from database, shutting down."),
2045 0 : "", CClientUIInterface::MSG_ERROR);
2046 0 : });
2047 0 : } catch (const std::exception& e) {
2048 0 : LogPrintf("%s\n", e.what());
2049 0 : maybe_load_error = ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
2050 0 : }
2051 0 : if (maybe_load_error.has_value()) {
2052 0 : switch (maybe_load_error.value()) {
2053 : case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:
2054 0 : strLoadError = _("Error loading block database");
2055 0 : break;
2056 : case ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK:
2057 : // If the loaded chain has a wrong genesis, bail out immediately
2058 : // (we're likely using a testnet datadir, or the other way around).
2059 0 : return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
2060 : case ChainstateLoadingError::ERROR_BAD_DEVNET_GENESIS_BLOCK:
2061 0 : return InitError(_("Incorrect or no devnet genesis block found. Wrong datadir for devnet specified?"));
2062 : case ChainstateLoadingError::ERROR_PRUNED_NEEDS_REINDEX:
2063 0 : strLoadError = _("You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain");
2064 0 : break;
2065 : case ChainstateLoadingError::ERROR_LOAD_GENESIS_BLOCK_FAILED:
2066 0 : strLoadError = _("Error initializing block database");
2067 0 : break;
2068 : case ChainstateLoadingError::ERROR_CHAINSTATE_UPGRADE_FAILED:
2069 0 : return InitError(_("Unsupported chainstate database format found. "
2070 : "Please restart with -reindex-chainstate. This will "
2071 : "rebuild the chainstate database."));
2072 : case ChainstateLoadingError::ERROR_REPLAYBLOCKS_FAILED:
2073 0 : strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.");
2074 0 : break;
2075 : case ChainstateLoadingError::ERROR_LOADCHAINTIP_FAILED:
2076 0 : strLoadError = _("Error initializing block database");
2077 0 : break;
2078 : case ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED:
2079 0 : strLoadError = _("Error opening block database");
2080 0 : break;
2081 : case ChainstateLoadingError::ERROR_COMMITING_EVO_DB:
2082 0 : strLoadError = _("Failed to commit Evo database");
2083 0 : break;
2084 : case ChainstateLoadingError::ERROR_UPGRADING_EVO_DB:
2085 0 : strLoadError = _("Failed to upgrade Evo database");
2086 0 : break;
2087 : case ChainstateLoadingError::ERROR_UPGRADING_SIGNALS_DB:
2088 0 : strLoadError = _("Error upgrading evo database for EHF");
2089 0 : break;
2090 : case ChainstateLoadingError::SHUTDOWN_PROBED:
2091 0 : break;
2092 : }
2093 0 : } else {
2094 0 : std::optional<ChainstateLoadVerifyError> maybe_verify_error;
2095 : try {
2096 0 : uiInterface.InitMessage(_("Verifying blocksā¦").translated);
2097 0 : auto check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
2098 0 : if (chainman.m_blockman.m_have_pruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
2099 0 : LogWarning("pruned datadir may not have more than %d blocks; only checking available blocks\n",
2100 : MIN_BLOCKS_TO_KEEP);
2101 0 : }
2102 0 : maybe_verify_error = VerifyLoadedChainstate(chainman,
2103 0 : *Assert(node.evodb.get()),
2104 0 : fReset,
2105 0 : fReindexChainState,
2106 0 : chainparams.GetConsensus(),
2107 0 : check_blocks,
2108 0 : args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL),
2109 0 : /*get_unix_time_seconds=*/static_cast<int64_t(*)()>(GetTime),
2110 0 : [](bool bls_state) {
2111 0 : LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls_state);
2112 0 : });
2113 0 : } catch (const std::exception& e) {
2114 0 : LogPrintf("%s\n", e.what());
2115 0 : maybe_verify_error = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE;
2116 0 : }
2117 0 : if (maybe_verify_error.has_value()) {
2118 0 : switch (maybe_verify_error.value()) {
2119 : case ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE:
2120 0 : strLoadError = _("The block database contains a block which appears to be from the future. "
2121 : "This may be due to your computer's date and time being set incorrectly. "
2122 : "Only rebuild the block database if you are sure that your computer's date and time are correct");
2123 0 : break;
2124 : case ChainstateLoadVerifyError::ERROR_CORRUPTED_BLOCK_DB:
2125 0 : strLoadError = _("Corrupted block database detected");
2126 0 : break;
2127 : case ChainstateLoadVerifyError::ERROR_EVO_DB_SANITY_FAILED:
2128 0 : strLoadError = _("Error initializing block database");
2129 0 : break;
2130 : case ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE:
2131 0 : strLoadError = _("Error opening block database");
2132 0 : break;
2133 : }
2134 0 : } else {
2135 0 : fLoaded = true;
2136 0 : LogPrintf(" block index %15dms\n", Ticks<std::chrono::milliseconds>(SteadyClock::now() - load_block_index_start_time));
2137 : }
2138 : }
2139 :
2140 0 : if (!fLoaded && !ShutdownRequested()) {
2141 : // first suggest a reindex
2142 0 : if (!fReset) {
2143 0 : bool fRet = uiInterface.ThreadSafeQuestion(
2144 0 : strLoadError + Untranslated(".\n\n") + _("Do you want to rebuild the block database now?"),
2145 0 : strLoadError.original + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
2146 0 : "", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
2147 0 : if (fRet) {
2148 0 : fReindex = true;
2149 0 : AbortShutdown();
2150 0 : } else {
2151 0 : LogPrintf("Aborted block database rebuild. Exiting.\n");
2152 0 : return false;
2153 : }
2154 0 : } else {
2155 0 : return InitError(strLoadError);
2156 : }
2157 0 : }
2158 0 : }
2159 :
2160 : // As LoadBlockIndex can take several minutes, it's possible the user
2161 : // requested to kill the GUI during the last operation. If so, exit.
2162 : // As the program has not fully started yet, Shutdown() is possibly overkill.
2163 0 : if (ShutdownRequested()) {
2164 0 : LogPrintf("Shutdown requested. Exiting.\n");
2165 0 : return false;
2166 : }
2167 :
2168 0 : ChainstateManager& chainman = *Assert(node.chainman);
2169 :
2170 0 : assert(!node.dstxman);
2171 0 : node.dstxman = std::make_unique<CDSTXManager>(*node.chainlocks);
2172 :
2173 0 : node.clhandler = std::make_unique<chainlock::ChainlockHandler>(*node.chainlocks, chainman, *node.mempool, *node.mn_sync);
2174 0 : RegisterValidationInterface(node.clhandler.get());
2175 :
2176 0 : assert(!node.govman);
2177 0 : node.govman = std::make_unique<CGovernanceManager>(*node.mn_metaman, *node.chainman, *node.chain_helper->superblocks, *node.dmnman, *node.mn_sync);
2178 :
2179 : // ********************************************************* Step 7c: Setup masternode mode or watch-only mode
2180 0 : assert(!node.active_ctx);
2181 0 : assert(!node.observer_ctx);
2182 :
2183 0 : const bool quorums_recovery = args.GetBoolArg("-llmq-data-recovery", llmq::DEFAULT_ENABLE_QUORUM_DATA_RECOVERY);
2184 0 : const bool quorums_watch = args.GetBoolArg("-watchquorums", llmq::DEFAULT_WATCH_QUORUMS);
2185 0 : const llmq::QvvecSyncModeMap sync_map{llmq::GetEnabledQuorumVvecSyncEntries(args)};
2186 0 : const util::DbWrapperParams dash_db_params{.path = args.GetDataDirNet(), .memory = false, .wipe = (fReindex || fReindexChainState)};
2187 : if (const auto operator_sk_str = args.GetArg("-masternodeblsprivkey", ""); !operator_sk_str.empty()) {
2188 : const CBLSSecretKey operator_sk{ParseHex(operator_sk_str)};
2189 : if (!operator_sk.IsValid()) {
2190 : return InitError(_("Invalid masternodeblsprivkey. Please see documentation."));
2191 : }
2192 : // Will init later in ThreadImport
2193 : node.active_ctx = std::make_unique<ActiveContext>(*node.llmq_ctx->bls_worker, chainman, *node.connman, *node.dmnman,
2194 : *node.govman, *node.chain_helper->superblocks,
2195 : *node.sporkman, *node.chainlocks, *node.mempool, *node.clhandler, *node.llmq_ctx->isman,
2196 : *node.llmq_ctx->qman, *node.llmq_ctx->qsnapman, *node.llmq_ctx->sigman,
2197 : *node.mn_sync, operator_sk, dash_db_params, quorums_watch);
2198 : RegisterValidationInterface(node.active_ctx.get());
2199 : } else if (quorums_watch) {
2200 : node.observer_ctx = std::make_unique<llmq::ObserverContext>(*node.dmnman, *node.llmq_ctx->qman, *node.llmq_ctx->qsnapman,
2201 : chainman, *node.sporkman, dash_db_params);
2202 : RegisterValidationInterface(node.observer_ctx.get());
2203 : }
2204 :
2205 : assert(!node.peerman);
2206 : node.peerman = PeerManager::make(chainparams, *node.connman, *node.addrman, node.banman.get(), *node.dstxman,
2207 : chainman, *node.mempool, *node.mn_metaman, *node.mn_sync,
2208 : *node.sporkman, *node.chainlocks, *node.clhandler,
2209 : node.active_ctx ? node.active_ctx->nodeman.get() : nullptr,
2210 : node.dmnman, node.cj_walletman, node.llmq_ctx, ignores_incoming_txs);
2211 : RegisterValidationInterface(node.peerman.get());
2212 :
2213 : g_ds_notification_interface = std::make_unique<CDSNotificationInterface>(
2214 : *node.connman, *node.dstxman, *node.mn_sync, *node.govman, chainman, node.dmnman // todo: replace unique_ptr for dmnman to reference
2215 : );
2216 : RegisterValidationInterface(g_ds_notification_interface.get());
2217 :
2218 : // ********************************************************* Step 7d: Setup other Dash services
2219 :
2220 : node.peerman->AddExtraHandler(std::make_unique<NetInstantSend>(node.peerman.get(), *node.llmq_ctx->isman, node.active_ctx ? node.active_ctx->is_signer.get() : nullptr, *node.llmq_ctx->sigman, *node.llmq_ctx->qman, *node.chainlocks, chainman.ActiveChainstate(), *node.mempool, *node.mn_sync));
2221 : node.peerman->AddExtraHandler(std::make_unique<llmq::NetSigning>(node.peerman.get(), *node.llmq_ctx->sigman, node.active_ctx ? node.active_ctx->shareman.get() : nullptr, *node.sporkman));
2222 :
2223 : {
2224 : llmq::QuorumRole* quorum_role = node.active_ctx ? static_cast<llmq::QuorumRole*>(node.active_ctx.get())
2225 : : static_cast<llmq::QuorumRole*>(node.observer_ctx.get());
2226 : auto net_quorum = std::make_unique<llmq::NetQuorum>(
2227 : node.peerman.get(), *node.llmq_ctx->bls_worker, *node.connman, *node.dmnman,
2228 : *node.llmq_ctx->qman, *node.llmq_ctx->qsnapman, chainman,
2229 : *node.mn_sync, *node.sporkman, quorum_role,
2230 : node.active_ctx ? node.active_ctx->nodeman.get() : nullptr,
2231 : llmq::DEFAULT_WORKER_COUNT, sync_map, quorums_recovery);
2232 : node.peerman->AddExtraHandler(std::move(net_quorum));
2233 : }
2234 :
2235 : if (node.active_ctx) {
2236 : node.peerman->AddExtraHandler(std::make_unique<llmq::NetDKG>(
2237 : node.peerman.get(), *node.sporkman, *node.active_ctx->qdkgsman, chainman, quorums_watch,
2238 : *node.llmq_ctx->qman, *node.active_ctx,
2239 : *node.llmq_ctx->bls_worker, *node.dmnman, *node.mn_metaman,
2240 : *node.active_ctx->dkgdbgman, *node.llmq_ctx->quorum_block_processor, *node.llmq_ctx->qsnapman,
2241 : *node.active_ctx->nodeman, *node.connman));
2242 : } else if (node.observer_ctx) {
2243 : node.peerman->AddExtraHandler(std::make_unique<llmq::NetDKG>(
2244 : node.peerman.get(), *node.sporkman, *node.observer_ctx->qdkgsman, chainman,
2245 : *node.llmq_ctx->qman, *node.observer_ctx));
2246 : } else {
2247 : node.peerman->AddExtraHandler(std::make_unique<llmq::NetDKGStub>(node.peerman.get()));
2248 : }
2249 :
2250 : if (node.active_ctx) {
2251 : auto cj_server = std::make_unique<CCoinJoinServer>(node.peerman.get(), chainman, *node.connman, *node.dmnman, *node.dstxman, *node.mn_metaman,
2252 : *node.mempool, *node.active_ctx->nodeman, *node.mn_sync, *node.llmq_ctx->isman);
2253 : node.active_ctx->SetCJServer(cj_server.get());
2254 : node.peerman->AddExtraHandler(std::move(cj_server));
2255 : } else {
2256 : assert(!node.cj_walletman);
2257 : // Can return nullptr if built without wallet support, must check before use
2258 : node.cj_walletman = CJWalletManager::make(chainman, *node.dmnman, *node.mn_metaman, *node.mempool, *node.mn_sync,
2259 : *node.llmq_ctx->isman, !ignores_incoming_txs);
2260 : }
2261 :
2262 : if (node.cj_walletman) {
2263 : RegisterValidationInterface(node.cj_walletman.get());
2264 : }
2265 :
2266 : bool fLoadCacheFiles = !(fReindex || fReindexChainState) && (chainman.ActiveChain().Tip() != nullptr);
2267 :
2268 : if (!node.netfulfilledman->LoadCache(fLoadCacheFiles)) {
2269 : auto file_path = fs::PathToString(gArgs.GetDataDirNet() / "netfulfilled.dat");
2270 : if (fLoadCacheFiles) {
2271 : return InitError(strprintf(_("Failed to load fulfilled requests cache from %s"), file_path));
2272 : }
2273 : return InitError(strprintf(_("Failed to clear fulfilled requests cache at %s"), file_path));
2274 : }
2275 :
2276 : if (!node.mn_metaman->LoadCache(fLoadCacheFiles)) {
2277 : auto file_path = fs::PathToString(gArgs.GetDataDirNet() / "mncache.dat");
2278 : if (fLoadCacheFiles) {
2279 : return InitError(strprintf(_("Failed to load masternode cache from %s"), file_path));
2280 : }
2281 : return InitError(strprintf(_("Failed to clear masternode cache at %s"), file_path));
2282 : }
2283 :
2284 : if (is_governance_enabled) {
2285 : if (!node.govman->LoadCache(fLoadCacheFiles)) {
2286 : auto file_path = fs::PathToString(gArgs.GetDataDirNet() / "governance.dat");
2287 : if (fLoadCacheFiles) {
2288 : return InitError(strprintf(_("Failed to load governance cache from %s"), file_path));
2289 : }
2290 : return InitError(strprintf(_("Failed to clear governance cache at %s"), file_path));
2291 : }
2292 : }
2293 : // Always register NetGovernance so it can suppress governance inv items in AlreadyHave()
2294 : // even when -disablegovernance is set. The handler's ProcessMessage/Schedule paths
2295 : // early-return on !IsValid(), and AlreadyHave() short-circuits to true so we don't grow
2296 : // m_requested_hash_time without a cleanup task.
2297 : node.peerman->AddExtraHandler(std::make_unique<NetGovernance>(node.peerman.get(), *node.govman, *node.mn_sync, *node.netfulfilledman, *node.connman));
2298 : node.peerman->AddExtraHandler(std::make_unique<SyncManager>(node.peerman.get(), *node.govman, *node.mn_sync, *node.connman, *node.netfulfilledman));
2299 :
2300 : // ********************************************************* Step 8: start indexers
2301 : if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
2302 : g_txindex = std::make_unique<TxIndex>(cache_sizes.tx_index, false, fReindex);
2303 : if (!g_txindex->Start(chainman.ActiveChainstate())) {
2304 : return false;
2305 : }
2306 : }
2307 :
2308 : if (args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX)) {
2309 : g_addressindex = std::make_unique<AddressIndex>(cache_sizes.address_index, false, fReindex);
2310 : if (!g_addressindex->Start(chainman.ActiveChainstate())) {
2311 : return false;
2312 : }
2313 : }
2314 :
2315 : if (args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX)) {
2316 : g_timestampindex = std::make_unique<TimestampIndex>(cache_sizes.timestamp_index, false, fReindex);
2317 : if (!g_timestampindex->Start(chainman.ActiveChainstate())) {
2318 : return false;
2319 : }
2320 : }
2321 :
2322 : if (args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX)) {
2323 : g_spentindex = std::make_unique<SpentIndex>(cache_sizes.spent_index, false, fReindex);
2324 : if (!g_spentindex->Start(chainman.ActiveChainstate())) {
2325 : return false;
2326 : }
2327 : }
2328 :
2329 : for (const auto& filter_type : g_enabled_filter_types) {
2330 : InitBlockFilterIndex(filter_type, cache_sizes.filter_index, false, fReindex);
2331 : if (!GetBlockFilterIndex(filter_type)->Start(chainman.ActiveChainstate())) {
2332 : return false;
2333 : }
2334 : }
2335 :
2336 : if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
2337 : g_coin_stats_index = std::make_unique<CoinStatsIndex>(/* cache size */ 0, false, fReindex);
2338 : if (!g_coin_stats_index->Start(chainman.ActiveChainstate())) {
2339 : return false;
2340 : }
2341 : }
2342 :
2343 : // ********************************************************* Step 9: load wallet
2344 : for (const auto& client : node.chain_clients) {
2345 : if (!client->load()) {
2346 : return false;
2347 : }
2348 : }
2349 :
2350 : // As InitLoadWallet can take several minutes, it's possible the user
2351 : // requested to kill the GUI during the last operation. If so, exit.
2352 : if (ShutdownRequested())
2353 : {
2354 : LogPrintf("Shutdown requested. Exiting.\n");
2355 : return false;
2356 : }
2357 : // ********************************************************* Step 10: data directory maintenance
2358 :
2359 : // if pruning, perform the initial blockstore prune
2360 : // after any wallet rescanning has taken place.
2361 : if (fPruneMode) {
2362 : if (!fReindex) {
2363 : LOCK(cs_main);
2364 : for (CChainState* chainstate : chainman.GetAll()) {
2365 : uiInterface.InitMessage(_("Pruning blockstoreā¦").translated);
2366 : chainstate->PruneAndFlush();
2367 : }
2368 : }
2369 : } else {
2370 : LogPrintf("Setting NODE_NETWORK on non-prune mode\n");
2371 : nLocalServices = ServiceFlags(nLocalServices | NODE_NETWORK);
2372 : }
2373 :
2374 : // As PruneAndFlush can take several minutes, it's possible the user
2375 : // requested to kill the GUI during the last operation. If so, exit.
2376 : if (ShutdownRequested())
2377 : {
2378 : LogPrintf("Shutdown requested. Exiting.\n");
2379 : return false;
2380 : }
2381 :
2382 : // ********************************************************* Step 10a: schedule Dash-specific tasks
2383 :
2384 : node.peerman->StartHandlers();
2385 : node.clhandler->Start();
2386 :
2387 : node.scheduler->scheduleEvery(std::bind(&CNetFulfilledRequestManager::DoMaintenance, std::ref(*node.netfulfilledman)), std::chrono::minutes{1});
2388 : node.scheduler->scheduleEvery(std::bind(&CMasternodeUtils::DoMaintenance, std::ref(*node.connman), std::ref(*node.dmnman), std::ref(*node.mn_sync), node.cj_walletman.get()), std::chrono::minutes{1});
2389 : node.scheduler->scheduleEvery(std::bind(&CDeterministicMNManager::DoMaintenance, std::ref(*node.dmnman)), std::chrono::seconds{10});
2390 : node.peerman->ScheduleHandlers(*node.scheduler);
2391 :
2392 : if (node.active_ctx) {
2393 : node.active_ctx->Start();
2394 : node.scheduler->scheduleEvery(std::bind(&llmq::CDKGSessionManager::CleanupOldContributions, std::ref(*node.active_ctx->qdkgsman)), std::chrono::hours{1});
2395 : }
2396 :
2397 : if (node.cj_walletman) {
2398 : node.cj_walletman->Schedule(*node.connman, *node.scheduler);
2399 : }
2400 :
2401 : if (::g_stats_client->active()) {
2402 : int nStatsPeriod = std::min(std::max((int)args.GetIntArg("-statsperiod", DEFAULT_STATSD_PERIOD), MIN_STATSD_PERIOD), MAX_STATSD_PERIOD);
2403 : node.scheduler->scheduleEvery(std::bind(&PeriodicStats, std::ref(node)), std::chrono::seconds{nStatsPeriod});
2404 : }
2405 :
2406 : // ********************************************************* Step 11: import blocks
2407 :
2408 : if (!CheckDiskSpace(gArgs.GetDataDirNet())) {
2409 : InitError(strprintf(_("Error: Disk space is low for %s"), fs::quoted(fs::PathToString(gArgs.GetDataDirNet()))));
2410 : return false;
2411 : }
2412 : if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) {
2413 : InitError(strprintf(_("Error: Disk space is low for %s"), fs::quoted(fs::PathToString(gArgs.GetBlocksDirPath()))));
2414 : return false;
2415 : }
2416 :
2417 0 : int chain_active_height = WITH_LOCK(cs_main, return chainman.ActiveChain().Height());
2418 :
2419 : // On first startup, warn on low block storage space
2420 : if (!fReindex && !fReindexChainState && chain_active_height <= 1) {
2421 : uint64_t additional_bytes_needed = fPruneMode ? nPruneTarget
2422 : : chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024;
2423 :
2424 : if (!CheckDiskSpace(args.GetBlocksDirPath(), additional_bytes_needed)) {
2425 : InitWarning(strprintf(_(
2426 : "Disk space for %s may not accommodate the block files. " \
2427 : "Approximately %u GB of data will be stored in this directory."
2428 : ),
2429 : fs::quoted(fs::PathToString(args.GetBlocksDirPath())),
2430 : chainparams.AssumedBlockchainSize()
2431 : ));
2432 : }
2433 : }
2434 :
2435 : // Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
2436 : // No locking, as this happens before any background thread is started.
2437 : boost::signals2::connection block_notify_genesis_wait_connection;
2438 : if (chainman.ActiveChain().Tip() == nullptr) {
2439 : block_notify_genesis_wait_connection = uiInterface.NotifyBlockTip_connect(std::bind(BlockNotifyGenesisWait, std::placeholders::_2));
2440 : } else {
2441 : fHaveGenesis = true;
2442 : }
2443 :
2444 : #if HAVE_SYSTEM
2445 : const std::string block_notify = args.GetArg("-blocknotify", "");
2446 : if (!block_notify.empty()) {
2447 0 : uiInterface.NotifyBlockTip_connect([block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
2448 0 : if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) return;
2449 0 : std::string command = block_notify;
2450 0 : ReplaceAll(command, "%s", pBlockIndex->GetBlockHash().GetHex());
2451 0 : std::thread t(runCommand, command);
2452 0 : t.detach(); // thread runs free
2453 0 : });
2454 : }
2455 : const std::string chainlock_notify = args.GetArg("-chainlocknotify", "");
2456 : if (!chainlock_notify.empty()) {
2457 0 : uiInterface.NotifyChainLock_connect([chainlock_notify](const std::string& bestChainLockHash, int bestChainLockHeight) {
2458 0 : std::string command = chainlock_notify;
2459 0 : ReplaceAll(command, "%s", bestChainLockHash);
2460 0 : std::thread t(runCommand, command);
2461 0 : t.detach(); // thread runs free
2462 0 : });
2463 : }
2464 : #endif
2465 :
2466 : std::vector<fs::path> vImportFiles;
2467 : for (const std::string& strFile : args.GetArgs("-loadblock")) {
2468 : vImportFiles.push_back(fs::PathFromString(strFile));
2469 : }
2470 :
2471 0 : chainman.m_load_block = std::thread(&util::TraceThread, "loadblk", [=, &args, &chainman, &node] {
2472 : // ThreadImport can switch fReindex from true to false, fetch its original state here to use later
2473 0 : bool skip_evodb_repair_on_reindex = fReindex || fReindexChainState;
2474 0 : ThreadImport(chainman, vImportFiles, args);
2475 :
2476 : {
2477 0 : const CBlockIndex* tip = WITH_LOCK(::cs_main, return chainman.ActiveTip());
2478 0 : const bool ibd = chainman.ActiveChainstate().IsInitialBlockDownload();
2479 0 : if (node.active_ctx) {
2480 : // On masternodes, defer the full broadcast until after
2481 : // nodeman->Init() so that GetProTxHash() is available
2482 : // for quorum connection setup and skShare derivation.
2483 : // Only kick CDSNotificationInterface here (cached block
2484 : // height for DS/MN payments/budgets).
2485 0 : g_ds_notification_interface->InitializeCurrentBlockTip(tip, ibd);
2486 0 : } else {
2487 : // Non-masternode nodes (including observer-only): broadcast
2488 : // to all subscribers now; no proTxHash dependency.
2489 0 : GetMainSignals().InitializeCurrentBlockTip(tip, ibd);
2490 : }
2491 : }
2492 :
2493 : // Seed InstantSend tip-height cache; NetInstantSend receives future
2494 : // updates via CValidationInterface but misses InitializeCurrentBlockTip.
2495 : // TODO: move cache updates from NetInstantSend to g_ds_notification due to specific of Tip's processing
2496 0 : node.llmq_ctx->isman->CacheTipHeight(chainman.ActiveChain().Tip());
2497 :
2498 : {
2499 : // Get all UTXOs for each MN collateral in one go so that we can fill coin cache early
2500 : // and reduce further locking overhead for cs_main in other parts of code including GUI
2501 0 : LogPrintf("Filling coin cache with masternode UTXOs...\n");
2502 0 : LOCK(cs_main);
2503 0 : const auto start{SteadyClock::now()};
2504 0 : const auto mnList{node.dmnman->GetListAtChainTip()};
2505 0 : mnList.ForEachMN(/*onlyValid=*/false, [&](const auto& dmn) {
2506 0 : Coin coin;
2507 0 : GetUTXOCoin(chainman.ActiveChainstate(), dmn.collateralOutpoint, coin);
2508 0 : });
2509 0 : LogPrintf("Filling coin cache with masternode UTXOs: done in %dms\n", Ticks<std::chrono::milliseconds>(SteadyClock::now() - start));
2510 0 : }
2511 :
2512 0 : if (skip_evodb_repair_on_reindex) {
2513 0 : LogPrintf("Skipping evodb repair during reindex\n");
2514 0 : node.dmnman->CompleteRepair(); // Mark as repaired since we're rebuilding fresh
2515 0 : } else if (node.dmnman->IsRepaired() && !args.GetBoolArg("-forceevodbrepair", false)) {
2516 0 : LogPrintf("Masternode list diffs are already repaired\n");
2517 0 : } else {
2518 : const CBlockIndex* start_index;
2519 : const CBlockIndex* stop_index;
2520 : {
2521 0 : LOCK(cs_main);
2522 0 : const auto& consensus_params = Params().GetConsensus();
2523 0 : start_index = chainman.ActiveChain()[consensus_params.DIP0003Height];
2524 0 : stop_index = chainman.ActiveChain().Tip();
2525 0 : }
2526 :
2527 0 : if (start_index && stop_index && start_index->nHeight < stop_index->nHeight) {
2528 0 : LogPrintf("Verifying and repairing masternode list diffs...\n");
2529 0 : const auto start{SteadyClock::now()};
2530 : // Create a callback that wraps CSpecialTxProcessor::BuildNewListFromBlock
2531 0 : auto build_list_func = [&node](const CBlock& block, const CBlockIndex* const pindexPrev,
2532 : const CDeterministicMNList& prevList, const CCoinsViewCache& view,
2533 : bool debugLogs, BlockValidationState& state,
2534 : CDeterministicMNList& mnListRet) -> bool {
2535 0 : return node.chain_helper->special_tx->RebuildListFromBlock(block, pindexPrev, prevList, view, debugLogs, state, mnListRet);
2536 : };
2537 0 : auto result = node.dmnman->RecalculateAndRepairDiffs(start_index, stop_index, chainman, build_list_func, true);
2538 :
2539 0 : if (!result.verification_errors.empty()) {
2540 0 : LogPrintf("WARNING: Verification errors:\n%s\n", Join(result.verification_errors, "\n"));
2541 0 : }
2542 :
2543 0 : if (!result.repair_errors.empty()) {
2544 : // Critical errors occurred - reindex required
2545 0 : LogPrintf("Failed to repair masternode list diffs. Database corruption detected. " /* Continued */
2546 : "Please restart with -reindex to rebuild the database.\n"
2547 : "Errors:\n%s\n",
2548 : Join(result.repair_errors, "\n"));
2549 0 : StartShutdown();
2550 0 : return;
2551 : }
2552 0 : node.dmnman->CompleteRepair();
2553 0 : LogPrintf("Successfully repaired %d masternode list diffs, verified %d snapshots in %ds\n",
2554 : result.diffs_recalculated, result.snapshots_verified,
2555 : Ticks<std::chrono::seconds>(SteadyClock::now() - start));
2556 0 : }
2557 : }
2558 :
2559 0 : if (node.active_ctx) {
2560 0 : node.active_ctx->nodeman->Init(chainman.ActiveTip());
2561 : // Now that nodeman->Init has set proTxHash, fan out the
2562 : // startup tip to all CValidationInterface subscribers.
2563 : // The earlier call only kicked CDSNotificationInterface
2564 : // directly because the full broadcast (NetQuorum,
2565 : // ActiveContext) depends on a valid proTxHash.
2566 0 : const CBlockIndex* tip = WITH_LOCK(::cs_main, return chainman.ActiveTip());
2567 0 : const bool ibd = chainman.ActiveChainstate().IsInitialBlockDownload();
2568 0 : GetMainSignals().InitializeCurrentBlockTip(tip, ibd);
2569 0 : }
2570 0 : });
2571 : #ifdef ENABLE_WALLET
2572 : if (!args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
2573 : g_wallet_init_interface.AutoLockMasternodeCollaterals(*node.wallet_loader);
2574 : }
2575 : #endif // ENABLE_WALLET
2576 :
2577 : // Wait for genesis block to be processed
2578 : {
2579 : WAIT_LOCK(g_genesis_wait_mutex, lock);
2580 : // We previously could hang here if StartShutdown() is called prior to
2581 : // ThreadImport getting started, so instead we just wait on a timer to
2582 : // check ShutdownRequested() regularly.
2583 : while (!fHaveGenesis && !ShutdownRequested()) {
2584 : g_genesis_wait_cv.wait_for(lock, std::chrono::milliseconds(500));
2585 : }
2586 : block_notify_genesis_wait_connection.disconnect();
2587 : }
2588 :
2589 : // As importing blocks can take several minutes, it's possible the user
2590 : // requested to kill the GUI during one of the last operations. If so, exit.
2591 : if (ShutdownRequested()) {
2592 : LogPrintf("Shutdown requested. Exiting.\n");
2593 : return false;
2594 : }
2595 :
2596 : // ********************************************************* Step 12: start node
2597 :
2598 : //// debug print
2599 : {
2600 : LOCK(cs_main);
2601 : LogPrintf("block tree size = %u\n", chainman.BlockIndex().size());
2602 : chain_active_height = chainman.ActiveChain().Height();
2603 : if (tip_info) {
2604 : tip_info->block_height = chain_active_height;
2605 : tip_info->block_time = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockTime() : Params().GenesisBlock().GetBlockTime();
2606 : tip_info->block_hash = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockHash() : Params().GenesisBlock().GetHash();
2607 : tip_info->verification_progress = GuessVerificationProgress(Params().TxData(), chainman.ActiveChain().Tip());
2608 : }
2609 : if (tip_info && chainman.m_best_header) {
2610 : tip_info->header_height = chainman.m_best_header->nHeight;
2611 : tip_info->header_time = chainman.m_best_header->GetBlockTime();
2612 : }
2613 : }
2614 : LogPrintf("nBestHeight = %d\n", chain_active_height);
2615 : if (node.peerman) node.peerman->SetBestHeight(chain_active_height);
2616 :
2617 : // Map ports with UPnP or NAT-PMP.
2618 : StartMapPort(args.GetBoolArg("-upnp", DEFAULT_UPNP), args.GetBoolArg("-natpmp", DEFAULT_NATPMP));
2619 :
2620 : CConnman::Options connOptions;
2621 : connOptions.nLocalServices = nLocalServices;
2622 : connOptions.nMaxConnections = nMaxConnections;
2623 : connOptions.m_max_outbound_full_relay = std::min(MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, connOptions.nMaxConnections);
2624 : connOptions.m_max_outbound_block_relay = std::min(MAX_BLOCK_RELAY_ONLY_CONNECTIONS, connOptions.nMaxConnections-connOptions.m_max_outbound_full_relay);
2625 : connOptions.m_max_outbound_onion = std::min(MAX_DESIRED_ONION_CONNECTIONS, connOptions.nMaxConnections / 2);
2626 : connOptions.nMaxAddnode = MAX_ADDNODE_CONNECTIONS;
2627 : connOptions.nMaxFeeler = MAX_FEELER_CONNECTIONS;
2628 : connOptions.uiInterface = &uiInterface;
2629 : connOptions.m_banman = node.banman.get();
2630 : connOptions.m_msgproc = node.peerman.get();
2631 : connOptions.nSendBufferMaxSize = 1000 * args.GetIntArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
2632 : connOptions.nReceiveFloodSize = 1000 * args.GetIntArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);
2633 : connOptions.m_added_nodes = args.GetArgs("-addnode");
2634 : connOptions.nMaxOutboundLimit = *opt_max_upload;
2635 : connOptions.m_peer_connect_timeout = peer_connect_timeout;
2636 : connOptions.socketEventsMode = ::g_socket_events_mode;
2637 : connOptions.m_active_masternode = node.active_ctx != nullptr;
2638 :
2639 : // Port to bind to if `-bind=addr` is provided without a `:port` suffix.
2640 : const uint16_t default_bind_port =
2641 : static_cast<uint16_t>(args.GetIntArg("-port", Params().GetDefaultPort()));
2642 :
2643 0 : const auto BadPortWarning = [](const char* prefix, uint16_t port) {
2644 0 : return strprintf(_("%s request to listen on port %u. This port is considered \"bad\" and "
2645 : "thus it is unlikely that any peer will connect to it. See "
2646 : "doc/p2p-bad-ports.md for details and a full list."),
2647 : prefix,
2648 : port);
2649 0 : };
2650 :
2651 : for (const std::string& bind_arg : args.GetArgs("-bind")) {
2652 : std::optional<CService> bind_addr;
2653 : const size_t index = bind_arg.rfind('=');
2654 : if (index == std::string::npos) {
2655 : bind_addr = Lookup(bind_arg, default_bind_port, /*fAllowLookup=*/false);
2656 : if (bind_addr.has_value()) {
2657 : connOptions.vBinds.push_back(bind_addr.value());
2658 : if (IsBadPort(bind_addr.value().GetPort())) {
2659 : InitWarning(BadPortWarning("-bind", bind_addr.value().GetPort()));
2660 : }
2661 : continue;
2662 : }
2663 : } else {
2664 : const std::string network_type = bind_arg.substr(index + 1);
2665 : if (network_type == "onion") {
2666 : const std::string truncated_bind_arg = bind_arg.substr(0, index);
2667 : bind_addr = Lookup(truncated_bind_arg, BaseParams().OnionServiceTargetPort(), false);
2668 : if (bind_addr.has_value()) {
2669 : connOptions.onion_binds.push_back(bind_addr.value());
2670 : continue;
2671 : }
2672 : }
2673 : }
2674 : return InitError(ResolveErrMsg("bind", bind_arg));
2675 : }
2676 :
2677 : for (const std::string& strBind : args.GetArgs("-whitebind")) {
2678 : NetWhitebindPermissions whitebind;
2679 : bilingual_str error;
2680 : if (!NetWhitebindPermissions::TryParse(strBind, whitebind, error)) return InitError(error);
2681 : connOptions.vWhiteBinds.push_back(whitebind);
2682 : }
2683 :
2684 : // If the user did not specify -bind= or -whitebind= then we bind
2685 : // on any address - 0.0.0.0 (IPv4) and :: (IPv6).
2686 : connOptions.bind_on_any = args.GetArgs("-bind").empty() && args.GetArgs("-whitebind").empty();
2687 :
2688 : // Emit a warning if a bad port is given to -port= but only if -bind and -whitebind are not
2689 : // given, because if they are, then -port= is ignored.
2690 : if (connOptions.bind_on_any && args.IsArgSet("-port")) {
2691 : const uint16_t port_arg = args.GetIntArg("-port", 0);
2692 : if (IsBadPort(port_arg)) {
2693 : InitWarning(BadPortWarning("-port", port_arg));
2694 : }
2695 : }
2696 :
2697 : CService onion_service_target;
2698 : if (!connOptions.onion_binds.empty()) {
2699 : onion_service_target = connOptions.onion_binds.front();
2700 : } else {
2701 : onion_service_target = DefaultOnionServiceTarget();
2702 : connOptions.onion_binds.push_back(onion_service_target);
2703 : }
2704 :
2705 : if (args.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION)) {
2706 : if (connOptions.onion_binds.size() > 1) {
2707 : InitWarning(strprintf(_("More than one onion bind address is provided. Using %s "
2708 : "for the automatically created Tor onion service."),
2709 : onion_service_target.ToStringAddrPort()));
2710 : }
2711 : StartTorControl(onion_service_target);
2712 : }
2713 :
2714 : if (connOptions.bind_on_any) {
2715 : // Only add all IP addresses of the machine if we would be listening on
2716 : // any address - 0.0.0.0 (IPv4) and :: (IPv6).
2717 : Discover();
2718 : }
2719 :
2720 : for (const auto& net : args.GetArgs("-whitelist")) {
2721 : NetWhitelistPermissions subnet;
2722 : bilingual_str error;
2723 : if (!NetWhitelistPermissions::TryParse(net, subnet, error)) return InitError(error);
2724 : connOptions.vWhitelistedRange.push_back(subnet);
2725 : }
2726 :
2727 : connOptions.vSeedNodes = args.GetArgs("-seednode");
2728 :
2729 : // Initiate outbound connections unless connect=0
2730 : connOptions.m_use_addrman_outgoing = !args.IsArgSet("-connect");
2731 : if (!connOptions.m_use_addrman_outgoing) {
2732 : const auto connect = args.GetArgs("-connect");
2733 : if (connect.size() != 1 || connect[0] != "0") {
2734 : connOptions.m_specified_outgoing = connect;
2735 : }
2736 : if (!connOptions.m_specified_outgoing.empty() && !connOptions.vSeedNodes.empty()) {
2737 : LogPrintf("-seednode is ignored when -connect is used\n");
2738 : }
2739 :
2740 : if (args.IsArgSet("-dnsseed") && args.GetBoolArg("-dnsseed", DEFAULT_DNSSEED) && args.IsArgSet("-proxy")) {
2741 : LogPrintf("-dnsseed is ignored when -connect is used and -proxy is specified\n");
2742 : }
2743 : }
2744 :
2745 : const std::string& i2psam_arg = args.GetArg("-i2psam", "");
2746 : if (!i2psam_arg.empty()) {
2747 : const std::optional<CService> addr{Lookup(i2psam_arg, 7656, fNameLookup)};
2748 : if (!addr.has_value() || !addr->IsValid()) {
2749 : return InitError(strprintf(_("Invalid -i2psam address or hostname: '%s'"), i2psam_arg));
2750 : }
2751 : SetProxy(NET_I2P, Proxy{addr.value()});
2752 : } else {
2753 : if (args.IsArgSet("-onlynet") && g_reachable_nets.Contains(NET_I2P)) {
2754 : return InitError(
2755 : _("Outbound connections restricted to i2p (-onlynet=i2p) but "
2756 : "-i2psam is not provided"));
2757 : }
2758 : g_reachable_nets.Remove(NET_I2P);
2759 : }
2760 :
2761 : connOptions.m_i2p_accept_incoming = args.GetBoolArg("-i2pacceptincoming", DEFAULT_I2P_ACCEPT_INCOMING);
2762 :
2763 : if (!node.connman->Start(*node.dmnman, *node.mn_metaman, *node.mn_sync, *node.scheduler, connOptions)) {
2764 : return false;
2765 : }
2766 :
2767 : // ********************************************************* Step 13: finished
2768 :
2769 : // At this point, the RPC is "started", but still in warmup, which means it
2770 : // cannot yet be called. Before we make it callable, we need to make sure
2771 : // that the RPC's view of the best block is valid and consistent with
2772 : // ChainstateManager's ActiveTip.
2773 : //
2774 : // If we do not do this, RPC's view of the best block will be height=0 and
2775 : // hash=0x0. This will lead to erroroneous responses for things like
2776 : // waitforblockheight.
2777 : RPCNotifyBlockChange(chainman.ActiveTip());
2778 : SetRPCWarmupFinished();
2779 :
2780 : uiInterface.InitMessage(_("Done loading").translated);
2781 :
2782 : for (const auto& client : node.chain_clients) {
2783 : client->start(*node.scheduler);
2784 : }
2785 :
2786 : BanMan* banman = node.banman.get();
2787 0 : node.scheduler->scheduleEvery([banman]{
2788 0 : banman->DumpBanlist();
2789 0 : }, DUMP_BANS_INTERVAL);
2790 :
2791 : if (node.peerman) node.peerman->StartScheduledTasks(*node.scheduler);
2792 :
2793 : #if HAVE_SYSTEM
2794 : StartupNotify(args);
2795 : #endif
2796 :
2797 : return true;
2798 0 : }
|