2011-05-14 20:10:21 +02:00
// Copyright (c) 2009-2010 Satoshi Nakamoto
2022-12-24 23:49:50 +00:00
// Copyright (c) 2009-2022 The Bitcoin Core developers
2014-12-01 09:39:44 +08:00
// Distributed under the MIT software license, see the accompanying
2012-05-18 22:02:28 +08:00
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2012-11-05 08:04:21 +01:00
2013-05-27 19:55:01 -04:00
# if defined(HAVE_CONFIG_H)
2017-11-10 13:57:53 +13:00
# include <config/bitcoin-config.h>
2013-05-27 19:55:01 -04:00
# endif
2017-11-10 13:57:53 +13:00
# include <init.h>
2013-04-13 00:13:08 -05:00
2022-05-27 16:47:05 -04:00
# include <kernel/checks.h>
2022-07-12 22:24:31 -04:00
# include <kernel/mempool_persist.h>
2022-06-30 23:47:41 -04:00
# include <kernel/validation_cache_sizes.h>
2022-05-27 16:47:05 -04:00
2017-11-10 13:57:53 +13:00
# include <addrman.h>
2017-10-05 16:40:43 -04:00
# include <banman.h>
2018-08-29 22:15:50 -07:00
# include <blockfilter.h>
2017-11-10 13:57:53 +13:00
# include <chain.h>
# include <chainparams.h>
2023-04-18 13:40:47 +02:00
# include <chainparamsbase.h>
2023-03-23 12:23:29 +01:00
# include <common/args.h>
2023-05-08 11:32:13 +02:00
# include <common/system.h>
2021-09-11 10:29:00 +08:00
# include <consensus/amount.h>
2020-06-16 18:58:56 +10:00
# include <deploymentstatus.h>
2020-06-05 21:55:17 +03:00
# include <hash.h>
2017-11-10 13:57:53 +13:00
# include <httprpc.h>
2019-06-17 10:56:52 +03:00
# include <httpserver.h>
2018-08-29 22:15:50 -07:00
# include <index/blockfilterindex.h>
2020-01-24 18:58:47 +01:00
# include <index/coinstatsindex.h>
2017-12-08 11:29:59 -08:00
# include <index/txindex.h>
2021-04-18 18:56:12 -04:00
# include <init/common.h>
2019-06-17 10:56:52 +03:00
# include <interfaces/chain.h>
2017-12-05 15:57:12 -05:00
# include <interfaces/init.h>
2020-05-19 15:13:50 +02:00
# include <interfaces/node.h>
2020-02-06 19:00:26 +02:00
# include <mapport.h>
2017-11-10 13:57:53 +13:00
# include <net.h>
2019-06-20 18:37:51 +09:00
# include <net_permissions.h>
2017-11-10 13:57:53 +13:00
# include <net_processing.h>
2019-06-17 10:56:52 +03:00
# include <netbase.h>
2021-08-31 13:32:40 +01:00
# include <netgroup.h>
2023-01-03 13:12:45 +01:00
# include <node/blockmanager_args.h>
2021-04-02 19:17:00 +02:00
# include <node/blockstorage.h>
2021-11-11 14:40:50 -05:00
# include <node/caches.h>
# include <node/chainstate.h>
2022-07-20 18:16:30 +02:00
# include <node/chainstatemanager_args.h>
2019-09-17 18:28:03 -04:00
# include <node/context.h>
2022-06-14 10:38:51 +02:00
# include <node/interface_ui.h>
2023-05-10 22:29:17 +02:00
# include <node/kernel_notifications.h>
2022-08-02 15:21:47 +02:00
# include <node/mempool_args.h>
2022-07-12 15:54:11 -04:00
# include <node/mempool_persist_args.h>
2021-12-08 16:19:31 -05:00
# include <node/miner.h>
2022-09-19 17:31:01 +03:00
# include <node/txreconciliation.h>
2022-06-30 23:47:41 -04:00
# include <node/validation_cache_args.h>
2017-11-10 13:57:53 +13:00
# include <policy/feerate.h>
# include <policy/fees.h>
2021-12-08 16:19:31 -05:00
# include <policy/fees_args.h>
2017-11-10 13:57:53 +13:00
# include <policy/policy.h>
2019-04-02 14:14:58 -04:00
# include <policy/settings.h>
2020-09-30 19:08:52 +02:00
# include <protocol.h>
2017-11-10 13:57:53 +13:00
# include <rpc/blockchain.h>
2019-06-17 10:56:52 +03:00
# include <rpc/register.h>
# include <rpc/server.h>
2017-05-30 15:55:17 -04:00
# include <rpc/util.h>
2017-11-10 13:57:53 +13:00
# include <scheduler.h>
2019-06-17 10:56:52 +03:00
# include <script/sigcache.h>
# include <script/standard.h>
2018-05-16 19:17:40 +00:00
# include <shutdown.h>
2020-06-05 21:55:17 +03:00
# include <sync.h>
2017-11-10 13:57:53 +13:00
# include <timedata.h>
2019-06-17 10:56:52 +03:00
# include <torcontrol.h>
2017-11-10 13:57:53 +13:00
# include <txdb.h>
# include <txmempool.h>
2019-12-29 18:54:33 +01:00
# include <util/asmap.h>
2023-04-17 22:20:59 +02:00
# include <util/chaintype.h>
2020-06-14 14:17:24 -04:00
# include <util/check.h>
2023-03-15 11:18:06 +01:00
# include <util/fs.h>
2023-03-06 23:41:46 +01:00
# include <util/fs_helpers.h>
2018-10-22 15:51:11 -07:00
# include <util/moneystr.h>
2023-05-12 00:23:21 +02:00
# include <util/result.h>
2021-11-17 12:47:30 +02:00
# include <util/strencodings.h>
2020-06-06 13:28:47 -04:00
# include <util/string.h>
2022-04-20 16:17:19 +02:00
# include <util/syserror.h>
2021-04-13 20:44:46 +03:00
# include <util/thread.h>
2019-06-17 10:56:52 +03:00
# include <util/threadnames.h>
2023-06-14 22:39:26 +01:00
# include <util/time.h>
2019-06-17 10:56:52 +03:00
# include <util/translation.h>
# include <validation.h>
2017-11-10 13:57:53 +13:00
# include <validationinterface.h>
2018-02-21 11:38:53 -05:00
# include <walletinitinterface.h>
2019-06-17 10:56:52 +03:00
2022-02-22 14:30:31 -05:00
# include <algorithm>
2020-06-11 08:58:46 +02:00
# include <condition_variable>
# include <cstdint>
# include <cstdio>
# include <fstream>
2020-03-04 19:41:18 +02:00
# include <functional>
# include <set>
2020-06-11 08:58:46 +02:00
# include <string>
2021-01-27 15:04:34 +08:00
# include <thread>
# include <vector>
2011-05-14 20:10:21 +02:00
2012-04-15 22:10:54 +02:00
# ifndef WIN32
2019-02-02 00:40:36 +02:00
# include <cerrno>
2012-04-15 22:10:54 +02:00
# include <signal.h>
2018-07-25 17:33:22 +08:00
# include <sys/stat.h>
2012-03-18 23:14:03 +01:00
# endif
2011-10-07 10:46:56 -04:00
2019-11-11 10:53:03 -05:00
# include <boost/signals2/signal.hpp>
2013-04-13 00:13:08 -05:00
2014-11-18 12:06:32 -05:00
# if ENABLE_ZMQ
2018-08-24 20:42:03 -04:00
# include <zmq/zmqabstractnotifier.h>
2017-11-10 13:57:53 +13:00
# include <zmq/zmqnotificationinterface.h>
2018-06-29 16:10:01 +02:00
# include <zmq/zmqrpc.h>
2014-11-18 12:06:32 -05:00
# endif
2023-02-19 10:20:34 +01:00
using kernel : : DEFAULT_STOPAFTERBLOCKIMPORT ;
2022-07-12 22:24:31 -04:00
using kernel : : DumpMempool ;
2022-06-30 23:47:41 -04:00
using kernel : : ValidationCacheSizes ;
2022-07-12 22:24:31 -04:00
2022-06-30 23:47:41 -04:00
using node : : ApplyArgsManOptions ;
2023-02-18 18:17:33 +01:00
using node : : BlockManager ;
2021-11-12 10:06:00 -05:00
using node : : CacheSizes ;
using node : : CalculateCacheSizes ;
2022-07-13 13:42:15 -04:00
using node : : DEFAULT_PERSIST_MEMPOOL ;
2021-11-12 10:06:00 -05:00
using node : : DEFAULT_PRINTPRIORITY ;
2023-02-18 18:17:33 +01:00
using node : : fReindex ;
2022-05-23 21:07:29 +02:00
using node : : g_indexes_ready_to_sync ;
2023-05-10 22:29:17 +02:00
using node : : KernelNotifications ;
2021-11-12 10:06:00 -05:00
using node : : LoadChainstate ;
2022-07-12 15:54:11 -04:00
using node : : MempoolPath ;
2021-11-12 10:06:00 -05:00
using node : : NodeContext ;
2023-02-18 18:17:33 +01:00
using node : : ShouldPersistMempool ;
2023-06-17 11:11:51 -03:00
using node : : ImportBlocks ;
2021-11-12 10:06:00 -05:00
using node : : VerifyLoadedChainstate ;
2023-01-09 07:25:04 -08:00
static constexpr bool DEFAULT_PROXYRANDOMIZE { true } ;
static constexpr bool DEFAULT_REST_ENABLE { false } ;
static constexpr bool DEFAULT_I2P_ACCEPT_INCOMING { true } ;
2011-06-26 19:23:24 +02:00
2013-04-26 00:46:47 +02:00
# ifdef WIN32
// Win32 LevelDB doesn't use filedescriptors, and the ones used for
2015-04-28 14:48:28 +00:00
// accessing block files don't count towards the fd_set size limit
2013-04-26 00:46:47 +02:00
// anyway.
# define MIN_CORE_FILEDESCRIPTORS 0
# else
# define MIN_CORE_FILEDESCRIPTORS 150
# endif
2019-12-24 13:18:44 -05:00
static const char * DEFAULT_ASMAP_FILENAME = " ip_asn.map " ;
2019-02-14 22:53:03 +02:00
/**
* The PID file facilities .
*/
static const char * BITCOIN_PID_FILENAME = " bitcoind.pid " ;
2020-08-21 20:13:40 +02:00
static fs : : path GetPidFile ( const ArgsManager & args )
2019-02-14 22:53:03 +02:00
{
2023-02-27 14:21:13 -05:00
return AbsPathForConfigVal ( args , args . GetPathArg ( " -pid " , BITCOIN_PID_FILENAME ) ) ;
2019-02-14 22:53:03 +02:00
}
2020-11-26 09:05:59 +00:00
[[nodiscard]] static bool CreatePidFile ( const ArgsManager & args )
2019-02-14 22:53:03 +02:00
{
2020-06-11 08:58:46 +02:00
std : : ofstream file { GetPidFile ( args ) } ;
2019-02-14 22:53:03 +02:00
if ( file ) {
2019-02-25 16:00:34 +07:00
# ifdef WIN32
2019-06-13 09:43:24 -04:00
tfm : : format ( file , " %d \n " , GetCurrentProcessId ( ) ) ;
2019-02-25 16:00:34 +07:00
# else
2019-06-13 09:43:24 -04:00
tfm : : format ( file , " %d \n " , getpid ( ) ) ;
2019-02-25 16:00:34 +07:00
# endif
2019-02-14 22:53:03 +02:00
return true ;
} else {
2022-04-20 16:17:19 +02:00
return InitError ( strprintf ( _ ( " Unable to create the PID file '%s': %s " ) , fs : : PathToString ( GetPidFile ( args ) ) , SysErrorString ( errno ) ) ) ;
2019-02-14 22:53:03 +02:00
}
}
2011-05-14 20:10:21 +02:00
//////////////////////////////////////////////////////////////////////////////
//
// Shutdown
//
2013-03-09 12:02:57 -05:00
//
// Thread management and startup/shutdown:
//
// The network-processing threads are all part of a thread group
// created by AppInit() or the Qt main() function.
//
// A clean exit happens when StartShutdown() or the SIGTERM
2018-05-16 19:17:40 +00:00
// signal handler sets ShutdownRequested(), which makes main thread's
2017-06-29 01:24:41 +09:00
// WaitForShutdown() interrupts the thread group.
// And then, WaitForShutdown() makes all other on-going threads
// in the thread group join the main thread.
// Shutdown() is then called to clean up database connections, and stop other
2013-03-09 12:02:57 -05:00
// threads that should only be stopped after the main network-processing
// threads have exited.
//
// Shutdown for Qt is very similar, only it uses a QTimer to detect
2018-05-16 19:17:40 +00:00
// ShutdownRequested() getting set, and then does the normal Qt
2013-03-23 18:14:12 -04:00
// shutdown thing.
2013-03-09 12:02:57 -05:00
//
2021-10-30 22:22:40 +08:00
# if HAVE_SYSTEM
static void ShutdownNotify ( const ArgsManager & args )
{
std : : vector < std : : thread > threads ;
for ( const auto & cmd : args . GetArgs ( " -shutdownnotify " ) ) {
threads . emplace_back ( runCommand , cmd ) ;
}
for ( auto & t : threads ) {
t . join ( ) ;
}
}
# endif
2019-09-17 18:28:03 -04:00
void Interrupt ( NodeContext & node )
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
{
2021-10-30 22:22:40 +08:00
# if HAVE_SYSTEM
ShutdownNotify ( * node . args ) ;
# endif
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
InterruptHTTPServer ( ) ;
InterruptHTTPRPC ( ) ;
InterruptRPC ( ) ;
InterruptREST ( ) ;
2015-09-08 17:48:45 +02:00
InterruptTorControl ( ) ;
2018-02-07 17:20:16 -05:00
InterruptMapPort ( ) ;
2019-09-17 18:59:36 -04:00
if ( node . connman )
node . connman - > Interrupt ( ) ;
2017-12-08 11:29:59 -08:00
if ( g_txindex ) {
g_txindex - > Interrupt ( ) ;
}
2018-08-29 22:15:50 -07:00
ForEachBlockFilterIndex ( [ ] ( BlockFilterIndex & index ) { index . Interrupt ( ) ; } ) ;
2020-01-24 18:58:47 +01:00
if ( g_coin_stats_index ) {
g_coin_stats_index - > Interrupt ( ) ;
}
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
}
2019-09-17 17:04:39 -04:00
void Shutdown ( NodeContext & node )
2011-05-14 20:10:21 +02:00
{
2020-06-05 21:55:17 +03:00
static Mutex g_shutdown_mutex ;
TRY_LOCK ( g_shutdown_mutex , lock_shutdown ) ;
if ( ! lock_shutdown ) return ;
2014-06-27 14:41:11 +02:00
LogPrintf ( " %s: In progress... \n " , __func__ ) ;
2020-08-21 20:13:40 +02:00
Assert ( node . args ) ;
2012-06-24 17:03:57 +02:00
2017-02-23 16:38:41 +09:00
/// Note: Shutdown() must be able to handle cases in which initialization failed part of the way,
2014-09-18 14:08:43 +02:00
/// for example if the data directory was found to be locked.
/// Be sure that anything that writes files or flushes caches only does this if the respective
/// module was initialized.
2018-06-13 14:50:59 -04:00
util : : ThreadRename ( " shutoff " ) ;
2020-07-19 09:07:54 +02:00
if ( node . mempool ) node . mempool - > AddTransactionsUpdated ( 1 ) ;
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
StopHTTPRPC ( ) ;
StopREST ( ) ;
StopRPC ( ) ;
StopHTTPServer ( ) ;
2019-09-17 17:04:39 -04:00
for ( const auto & client : node . chain_clients ) {
2017-09-28 14:13:29 -04:00
client - > flush ( ) ;
}
2018-02-07 17:20:16 -05:00
StopMapPort ( ) ;
2017-09-07 14:26:20 -04:00
// Because these depend on each-other, we make sure that neither can be
// using the other before destroying them.
2020-08-29 10:31:11 +01:00
if ( node . peerman ) UnregisterValidationInterface ( node . peerman . get ( ) ) ;
2021-04-12 14:54:58 +03:00
if ( node . connman ) node . connman - > Stop ( ) ;
2016-04-16 14:47:18 -04:00
2015-08-25 20:12:08 +02:00
StopTorControl ( ) ;
2018-01-24 21:15:56 -05:00
// After everything has been shut down, but before things get flushed, stop the
2021-01-27 15:04:34 +08:00
// CScheduler/checkqueue, scheduler and load block thread.
2020-02-28 12:02:10 +10:00
if ( node . scheduler ) node . scheduler - > stop ( ) ;
2023-06-17 11:11:51 -03:00
if ( node . chainman & & node . chainman - > m_thread_load . joinable ( ) ) node . chainman - > m_thread_load . join ( ) ;
2020-08-21 09:24:05 +03:00
StopScriptCheckWorkerThreads ( ) ;
2018-01-24 21:15:56 -05:00
2018-08-06 12:08:35 -04:00
// After the threads that potentially access these pointers have been stopped,
// destruct and reset all to nullptr.
2020-08-29 10:31:11 +01:00
node . peerman . reset ( ) ;
2019-09-17 18:59:36 -04:00
node . connman . reset ( ) ;
node . banman . reset ( ) ;
2020-10-23 09:34:27 +01:00
node . addrman . reset ( ) ;
2021-08-31 13:32:40 +01:00
node . netgroupman . reset ( ) ;
2018-08-06 12:08:35 -04:00
2022-07-07 16:32:52 -04:00
if ( node . mempool & & node . mempool - > GetLoadTried ( ) & & ShouldPersistMempool ( * node . args ) ) {
2022-07-12 15:54:11 -04:00
DumpMempool ( * node . mempool , MempoolPath ( * node . args ) ) ;
2017-03-09 17:12:25 -05:00
}
2014-03-17 08:19:54 -04:00
2020-09-10 14:27:36 +02:00
// Drop transactions we were still watching, and record fee estimations.
if ( node . fee_estimator ) node . fee_estimator - > Flush ( ) ;
2014-03-17 08:19:54 -04:00
2018-05-02 10:02:48 -04:00
// FlushStateToDisk generates a ChainStateFlushed callback, which we should avoid missing
2020-04-18 08:05:52 -04:00
if ( node . chainman ) {
2019-07-24 13:39:42 -04:00
LOCK ( cs_main ) ;
2022-03-09 12:37:19 -05:00
for ( Chainstate * chainstate : node . chainman - > GetAll ( ) ) {
2019-12-12 10:48:28 -05:00
if ( chainstate - > CanFlushToDisk ( ) ) {
chainstate - > ForceFlushStateToDisk ( ) ;
}
2019-07-24 13:39:42 -04:00
}
2017-07-15 20:03:11 -04:00
}
2017-06-27 19:07:52 -04:00
// After there are no more peers/RPC left to give us new data which may generate
// CValidationInterface callbacks, flush them...
GetMainSignals ( ) . FlushBackgroundCallbacks ( ) ;
2020-01-08 15:07:46 -05:00
// Stop and delete all indexes only after flushing background callbacks.
if ( g_txindex ) {
g_txindex - > Stop ( ) ;
g_txindex . reset ( ) ;
}
2020-01-24 18:58:47 +01:00
if ( g_coin_stats_index ) {
g_coin_stats_index - > Stop ( ) ;
g_coin_stats_index . reset ( ) ;
}
2020-01-08 15:07:46 -05:00
ForEachBlockFilterIndex ( [ ] ( BlockFilterIndex & index ) { index . Stop ( ) ; } ) ;
DestroyAllBlockFilterIndexes ( ) ;
2017-06-27 19:07:52 -04:00
// Any future callbacks will be dropped. This should absolutely be safe - if
// missing a callback results in an unrecoverable situation, unclean shutdown
// would too. The only reason to do the above flushes is to let the wallet catch
// up with our current chain to avoid any strange pruning edge cases and make
// next startup faster by avoiding rescan.
2020-04-18 08:05:52 -04:00
if ( node . chainman ) {
2013-03-09 12:02:57 -05:00
LOCK ( cs_main ) ;
2022-03-09 12:37:19 -05:00
for ( Chainstate * chainstate : node . chainman - > GetAll ( ) ) {
2019-12-12 10:48:28 -05:00
if ( chainstate - > CanFlushToDisk ( ) ) {
chainstate - > ForceFlushStateToDisk ( ) ;
chainstate - > ResetCoinsViews ( ) ;
}
Improve chainstate/blockindex disk writing policy
There are 3 pieces of data that are maintained on disk. The actual block
and undo data, the block index (which can refer to positions on disk),
and the chainstate (which refers to the best block hash).
Earlier, there was no guarantee that blocks were written to disk before
block index entries referring to them were written. This commit introduces
dirty flags for block index data, and delays writing entries until the actual
block data is flushed.
With this stricter ordering in writes, it is now safe to not always flush
after every block, so there is no need for the IsInitialBlockDownload()
check there - instead we just write whenever enough time has passed or
the cache size grows too large. Also updating the wallet's best known block
is delayed until this is done, otherwise the wallet may end up referring to an
unknown block.
In addition, only do a write inside the block processing loop if necessary
(because of cache size exceeded). Otherwise, move the writing to a point
after processing is done, after relaying.
2014-11-07 02:38:35 -08:00
}
2011-05-14 20:10:21 +02:00
}
2019-09-17 17:04:39 -04:00
for ( const auto & client : node . chain_clients ) {
2017-09-28 14:13:29 -04:00
client - > stop ( ) ;
}
2014-11-18 12:06:32 -05:00
# if ENABLE_ZMQ
2018-06-29 15:16:31 +02:00
if ( g_zmq_notification_interface ) {
2023-04-17 10:42:49 +02:00
UnregisterValidationInterface ( g_zmq_notification_interface . get ( ) ) ;
g_zmq_notification_interface . reset ( ) ;
2014-11-18 12:06:32 -05:00
}
# endif
2019-09-17 17:04:39 -04:00
node . chain_clients . clear ( ) ;
2014-10-19 18:17:01 -07:00
UnregisterAllValidationInterfaces ( ) ;
2017-01-19 16:49:22 -05:00
GetMainSignals ( ) . UnregisterBackgroundSignalScheduler ( ) ;
2022-05-25 14:31:54 -04:00
node . kernel . reset ( ) ;
2020-07-19 20:30:46 +02:00
node . mempool . reset ( ) ;
2020-07-28 19:12:50 +02:00
node . fee_estimator . reset ( ) ;
2020-10-06 17:35:11 -04:00
node . chainman . reset ( ) ;
2020-02-12 11:08:28 -08:00
node . scheduler . reset ( ) ;
2020-04-04 22:50:40 +03:00
try {
2020-08-21 20:13:40 +02:00
if ( ! fs : : remove ( GetPidFile ( * node . args ) ) ) {
2020-04-04 22:50:40 +03:00
LogPrintf ( " %s: Unable to remove PID file: File does not exist \n " , __func__ ) ;
}
} catch ( const fs : : filesystem_error & e ) {
LogPrintf ( " %s: Unable to remove PID file: %s \n " , __func__ , fsbridge : : get_filesystem_error_message ( e ) ) ;
}
2014-06-27 14:41:11 +02:00
LogPrintf ( " %s: done \n " , __func__ ) ;
2011-05-14 20:10:21 +02:00
}
2014-12-01 09:39:44 +08:00
/**
2017-03-22 13:29:41 -07:00
* Signal handlers are very limited in what they are allowed to do .
* The execution context the handler is invoked in is not guaranteed ,
* so we restrict handler operations to just touching variables :
2014-12-01 09:39:44 +08:00
*/
2018-04-30 23:31:11 +08:00
# ifndef WIN32
2017-03-22 13:29:41 -07:00
static void HandleSIGTERM ( int )
2011-05-14 20:10:21 +02:00
{
2018-05-16 19:17:40 +00:00
StartShutdown ( ) ;
2011-05-14 20:10:21 +02:00
}
2017-03-22 13:29:41 -07:00
static void HandleSIGHUP ( int )
2012-03-02 12:31:16 -07:00
{
2019-01-25 15:54:49 -05:00
LogInstance ( ) . m_reopen_file = true ;
2012-03-02 12:31:16 -07:00
}
2018-04-30 23:31:11 +08:00
# else
static BOOL WINAPI consoleCtrlHandler ( DWORD dwCtrlType )
{
2018-05-16 19:17:40 +00:00
StartShutdown ( ) ;
2018-04-30 23:31:11 +08:00
Sleep ( INFINITE ) ;
return true ;
}
# endif
2011-05-14 20:10:21 +02:00
2017-03-22 13:29:41 -07:00
# ifndef WIN32
static void registerSignalHandler ( int signal , void ( * handler ) ( int ) )
{
struct sigaction sa ;
sa . sa_handler = handler ;
sigemptyset ( & sa . sa_mask ) ;
sa . sa_flags = 0 ;
2017-08-07 07:36:37 +02:00
sigaction ( signal , & sa , nullptr ) ;
2017-03-22 13:29:41 -07:00
}
# endif
2019-03-29 19:11:43 +01:00
static boost : : signals2 : : connection rpc_notify_block_change_connection ;
2018-05-02 17:14:48 +02:00
static void OnRPCStarted ( )
2016-09-01 21:55:21 -04:00
{
2020-03-04 19:48:32 +02:00
rpc_notify_block_change_connection = uiInterface . NotifyBlockTip_connect ( std : : bind ( RPCNotifyBlockChange , std : : placeholders : : _2 ) ) ;
2016-09-01 21:55:21 -04:00
}
2012-05-11 15:28:59 +02:00
2018-05-02 17:14:48 +02:00
static void OnRPCStopped ( )
2014-10-19 04:46:17 -04:00
{
2019-03-29 19:11:43 +01:00
rpc_notify_block_change_connection . disconnect ( ) ;
2020-03-04 19:48:32 +02:00
RPCNotifyBlockChange ( nullptr ) ;
2018-04-03 21:53:07 -07:00
g_best_block_cv . notify_all ( ) ;
2016-12-25 20:19:40 +00:00
LogPrint ( BCLog : : RPC , " RPC stopped. \n " ) ;
2014-10-19 04:46:17 -04:00
}
2017-12-05 15:57:12 -05:00
void SetupServerArgs ( ArgsManager & argsman )
2012-05-13 11:36:10 +02:00
{
2020-08-21 20:13:40 +02:00
SetupHelpOptions ( argsman ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -help-debug " , " Print help message with debugging options and exit " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ; // server-only for now
2019-02-06 13:57:52 -05:00
2021-04-18 19:01:01 -04:00
init : : AddLoggingArgs ( argsman ) ;
2023-04-17 22:20:59 +02:00
const auto defaultBaseParams = CreateBaseChainParams ( ChainType : : MAIN ) ;
const auto testnetBaseParams = CreateBaseChainParams ( ChainType : : TESTNET ) ;
const auto signetBaseParams = CreateBaseChainParams ( ChainType : : SIGNET ) ;
const auto regtestBaseParams = CreateBaseChainParams ( ChainType : : REGTEST ) ;
const auto defaultChainParams = CreateChainParams ( argsman , ChainType : : MAIN ) ;
const auto testnetChainParams = CreateChainParams ( argsman , ChainType : : TESTNET ) ;
const auto signetChainParams = CreateChainParams ( argsman , ChainType : : SIGNET ) ;
const auto regtestChainParams = CreateChainParams ( argsman , ChainType : : REGTEST ) ;
2015-02-04 00:11:49 -08:00
2018-06-11 14:23:13 -07:00
// Hidden Options
2019-02-06 13:57:52 -05:00
std : : vector < std : : string > hidden_args = {
2018-09-20 16:41:08 -04:00
" -dbcrashratio " , " -forcecompactdb " ,
2018-06-11 14:23:13 -07:00
// GUI args. These will be overwritten by SetupUIArgs for the GUI
2019-10-12 12:49:29 -04:00
" -choosedatadir " , " -lang=<lang> " , " -min " , " -resetguisettings " , " -splash " , " -uiplatform " } ;
2018-06-11 14:23:13 -07:00
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -version " , " Print version and exit " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2019-07-05 18:30:15 +02:00
# if HAVE_SYSTEM
2022-01-14 10:34:17 +00:00
argsman . AddArg ( " -alertnotify=<cmd> " , " Execute command when an alert is raised (%s in cmd is replaced by message) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2019-03-14 11:30:37 +01:00
# endif
2020-09-25 14:55:40 +03:00
argsman . AddArg ( " -assumevalid=<hex> " , strprintf ( " If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: %s, testnet: %s, signet: %s) " , defaultChainParams - > GetConsensus ( ) . defaultAssumeValid . GetHex ( ) , testnetChainParams - > GetConsensus ( ) . defaultAssumeValid . GetHex ( ) , signetChainParams - > GetConsensus ( ) . defaultAssumeValid . GetHex ( ) ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -blocksdir=<dir> " , " Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-12-10 11:39:37 +01:00
argsman . AddArg ( " -fastprune " , " Use smaller block files and lower minimum prune height for testing purposes " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2019-07-05 18:30:15 +02:00
# if HAVE_SYSTEM
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -blocknotify=<cmd> " , " Execute command when the best block changes (%s in cmd is replaced by block hash) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2019-03-14 11:30:37 +01:00
# endif
2020-07-19 14:47:05 +07:00
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 ) ;
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 ) ;
2021-04-30 20:20:05 +02:00
argsman . AddArg ( " -coinstatsindex " , strprintf ( " Maintain coinstats index used by the gettxoutsetinfo RPC (default: %u) " , DEFAULT_COINSTATSINDEX ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2021-12-29 12:55:05 +01:00
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 ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -datadir=<dir> " , " Specify data directory " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -dbbatchsize " , strprintf ( " Maximum database write batch size in bytes (default: %u) " , nDefaultDbBatchSize ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : OPTIONS ) ;
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 ) ;
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 ) ;
2023-03-21 13:14:53 -04:00
argsman . AddArg ( " -allowignoredconf " , strprintf ( " For backwards compatibility, treat an unused %s file in the datadir as a warning, not an error. " , BITCOIN_CONF_FILENAME ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -loadblock=<file> " , " Imports blocks from external file on startup " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2022-05-18 12:12:04 -04:00
argsman . AddArg ( " -maxmempool=<n> " , strprintf ( " Keep the transaction memory pool below <n> megabytes (default: %u) " , DEFAULT_MAX_MEMPOOL_SIZE_MB ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -maxorphantx=<n> " , strprintf ( " Keep at most <n> unconnectable transactions in memory (default: %u) " , DEFAULT_MAX_ORPHAN_TRANSACTIONS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2022-06-21 10:37:10 -04:00
argsman . AddArg ( " -mempoolexpiry=<n> " , strprintf ( " Do not keep transactions in the mempool longer than <n> hours (default: %u) " , DEFAULT_MEMPOOL_EXPIRY_HOURS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-09-25 14:55:40 +03:00
argsman . AddArg ( " -minimumchainwork=<hex> " , strprintf ( " Minimum work assumed to exist on a valid chain in hex (default: %s, testnet: %s, signet: %s) " , defaultChainParams - > GetConsensus ( ) . nMinimumChainWork . GetHex ( ) , testnetChainParams - > GetConsensus ( ) . nMinimumChainWork . GetHex ( ) , signetChainParams - > GetConsensus ( ) . nMinimumChainWork . GetHex ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : OPTIONS ) ;
2020-07-19 14:47:05 +07:00
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) " ,
scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
2019-07-27 12:06:32 +03:00
- GetNumCores ( ) , MAX_SCRIPTCHECK_THREADS , DEFAULT_SCRIPTCHECK_THREADS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-07-19 14:47:05 +07:00
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 ) ;
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 ) ;
2021-05-13 19:20:47 +02:00
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. "
2015-05-04 18:46:33 +02:00
" Warning: Reverting this setting requires re-downloading the entire blockchain. "
scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
2019-07-27 12:06:32 +03:00
" (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 ) ;
2022-04-06 17:05:32 +02:00
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 : : OPTIONS ) ;
2022-05-23 21:07:29 +02:00
argsman . AddArg ( " -reindex-chainstate " , " Rebuild chain state from the currently indexed blocks. When in pruning mode or if blocks on disk might be corrupted, use full -reindex instead. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-07-19 14:47:05 +07:00
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 ) ;
2020-09-28 10:38:36 -05:00
# if HAVE_SYSTEM
argsman . AddArg ( " -startupnotify=<cmd> " , " Execute command on startup. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2021-10-30 22:22:40 +08:00
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 ) ;
2014-06-04 13:16:07 +02:00
# endif
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -txindex " , strprintf ( " Maintain a full transaction index, used by the getrawtransaction rpc call (default: %u) " , DEFAULT_TXINDEX ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -blockfilterindex=<type> " ,
2018-08-29 22:15:50 -07:00
strprintf ( " Maintain an index of compact filters by block (default: %s, values: %s). " , DEFAULT_BLOCKFILTERINDEX , ListBlockFilterTypes ( ) ) +
" If <type> is not supplied or if <type> = 1, indexes for all known types are enabled. " ,
scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
2019-07-27 12:06:32 +03:00
ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2021-04-16 20:04:38 +02:00
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 ) ;
2020-07-19 14:47:05 +07:00
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 ) ;
argsman . AddArg ( " -bantime=<n> " , strprintf ( " Default duration (in seconds) of manually configured bans (default: %u) " , DEFAULT_MISBEHAVING_BANTIME ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2020-09-29 18:03:43 +03:00
argsman . AddArg ( " -bind=<addr>[:<port>][=onion] " , strprintf ( " Bind to given address and always listen on it (default: 0.0.0.0). Use [host]:port notation for IPv6. Append =onion to tag any incoming connections to that address and port as incoming Tor connections (default: 127.0.0.1:%u=onion, testnet: 127.0.0.1:%u=onion, signet: 127.0.0.1:%u=onion, regtest: 127.0.0.1:%u=onion) " , defaultBaseParams - > OnionServiceTargetPort ( ) , testnetBaseParams - > OnionServiceTargetPort ( ) , signetBaseParams - > OnionServiceTargetPort ( ) , regtestBaseParams - > OnionServiceTargetPort ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY , OptionsCategory : : CONNECTION ) ;
2022-03-24 20:12:32 +01:00
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 ) ;
2020-07-19 14:47:05 +07:00
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 ) ;
argsman . AddArg ( " -discover " , " Discover own IP addresses (default: 1 when listening and no -externalip or -proxy) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -dns " , strprintf ( " Allow DNS lookups for -addnode, -seednode and -connect (default: %u) " , DEFAULT_NAME_LOOKUP ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2023-01-16 11:25:13 -03:00
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 ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -externalip=<ip> " , " Specify your own public address " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2021-08-18 21:08:08 -04:00
argsman . AddArg ( " -fixedseeds " , strprintf ( " Allow fixed seeds if DNS seeds don't provide peers (default: %u) " , DEFAULT_FIXEDSEEDS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -forcednsseed " , strprintf ( " Always query for peer addresses via DNS lookup (default: %u) " , DEFAULT_FORCEDNSSEED ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2023-01-16 11:25:13 -03:00
argsman . AddArg ( " -listen " , strprintf ( " Accept connections from outside (default: %u if no -proxy, -connect or -maxconnections=0) " , DEFAULT_LISTEN ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2020-08-01 15:10:26 +02:00
argsman . AddArg ( " -listenonion " , strprintf ( " Automatically create Tor onion service (default: %d) " , DEFAULT_LISTEN_ONION ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2021-04-17 12:33:06 +02:00
argsman . AddArg ( " -maxconnections=<n> " , strprintf ( " Maintain at most <n> connections to peers (default: %u). This limit does not apply to connections manually added via -addnode or the addnode RPC, which have a separate limit of %u. " , DEFAULT_MAX_PEER_CONNECTIONS , MAX_ADDNODE_CONNECTIONS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -maxreceivebuffer=<n> " , strprintf ( " Maximum per-connection receive buffer, <n>*1000 bytes (default: %u) " , DEFAULT_MAXRECEIVEBUFFER ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -maxsendbuffer=<n> " , strprintf ( " Maximum per-connection send buffer, <n>*1000 bytes (default: %u) " , DEFAULT_MAXSENDBUFFER ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2022-03-18 01:18:14 +01:00
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 ) ;
2021-11-17 12:47:30 +02:00
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 ) ;
2020-08-01 15:10:26 +02:00
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 ) ;
2020-12-04 18:03:05 +01:00
argsman . AddArg ( " -i2psam=<ip:port> " , " I2P SAM proxy to reach I2P peers and accept I2P connections (default: none) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2023-01-09 07:25:04 -08:00
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 ) ;
2022-03-01 21:13:22 +01:00
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 ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -peerbloomfilters " , strprintf ( " Support filtering of blocks and transaction with bloom filters (default: %u) " , DEFAULT_PEERBLOOMFILTERS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -peerblockfilters " , strprintf ( " Serve compact block filters to peers per BIP 157 (default: %u) " , DEFAULT_PEERBLOCKFILTERS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2022-11-14 11:45:52 +02:00
argsman . AddArg ( " -txreconciliation " , strprintf ( " Enable transaction reconciliations per BIP 330 (default: %d) " , DEFAULT_TXRECONCILIATION_ENABLE ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : CONNECTION ) ;
2021-11-18 09:19:09 +01:00
// TODO: remove the sentence "Nodes not using ... incoming connections." once the changes from
// https://github.com/bitcoin/bitcoin/pull/23542 have become widespread.
2021-05-31 17:18:49 +02:00
argsman . AddArg ( " -port=<port> " , strprintf ( " Listen for connections on <port>. Nodes not using the default ports (default: %u, testnet: %u, signet: %u, regtest: %u) are unlikely to get incoming connections. Not relevant for I2P (see doc/i2p.md). " , defaultChainParams - > GetDefaultPort ( ) , testnetChainParams - > GetDefaultPort ( ) , signetChainParams - > GetDefaultPort ( ) , regtestChainParams - > GetDefaultPort ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY , OptionsCategory : : CONNECTION ) ;
2022-04-12 03:00:28 -04:00
argsman . AddArg ( " -proxy=<ip:port> " , " Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled) " , ArgsManager : : ALLOW_ANY | ArgsManager : : DISALLOW_ELISION , OptionsCategory : : CONNECTION ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -proxyrandomize " , strprintf ( " Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u) " , DEFAULT_PROXYRANDOMIZE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
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 ) ;
2021-08-18 21:08:08 -04:00
argsman . AddArg ( " -networkactive " , " Enable all P2P network activity (default: 1). Can be changed by the setnetworkactive RPC command " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2021-02-03 10:20:30 -08:00
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 ) ;
argsman . AddArg ( " -peertimeout=<n> " , strprintf ( " Specify a p2p connection timeout delay in seconds. After connecting to a peer, wait this amount of time before considering disconnection based on inactivity (minimum: 1, default: %d) " , DEFAULT_PEER_CONNECT_TIMEOUT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : CONNECTION ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -torcontrol=<ip>:<port> " , strprintf ( " Tor control port to use if onion listening enabled (default: %s) " , DEFAULT_TOR_CONTROL ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -torpassword=<pass> " , " Tor control port password (default: empty) " , ArgsManager : : ALLOW_ANY | ArgsManager : : SENSITIVE , OptionsCategory : : CONNECTION ) ;
2012-05-13 11:36:10 +02:00
# ifdef USE_UPNP
# if USE_UPNP
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -upnp " , " Use UPnP to map the listening port (default: 1 when listening and no -proxy) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2012-05-13 11:36:10 +02:00
# else
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -upnp " , strprintf ( " Use UPnP to map the listening port (default: %u) " , 0 ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2013-10-11 23:09:59 +02:00
# endif
2018-06-11 14:23:13 -07:00
# else
hidden_args . emplace_back ( " -upnp " ) ;
2012-05-13 11:36:10 +02:00
# endif
2020-02-23 02:12:19 +02:00
# ifdef USE_NATPMP
2021-08-18 21:08:08 -04:00
argsman . AddArg ( " -natpmp " , strprintf ( " Use NAT-PMP to map the listening port (default: %s) " , DEFAULT_NATPMP ? " 1 when listening and no -proxy " : " 0 " ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2020-02-23 02:12:19 +02:00
# else
hidden_args . emplace_back ( " -natpmp " ) ;
# endif // USE_NATPMP
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -whitebind=<[permissions@]addr> " , " Bind to the given address and add permission flags to the peers connecting to it. "
2020-06-06 13:28:47 -04:00
" Use [host]:port notation for IPv6. Allowed permissions: " + Join ( NET_PERMISSIONS_DOC , " , " ) + " . "
2020-06-06 17:07:25 +02:00
" Specify multiple permissions separated by commas (default: download,noban,mempool,relay). Can be specified multiple times. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2019-08-23 13:31:41 +09:00
2020-07-19 14:47:05 +07:00
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 "
2020-06-06 17:07:25 +02:00
" CIDR-notated network (e.g. 1.2.3.0/24). Uses the same permissions as "
2019-08-23 13:31:41 +09:00
" -whitebind. Can be specified multiple times. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2014-02-03 07:23:20 +01:00
2020-07-19 14:31:51 +07:00
g_wallet_init_interface . AddWalletOptions ( argsman ) ;
2014-02-03 07:23:20 +01:00
2014-11-18 12:06:32 -05:00
# if ENABLE_ZMQ
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -zmqpubhashblock=<address> " , " Enable publish hash block in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashtx=<address> " , " Enable publish hash transaction in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawblock=<address> " , " Enable publish raw block in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawtx=<address> " , " Enable publish raw transaction in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
Add 'sequence' zmq publisher to track all block (dis)connects, mempool deltas
Using the zmq notifications to avoid excessive mempool polling can be difficult
given the current notifications available. It announces all transactions
being added to mempool or included in blocks, but announces no evictions
and gives no indication if the transaction is in the mempool or a block.
Block notifications for zmq are also substandard, in that it only announces
block tips, while all block transactions are still announced.
This commit adds a unified stream which can be used to closely track mempool:
1) getrawmempool to fill out mempool knowledge
2) if txhash is announced, add or remove from set
based on add/remove flag
3) if blockhash is announced, get block txn list,
remove from those transactions local view of mempool
4) if we drop a sequence number, go to (1)
The mempool sequence number starts at the value 1, and
increments each time a transaction enters the mempool,
or is evicted from the mempool for any reason, including
block inclusion. The mempool sequence number is published
via ZMQ for any transaction-related notification.
These features allow for ZMQ/RPC consumer to track mempool
state in a more exacting way, without unnecesarily polling
getrawmempool. See interface_zmq.py::test_mempool_sync for
example usage.
2020-09-04 11:55:58 -04:00
argsman . AddArg ( " -zmqpubsequence=<address> " , " Enable publish hash block and tx sequence in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
2020-07-19 14:47:05 +07:00
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 ) ;
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 ) ;
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 ) ;
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 ) ;
Add 'sequence' zmq publisher to track all block (dis)connects, mempool deltas
Using the zmq notifications to avoid excessive mempool polling can be difficult
given the current notifications available. It announces all transactions
being added to mempool or included in blocks, but announces no evictions
and gives no indication if the transaction is in the mempool or a block.
Block notifications for zmq are also substandard, in that it only announces
block tips, while all block transactions are still announced.
This commit adds a unified stream which can be used to closely track mempool:
1) getrawmempool to fill out mempool knowledge
2) if txhash is announced, add or remove from set
based on add/remove flag
3) if blockhash is announced, get block txn list,
remove from those transactions local view of mempool
4) if we drop a sequence number, go to (1)
The mempool sequence number starts at the value 1, and
increments each time a transaction enters the mempool,
or is evicted from the mempool for any reason, including
block inclusion. The mempool sequence number is published
via ZMQ for any transaction-related notification.
These features allow for ZMQ/RPC consumer to track mempool
state in a more exacting way, without unnecesarily polling
getrawmempool. See interface_zmq.py::test_mempool_sync for
example usage.
2020-09-04 11:55:58 -04:00
argsman . AddArg ( " -zmqpubsequencehwm=<n> " , strprintf ( " Set publish hash sequence message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
2018-06-11 14:23:13 -07:00
# else
hidden_args . emplace_back ( " -zmqpubhashblock=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubhashtx=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawblock=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawtx=<address> " ) ;
Add 'sequence' zmq publisher to track all block (dis)connects, mempool deltas
Using the zmq notifications to avoid excessive mempool polling can be difficult
given the current notifications available. It announces all transactions
being added to mempool or included in blocks, but announces no evictions
and gives no indication if the transaction is in the mempool or a block.
Block notifications for zmq are also substandard, in that it only announces
block tips, while all block transactions are still announced.
This commit adds a unified stream which can be used to closely track mempool:
1) getrawmempool to fill out mempool knowledge
2) if txhash is announced, add or remove from set
based on add/remove flag
3) if blockhash is announced, get block txn list,
remove from those transactions local view of mempool
4) if we drop a sequence number, go to (1)
The mempool sequence number starts at the value 1, and
increments each time a transaction enters the mempool,
or is evicted from the mempool for any reason, including
block inclusion. The mempool sequence number is published
via ZMQ for any transaction-related notification.
These features allow for ZMQ/RPC consumer to track mempool
state in a more exacting way, without unnecesarily polling
getrawmempool. See interface_zmq.py::test_mempool_sync for
example usage.
2020-09-04 11:55:58 -04:00
hidden_args . emplace_back ( " -zmqpubsequence=<n> " ) ;
2018-08-24 20:42:03 -04:00
hidden_args . emplace_back ( " -zmqpubhashblockhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubhashtxhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawblockhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawtxhwm=<n> " ) ;
Add 'sequence' zmq publisher to track all block (dis)connects, mempool deltas
Using the zmq notifications to avoid excessive mempool polling can be difficult
given the current notifications available. It announces all transactions
being added to mempool or included in blocks, but announces no evictions
and gives no indication if the transaction is in the mempool or a block.
Block notifications for zmq are also substandard, in that it only announces
block tips, while all block transactions are still announced.
This commit adds a unified stream which can be used to closely track mempool:
1) getrawmempool to fill out mempool knowledge
2) if txhash is announced, add or remove from set
based on add/remove flag
3) if blockhash is announced, get block txn list,
remove from those transactions local view of mempool
4) if we drop a sequence number, go to (1)
The mempool sequence number starts at the value 1, and
increments each time a transaction enters the mempool,
or is evicted from the mempool for any reason, including
block inclusion. The mempool sequence number is published
via ZMQ for any transaction-related notification.
These features allow for ZMQ/RPC consumer to track mempool
state in a more exacting way, without unnecesarily polling
getrawmempool. See interface_zmq.py::test_mempool_sync for
example usage.
2020-09-04 11:55:58 -04:00
hidden_args . emplace_back ( " -zmqpubsequencehwm=<n> " ) ;
2014-11-18 12:06:32 -05:00
# endif
2020-07-19 14:47:05 +07:00
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 ) ;
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 ) ;
argsman . AddArg ( " -checkblockindex " , strprintf ( " Do a consistency check for the block tree, chainstate, and other validation data structures occasionally. (default: %u, regtest: %u) " , defaultChainParams - > DefaultConsistencyChecks ( ) , regtestChainParams - > DefaultConsistencyChecks ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2020-10-23 22:03:24 +01:00
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 ) ;
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 ) ;
2020-06-10 23:57:58 +00:00
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 ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -deprecatedrpc=<method> " , " Allows deprecated RPC method(s) to be used " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -stopafterblockimport " , strprintf ( " Stop running after importing blocks from disk (default: %u) " , DEFAULT_STOPAFTERBLOCKIMPORT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
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 ) ;
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 ) ;
2022-03-17 21:54:40 -04:00
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_KVB ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2020-07-19 14:47:05 +07:00
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 ) ;
2022-03-17 21:54:40 -04:00
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_KVB ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -addrmantest " , " Allows to test address relay on localhost " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2021-08-18 21:08:08 -04:00
argsman . AddArg ( " -capturemessages " , " Capture all P2P messages to disk " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -mocktime=<n> " , " Replace actual time with " + UNIX_EPOCH_TIME + " (default: 0) " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2022-06-30 23:47:41 -04:00
argsman . AddArg ( " -maxsigcachesize=<n> " , strprintf ( " Limit sum of signature cache and script execution cache sizes to <n> MiB (default: %u) " , DEFAULT_MAX_SIG_CACHE_BYTES > > 20 ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2022-07-20 18:16:30 +02:00
argsman . AddArg ( " -maxtipage=<n> " ,
strprintf ( " Maximum tip age in seconds to consider node in initial block download (default: %u) " ,
Ticks < std : : chrono : : seconds > ( DEFAULT_MAX_TIP_AGE ) ) ,
ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2021-05-01 18:29:22 +02:00
argsman . AddArg ( " -printpriority " , strprintf ( " Log transaction fee rate in " + CURRENCY_UNIT + " /kvB when mining blocks (default: %u) " , DEFAULT_PRINTPRIORITY ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -uacomment=<cmt> " , " Append comment to the user agent string " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
2018-04-28 16:54:58 -04:00
2020-07-19 14:31:51 +07:00
SetupChainParamsBaseOptions ( argsman ) ;
2018-04-28 16:54:58 -04:00
2020-07-19 14:47:05 +07:00
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 ) ;
2022-07-19 09:52:55 +01:00
argsman . AddArg ( " -incrementalrelayfee=<amt> " , strprintf ( " Fee rate (in %s/kvB) used to define cost of relay, used for mempool limiting and replacement policy. (default: %s) " , CURRENCY_UNIT , FormatMoney ( DEFAULT_INCREMENTAL_RELAY_FEE ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : NODE_RELAY ) ;
2021-04-22 12:20:18 +02:00
argsman . AddArg ( " -dustrelayfee=<amt> " , strprintf ( " Fee rate (in %s/kvB) used to define dust, the value of an output such that it will cost more than its value in fees at this fee rate to spend it. (default: %s) " , CURRENCY_UNIT , FormatMoney ( DUST_RELAY_TX_FEE ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : NODE_RELAY ) ;
2023-06-14 22:39:26 +01:00
argsman . AddArg ( " -acceptstalefeeestimates " , strprintf ( " Read fee estimates even if they are stale (%sdefault: %u) fee estimates are considered stale if they are %s hours old " , " regtest only; " , DEFAULT_ACCEPT_STALE_FEE_ESTIMATES , Ticks < std : : chrono : : hours > ( MAX_FILE_AGE ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2020-07-19 14:47:05 +07:00
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 ) ;
argsman . AddArg ( " -datacarrier " , strprintf ( " Relay and mine data carrier transactions (default: %u) " , DEFAULT_ACCEPT_DATACARRIER ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : NODE_RELAY ) ;
argsman . AddArg ( " -datacarriersize " , strprintf ( " Maximum size of data in data carrier transactions we relay and mine (default: %u) " , MAX_OP_RETURN_RELAY ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : NODE_RELAY ) ;
2022-04-27 10:25:22 -04:00
argsman . AddArg ( " -mempoolfullrbf " , strprintf ( " Accept transaction replace-by-fee without requiring replaceability signaling (default: %u) " , DEFAULT_MEMPOOL_FULL_RBF ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : NODE_RELAY ) ;
2022-09-19 14:24:11 +02:00
argsman . AddArg ( " -permitbaremultisig " , strprintf ( " Relay non-P2SH multisig (default: %u) " , DEFAULT_PERMIT_BAREMULTISIG ) , ArgsManager : : ALLOW_ANY ,
OptionsCategory : : NODE_RELAY ) ;
2021-04-22 12:20:18 +02:00
argsman . AddArg ( " -minrelaytxfee=<amt> " , strprintf ( " Fees (in %s/kvB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s) " ,
scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
2019-07-27 12:06:32 +03:00
CURRENCY_UNIT , FormatMoney ( DEFAULT_MIN_RELAY_TX_FEE ) ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : NODE_RELAY ) ;
2020-07-19 14:47:05 +07:00
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 ) ;
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 ) ;
argsman . AddArg ( " -blockmaxweight=<n> " , strprintf ( " Set maximum BIP141 block weight (default: %d) " , DEFAULT_BLOCK_MAX_WEIGHT ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : BLOCK_CREATION ) ;
2021-04-22 12:20:18 +02:00
argsman . AddArg ( " -blockmintxfee=<amt> " , strprintf ( " Set lowest fee rate (in %s/kvB) for transactions to be included in block creation. (default: %s) " , CURRENCY_UNIT , FormatMoney ( DEFAULT_BLOCK_MIN_TX_FEE ) ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : BLOCK_CREATION ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -blockversion=<n> " , " Override block version to test forking scenarios " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : BLOCK_CREATION ) ;
argsman . AddArg ( " -rest " , strprintf ( " Accept public REST requests (default: %u) " , DEFAULT_REST_ENABLE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -rpcallowip=<ip> " , " Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times " , ArgsManager : : ALLOW_ANY , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -rpcauth=<userpw> " , " Username and HMAC-SHA-256 hashed password for JSON-RPC connections. The field <userpw> comes in the format: <USERNAME>:<SALT>$<HASH>. A canonical python script is included in share/rpcauth. The client then connects normally using the rpcuser=<USERNAME>/rpcpassword=<PASSWORD> pair of arguments. This option can be specified multiple times " , ArgsManager : : ALLOW_ANY | ArgsManager : : SENSITIVE , OptionsCategory : : RPC ) ;
2023-01-05 22:35:17 -05:00
argsman . AddArg ( " -rpcbind=<addr>[:port] " , " Bind to given address to listen for JSON-RPC connections. Do not expose the RPC server to untrusted networks such as the public internet! This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost) " , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY , OptionsCategory : : RPC ) ;
2022-05-17 14:44:20 -07:00
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 ) ;
2020-07-19 14:47:05 +07:00
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 ) ;
argsman . AddArg ( " -rpcpassword=<pw> " , " Password for JSON-RPC connections " , ArgsManager : : ALLOW_ANY | ArgsManager : : SENSITIVE , OptionsCategory : : RPC ) ;
2020-09-25 14:55:40 +03:00
argsman . AddArg ( " -rpcport=<port> " , strprintf ( " Listen for JSON-RPC connections on <port> (default: %u, testnet: %u, signet: %u, regtest: %u) " , defaultBaseParams - > RPCPort ( ) , testnetBaseParams - > RPCPort ( ) , signetBaseParams - > RPCPort ( ) , regtestBaseParams - > RPCPort ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY , OptionsCategory : : RPC ) ;
2020-07-19 14:47:05 +07:00
argsman . AddArg ( " -rpcserialversion " , strprintf ( " Sets the serialization of raw transaction or block hex returned in non-verbose mode, non-segwit(0) or segwit(1) (default: %d) " , DEFAULT_RPC_SERIALIZE_VERSION ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -rpcservertimeout=<n> " , strprintf ( " Timeout during HTTP requests (default: %d) " , DEFAULT_HTTP_SERVER_TIMEOUT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -rpcthreads=<n> " , strprintf ( " Set the number of threads to service RPC calls (default: %d) " , DEFAULT_HTTP_THREADS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -rpcuser=<user> " , " Username for JSON-RPC connections " , ArgsManager : : ALLOW_ANY | ArgsManager : : SENSITIVE , OptionsCategory : : RPC ) ;
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 ) ;
2021-08-18 21:08:08 -04:00
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 ) ;
2020-07-19 14:47:05 +07:00
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 ) ;
argsman . AddArg ( " -server " , " Accept command line and JSON-RPC commands " , ArgsManager : : ALLOW_ANY , OptionsCategory : : RPC ) ;
2018-04-28 19:40:51 -04:00
2021-01-25 22:45:54 +01:00
# if HAVE_DECL_FORK
2021-08-18 21:08:08 -04:00
argsman . AddArg ( " -daemon " , strprintf ( " Run in the background as a daemon and accept commands (default: %d) " , DEFAULT_DAEMON ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -daemonwait " , strprintf ( " Wait for initialization to be finished before exiting. This implies -daemon (default: %d) " , DEFAULT_DAEMONWAIT ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2018-06-11 14:23:13 -07:00
# else
hidden_args . emplace_back ( " -daemon " ) ;
2021-03-16 10:48:26 +02:00
hidden_args . emplace_back ( " -daemonwait " ) ;
2018-06-11 14:23:13 -07:00
# endif
// Add the hidden options
2020-07-19 14:47:05 +07:00
argsman . AddHiddenArgs ( hidden_args ) ;
2012-05-13 11:36:10 +02:00
}
2016-07-22 15:57:25 +02:00
static bool fHaveGenesis = false ;
2022-04-20 17:10:13 +10:00
static GlobalMutex g_genesis_wait_mutex ;
2017-11-03 07:49:16 -04:00
static std : : condition_variable g_genesis_wait_cv ;
2016-07-22 15:57:25 +02:00
2020-03-04 19:41:18 +02:00
static void BlockNotifyGenesisWait ( const CBlockIndex * pBlockIndex )
2016-07-22 15:57:25 +02:00
{
2017-08-07 07:36:37 +02:00
if ( pBlockIndex ! = nullptr ) {
2016-07-22 15:57:25 +02:00
{
2017-11-03 07:49:16 -04:00
LOCK ( g_genesis_wait_mutex ) ;
2016-07-22 15:57:25 +02:00
fHaveGenesis = true ;
}
2017-11-03 07:49:16 -04:00
g_genesis_wait_cv . notify_all ( ) ;
2016-07-22 15:57:25 +02:00
}
}
2020-09-28 10:38:36 -05:00
# if HAVE_SYSTEM
static void StartupNotify ( const ArgsManager & args )
{
std : : string cmd = args . GetArg ( " -startupnotify " , " " ) ;
if ( ! cmd . empty ( ) ) {
std : : thread t ( runCommand , cmd ) ;
t . detach ( ) ; // thread runs free
}
}
# endif
2021-04-02 13:35:01 -04:00
static bool AppInitServers ( NodeContext & node )
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
{
2020-08-21 20:13:40 +02:00
const ArgsManager & args = * Assert ( node . args ) ;
2016-09-01 21:55:21 -04:00
RPCServer : : OnStarted ( & OnRPCStarted ) ;
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
RPCServer : : OnStopped ( & OnRPCStopped ) ;
2015-08-28 16:55:16 +02:00
if ( ! InitHTTPServer ( ) )
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
return false ;
2018-07-27 08:22:42 +02:00
StartRPC ( ) ;
2020-06-18 22:19:26 +03:00
node . rpc_interruption_point = RpcInterruptionPoint ;
2021-04-02 13:35:01 -04:00
if ( ! StartHTTPRPC ( & node ) )
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
return false ;
2021-04-02 13:35:01 -04:00
if ( args . GetBoolArg ( " -rest " , DEFAULT_REST_ENABLE ) ) StartREST ( & node ) ;
2018-07-27 08:22:42 +02:00
StartHTTPServer ( ) ;
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
return true ;
}
2015-10-08 09:58:31 +02:00
// Parameter interaction based on rules
2020-08-21 20:13:40 +02:00
void InitParameterInteraction ( ArgsManager & args )
2015-10-08 09:58:31 +02:00
{
// when specifying an explicit binding address, you want to listen on it
// even when -connect or -proxy is specified
2020-08-21 20:38:01 +02:00
if ( args . IsArgSet ( " -bind " ) ) {
if ( args . SoftSetBoolArg ( " -listen " , true ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -bind set -> setting -listen=1 \n " , __func__ ) ;
}
2020-08-21 20:38:01 +02:00
if ( args . IsArgSet ( " -whitebind " ) ) {
if ( args . SoftSetBoolArg ( " -listen " , true ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -whitebind set -> setting -listen=1 \n " , __func__ ) ;
}
2023-01-16 11:25:13 -03:00
if ( args . IsArgSet ( " -connect " ) | | args . GetIntArg ( " -maxconnections " , DEFAULT_MAX_PEER_CONNECTIONS ) < = 0 ) {
2015-10-08 09:58:31 +02:00
// when only connecting to trusted nodes, do not seed via DNS, or listen by default
2020-08-21 20:38:01 +02:00
if ( args . SoftSetBoolArg ( " -dnsseed " , false ) )
2023-01-16 11:25:13 -03:00
LogPrintf ( " %s: parameter interaction: -connect or -maxconnections=0 set -> setting -dnsseed=0 \n " , __func__ ) ;
2020-08-21 20:38:01 +02:00
if ( args . SoftSetBoolArg ( " -listen " , false ) )
2023-01-16 11:25:13 -03:00
LogPrintf ( " %s: parameter interaction: -connect or -maxconnections=0 set -> setting -listen=0 \n " , __func__ ) ;
2015-10-08 09:58:31 +02:00
}
2022-04-12 03:00:28 -04:00
std : : string proxy_arg = args . GetArg ( " -proxy " , " " ) ;
if ( proxy_arg ! = " " & & proxy_arg ! = " 0 " ) {
2015-10-08 09:58:31 +02:00
// to protect privacy, do not listen by default if a default proxy server is specified
2020-08-21 20:38:01 +02:00
if ( args . SoftSetBoolArg ( " -listen " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -listen=0 \n " , __func__ ) ;
2020-02-23 02:12:19 +02:00
// to protect privacy, do not map ports when a proxy is set. The user may still specify -listen=1
2015-10-08 09:58:31 +02:00
// to listen locally, so don't rely on this happening through -listen below.
2020-08-21 20:38:01 +02:00
if ( args . SoftSetBoolArg ( " -upnp " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -upnp=0 \n " , __func__ ) ;
2020-02-23 02:12:19 +02:00
if ( args . SoftSetBoolArg ( " -natpmp " , false ) ) {
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -natpmp=0 \n " , __func__ ) ;
}
2015-10-08 09:58:31 +02:00
// to protect privacy, do not discover addresses by default
2020-08-21 20:38:01 +02:00
if ( args . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -discover=0 \n " , __func__ ) ;
}
2020-08-21 20:38:01 +02:00
if ( ! args . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) ) {
2015-10-08 09:58:31 +02:00
// do not map ports or try to retrieve public IP when not listening (pointless)
2020-08-21 20:38:01 +02:00
if ( args . SoftSetBoolArg ( " -upnp " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -upnp=0 \n " , __func__ ) ;
2020-02-23 02:12:19 +02:00
if ( args . SoftSetBoolArg ( " -natpmp " , false ) ) {
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -natpmp=0 \n " , __func__ ) ;
}
2020-08-21 20:38:01 +02:00
if ( args . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -discover=0 \n " , __func__ ) ;
2020-08-21 20:38:01 +02:00
if ( args . SoftSetBoolArg ( " -listenonion " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -listenonion=0 \n " , __func__ ) ;
2020-12-04 18:03:05 +01:00
if ( args . SoftSetBoolArg ( " -i2pacceptincoming " , false ) ) {
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -i2pacceptincoming=0 \n " , __func__ ) ;
}
2015-10-08 09:58:31 +02:00
}
2020-08-21 20:38:01 +02:00
if ( args . IsArgSet ( " -externalip " ) ) {
2015-10-08 09:58:31 +02:00
// if an explicit public IP is specified, do not try to find others
2020-08-21 20:38:01 +02:00
if ( args . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -externalip set -> setting -discover=0 \n " , __func__ ) ;
}
2020-08-21 20:38:01 +02:00
if ( args . GetBoolArg ( " -blocksonly " , DEFAULT_BLOCKSONLY ) ) {
2022-11-08 13:52:49 +00:00
// disable whitelistrelay in blocksonly mode
2020-08-21 20:38:01 +02:00
if ( args . SoftSetBoolArg ( " -whitelistrelay " , false ) )
2015-11-25 23:00:23 +00:00
LogPrintf ( " %s: parameter interaction: -blocksonly=1 -> setting -whitelistrelay=0 \n " , __func__ ) ;
2022-11-08 13:52:49 +00:00
// Reduce default mempool size in blocksonly mode to avoid unexpected resource usage
if ( args . SoftSetArg ( " -maxmempool " , ToString ( DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB ) ) )
LogPrintf ( " %s: parameter interaction: -blocksonly=1 -> setting -maxmempool=%d \n " , __func__ , DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB ) ;
2015-10-08 10:01:29 +02:00
}
2015-11-25 23:00:23 +00:00
// Forcing relay from whitelisted hosts implies we will accept relays from them in the first place.
2020-08-21 20:38:01 +02:00
if ( args . GetBoolArg ( " -whitelistforcerelay " , DEFAULT_WHITELISTFORCERELAY ) ) {
if ( args . SoftSetBoolArg ( " -whitelistrelay " , true ) )
2015-11-25 23:00:23 +00:00
LogPrintf ( " %s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1 \n " , __func__ ) ;
}
2022-07-22 14:51:44 -04:00
if ( args . IsArgSet ( " -onlynet " ) ) {
const auto onlynets = args . GetArgs ( " -onlynet " ) ;
bool clearnet_reachable = std : : any_of ( onlynets . begin ( ) , onlynets . end ( ) , [ ] ( const auto & net ) {
const auto n = ParseNetwork ( net ) ;
return n = = NET_IPV4 | | n = = NET_IPV6 ;
} ) ;
if ( ! clearnet_reachable & & args . SoftSetBoolArg ( " -dnsseed " , false ) ) {
LogPrintf ( " %s: parameter interaction: -onlynet excludes IPv4 and IPv6 -> setting -dnsseed=0 \n " , __func__ ) ;
}
}
2015-10-08 09:58:31 +02:00
}
2018-03-26 21:35:35 -07:00
/**
* Initialize global loggers .
*
* Note that this is called very early in the process lifetime , so you should be
* careful about what global state you rely on here .
*/
2020-08-21 20:13:40 +02:00
void InitLogging ( const ArgsManager & args )
2015-11-26 14:03:27 +01:00
{
2021-04-18 19:03:26 -04:00
init : : SetLoggingOptions ( args ) ;
2021-04-18 19:07:13 -04:00
init : : LogPackageVersion ( ) ;
2015-11-26 14:03:27 +01:00
}
2016-10-25 11:34:27 +02:00
namespace { // Variables internal to initialization process only
int nMaxConnections ;
int nUserMaxConnections ;
int nFD ;
2022-08-20 14:18:42 +02:00
ServiceFlags nLocalServices = ServiceFlags ( NODE_NETWORK_LIMITED | NODE_WITNESS ) ;
2018-11-15 15:30:26 -08:00
int64_t peer_connect_timeout ;
2019-12-06 21:47:55 +01:00
std : : set < BlockFilterType > g_enabled_filter_types ;
2016-10-25 11:34:27 +02:00
2017-05-31 22:21:25 +02:00
} // namespace
2016-10-25 11:34:27 +02:00
2017-02-24 18:20:03 -05:00
[[noreturn]] static void new_handler_terminate ( )
{
// Rather than throwing std::bad-alloc if allocation fails, terminate
// immediately to (try to) avoid chain corruption.
// Since LogPrintf may itself allocate memory, set the handler directly
// to terminate first.
std : : set_new_handler ( std : : terminate ) ;
LogPrintf ( " Error: Out of memory. Terminating. \n " ) ;
// The log was successful, terminate now.
std : : terminate ( ) ;
} ;
2023-05-20 10:51:17 -03:00
bool AppInitBasicSetup ( const ArgsManager & args , std : : atomic < int > & exit_status )
2011-05-14 20:10:21 +02:00
{
2012-05-21 16:47:29 +02:00
// ********************************************************* Step 1: setup
2011-05-14 20:10:21 +02:00
# ifdef _MSC_VER
2012-07-26 00:48:39 +00:00
// Turn off Microsoft heap dump noise
2011-05-14 20:10:21 +02:00
_CrtSetReportMode ( _CRT_WARN , _CRTDBG_MODE_FILE ) ;
2017-08-07 07:36:37 +02:00
_CrtSetReportFile ( _CRT_WARN , CreateFileA ( " NUL " , GENERIC_WRITE , 0 , nullptr , OPEN_EXISTING , 0 , 0 ) ) ;
2012-07-26 00:48:39 +00:00
// Disable confusing "helpful" text message on abort, Ctrl-C
2011-05-14 20:10:21 +02:00
_set_abort_behavior ( 0 , _WRITE_ABORT_MSG | _CALL_REPORTFAULT ) ;
# endif
2012-07-20 08:45:49 +02:00
# ifdef WIN32
2020-01-13 16:36:16 +08:00
// Enable heap terminate-on-corruption
HeapSetInformation ( nullptr , HeapEnableTerminationOnCorruption , nullptr , 0 ) ;
2011-05-14 20:10:21 +02:00
# endif
2020-04-11 18:48:04 +03:00
if ( ! SetupNetworking ( ) ) {
return InitError ( Untranslated ( " Initializing networking failed. " ) ) ;
}
2015-09-02 16:18:16 +02:00
# ifndef WIN32
2011-05-14 20:10:21 +02:00
// Clean shutdown on SIGTERM
2017-03-22 13:29:41 -07:00
registerSignalHandler ( SIGTERM , HandleSIGTERM ) ;
registerSignalHandler ( SIGINT , HandleSIGTERM ) ;
2012-03-02 12:31:16 -07:00
// Reopen debug.log on SIGHUP
2017-03-22 13:29:41 -07:00
registerSignalHandler ( SIGHUP , HandleSIGHUP ) ;
2013-05-05 13:37:03 +08:00
2015-09-15 01:39:12 +02:00
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
2013-05-05 13:37:03 +08:00
signal ( SIGPIPE , SIG_IGN ) ;
2018-04-30 23:31:11 +08:00
# else
SetConsoleCtrlHandler ( consoleCtrlHandler , true ) ;
2011-05-14 20:10:21 +02:00
# endif
2017-02-24 18:20:03 -05:00
std : : set_new_handler ( new_handler_terminate ) ;
2016-10-25 11:34:27 +02:00
return true ;
}
2011-05-14 20:10:21 +02:00
2023-05-04 12:07:26 +01:00
bool AppInitParameterInteraction ( const ArgsManager & args )
2016-10-25 11:34:27 +02:00
{
2015-04-09 15:58:34 +02:00
const CChainParams & chainparams = Params ( ) ;
2016-10-25 11:34:27 +02:00
// ********************************************************* Step 2: parameter interactions
2014-11-13 15:15:53 +01:00
2015-11-28 22:28:21 +01:00
// also see: InitParameterInteraction()
2014-02-14 11:33:07 -05:00
2020-06-01 18:05:15 +10:00
// Error if network-specific options (-addnode, -connect, etc) are
2019-03-19 16:37:39 -04:00
// specified in default section of config file, but not overridden
2023-04-17 22:20:59 +02:00
// on the command line or in this chain's section of the config file.
ChainType chain = args . GetChainType ( ) ;
if ( chain = = ChainType : : SIGNET ) {
2020-09-30 19:08:52 +02:00
LogPrintf ( " Signet derived magic (message start): %s \n " , HexStr ( chainparams . MessageStart ( ) ) ) ;
}
2020-06-01 18:05:15 +10:00
bilingual_str errors ;
2020-08-21 20:38:01 +02:00
for ( const auto & arg : args . GetUnsuitableSectionOnlyArgs ( ) ) {
2023-04-17 22:20:59 +02:00
errors + = strprintf ( _ ( " Config setting for %s only applied on %s network when in [%s] section. " ) + Untranslated ( " \n " ) , arg , ChainTypeToString ( chain ) , ChainTypeToString ( chain ) ) ;
2020-06-01 18:05:15 +10:00
}
if ( ! errors . empty ( ) ) {
return InitError ( errors ) ;
2019-03-19 16:37:39 -04:00
}
// Warn if unrecognized section name are present in the config file.
2020-06-01 18:05:15 +10:00
bilingual_str warnings ;
2020-08-21 20:38:01 +02:00
for ( const auto & section : args . GetUnrecognizedSections ( ) ) {
2020-06-01 18:05:15 +10:00
warnings + = strprintf ( Untranslated ( " %s:%i " ) + _ ( " Section [%s] is not recognized. " ) + Untranslated ( " \n " ) , section . m_file , section . m_line , section . m_name ) ;
}
if ( ! warnings . empty ( ) ) {
InitWarning ( warnings ) ;
2019-03-19 16:37:39 -04:00
}
2023-03-10 12:36:47 +01:00
if ( ! fs : : is_directory ( args . GetBlocksDirPath ( ) ) ) {
2020-08-21 20:38:01 +02:00
return InitError ( strprintf ( _ ( " Specified blocks directory \" %s \" does not exist. " ) , args . GetArg ( " -blocksdir " , " " ) ) ) ;
2018-03-09 12:12:43 +08:00
}
2018-08-29 22:15:50 -07:00
// parse and validate enabled filter types
2020-08-21 20:38:01 +02:00
std : : string blockfilterindex_value = args . GetArg ( " -blockfilterindex " , DEFAULT_BLOCKFILTERINDEX ) ;
2018-08-29 22:15:50 -07:00
if ( blockfilterindex_value = = " " | | blockfilterindex_value = = " 1 " ) {
g_enabled_filter_types = AllBlockFilterTypes ( ) ;
} else if ( blockfilterindex_value ! = " 0 " ) {
2020-08-21 20:38:01 +02:00
const std : : vector < std : : string > names = args . GetArgs ( " -blockfilterindex " ) ;
2018-08-29 22:15:50 -07:00
for ( const auto & name : names ) {
BlockFilterType filter_type ;
if ( ! BlockFilterTypeByName ( name , filter_type ) ) {
2020-04-11 18:48:04 +03:00
return InitError ( strprintf ( _ ( " Unknown -blockfilterindex value %s. " ) , name ) ) ;
2018-08-29 22:15:50 -07:00
}
2019-12-06 21:47:55 +01:00
g_enabled_filter_types . insert ( filter_type ) ;
2018-08-29 22:15:50 -07:00
}
}
2020-05-04 11:13:13 -04:00
// Signal NODE_COMPACT_FILTERS if peerblockfilters and basic filters index are both enabled.
2020-08-21 20:38:01 +02:00
if ( args . GetBoolArg ( " -peerblockfilters " , DEFAULT_PEERBLOCKFILTERS ) ) {
2020-05-04 11:13:13 -04:00
if ( g_enabled_filter_types . count ( BlockFilterType : : BASIC ) ! = 1 ) {
return InitError ( _ ( " Cannot set -peerblockfilters without -blockfilterindex. " ) ) ;
}
nLocalServices = ServiceFlags ( nLocalServices | NODE_COMPACT_FILTERS ) ;
2020-05-04 13:45:41 -04:00
}
2019-08-22 21:40:41 -04:00
if ( args . GetIntArg ( " -prune " , 0 ) ) {
2020-08-21 20:38:01 +02:00
if ( args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) )
2020-04-11 18:48:04 +03:00
return InitError ( _ ( " Prune mode is incompatible with -txindex. " ) ) ;
2022-03-21 13:13:49 +01:00
if ( args . GetBoolArg ( " -reindex-chainstate " , false ) ) {
return InitError ( _ ( " Prune mode is incompatible with -reindex-chainstate. Use full -reindex instead. " ) ) ;
}
Add block pruning functionality
This adds a -prune=N option to bitcoind, which if set to N>0 will enable block
file pruning. When pruning is enabled, block and undo files will be deleted to
try to keep total space used by those files to below the prune target (N, in
MB) specified by the user, subject to some constraints:
- The last 288 blocks on the main chain are always kept (MIN_BLOCKS_TO_KEEP),
- N must be at least 550MB (chosen as a value for the target that could
reasonably be met, with some assumptions about block sizes, orphan rates,
etc; see comment in main.h),
- No blocks are pruned until chainActive is at least 100,000 blocks long (on
mainnet; defined separately for mainnet, testnet, and regtest in chainparams
as nPruneAfterHeight).
This unsets NODE_NETWORK if pruning is enabled.
Also included is an RPC test for pruning (pruning.py).
Thanks to @rdponticelli for earlier work on this feature; this is based in
part off that work.
2015-02-23 14:27:44 -05:00
}
2015-11-14 04:46:23 -08:00
2021-05-28 13:30:35 -07:00
// If -forcednsseed is set to true, ensure -dnsseed has not been set to false
if ( args . GetBoolArg ( " -forcednsseed " , DEFAULT_FORCEDNSSEED ) & & ! args . GetBoolArg ( " -dnsseed " , DEFAULT_DNSSEED ) ) {
return InitError ( _ ( " Cannot set -forcednsseed to true when setting -dnsseed to false. " ) ) ;
}
2017-06-01 12:34:02 +02:00
// -bind and -whitebind can't be set when not listening
2020-08-21 20:38:01 +02:00
size_t nUserBind = args . GetArgs ( " -bind " ) . size ( ) + args . GetArgs ( " -whitebind " ) . size ( ) ;
if ( nUserBind ! = 0 & & ! args . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) ) {
2020-04-11 18:48:04 +03:00
return InitError ( Untranslated ( " Cannot set -bind or -whitebind together with -listen=0 " ) ) ;
2017-06-01 12:34:02 +02:00
}
2020-12-26 12:01:25 +03:30
// if listen=0, then disallow listenonion=1
if ( ! args . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) & & args . GetBoolArg ( " -listenonion " , DEFAULT_LISTEN_ONION ) ) {
return InitError ( Untranslated ( " Cannot set -listen=0 together with -listenonion=1 " ) ) ;
}
2014-11-16 03:19:23 -08:00
// Make sure enough file descriptors are available
2017-06-01 12:34:02 +02:00
int nBind = std : : max ( nUserBind , size_t ( 1 ) ) ;
2019-08-22 21:40:41 -04:00
nUserMaxConnections = args . GetIntArg ( " -maxconnections " , DEFAULT_MAX_PEER_CONNECTIONS ) ;
2016-10-25 11:34:27 +02:00
nMaxConnections = std : : max ( nUserMaxConnections , 0 ) ;
2014-11-16 03:19:23 -08:00
2020-07-13 13:20:47 -04:00
nFD = RaiseFileDescriptorLimit ( nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS + nBind + NUM_FDS_MESSAGE_CAPTURE ) ;
2018-11-13 14:09:05 -05:00
# ifdef USE_POLL
int fd_max = nFD ;
# else
int fd_max = FD_SETSIZE ;
# endif
2021-09-29 11:26:12 +03:00
// Trim requested connection counts, to fit into system limitations
// <int> in std::min<int>(...) to work around FreeBSD compilation issue described in #2695
2020-07-13 13:20:47 -04:00
nMaxConnections = std : : max ( std : : min < int > ( nMaxConnections , fd_max - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE ) , 0 ) ;
2014-11-16 03:19:23 -08:00
if ( nFD < MIN_CORE_FILEDESCRIPTORS )
2020-04-11 18:48:04 +03:00
return InitError ( _ ( " Not enough file descriptors available. " ) ) ;
2020-07-13 13:20:47 -04:00
nMaxConnections = std : : min ( nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE , nMaxConnections ) ;
2014-11-16 03:19:23 -08:00
if ( nMaxConnections < nUserMaxConnections )
2020-05-09 14:46:01 +03:00
InitWarning ( strprintf ( _ ( " Reducing -maxconnections from %d to %d, because of system limitations. " ) , nUserMaxConnections , nMaxConnections ) ) ;
2014-11-16 03:19:23 -08:00
2012-05-21 16:47:29 +02:00
// ********************************************************* Step 3: parameter-to-internal-flags
2023-05-12 00:23:21 +02:00
auto result = init : : SetLoggingCategories ( args ) ;
if ( ! result ) return InitError ( util : : ErrorString ( result ) ) ;
2023-05-12 00:58:35 +02:00
result = init : : SetLoggingLevel ( args ) ;
if ( ! result ) return InitError ( util : : ErrorString ( result ) ) ;
2017-04-02 19:56:03 -04:00
2019-08-22 21:40:41 -04:00
nConnectTimeout = args . GetIntArg ( " -timeout " , DEFAULT_CONNECT_TIMEOUT ) ;
2018-11-15 15:30:26 -08:00
if ( nConnectTimeout < = 0 ) {
2014-09-25 09:01:54 +02:00
nConnectTimeout = DEFAULT_CONNECT_TIMEOUT ;
2018-11-15 15:30:26 -08:00
}
2019-08-22 21:40:41 -04:00
peer_connect_timeout = args . GetIntArg ( " -peertimeout " , DEFAULT_PEER_CONNECT_TIMEOUT ) ;
2018-11-15 15:30:26 -08:00
if ( peer_connect_timeout < = 0 ) {
2022-06-30 03:38:27 +05:30
return InitError ( Untranslated ( " peertimeout must be a positive integer. " ) ) ;
2018-11-15 15:30:26 -08:00
}
2012-05-21 16:47:29 +02:00
2016-12-13 11:51:51 -05:00
// Sanity check argument for min fee for including tx in block
// TODO: Harmonize which arguments need sanity checking and where that happens
2020-08-21 20:38:01 +02:00
if ( args . IsArgSet ( " -blockmintxfee " ) ) {
2021-06-11 12:33:20 +08:00
if ( ! ParseMoney ( args . GetArg ( " -blockmintxfee " , " " ) ) ) {
2020-08-21 20:38:01 +02:00
return InitError ( AmountErrMsg ( " blockmintxfee " , args . GetArg ( " -blockmintxfee " , " " ) ) ) ;
2021-06-11 12:33:20 +08:00
}
2016-12-13 11:51:51 -05:00
}
2019-08-22 21:40:41 -04:00
nBytesPerSigOp = args . GetIntArg ( " -bytespersigop " , nBytesPerSigOp ) ;
2015-06-24 03:36:22 +00:00
2018-04-13 14:05:55 +01:00
if ( ! g_wallet_init_interface . ParameterInteraction ( ) ) return false ;
2014-07-16 20:04:04 -04:00
2015-06-19 10:42:39 -04:00
// Option to startup with mocktime set (used for regression testing):
2019-08-22 21:40:41 -04:00
SetMockTime ( args . GetIntArg ( " -mocktime " , 0 ) ) ; // SetMockTime(0) is a no-op
2015-06-19 10:42:39 -04:00
2020-08-21 20:38:01 +02:00
if ( args . GetBoolArg ( " -peerbloomfilters " , DEFAULT_PEERBLOOMFILTERS ) )
2016-06-08 19:12:22 +02:00
nLocalServices = ServiceFlags ( nLocalServices | NODE_BLOOM ) ;
2015-08-20 21:15:27 -07:00
2019-08-22 21:40:41 -04:00
if ( args . GetIntArg ( " -rpcserialversion " , DEFAULT_RPC_SERIALIZE_VERSION ) < 0 )
2020-04-11 18:48:04 +03:00
return InitError ( Untranslated ( " rpcserialversion must be non-negative. " ) ) ;
2016-11-20 09:54:51 -05:00
2019-08-22 21:40:41 -04:00
if ( args . GetIntArg ( " -rpcserialversion " , DEFAULT_RPC_SERIALIZE_VERSION ) > 1 )
2020-04-11 18:48:04 +03:00
return InitError ( Untranslated ( " Unknown rpcserialversion requested. " ) ) ;
2016-12-05 23:26:32 -08:00
2022-07-21 11:13:13 +02:00
// Also report errors from parsing before daemonization
{
2023-05-09 11:15:46 +02:00
kernel : : Notifications notifications { } ;
2022-07-21 11:13:13 +02:00
ChainstateManager : : Options chainman_opts_dummy {
. chainparams = chainparams ,
2022-08-16 23:32:55 -04:00
. datadir = args . GetDataDirNet ( ) ,
2023-05-10 22:29:17 +02:00
. notifications = notifications ,
2022-07-21 11:13:13 +02:00
} ;
2022-09-01 15:35:23 -04:00
auto chainman_result { ApplyArgsManOptions ( args , chainman_opts_dummy ) } ;
if ( ! chainman_result ) {
return InitError ( util : : ErrorString ( chainman_result ) ) ;
2022-07-21 11:13:13 +02:00
}
2023-02-18 18:17:33 +01:00
BlockManager : : Options blockman_opts_dummy {
2023-05-04 12:19:35 +02:00
. chainparams = chainman_opts_dummy . chainparams ,
2023-02-18 18:17:33 +01:00
. blocks_dir = args . GetBlocksDirPath ( ) ,
2023-06-15 23:09:37 +02:00
. notifications = chainman_opts_dummy . notifications ,
2023-05-04 12:19:35 +02:00
} ;
2022-09-01 15:35:23 -04:00
auto blockman_result { ApplyArgsManOptions ( args , blockman_opts_dummy ) } ;
if ( ! blockman_result ) {
return InitError ( util : : ErrorString ( blockman_result ) ) ;
2023-01-03 13:12:45 +01:00
}
2022-07-21 11:13:13 +02:00
}
2016-10-25 11:34:27 +02:00
return true ;
}
2016-07-25 17:22:37 -04:00
2016-10-25 12:03:22 +02:00
static bool LockDataDirectory ( bool probeOnly )
2016-10-25 11:34:27 +02:00
{
2012-05-21 16:47:29 +02:00
// Make sure only a single Bitcoin process is using the data directory.
2022-07-26 11:12:53 +02:00
const fs : : path & datadir = gArgs . GetDataDirNet ( ) ;
2018-03-07 03:08:55 -08:00
if ( ! DirIsWritable ( datadir ) ) {
2021-09-10 00:17:20 -04:00
return InitError ( strprintf ( _ ( " Cannot write to data directory '%s'; check permissions. " ) , fs : : PathToString ( datadir ) ) ) ;
2018-03-07 03:08:55 -08:00
}
2017-12-26 19:41:55 +13:00
if ( ! LockDirectory ( datadir , " .lock " , probeOnly ) ) {
2021-09-10 00:17:20 -04:00
return InitError ( strprintf ( _ ( " Cannot obtain a lock on data directory %s. %s is probably already running. " ) , fs : : PathToString ( datadir ) , PACKAGE_NAME ) ) ;
2015-05-18 19:37:43 -04:00
}
2016-10-25 11:34:27 +02:00
return true ;
}
2022-05-27 16:47:05 -04:00
bool AppInitSanityChecks ( const kernel : : Context & kernel )
2016-10-25 12:03:22 +02:00
{
// ********************************************************* Step 4: sanity checks
2022-09-01 15:35:23 -04:00
auto result { kernel : : SanityChecks ( kernel ) } ;
if ( ! result ) {
InitError ( util : : ErrorString ( result ) ) ;
2020-04-11 18:48:04 +03:00
return InitError ( strprintf ( _ ( " Initialization sanity check failed. %s is shutting down. " ) , PACKAGE_NAME ) ) ;
2021-04-18 18:58:43 -04:00
}
2016-10-25 12:03:22 +02:00
// Probe the data directory lock to give an early error message, if possible
2017-07-15 10:46:06 +02:00
// We cannot hold the data directory lock here, as the forking for daemon() hasn't yet happened,
// and a fork will cause weird behavior to it.
2016-10-25 12:03:22 +02:00
return LockDataDirectory ( true ) ;
}
2017-07-15 10:46:06 +02:00
bool AppInitLockDataDirectory ( )
2016-10-25 11:34:27 +02:00
{
2016-10-25 12:03:22 +02:00
// After daemonization get the data directory lock again and hold on to it until exit
// This creates a slight window for a race condition to happen, however this condition is harmless: it
// will at most make us exit without printing a message to console.
if ( ! LockDataDirectory ( false ) ) {
// Detailed error printed inside LockDataDirectory
return false ;
}
2017-07-15 10:46:06 +02:00
return true ;
}
2015-05-18 19:37:43 -04:00
2020-05-29 00:07:18 -04:00
bool AppInitInterfaces ( NodeContext & node )
{
2017-12-05 15:57:12 -05:00
node . chain = node . init - > makeChain ( ) ;
2020-05-29 00:07:18 -04:00
return true ;
}
2021-04-02 13:35:01 -04:00
bool AppInitMain ( NodeContext & node , interfaces : : BlockAndHeaderTipInfo * tip_info )
2017-07-15 10:46:06 +02:00
{
2020-08-21 20:13:40 +02:00
const ArgsManager & args = * Assert ( node . args ) ;
2017-07-15 10:46:06 +02:00
const CChainParams & chainparams = Params ( ) ;
2021-11-17 12:47:30 +02:00
auto opt_max_upload = ParseByteUnits ( args . GetArg ( " -maxuploadtarget " , DEFAULT_MAX_UPLOAD_TARGET ) , ByteUnit : : M ) ;
if ( ! opt_max_upload ) {
2022-02-03 13:36:10 +01:00
return InitError ( strprintf ( _ ( " Unable to parse -maxuploadtarget: '%s' " ) , args . GetArg ( " -maxuploadtarget " , " " ) ) ) ;
2021-11-17 12:47:30 +02:00
}
2017-07-15 10:46:06 +02:00
// ********************************************************* Step 4a: application initialization
2020-08-21 20:13:40 +02:00
if ( ! CreatePidFile ( args ) ) {
2019-02-02 00:40:36 +02:00
// Detailed error printed inside CreatePidFile().
return false ;
}
2021-04-18 19:05:03 -04:00
if ( ! init : : StartLogging ( args ) ) {
// Detailed error printed inside StartLogging().
return false ;
2018-08-24 15:03:01 -07:00
}
2016-12-11 04:39:26 +00:00
LogPrintf ( " Using at most %i automatic connections (%i file descriptors available) \n " , nMaxConnections , nFD ) ;
2011-05-14 20:10:21 +02:00
2018-01-18 13:15:00 -05:00
// Warn about relative -datadir path.
2022-02-04 18:23:50 +02:00
if ( args . IsArgSet ( " -datadir " ) & & ! args . GetPathArg ( " -datadir " ) . is_absolute ( ) ) {
2018-04-05 10:17:32 -04:00
LogPrintf ( " Warning: relative datadir option '%s' specified, which will be interpreted relative to the " /* Continued */
2018-01-18 13:15:00 -05:00
" current working directory '%s'. This is fragile, because if bitcoin is started in the future "
" from a different location, it will be unable to locate the current data files. There could "
" also be data loss if bitcoin is started while in a temporary directory. \n " ,
2021-09-10 00:17:20 -04:00
args . GetArg ( " -datadir " , " " ) , fs : : PathToString ( fs : : current_path ( ) ) ) ;
2018-01-18 13:15:00 -05:00
}
2022-06-30 23:47:41 -04:00
ValidationCacheSizes validation_cache_sizes { } ;
ApplyArgsManOptions ( args , validation_cache_sizes ) ;
if ( ! InitSignatureCache ( validation_cache_sizes . signature_cache_bytes )
| | ! InitScriptExecutionCache ( validation_cache_sizes . script_execution_cache_bytes ) )
{
return InitError ( strprintf ( _ ( " Unable to allocate memory for -maxsigcachesize: '%s' MiB " ) , args . GetIntArg ( " -maxsigcachesize " , DEFAULT_MAX_SIG_CACHE_BYTES > > 20 ) ) ) ;
2022-06-30 23:10:55 -04:00
}
2016-10-05 16:58:47 -04:00
2019-08-22 21:40:41 -04:00
int script_threads = args . GetIntArg ( " -par " , DEFAULT_SCRIPTCHECK_THREADS ) ;
2019-11-02 17:14:38 -04:00
if ( script_threads < = 0 ) {
// -par=0 means autodetect (number of cores - 1 script threads)
// -par=-n means "leave n cores free" (number of cores - n - 1 script threads)
script_threads + = GetNumCores ( ) ;
}
// Subtract 1 because the main thread counts towards the par threads
script_threads = std : : max ( script_threads - 1 , 0 ) ;
// Number of script-checking threads <= MAX_SCRIPTCHECK_THREADS
script_threads = std : : min ( script_threads , MAX_SCRIPTCHECK_THREADS ) ;
LogPrintf ( " Script verification uses %d additional threads \n " , script_threads ) ;
if ( script_threads > = 1 ) {
2020-08-21 09:24:05 +03:00
StartScriptCheckWorkerThreads ( script_threads ) ;
2012-12-01 23:04:14 +01:00
}
2020-02-12 11:08:28 -08:00
assert ( ! node . scheduler ) ;
2021-03-10 17:28:08 +08:00
node . scheduler = std : : make_unique < CScheduler > ( ) ;
2020-02-12 11:08:28 -08:00
2015-04-03 11:50:06 -04:00
// Start the lightweight task scheduler thread
2021-04-13 21:17:55 +03:00
node . scheduler - > m_service_thread = std : : thread ( util : : TraceThread , " scheduler " , [ & ] { node . scheduler - > serviceQueue ( ) ; } ) ;
2015-04-03 11:50:06 -04:00
2019-10-29 11:55:59 -07:00
// Gather some entropy once per minute.
2020-02-12 11:08:28 -08:00
node . scheduler - > scheduleEvery ( [ ] {
2019-10-29 11:55:59 -07:00
RandAddPeriodic ( ) ;
2020-03-06 18:06:50 -05:00
} , std : : chrono : : minutes { 1 } ) ;
2019-10-29 11:55:59 -07:00
2020-02-12 11:08:28 -08:00
GetMainSignals ( ) . RegisterBackgroundSignalScheduler ( * node . scheduler ) ;
2017-01-19 16:49:22 -05:00
2021-08-30 21:04:06 -04:00
// Create client interfaces for wallets that are supposed to be loaded
// according to -wallet and -disablewallet options. This only constructs
// the interfaces, it doesn't load wallet data. Wallets actually get loaded
// when load() and start() interface methods are called below.
g_wallet_init_interface . Construct ( node ) ;
uiInterface . InitWallet ( ) ;
2017-11-03 16:28:18 -04:00
/* Register RPC commands regardless of -server setting so they will be
* available in the GUI RPC console even if external calls are disabled .
*/
RegisterAllCoreRPCCommands ( tableRPC ) ;
2019-09-17 17:04:39 -04:00
for ( const auto & client : node . chain_clients ) {
2017-09-28 14:13:29 -04:00
client - > registerRpcs ( ) ;
}
2018-06-29 16:10:01 +02:00
# if ENABLE_ZMQ
RegisterZMQRPCCommands ( tableRPC ) ;
# endif
2017-11-03 16:28:18 -04:00
2014-10-29 18:08:31 +01:00
/* Start the RPC server already. It will be started in "warmup" mode
* and not really process calls already ( but it will signify connections
* that the server is there and will be ready later ) . Warmup mode will
* be disabled when initialisation is finished .
*/
2020-08-21 20:38:01 +02:00
if ( args . GetBoolArg ( " -server " , false ) ) {
2018-07-11 08:00:15 -04:00
uiInterface . InitMessage_connect ( SetRPCWarmupStatus ) ;
2021-04-02 13:35:01 -04:00
if ( ! AppInitServers ( node ) )
2020-04-11 18:48:04 +03:00
return InitError ( _ ( " Unable to start HTTP server. See debug log for details. " ) ) ;
2014-10-29 18:08:31 +01:00
}
2013-01-11 23:18:00 +01:00
// ********************************************************* Step 5: verify wallet database integrity
2019-09-17 17:04:39 -04:00
for ( const auto & client : node . chain_clients ) {
2017-09-28 14:13:29 -04:00
if ( ! client - > verify ( ) ) {
return false ;
}
}
2018-02-21 11:38:53 -05:00
2012-09-18 14:30:47 -04:00
// ********************************************************* Step 6: network initialization
2016-10-02 11:29:35 -04:00
// Note that we absolutely cannot open any actual connections
// until the very end ("start node") as the UTXO/block state
// is not yet setup and may end up being set up twice if we
// need to reindex later.
2012-05-21 16:47:29 +02:00
2020-09-06 19:37:13 +02:00
fListen = args . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) ;
fDiscover = args . GetBoolArg ( " -discover " , true ) ;
2020-10-22 10:56:38 +01:00
const bool ignores_incoming_txs { args . GetBoolArg ( " -blocksonly " , DEFAULT_BLOCKSONLY ) } ;
2020-09-06 19:37:13 +02:00
2021-08-05 11:09:55 +01:00
{
2021-08-24 09:49:01 +01:00
// Read asmap file if configured
std : : vector < bool > asmap ;
if ( args . IsArgSet ( " -asmap " ) ) {
2022-02-05 19:36:33 +01:00
fs : : path asmap_path = args . GetPathArg ( " -asmap " , DEFAULT_ASMAP_FILENAME ) ;
2021-08-24 09:49:01 +01:00
if ( ! asmap_path . is_absolute ( ) ) {
2023-03-10 12:36:47 +01:00
asmap_path = args . GetDataDirNet ( ) / asmap_path ;
2021-08-24 09:49:01 +01:00
}
if ( ! fs : : exists ( asmap_path ) ) {
2021-09-10 00:17:20 -04:00
InitError ( strprintf ( _ ( " Could not find asmap file %s " ) , fs : : quoted ( fs : : PathToString ( asmap_path ) ) ) ) ;
2021-08-24 09:49:01 +01:00
return false ;
}
2021-09-01 12:41:47 +01:00
asmap = DecodeAsmap ( asmap_path ) ;
2021-08-24 09:49:01 +01:00
if ( asmap . size ( ) = = 0 ) {
2021-09-10 00:17:20 -04:00
InitError ( strprintf ( _ ( " Could not parse asmap file %s " ) , fs : : quoted ( fs : : PathToString ( asmap_path ) ) ) ) ;
2021-08-24 09:49:01 +01:00
return false ;
}
const uint256 asmap_version = SerializeHash ( asmap ) ;
LogPrintf ( " Using asmap version %s for IP bucketing \n " , asmap_version . ToString ( ) ) ;
} else {
LogPrintf ( " Using /16 prefix for IP bucketing \n " ) ;
}
2021-08-31 13:32:40 +01:00
// Initialize netgroup manager
assert ( ! node . netgroupman ) ;
2021-08-31 18:40:18 +01:00
node . netgroupman = std : : make_unique < NetGroupManager > ( std : : move ( asmap ) ) ;
2021-08-31 13:32:40 +01:00
// Initialize addrman
assert ( ! node . addrman ) ;
2021-08-05 11:09:55 +01:00
uiInterface . InitMessage ( _ ( " Loading P2P addresses… " ) . translated ) ;
2022-09-01 15:35:23 -04:00
auto addrman { LoadAddrman ( * node . netgroupman , args ) } ;
if ( ! addrman ) return InitError ( util : : ErrorString ( addrman ) ) ;
node . addrman = std : : move ( * addrman ) ;
2021-08-05 11:09:55 +01:00
}
2021-08-24 09:49:01 +01:00
2019-09-17 18:59:36 -04:00
assert ( ! node . banman ) ;
2023-03-10 12:36:47 +01:00
node . banman = std : : make_unique < BanMan > ( args . GetDataDirNet ( ) / " banlist " , & uiInterface , args . GetIntArg ( " -bantime " , DEFAULT_MISBEHAVING_BANTIME ) ) ;
2019-09-17 18:59:36 -04:00
assert ( ! node . connman ) ;
2022-01-31 19:32:59 +07:00
node . connman = std : : make_unique < CConnman > ( GetRand < uint64_t > ( ) ,
GetRand < uint64_t > ( ) ,
2021-08-31 18:40:18 +01:00
* node . addrman , * node . netgroupman , args . GetBoolArg ( " -networkactive " , true ) ) ;
2020-07-19 09:07:54 +02:00
2020-07-28 19:12:50 +02:00
assert ( ! node . fee_estimator ) ;
2020-09-06 19:37:13 +02:00
// Don't initialize fee estimation with old data if we don't relay transactions,
// as they would never get updated.
2023-06-08 13:14:11 +01:00
if ( ! ignores_incoming_txs ) {
2023-06-14 22:39:26 +01:00
bool read_stale_estimates = args . GetBoolArg ( " -acceptstalefeeestimates " , DEFAULT_ACCEPT_STALE_FEE_ESTIMATES ) ;
if ( read_stale_estimates & & ( chainparams . GetChainType ( ) ! = ChainType : : REGTEST ) ) {
return InitError ( strprintf ( _ ( " acceptstalefeeestimates is not supported on %s chain. " ) , chainparams . GetChainTypeString ( ) ) ) ;
}
node . fee_estimator = std : : make_unique < CBlockPolicyEstimator > ( FeeestPath ( args ) , read_stale_estimates ) ;
2023-06-08 13:14:11 +01:00
// Flush estimates to disk periodically
CBlockPolicyEstimator * fee_estimator = node . fee_estimator . get ( ) ;
node . scheduler - > scheduleEvery ( [ fee_estimator ] { fee_estimator - > FlushFeeEstimates ( ) ; } , FEE_FLUSH_INTERVAL ) ;
}
2020-07-28 19:12:50 +02:00
2021-05-27 14:07:35 +02:00
// Check port numbers
for ( const std : : string port_option : {
" -port " ,
" -rpcport " ,
} ) {
if ( args . IsArgSet ( port_option ) ) {
const std : : string port = args . GetArg ( port_option , " " ) ;
uint16_t n ;
if ( ! ParseUInt16 ( port , & n ) | | n = = 0 ) {
return InitError ( InvalidPortErrMsg ( port_option , port ) ) ;
}
}
}
for ( const std : : string port_option : {
" -i2psam " ,
" -onion " ,
" -proxy " ,
" -rpcbind " ,
" -torcontrol " ,
" -whitebind " ,
" -zmqpubhashblock " ,
" -zmqpubhashtx " ,
" -zmqpubrawblock " ,
" -zmqpubrawtx " ,
" -zmqpubsequence " ,
} ) {
for ( const std : : string & socket_addr : args . GetArgs ( port_option ) ) {
std : : string host_out ;
uint16_t port_out { 0 } ;
if ( ! SplitHostPort ( socket_addr , port_out , host_out ) ) {
return InitError ( InvalidPortErrMsg ( port_option , socket_addr ) ) ;
}
}
}
for ( const std : : string & socket_addr : args . GetArgs ( " -bind " ) ) {
std : : string host_out ;
uint16_t port_out { 0 } ;
std : : string bind_socket_addr = socket_addr . substr ( 0 , socket_addr . rfind ( ' = ' ) ) ;
if ( ! SplitHostPort ( bind_socket_addr , port_out , host_out ) ) {
return InitError ( InvalidPortErrMsg ( " -bind " , socket_addr ) ) ;
}
}
2015-09-09 14:24:56 +02:00
// sanitize comments per BIP-0014, format user agent and check total size
2017-01-27 17:43:41 +09:00
std : : vector < std : : string > uacomments ;
2020-08-21 20:38:01 +02:00
for ( const std : : string & cmt : args . GetArgs ( " -uacomment " ) ) {
2017-06-27 03:10:39 +02:00
if ( cmt ! = SanitizeString ( cmt , SAFE_CHARS_UA_COMMENT ) )
2020-04-11 18:48:04 +03:00
return InitError ( strprintf ( _ ( " User Agent comment (%s) contains unsafe characters . " ), cmt)) ;
2017-06-27 03:10:39 +02:00
uacomments . push_back ( cmt ) ;
2015-09-09 14:24:56 +02:00
}
strSubVersion = FormatSubVersion ( CLIENT_NAME , CLIENT_VERSION , uacomments ) ;
2015-07-31 18:05:42 +02:00
if ( strSubVersion . size ( ) > MAX_SUBVERSION_LENGTH ) {
2020-04-11 18:48:04 +03:00
return InitError ( strprintf ( _ ( " Total length of network version string (%i) exceeds maximum length (%i). Reduce the number or size of uacomments. " ) ,
2015-07-31 18:05:42 +02:00
strSubVersion . size ( ) , MAX_SUBVERSION_LENGTH ) ) ;
}
2020-08-21 20:38:01 +02:00
if ( args . IsArgSet ( " -onlynet " ) ) {
2012-05-21 16:47:29 +02:00
std : : set < enum Network > nets ;
2020-08-21 20:38:01 +02:00
for ( const std : : string & snet : args . GetArgs ( " -onlynet " ) ) {
2012-05-21 16:47:29 +02:00
enum Network net = ParseNetwork ( snet ) ;
if ( net = = NET_UNROUTABLE )
2020-04-11 18:48:04 +03:00
return InitError ( strprintf ( _ ( " Unknown network specified in -onlynet: '%s' " ) , snet ) ) ;
2012-05-21 16:47:29 +02:00
nets . insert ( net ) ;
}
for ( int n = 0 ; n < NET_MAX ; n + + ) {
enum Network net = ( enum Network ) n ;
2022-01-30 22:46:25 +01:00
assert ( IsReachable ( net ) ) ;
2012-05-21 16:47:29 +02:00
if ( ! nets . count ( net ) )
2019-01-09 16:41:37 -08:00
SetReachable ( net , false ) ;
2012-05-21 16:47:29 +02:00
}
}
2021-09-09 17:40:11 +02:00
if ( ! args . IsArgSet ( " -cjdnsreachable " ) ) {
2022-09-01 18:25:25 -04:00
if ( args . IsArgSet ( " -onlynet " ) & & IsReachable ( NET_CJDNS ) ) {
return InitError (
_ ( " Outbound connections restricted to CJDNS (-onlynet=cjdns) but "
" -cjdnsreachable is not provided " ) ) ;
}
2021-09-09 17:40:11 +02:00
SetReachable ( NET_CJDNS , false ) ;
}
// Now IsReachable(NET_CJDNS) is true if:
// 1. -cjdnsreachable is given and
// 2.1. -onlynet is not given or
// 2.2. -onlynet=cjdns is given
2022-07-22 14:51:44 -04:00
// Requesting DNS seeds entails connecting to IPv4/IPv6, which -onlynet options may prohibit:
// If -dnsseed=1 is explicitly specified, abort. If it's left unspecified by the user, we skip
// the DNS seeds by adjusting -dnsseed in InitParameterInteraction.
if ( args . GetBoolArg ( " -dnsseed " ) = = true & & ! IsReachable ( NET_IPV4 ) & & ! IsReachable ( NET_IPV6 ) ) {
return InitError ( strprintf ( _ ( " Incompatible options: -dnsseed=1 was explicitly specified, but -onlynet forbids connections to IPv4/IPv6 " ) ) ) ;
} ;
2017-02-15 17:08:36 -08:00
// Check for host lookup allowed before parsing any network related parameters
2020-08-21 20:38:01 +02:00
fNameLookup = args . GetBoolArg ( " -dns " , DEFAULT_NAME_LOOKUP ) ;
2017-02-15 17:08:36 -08:00
2021-11-08 17:34:32 +01:00
Proxy onion_proxy ;
2021-08-30 14:33:29 +02:00
2020-08-21 20:38:01 +02:00
bool proxyRandomize = args . GetBoolArg ( " -proxyrandomize " , DEFAULT_PROXYRANDOMIZE ) ;
2015-06-10 09:19:13 +02:00
// -proxy sets a proxy for all outgoing network traffic
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
2020-08-21 20:38:01 +02:00
std : : string proxyArg = args . GetArg ( " -proxy " , " " ) ;
2015-06-10 09:19:13 +02:00
if ( proxyArg ! = " " & & proxyArg ! = " 0 " ) {
2022-10-10 15:02:59 -03:00
const std : : optional < CService > proxyAddr { Lookup ( proxyArg , 9050 , fNameLookup ) } ;
if ( ! proxyAddr . has_value ( ) ) {
2020-04-11 18:48:04 +03:00
return InitError ( strprintf ( _ ( " Invalid -proxy address or hostname: '%s' " ) , proxyArg ) ) ;
2017-02-15 17:08:36 -08:00
}
2022-10-10 15:02:59 -03:00
Proxy addrProxy = Proxy ( proxyAddr . value ( ) , proxyRandomize ) ;
2012-05-24 19:02:21 +02:00
if ( ! addrProxy . IsValid ( ) )
2020-04-11 18:48:04 +03:00
return InitError ( strprintf ( _ ( " Invalid -proxy address or hostname: '%s' " ) , proxyArg ) ) ;
2012-05-24 19:02:21 +02:00
2014-11-23 15:12:50 -08:00
SetProxy ( NET_IPV4 , addrProxy ) ;
SetProxy ( NET_IPV6 , addrProxy ) ;
2021-09-21 12:26:51 +02:00
SetProxy ( NET_CJDNS , addrProxy ) ;
2014-06-11 13:20:59 +02:00
SetNameProxy ( addrProxy ) ;
2021-08-30 14:33:29 +02:00
onion_proxy = addrProxy ;
2012-05-01 21:04:07 +02:00
}
2022-04-26 10:45:10 +02:00
const bool onlynet_used_with_onion { args . IsArgSet ( " -onlynet " ) & & IsReachable ( NET_ONION ) } ;
2015-06-10 09:19:13 +02:00
// -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
// -noonion (or -onion=0) disables connecting to .onion entirely
// An empty string is used to not override the onion proxy (in which case it defaults to -proxy set above, or none)
2020-08-21 20:38:01 +02:00
std : : string onionArg = args . GetArg ( " -onion " , " " ) ;
2015-06-10 09:19:13 +02:00
if ( onionArg ! = " " ) {
if ( onionArg = = " 0 " ) { // Handle -noonion/-onion=0
2021-11-08 17:34:32 +01:00
onion_proxy = Proxy { } ;
2022-04-26 10:45:10 +02:00
if ( onlynet_used_with_onion ) {
return InitError (
_ ( " Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
" reaching the Tor network is explicitly forbidden: -onion=0 " ) ) ;
}
2015-06-10 09:19:13 +02:00
} else {
2022-10-10 15:02:59 -03:00
const std : : optional < CService > addr { Lookup ( onionArg , 9050 , fNameLookup ) } ;
if ( ! addr . has_value ( ) | | ! addr - > IsValid ( ) ) {
2020-04-11 18:48:04 +03:00
return InitError ( strprintf ( _ ( " Invalid -onion address or hostname: '%s' " ) , onionArg ) ) ;
2017-02-15 17:08:36 -08:00
}
2022-10-10 15:02:59 -03:00
onion_proxy = Proxy { addr . value ( ) , proxyRandomize } ;
2021-08-30 14:33:29 +02:00
}
}
if ( onion_proxy . IsValid ( ) ) {
SetProxy ( NET_ONION , onion_proxy ) ;
} else {
2022-04-26 10:45:10 +02:00
// If -listenonion is set, then we will (try to) connect to the Tor control port
// later from the torcontrol thread and may retrieve the onion proxy from there.
const bool listenonion_disabled { ! args . GetBoolArg ( " -listenonion " , DEFAULT_LISTEN_ONION ) } ;
if ( onlynet_used_with_onion & & listenonion_disabled ) {
2021-08-30 14:33:29 +02:00
return InitError (
_ ( " Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
2022-04-26 10:45:10 +02:00
" reaching the Tor network is not provided: none of -proxy, -onion or "
" -listenonion is given " ) ) ;
2015-06-10 09:19:13 +02:00
}
2021-08-30 14:33:29 +02:00
SetReachable ( NET_ONION , false ) ;
2012-05-24 19:02:21 +02:00
}
2020-08-21 20:38:01 +02:00
for ( const std : : string & strAddr : args . GetArgs ( " -externalip " ) ) {
2022-10-10 15:02:59 -03:00
const std : : optional < CService > addrLocal { Lookup ( strAddr , GetListenPort ( ) , fNameLookup ) } ;
if ( addrLocal . has_value ( ) & & addrLocal - > IsValid ( ) )
AddLocal ( addrLocal . value ( ) , LOCAL_MANUAL ) ;
2017-06-27 03:10:39 +02:00
else
2020-06-05 14:26:16 +02:00
return InitError ( ResolveErrMsg ( " externalip " , strAddr ) ) ;
2012-05-21 16:47:29 +02:00
}
2014-11-18 12:06:32 -05:00
# if ENABLE_ZMQ
2023-05-03 22:24:21 +02:00
g_zmq_notification_interface = CZMQNotificationInterface : : Create (
[ & chainman = node . chainman ] ( CBlock & block , const CBlockIndex & index ) {
assert ( chainman ) ;
2023-02-18 15:49:41 +01:00
return chainman - > m_blockman . ReadBlockFromDisk ( block , index ) ;
2023-05-03 22:24:21 +02:00
} ) ;
2014-11-18 12:06:32 -05:00
2018-06-29 15:16:31 +02:00
if ( g_zmq_notification_interface ) {
2023-04-17 10:42:49 +02:00
RegisterValidationInterface ( g_zmq_notification_interface . get ( ) ) ;
2014-11-18 12:06:32 -05:00
}
# endif
2012-10-05 19:22:21 +02:00
// ********************************************************* Step 7: load block chain
2012-05-21 16:47:29 +02:00
2023-05-09 11:15:46 +02:00
node . notifications = std : : make_unique < KernelNotifications > ( node . exit_status ) ;
2020-08-21 20:38:01 +02:00
fReindex = args . GetBoolArg ( " -reindex " , false ) ;
bool fReindexChainState = args . GetBoolArg ( " -reindex-chainstate " , false ) ;
2022-07-20 18:16:30 +02:00
ChainstateManager : : Options chainman_opts {
. chainparams = chainparams ,
2022-08-16 23:32:55 -04:00
. datadir = args . GetDataDirNet ( ) ,
2022-07-20 18:16:30 +02:00
. adjusted_time_callback = GetAdjustedTime ,
2023-05-10 22:29:17 +02:00
. notifications = * node . notifications ,
2022-07-20 18:16:30 +02:00
} ;
2022-09-01 15:35:23 -04:00
Assert ( ApplyArgsManOptions ( args , chainman_opts ) ) ; // no error can happen, already checked in AppInitParameterInteraction
2012-10-21 21:23:13 +02:00
2023-02-18 18:17:33 +01:00
BlockManager : : Options blockman_opts {
2023-05-04 12:19:35 +02:00
. chainparams = chainman_opts . chainparams ,
2023-02-18 18:17:33 +01:00
. blocks_dir = args . GetBlocksDirPath ( ) ,
2023-06-15 23:09:37 +02:00
. notifications = chainman_opts . notifications ,
2023-05-04 12:19:35 +02:00
} ;
2022-09-01 15:35:23 -04:00
Assert ( ApplyArgsManOptions ( args , blockman_opts ) ) ; // no error can happen, already checked in AppInitParameterInteraction
2023-01-03 13:12:45 +01:00
2012-11-04 17:11:48 +01:00
// cache size calculations
2021-09-21 11:37:03 -04:00
CacheSizes cache_sizes = CalculateCacheSizes ( args , g_enabled_filter_types . size ( ) ) ;
2015-05-04 01:56:42 +02:00
LogPrintf ( " Cache configuration: \n " ) ;
2021-09-21 11:37:03 -04:00
LogPrintf ( " * Using %.1f MiB for block index database \n " , cache_sizes . block_tree_db * ( 1.0 / 1024 / 1024 ) ) ;
2020-08-21 20:38:01 +02:00
if ( args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ) {
2021-09-21 11:37:03 -04:00
LogPrintf ( " * Using %.1f MiB for transaction index database \n " , cache_sizes . tx_index * ( 1.0 / 1024 / 1024 ) ) ;
2017-12-08 11:29:59 -08:00
}
2018-08-29 22:15:50 -07:00
for ( BlockFilterType filter_type : g_enabled_filter_types ) {
LogPrintf ( " * Using %.1f MiB for %s block filter index database \n " ,
2021-09-21 11:37:03 -04:00
cache_sizes . filter_index * ( 1.0 / 1024 / 1024 ) , BlockFilterTypeName ( filter_type ) ) ;
2018-08-29 22:15:50 -07:00
}
2021-09-21 11:37:03 -04:00
LogPrintf ( " * Using %.1f MiB for chain state database \n " , cache_sizes . coins_db * ( 1.0 / 1024 / 1024 ) ) ;
2012-11-04 17:11:48 +01:00
2021-09-13 17:02:55 -04:00
assert ( ! node . mempool ) ;
assert ( ! node . chainman ) ;
pool: Add and use MemPoolOptions, ApplyArgsManOptions
Reviewers: Note that CTxMemPool now requires a non-defaulted
CTxMemPool::Options for its constructor. Meaning that there's no need to
worry about a stray CTxMemPool constructor somewhere defaulting to
something incorrect. All instances of CTxMemPool construction are
addressed here in this commit.
We set options for CTxMemPool and construct it in many different ways. A
good example can be seen in how we determine CTxMemPool's check_ratio in
AppInitMain(...).
1. We first set the default based on chainparams's
DefaultConsistencyChecks()
2. Then, we apply the ArgsManager option on top of that default
3. Finally, we clamp the result of that between 0 and 1 Million
With this patch, most CTxMemPool construction are along the lines of:
MemPoolOptions mempool_opts{...default overrides...};
ApplyArgsManOptions(argsman, mempool_opts);
...hard overrides...
CTxMemPool pool{mempool_opts};
This "compositional" style of building options means that we can omit
unnecessary/irrelevant steps wherever we want but also maintain full
customizability.
For example:
- For users of libbitcoinkernel, where we eventually want to remove
ArgsManager, they simply won't call (or even know about)
ApplyArgsManOptions.
- See src/init.cpp to see how the check_ratio CTxMemPool option works
after this change.
A MemPoolOptionsForTest helper was also added and used by tests/fuzz
tests where a local CTxMemPool needed to be created.
The change in src/test/fuzz/tx_pool.cpp seemingly changes behaviour by
applying ArgsManager options on top of the CTxMemPool::Options defaults.
However, in future commits where we introduce flags like -maxmempool,
the call to ApplyArgsManOptions is actually what preserves the existing
behaviour. Previously, although it wasn't obvious, our CTxMemPool would
consult gArgs for flags like -maxmempool when it needed it, so it
already relied on ArgsManager information. This patchset just laid bare
the obfuscatory perils of globals.
[META] As this patchset progresses, we will move more and more
CTxMemPool-relevant options into MemPoolOptions and add their
ArgsMan-related logic to ApplyArgsManOptions.
2022-03-18 13:51:37 -04:00
CTxMemPool : : Options mempool_opts {
2022-07-01 01:23:02 +02:00
. estimator = node . fee_estimator . get ( ) ,
. check_ratio = chainparams . DefaultConsistencyChecks ( ) ? 1 : 0 ,
pool: Add and use MemPoolOptions, ApplyArgsManOptions
Reviewers: Note that CTxMemPool now requires a non-defaulted
CTxMemPool::Options for its constructor. Meaning that there's no need to
worry about a stray CTxMemPool constructor somewhere defaulting to
something incorrect. All instances of CTxMemPool construction are
addressed here in this commit.
We set options for CTxMemPool and construct it in many different ways. A
good example can be seen in how we determine CTxMemPool's check_ratio in
AppInitMain(...).
1. We first set the default based on chainparams's
DefaultConsistencyChecks()
2. Then, we apply the ArgsManager option on top of that default
3. Finally, we clamp the result of that between 0 and 1 Million
With this patch, most CTxMemPool construction are along the lines of:
MemPoolOptions mempool_opts{...default overrides...};
ApplyArgsManOptions(argsman, mempool_opts);
...hard overrides...
CTxMemPool pool{mempool_opts};
This "compositional" style of building options means that we can omit
unnecessary/irrelevant steps wherever we want but also maintain full
customizability.
For example:
- For users of libbitcoinkernel, where we eventually want to remove
ArgsManager, they simply won't call (or even know about)
ApplyArgsManOptions.
- See src/init.cpp to see how the check_ratio CTxMemPool option works
after this change.
A MemPoolOptionsForTest helper was also added and used by tests/fuzz
tests where a local CTxMemPool needed to be created.
The change in src/test/fuzz/tx_pool.cpp seemingly changes behaviour by
applying ArgsManager options on top of the CTxMemPool::Options defaults.
However, in future commits where we introduce flags like -maxmempool,
the call to ApplyArgsManOptions is actually what preserves the existing
behaviour. Previously, although it wasn't obvious, our CTxMemPool would
consult gArgs for flags like -maxmempool when it needed it, so it
already relied on ArgsManager information. This patchset just laid bare
the obfuscatory perils of globals.
[META] As this patchset progresses, we will move more and more
CTxMemPool-relevant options into MemPoolOptions and add their
ArgsMan-related logic to ApplyArgsManOptions.
2022-03-18 13:51:37 -04:00
} ;
2022-09-01 15:35:23 -04:00
auto result { ApplyArgsManOptions ( args , chainparams , mempool_opts ) } ;
if ( ! result ) {
return InitError ( util : : ErrorString ( result ) ) ;
2022-07-20 15:48:52 +02:00
}
pool: Add and use MemPoolOptions, ApplyArgsManOptions
Reviewers: Note that CTxMemPool now requires a non-defaulted
CTxMemPool::Options for its constructor. Meaning that there's no need to
worry about a stray CTxMemPool constructor somewhere defaulting to
something incorrect. All instances of CTxMemPool construction are
addressed here in this commit.
We set options for CTxMemPool and construct it in many different ways. A
good example can be seen in how we determine CTxMemPool's check_ratio in
AppInitMain(...).
1. We first set the default based on chainparams's
DefaultConsistencyChecks()
2. Then, we apply the ArgsManager option on top of that default
3. Finally, we clamp the result of that between 0 and 1 Million
With this patch, most CTxMemPool construction are along the lines of:
MemPoolOptions mempool_opts{...default overrides...};
ApplyArgsManOptions(argsman, mempool_opts);
...hard overrides...
CTxMemPool pool{mempool_opts};
This "compositional" style of building options means that we can omit
unnecessary/irrelevant steps wherever we want but also maintain full
customizability.
For example:
- For users of libbitcoinkernel, where we eventually want to remove
ArgsManager, they simply won't call (or even know about)
ApplyArgsManOptions.
- See src/init.cpp to see how the check_ratio CTxMemPool option works
after this change.
A MemPoolOptionsForTest helper was also added and used by tests/fuzz
tests where a local CTxMemPool needed to be created.
The change in src/test/fuzz/tx_pool.cpp seemingly changes behaviour by
applying ArgsManager options on top of the CTxMemPool::Options defaults.
However, in future commits where we introduce flags like -maxmempool,
the call to ApplyArgsManOptions is actually what preserves the existing
behaviour. Previously, although it wasn't obvious, our CTxMemPool would
consult gArgs for flags like -maxmempool when it needed it, so it
already relied on ArgsManager information. This patchset just laid bare
the obfuscatory perils of globals.
[META] As this patchset progresses, we will move more and more
CTxMemPool-relevant options into MemPoolOptions and add their
ArgsMan-related logic to ApplyArgsManOptions.
2022-03-18 13:51:37 -04:00
mempool_opts . check_ratio = std : : clamp < int > ( mempool_opts . check_ratio , 0 , 1'000'000 ) ;
2022-06-06 17:14:39 -04:00
int64_t descendant_limit_bytes = mempool_opts . limits . descendant_size_vbytes * 40 ;
if ( mempool_opts . max_size_bytes < 0 | | mempool_opts . max_size_bytes < descendant_limit_bytes ) {
return InitError ( strprintf ( _ ( " -maxmempool must be at least %d MB " ) , std : : ceil ( descendant_limit_bytes / 1'000'000 .0 ) ) ) ;
}
2022-05-18 11:48:29 -04:00
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 ) , mempool_opts . max_size_bytes * ( 1.0 / 1024 / 1024 ) ) ;
2021-09-13 17:02:55 -04:00
2022-02-22 14:20:55 -05:00
for ( bool fLoaded = false ; ! fLoaded & & ! ShutdownRequested ( ) ; ) {
pool: Add and use MemPoolOptions, ApplyArgsManOptions
Reviewers: Note that CTxMemPool now requires a non-defaulted
CTxMemPool::Options for its constructor. Meaning that there's no need to
worry about a stray CTxMemPool constructor somewhere defaulting to
something incorrect. All instances of CTxMemPool construction are
addressed here in this commit.
We set options for CTxMemPool and construct it in many different ways. A
good example can be seen in how we determine CTxMemPool's check_ratio in
AppInitMain(...).
1. We first set the default based on chainparams's
DefaultConsistencyChecks()
2. Then, we apply the ArgsManager option on top of that default
3. Finally, we clamp the result of that between 0 and 1 Million
With this patch, most CTxMemPool construction are along the lines of:
MemPoolOptions mempool_opts{...default overrides...};
ApplyArgsManOptions(argsman, mempool_opts);
...hard overrides...
CTxMemPool pool{mempool_opts};
This "compositional" style of building options means that we can omit
unnecessary/irrelevant steps wherever we want but also maintain full
customizability.
For example:
- For users of libbitcoinkernel, where we eventually want to remove
ArgsManager, they simply won't call (or even know about)
ApplyArgsManOptions.
- See src/init.cpp to see how the check_ratio CTxMemPool option works
after this change.
A MemPoolOptionsForTest helper was also added and used by tests/fuzz
tests where a local CTxMemPool needed to be created.
The change in src/test/fuzz/tx_pool.cpp seemingly changes behaviour by
applying ArgsManager options on top of the CTxMemPool::Options defaults.
However, in future commits where we introduce flags like -maxmempool,
the call to ApplyArgsManOptions is actually what preserves the existing
behaviour. Previously, although it wasn't obvious, our CTxMemPool would
consult gArgs for flags like -maxmempool when it needed it, so it
already relied on ArgsManager information. This patchset just laid bare
the obfuscatory perils of globals.
[META] As this patchset progresses, we will move more and more
CTxMemPool-relevant options into MemPoolOptions and add their
ArgsMan-related logic to ApplyArgsManOptions.
2022-03-18 13:51:37 -04:00
node . mempool = std : : make_unique < CTxMemPool > ( mempool_opts ) ;
2021-09-13 17:02:55 -04:00
2023-05-17 12:43:23 +02:00
node . chainman = std : : make_unique < ChainstateManager > ( node . kernel - > interrupt , chainman_opts , blockman_opts ) ;
2021-09-13 17:02:55 -04:00
ChainstateManager & chainman = * node . chainman ;
2021-12-01 18:16:29 -05:00
node : : ChainstateLoadOptions options ;
options . mempool = Assert ( node . mempool . get ( ) ) ;
options . reindex = node : : fReindex ;
options . reindex_chainstate = fReindexChainState ;
2023-01-16 17:23:18 +01:00
options . prune = chainman . m_blockman . IsPruneMode ( ) ;
2021-12-01 18:16:29 -05:00
options . check_blocks = args . GetIntArg ( " -checkblocks " , DEFAULT_CHECKBLOCKS ) ;
options . check_level = args . GetIntArg ( " -checklevel " , DEFAULT_CHECKLEVEL ) ;
2022-10-06 17:11:02 -04:00
options . require_full_verification = args . IsArgSet ( " -checkblocks " ) | | args . IsArgSet ( " -checklevel " ) ;
2021-12-01 18:16:29 -05:00
options . check_interrupt = ShutdownRequested ;
options . coins_error_cb = [ ] {
uiInterface . ThreadSafeMessageBox (
_ ( " Error reading from database, shutting down. " ) ,
" " , CClientUIInterface : : MSG_ERROR ) ;
} ;
2021-05-02 21:53:36 +03:00
uiInterface . InitMessage ( _ ( " Loading block index… " ) . translated ) ;
2022-06-28 17:50:53 +02:00
const auto load_block_index_start_time { SteadyClock : : now ( ) } ;
2021-12-01 18:16:29 -05:00
auto catch_exceptions = [ ] ( auto & & f ) {
2021-08-18 13:54:08 -04:00
try {
2021-12-01 18:16:29 -05:00
return f ( ) ;
2021-08-18 13:54:08 -04:00
} catch ( const std : : exception & e ) {
LogPrintf ( " %s \n " , e . what ( ) ) ;
2021-12-01 18:16:29 -05:00
return std : : make_tuple ( node : : ChainstateLoadStatus : : FAILURE , _ ( " Error opening block database " ) ) ;
2021-08-18 13:54:08 -04:00
}
2021-12-01 18:16:29 -05:00
} ;
auto [ status , error ] = catch_exceptions ( [ & ] { return LoadChainstate ( chainman , cache_sizes , options ) ; } ) ;
if ( status = = node : : ChainstateLoadStatus : : SUCCESS ) {
uiInterface . InitMessage ( _ ( " Verifying blocks… " ) . translated ) ;
if ( chainman . m_blockman . m_have_pruned & & options . check_blocks > MIN_BLOCKS_TO_KEEP ) {
LogPrintfCategory ( BCLog : : PRUNE , " pruned datadir may not have more than %d blocks; only checking available blocks \n " ,
MIN_BLOCKS_TO_KEEP ) ;
}
std : : tie ( status , error ) = catch_exceptions ( [ & ] { return VerifyLoadedChainstate ( chainman , options ) ; } ) ;
if ( status = = node : : ChainstateLoadStatus : : SUCCESS ) {
2021-11-10 15:57:14 -05:00
fLoaded = true ;
2022-06-28 17:50:53 +02:00
LogPrintf ( " block index %15dms \n " , Ticks < std : : chrono : : milliseconds > ( SteadyClock : : now ( ) - load_block_index_start_time ) ) ;
2021-11-10 15:57:14 -05:00
}
2021-09-20 17:08:18 -04:00
}
2013-02-16 17:58:45 +01:00
2023-06-12 11:48:27 -04:00
if ( status = = node : : ChainstateLoadStatus : : FAILURE_FATAL | | status = = node : : ChainstateLoadStatus : : FAILURE_INCOMPATIBLE_DB | | status = = node : : ChainstateLoadStatus : : FAILURE_INSUFFICIENT_DBCACHE ) {
2021-12-01 18:16:29 -05:00
return InitError ( error ) ;
}
2018-05-16 19:17:40 +00:00
if ( ! fLoaded & & ! ShutdownRequested ( ) ) {
2013-02-16 17:58:45 +01:00
// first suggest a reindex
2021-12-01 18:16:29 -05:00
if ( ! options . reindex ) {
2016-06-24 16:35:21 +02:00
bool fRet = uiInterface . ThreadSafeQuestion (
2021-12-01 18:16:29 -05:00
error + Untranslated ( " . \n \n " ) + _ ( " Do you want to rebuild the block database now? " ) ,
error . original + " . \n Please restart with -reindex or -reindex-chainstate to recover. " ,
2013-02-16 17:58:45 +01:00
" " , CClientUIInterface : : MSG_ERROR | CClientUIInterface : : BTN_ABORT ) ;
if ( fRet ) {
fReindex = true ;
2018-05-16 19:17:40 +00:00
AbortShutdown ( ) ;
2013-02-16 17:58:45 +01:00
} else {
2013-09-18 20:38:08 +10:00
LogPrintf ( " Aborted block database rebuild. Exiting. \n " ) ;
2013-02-16 17:58:45 +01:00
return false ;
}
} else {
2021-12-01 18:16:29 -05:00
return InitError ( error ) ;
2013-02-16 17:58:45 +01:00
}
}
}
2012-04-18 12:30:24 +01:00
2013-12-16 23:36:22 +01:00
// As LoadBlockIndex can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit.
2012-04-18 12:30:24 +01:00
// As the program has not fully started yet, Shutdown() is possibly overkill.
2018-05-16 19:17:40 +00:00
if ( ShutdownRequested ( ) ) {
2013-09-18 20:38:08 +10:00
LogPrintf ( " Shutdown requested. Exiting. \n " ) ;
2012-04-18 12:30:24 +01:00
return false ;
}
2011-05-14 20:10:21 +02:00
2021-09-13 17:02:55 -04:00
ChainstateManager & chainman = * Assert ( node . chainman ) ;
assert ( ! node . peerman ) ;
2022-05-18 18:29:04 +02:00
node . peerman = PeerManager : : make ( * node . connman , * node . addrman , node . banman . get ( ) ,
2021-09-13 17:02:55 -04:00
chainman , * node . mempool , ignores_incoming_txs ) ;
RegisterValidationInterface ( node . peerman . get ( ) ) ;
2017-12-08 11:29:59 -08:00
// ********************************************************* Step 8: start indexers
2022-05-23 21:07:29 +02:00
2023-06-17 11:11:51 -03:00
// If reindex-chainstate was specified, delay syncing indexes until ImportBlocks has reindexed the chain
2022-05-23 21:07:29 +02:00
if ( ! fReindexChainState ) g_indexes_ready_to_sync = true ;
2020-08-21 20:38:01 +02:00
if ( args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ) {
2022-09-01 15:35:23 -04:00
auto result { WITH_LOCK ( cs_main , return CheckLegacyTxindex ( * Assert ( chainman . m_blockman . m_block_tree_db ) ) ) } ;
if ( ! result ) {
return InitError ( util : : ErrorString ( result ) ) ;
2021-08-04 20:55:31 +02:00
}
2022-01-13 07:57:54 -05:00
g_txindex = std : : make_unique < TxIndex > ( interfaces : : MakeChain ( node ) , cache_sizes . tx_index , false , fReindex ) ;
2023-06-16 10:16:22 -03:00
node . indexes . emplace_back ( g_txindex . get ( ) ) ;
2017-12-08 11:29:59 -08:00
}
2018-08-29 22:15:50 -07:00
for ( const auto & filter_type : g_enabled_filter_types ) {
2022-01-13 07:57:54 -05:00
InitBlockFilterIndex ( [ & ] { return interfaces : : MakeChain ( node ) ; } , filter_type , cache_sizes . filter_index , false , fReindex ) ;
2023-06-16 10:16:22 -03:00
node . indexes . emplace_back ( GetBlockFilterIndex ( filter_type ) ) ;
2018-08-29 22:15:50 -07:00
}
2020-01-24 18:58:47 +01:00
if ( args . GetBoolArg ( " -coinstatsindex " , DEFAULT_COINSTATSINDEX ) ) {
2022-10-03 09:37:27 +01:00
g_coin_stats_index = std : : make_unique < CoinStatsIndex > ( interfaces : : MakeChain ( node ) , /*cache_size=*/ 0 , false , fReindex ) ;
2023-06-16 10:16:22 -03:00
node . indexes . emplace_back ( g_coin_stats_index . get ( ) ) ;
2020-01-24 18:58:47 +01:00
}
2023-05-17 00:55:09 -03:00
// Init indexes
for ( auto index : node . indexes ) if ( ! index - > Init ( ) ) return false ;
2023-06-16 10:16:22 -03:00
// Now that all indexes are loaded, start them
2023-05-17 00:55:09 -03:00
if ( ! StartIndexBackgroundSync ( node ) ) return false ;
2023-06-16 10:16:22 -03:00
2017-12-08 11:29:59 -08:00
// ********************************************************* Step 9: load wallet
2019-09-17 17:04:39 -04:00
for ( const auto & client : node . chain_clients ) {
2017-09-28 14:13:29 -04:00
if ( ! client - > load ( ) ) {
return false ;
}
}
2015-06-30 13:22:48 -04:00
2017-12-08 11:29:59 -08:00
// ********************************************************* Step 10: data directory maintenance
2015-06-30 13:22:48 -04:00
2022-08-20 14:18:42 +02:00
// if pruning, perform the initial blockstore prune
2015-06-30 13:22:48 -04:00
// after any wallet rescanning has taken place.
2023-01-16 17:23:18 +01:00
if ( chainman . m_blockman . IsPruneMode ( ) ) {
2015-06-30 13:22:48 -04:00
if ( ! fReindex ) {
2019-12-12 10:48:28 -05:00
LOCK ( cs_main ) ;
2022-03-09 12:37:19 -05:00
for ( Chainstate * chainstate : chainman . GetAll ( ) ) {
2021-05-02 21:53:36 +03:00
uiInterface . InitMessage ( _ ( " Pruning blockstore… " ) . translated ) ;
2019-12-12 10:48:28 -05:00
chainstate - > PruneAndFlush ( ) ;
}
2015-06-30 13:22:48 -04:00
}
2022-08-20 14:18:42 +02:00
} else {
LogPrintf ( " Setting NODE_NETWORK on non-prune mode \n " ) ;
nLocalServices = ServiceFlags ( nLocalServices | NODE_NETWORK ) ;
2015-06-30 13:22:48 -04:00
}
2017-12-08 11:29:59 -08:00
// ********************************************************* Step 11: import blocks
2012-01-03 10:14:22 -05:00
2023-03-10 12:36:47 +01:00
if ( ! CheckDiskSpace ( args . GetDataDirNet ( ) ) ) {
InitError ( strprintf ( _ ( " Error: Disk space is low for %s " ) , fs : : quoted ( fs : : PathToString ( args . GetDataDirNet ( ) ) ) ) ) ;
2016-07-22 16:01:51 +02:00
return false ;
2019-01-07 10:56:28 -08:00
}
2023-03-10 12:36:47 +01:00
if ( ! CheckDiskSpace ( args . GetBlocksDirPath ( ) ) ) {
InitError ( strprintf ( _ ( " Error: Disk space is low for %s " ) , fs : : quoted ( fs : : PathToString ( args . GetBlocksDirPath ( ) ) ) ) ) ;
2019-01-07 10:56:28 -08:00
return false ;
}
2016-07-22 16:01:51 +02:00
2022-06-08 15:48:58 -05:00
int chain_active_height = WITH_LOCK ( cs_main , return chainman . ActiveChain ( ) . Height ( ) ) ;
// On first startup, warn on low block storage space
if ( ! fReindex & & ! fReindexChainState & & chain_active_height < = 1 ) {
2023-03-09 18:17:06 +01:00
uint64_t assumed_chain_bytes { chainparams . AssumedBlockchainSize ( ) * 1024 * 1024 * 1024 } ;
2023-01-16 17:08:35 +01:00
uint64_t additional_bytes_needed {
2023-01-16 17:23:18 +01:00
chainman . m_blockman . IsPruneMode ( ) ?
2023-03-09 18:17:06 +01:00
std : : min ( chainman . m_blockman . GetPruneTarget ( ) , assumed_chain_bytes ) :
assumed_chain_bytes } ;
2022-06-08 15:48:58 -05:00
if ( ! CheckDiskSpace ( args . GetBlocksDirPath ( ) , additional_bytes_needed ) ) {
InitWarning ( strprintf ( _ (
" Disk space for %s may not accommodate the block files. " \
" Approximately %u GB of data will be stored in this directory. "
) ,
fs : : quoted ( fs : : PathToString ( args . GetBlocksDirPath ( ) ) ) ,
chainparams . AssumedBlockchainSize ( )
) ) ;
}
}
2016-07-22 15:57:25 +02:00
// Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
// No locking, as this happens before any background thread is started.
2019-03-29 19:11:43 +01:00
boost : : signals2 : : connection block_notify_genesis_wait_connection ;
2022-05-06 16:58:53 +02:00
if ( WITH_LOCK ( chainman . GetMutex ( ) , return chainman . ActiveChain ( ) . Tip ( ) = = nullptr ) ) {
2020-03-04 19:41:18 +02:00
block_notify_genesis_wait_connection = uiInterface . NotifyBlockTip_connect ( std : : bind ( BlockNotifyGenesisWait , std : : placeholders : : _2 ) ) ;
2016-07-22 15:57:25 +02:00
} else {
fHaveGenesis = true ;
}
2019-07-05 18:30:15 +02:00
# if HAVE_SYSTEM
2020-08-30 17:27:22 +01:00
const std : : string block_notify = args . GetArg ( " -blocknotify " , " " ) ;
if ( ! block_notify . empty ( ) ) {
uiInterface . NotifyBlockTip_connect ( [ block_notify ] ( SynchronizationState sync_state , const CBlockIndex * pBlockIndex ) {
if ( sync_state ! = SynchronizationState : : POST_INIT | | ! pBlockIndex ) return ;
std : : string command = block_notify ;
2022-05-05 08:28:29 +02:00
ReplaceAll ( command , " %s " , pBlockIndex - > GetBlockHash ( ) . GetHex ( ) ) ;
2020-08-30 17:27:22 +01:00
std : : thread t ( runCommand , command ) ;
t . detach ( ) ; // thread runs free
} ) ;
2020-08-22 09:44:49 +02:00
}
2019-03-14 11:30:37 +01:00
# endif
2014-08-14 12:32:34 -04:00
2017-03-01 17:05:50 +01:00
std : : vector < fs : : path > vImportFiles ;
2020-08-21 20:38:01 +02:00
for ( const std : : string & strFile : args . GetArgs ( " -loadblock " ) ) {
2021-09-10 00:17:20 -04:00
vImportFiles . push_back ( fs : : PathFromString ( strFile ) ) ;
2012-09-24 13:37:03 -04:00
}
2016-07-22 15:57:25 +02:00
2023-06-17 11:11:51 -03:00
chainman . m_thread_load = std : : thread ( & util : : TraceThread , " initload " , [ = , & chainman , & args ] {
2023-06-15 05:11:34 -03:00
// Import blocks
2023-06-17 11:11:51 -03:00
ImportBlocks ( chainman , vImportFiles ) ;
2023-06-15 05:11:34 -03:00
// Load mempool from disk
chainman . ActiveChainstate ( ) . LoadMempool ( ShouldPersistMempool ( args ) ? MempoolPath ( args ) : fs : : path { } ) ;
2020-08-21 20:13:40 +02:00
} ) ;
2016-05-16 20:33:32 -07:00
// Wait for genesis block to be processed
2016-07-22 15:57:25 +02:00
{
2017-11-03 07:49:16 -04:00
WAIT_LOCK ( g_genesis_wait_mutex , lock ) ;
2018-02-06 13:32:53 -05:00
// We previously could hang here if StartShutdown() is called prior to
2023-06-17 11:11:51 -03:00
// ImportBlocks getting started, so instead we just wait on a timer to
2018-02-06 13:32:53 -05:00
// check ShutdownRequested() regularly.
while ( ! fHaveGenesis & & ! ShutdownRequested ( ) ) {
2017-11-03 07:49:16 -04:00
g_genesis_wait_cv . wait_for ( lock , std : : chrono : : milliseconds ( 500 ) ) ;
2016-05-16 20:33:32 -07:00
}
2019-03-29 19:11:43 +01:00
block_notify_genesis_wait_connection . disconnect ( ) ;
2014-11-07 23:18:21 -08:00
}
2012-09-24 13:37:03 -04:00
2018-02-06 13:32:53 -05:00
if ( ShutdownRequested ( ) ) {
return false ;
}
2017-12-08 11:29:59 -08:00
// ********************************************************* Step 12: start node
2011-05-14 20:10:21 +02:00
2012-05-21 16:47:29 +02:00
//// debug print
2017-08-22 21:02:25 +12:00
{
LOCK ( cs_main ) ;
2020-06-29 10:30:03 -04:00
LogPrintf ( " block tree size = %u \n " , chainman . BlockIndex ( ) . size ( ) ) ;
chain_active_height = chainman . ActiveChain ( ) . Height ( ) ;
2020-05-19 15:13:50 +02:00
if ( tip_info ) {
tip_info - > block_height = chain_active_height ;
2022-05-18 18:36:31 +02:00
tip_info - > block_time = chainman . ActiveChain ( ) . Tip ( ) ? chainman . ActiveChain ( ) . Tip ( ) - > GetBlockTime ( ) : chainman . GetParams ( ) . GenesisBlock ( ) . GetBlockTime ( ) ;
tip_info - > verification_progress = GuessVerificationProgress ( chainman . GetParams ( ) . TxData ( ) , chainman . ActiveChain ( ) . Tip ( ) ) ;
2020-05-19 15:13:50 +02:00
}
2022-03-18 12:35:52 -04:00
if ( tip_info & & chainman . m_best_header ) {
tip_info - > header_height = chainman . m_best_header - > nHeight ;
tip_info - > header_time = chainman . m_best_header - > GetBlockTime ( ) ;
2020-05-19 15:13:50 +02:00
}
2017-08-22 21:02:25 +12:00
}
LogPrintf ( " nBestHeight = %d \n " , chain_active_height ) ;
2021-01-02 10:25:05 +01:00
if ( node . peerman ) node . peerman - > SetBestHeight ( chain_active_height ) ;
2017-08-22 21:02:25 +12:00
2020-02-23 02:12:19 +02:00
// Map ports with UPnP or NAT-PMP.
2023-03-10 12:36:47 +01:00
StartMapPort ( args . GetBoolArg ( " -upnp " , DEFAULT_UPNP ) , args . GetBoolArg ( " -natpmp " , DEFAULT_NATPMP ) ) ;
2016-05-26 23:29:39 -04:00
2016-05-26 23:53:08 -04:00
CConnman : : Options connOptions ;
connOptions . nLocalServices = nLocalServices ;
connOptions . nMaxConnections = nMaxConnections ;
2019-03-09 12:55:06 -05:00
connOptions . m_max_outbound_full_relay = std : : min ( MAX_OUTBOUND_FULL_RELAY_CONNECTIONS , connOptions . nMaxConnections ) ;
2020-06-08 22:04:07 -07:00
connOptions . m_max_outbound_block_relay = std : : min ( MAX_BLOCK_RELAY_ONLY_CONNECTIONS , connOptions . nMaxConnections - connOptions . m_max_outbound_full_relay ) ;
2016-12-11 04:39:26 +00:00
connOptions . nMaxAddnode = MAX_ADDNODE_CONNECTIONS ;
2019-05-08 04:34:01 -04:00
connOptions . nMaxFeeler = MAX_FEELER_CONNECTIONS ;
2016-05-26 23:53:08 -04:00
connOptions . uiInterface = & uiInterface ;
2019-09-17 18:59:36 -04:00
connOptions . m_banman = node . banman . get ( ) ;
2020-08-29 10:31:11 +01:00
connOptions . m_msgproc = node . peerman . get ( ) ;
2019-08-22 21:40:41 -04:00
connOptions . nSendBufferMaxSize = 1000 * args . GetIntArg ( " -maxsendbuffer " , DEFAULT_MAXSENDBUFFER ) ;
connOptions . nReceiveFloodSize = 1000 * args . GetIntArg ( " -maxreceivebuffer " , DEFAULT_MAXRECEIVEBUFFER ) ;
2020-08-21 20:38:01 +02:00
connOptions . m_added_nodes = args . GetArgs ( " -addnode " ) ;
2021-11-17 12:47:30 +02:00
connOptions . nMaxOutboundLimit = * opt_max_upload ;
2018-11-15 15:30:26 -08:00
connOptions . m_peer_connect_timeout = peer_connect_timeout ;
2016-09-12 15:04:20 -04:00
2020-10-18 14:45:35 +02:00
// Port to bind to if `-bind=addr` is provided without a `:port` suffix.
const uint16_t default_bind_port =
static_cast < uint16_t > ( args . GetIntArg ( " -port " , Params ( ) . GetDefaultPort ( ) ) ) ;
2021-11-18 09:19:09 +01:00
const auto BadPortWarning = [ ] ( const char * prefix , uint16_t port ) {
return strprintf ( _ ( " %s request to listen on port %u. This port is considered \" bad \" and "
2022-09-20 15:26:35 +01:00
" thus it is unlikely that any peer will connect to it. See "
2021-11-18 09:19:09 +01:00
" doc/p2p-bad-ports.md for details and a full list. " ) ,
prefix ,
port ) ;
} ;
2020-09-29 18:03:43 +03:00
for ( const std : : string & bind_arg : args . GetArgs ( " -bind " ) ) {
2022-10-10 15:02:59 -03:00
std : : optional < CService > bind_addr ;
2020-09-29 18:03:43 +03:00
const size_t index = bind_arg . rfind ( ' = ' ) ;
if ( index = = std : : string : : npos ) {
2022-10-10 15:02:59 -03:00
bind_addr = Lookup ( bind_arg , default_bind_port , /*fAllowLookup=*/ false ) ;
if ( bind_addr . has_value ( ) ) {
connOptions . vBinds . push_back ( bind_addr . value ( ) ) ;
if ( IsBadPort ( bind_addr . value ( ) . GetPort ( ) ) ) {
InitWarning ( BadPortWarning ( " -bind " , bind_addr . value ( ) . GetPort ( ) ) ) ;
2021-11-18 09:19:09 +01:00
}
2020-09-29 18:03:43 +03:00
continue ;
}
} else {
const std : : string network_type = bind_arg . substr ( index + 1 ) ;
if ( network_type = = " onion " ) {
const std : : string truncated_bind_arg = bind_arg . substr ( 0 , index ) ;
2022-10-10 15:02:59 -03:00
bind_addr = Lookup ( truncated_bind_arg , BaseParams ( ) . OnionServiceTargetPort ( ) , false ) ;
if ( bind_addr . has_value ( ) ) {
connOptions . onion_binds . push_back ( bind_addr . value ( ) ) ;
2020-09-29 18:03:43 +03:00
continue ;
}
}
2017-06-27 03:10:39 +02:00
}
2020-09-29 18:03:43 +03:00
return InitError ( ResolveErrMsg ( " bind " , bind_arg ) ) ;
2017-06-01 12:34:02 +02:00
}
2020-09-29 18:03:43 +03:00
2020-08-21 20:38:01 +02:00
for ( const std : : string & strBind : args . GetArgs ( " -whitebind " ) ) {
2019-06-20 18:37:51 +09:00
NetWhitebindPermissions whitebind ;
2020-06-05 14:26:16 +02:00
bilingual_str error ;
if ( ! NetWhitebindPermissions : : TryParse ( strBind , whitebind , error ) ) return InitError ( error ) ;
2019-06-20 18:37:51 +09:00
connOptions . vWhiteBinds . push_back ( whitebind ) ;
2017-06-01 12:34:02 +02:00
}
2020-10-22 20:34:31 +02:00
// If the user did not specify -bind= or -whitebind= then we bind
// on any address - 0.0.0.0 (IPv4) and :: (IPv6).
connOptions . bind_on_any = args . GetArgs ( " -bind " ) . empty ( ) & & args . GetArgs ( " -whitebind " ) . empty ( ) ;
2021-11-18 09:19:09 +01:00
// Emit a warning if a bad port is given to -port= but only if -bind and -whitebind are not
// given, because if they are, then -port= is ignored.
if ( connOptions . bind_on_any & & args . IsArgSet ( " -port " ) ) {
const uint16_t port_arg = args . GetIntArg ( " -port " , 0 ) ;
if ( IsBadPort ( port_arg ) ) {
InitWarning ( BadPortWarning ( " -port " , port_arg ) ) ;
}
}
2020-10-22 20:34:31 +02:00
CService onion_service_target ;
if ( ! connOptions . onion_binds . empty ( ) ) {
onion_service_target = connOptions . onion_binds . front ( ) ;
} else {
onion_service_target = DefaultOnionServiceTarget ( ) ;
connOptions . onion_binds . push_back ( onion_service_target ) ;
}
if ( args . GetBoolArg ( " -listenonion " , DEFAULT_LISTEN_ONION ) ) {
if ( connOptions . onion_binds . size ( ) > 1 ) {
InitWarning ( strprintf ( _ ( " More than one onion bind address is provided. Using %s "
" for the automatically created Tor onion service. " ) ,
2022-07-18 13:28:40 +02:00
onion_service_target . ToStringAddrPort ( ) ) ) ;
2020-10-22 20:34:31 +02:00
}
StartTorControl ( onion_service_target ) ;
}
2020-10-19 15:32:54 +02:00
if ( connOptions . bind_on_any ) {
// Only add all IP addresses of the machine if we would be listening on
// any address - 0.0.0.0 (IPv4) and :: (IPv6).
Discover ( ) ;
}
2020-08-21 20:38:01 +02:00
for ( const auto & net : args . GetArgs ( " -whitelist " ) ) {
2019-06-20 18:37:51 +09:00
NetWhitelistPermissions subnet ;
2020-06-05 14:26:16 +02:00
bilingual_str error ;
if ( ! NetWhitelistPermissions : : TryParse ( net , subnet , error ) ) return InitError ( error ) ;
2017-06-27 03:10:39 +02:00
connOptions . vWhitelistedRange . push_back ( subnet ) ;
2017-06-01 11:07:08 +02:00
}
2020-08-21 20:38:01 +02:00
connOptions . vSeedNodes = args . GetArgs ( " -seednode " ) ;
2017-09-11 16:13:52 +02:00
2017-06-15 09:39:07 +02:00
// Initiate outbound connections unless connect=0
2020-08-21 20:38:01 +02:00
connOptions . m_use_addrman_outgoing = ! args . IsArgSet ( " -connect " ) ;
2017-06-15 09:39:07 +02:00
if ( ! connOptions . m_use_addrman_outgoing ) {
2020-08-21 20:38:01 +02:00
const auto connect = args . GetArgs ( " -connect " ) ;
2017-06-15 09:39:07 +02:00
if ( connect . size ( ) ! = 1 | | connect [ 0 ] ! = " 0 " ) {
connOptions . m_specified_outgoing = connect ;
}
2020-09-25 12:33:47 -07:00
if ( ! connOptions . m_specified_outgoing . empty ( ) & & ! connOptions . vSeedNodes . empty ( ) ) {
LogPrintf ( " -seednode is ignored when -connect is used \n " ) ;
}
if ( args . IsArgSet ( " -dnsseed " ) & & args . GetBoolArg ( " -dnsseed " , DEFAULT_DNSSEED ) & & args . IsArgSet ( " -proxy " ) ) {
LogPrintf ( " -dnsseed is ignored when -connect is used and -proxy is specified \n " ) ;
}
2017-06-15 09:39:07 +02:00
}
2020-12-04 18:03:05 +01:00
const std : : string & i2psam_arg = args . GetArg ( " -i2psam " , " " ) ;
if ( ! i2psam_arg . empty ( ) ) {
2022-10-10 15:02:59 -03:00
const std : : optional < CService > addr { Lookup ( i2psam_arg , 7656 , fNameLookup ) } ;
if ( ! addr . has_value ( ) | | ! addr - > IsValid ( ) ) {
2020-12-04 18:03:05 +01:00
return InitError ( strprintf ( _ ( " Invalid -i2psam address or hostname: '%s' " ) , i2psam_arg ) ) ;
}
2022-10-10 15:02:59 -03:00
SetProxy ( NET_I2P , Proxy { addr . value ( ) } ) ;
2020-12-04 18:03:05 +01:00
} else {
2022-09-01 18:25:25 -04:00
if ( args . IsArgSet ( " -onlynet " ) & & IsReachable ( NET_I2P ) ) {
return InitError (
_ ( " Outbound connections restricted to i2p (-onlynet=i2p) but "
" -i2psam is not provided " ) ) ;
}
2020-12-04 18:03:05 +01:00
SetReachable ( NET_I2P , false ) ;
}
2023-01-09 07:25:04 -08:00
connOptions . m_i2p_accept_incoming = args . GetBoolArg ( " -i2pacceptincoming " , DEFAULT_I2P_ACCEPT_INCOMING ) ;
2020-12-04 18:03:05 +01:00
2020-02-12 11:08:28 -08:00
if ( ! node . connman - > Start ( * node . scheduler , connOptions ) ) {
2017-06-01 12:34:02 +02:00
return false ;
}
2011-05-14 20:10:21 +02:00
2017-12-08 11:29:59 -08:00
// ********************************************************* Step 13: finished
2012-05-21 16:47:29 +02:00
2021-08-18 14:36:28 -04:00
// At this point, the RPC is "started", but still in warmup, which means it
// cannot yet be called. Before we make it callable, we need to make sure
// that the RPC's view of the best block is valid and consistent with
2022-07-12 17:49:21 +02:00
// ChainstateManager's active tip.
2021-08-18 14:36:28 -04:00
//
// If we do not do this, RPC's view of the best block will be height=0 and
// hash=0x0. This will lead to erroroneous responses for things like
// waitforblockheight.
2022-07-12 17:49:21 +02:00
RPCNotifyBlockChange ( WITH_LOCK ( chainman . GetMutex ( ) , return chainman . ActiveTip ( ) ) ) ;
2014-10-29 18:08:31 +01:00
SetRPCWarmupFinished ( ) ;
2021-08-18 14:36:28 -04:00
2019-06-28 21:09:58 +03:00
uiInterface . InitMessage ( _ ( " Done loading " ) . translated ) ;
2012-05-21 16:47:29 +02:00
2019-09-17 17:04:39 -04:00
for ( const auto & client : node . chain_clients ) {
2020-02-12 11:08:28 -08:00
client - > start ( * node . scheduler ) ;
2017-09-28 14:13:29 -04:00
}
2011-05-14 20:10:21 +02:00
2019-09-17 18:59:36 -04:00
BanMan * banman = node . banman . get ( ) ;
2020-02-12 11:08:28 -08:00
node . scheduler - > scheduleEvery ( [ banman ] {
2019-09-17 18:28:03 -04:00
banman - > DumpBanlist ( ) ;
2020-03-06 18:06:50 -05:00
} , DUMP_BANS_INTERVAL ) ;
2017-10-05 13:10:58 -04:00
2021-07-28 16:18:53 -06:00
if ( node . peerman ) node . peerman - > StartScheduledTasks ( * node . scheduler ) ;
2020-09-28 10:38:36 -05:00
# if HAVE_SYSTEM
StartupNotify ( args ) ;
# endif
2017-12-05 10:39:44 -05:00
return true ;
2011-05-14 20:10:21 +02:00
}
2023-06-16 10:16:22 -03:00
2023-05-17 00:55:09 -03:00
bool StartIndexBackgroundSync ( NodeContext & node )
2023-06-16 10:16:22 -03:00
{
2023-05-17 00:55:09 -03:00
for ( auto index : node . indexes ) if ( ! index - > StartBackgroundSync ( ) ) return false ;
2023-06-16 10:16:22 -03:00
return true ;
}