2011-05-14 14:10:21 -04:00
// Copyright (c) 2009-2010 Satoshi Nakamoto
2020-01-14 16:17:38 -03:00
// Copyright (c) 2009-2020 The Bitcoin Core developers
2014-11-30 22:39:44 -03:00
// Distributed under the MIT software license, see the accompanying
2012-05-18 10:02:28 -04:00
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2012-11-05 04:04:21 -03:00
2013-05-27 19:55:01 -04:00
# if defined(HAVE_CONFIG_H)
2017-11-09 21:57:53 -03:00
# include <config/bitcoin-config.h>
2013-05-27 19:55:01 -04:00
# endif
2017-11-09 21:57:53 -03:00
# include <init.h>
2013-04-13 02:13:08 -03:00
2017-11-09 21:57:53 -03:00
# include <addrman.h>
# include <amount.h>
2017-10-05 17:40:43 -03:00
# include <banman.h>
2018-08-30 02:15:50 -03:00
# include <blockfilter.h>
2017-11-09 21:57:53 -03:00
# include <chain.h>
# include <chainparams.h>
# include <compat/sanity.h>
# include <consensus/validation.h>
# include <fs.h>
2020-06-05 14:55:17 -04:00
# include <hash.h>
2017-11-09 21:57:53 -03:00
# include <httprpc.h>
2019-06-17 03:56:52 -04:00
# include <httpserver.h>
2018-08-30 02:15:50 -03:00
# include <index/blockfilterindex.h>
2017-12-08 16:29:59 -03:00
# include <index/txindex.h>
2019-06-17 03:56:52 -04:00
# include <interfaces/chain.h>
2020-05-19 09:13:50 -04:00
# include <interfaces/node.h>
2017-11-09 21:57:53 -03:00
# include <key.h>
2020-02-06 14:00:26 -03:00
# include <mapport.h>
2017-11-09 21:57:53 -03:00
# include <miner.h>
# include <net.h>
2019-06-20 05:37:51 -04:00
# include <net_permissions.h>
2017-11-09 21:57:53 -03:00
# include <net_processing.h>
2019-06-17 03:56:52 -04:00
# include <netbase.h>
2019-09-17 19:28:03 -03:00
# include <node/context.h>
2020-06-19 18:14:17 -04:00
# include <node/ui_interface.h>
2017-11-09 21:57:53 -03:00
# include <policy/feerate.h>
# include <policy/fees.h>
# include <policy/policy.h>
2019-04-02 15:14:58 -03:00
# include <policy/settings.h>
2020-09-30 14:08:52 -03:00
# include <protocol.h>
2017-11-09 21:57:53 -03:00
# include <rpc/blockchain.h>
2019-06-17 03:56:52 -04:00
# include <rpc/register.h>
# include <rpc/server.h>
2017-05-30 15:55:17 -04:00
# include <rpc/util.h>
2017-11-09 21:57:53 -03:00
# include <scheduler.h>
2019-06-17 03:56:52 -04:00
# include <script/sigcache.h>
# include <script/standard.h>
2018-05-16 15:17:40 -04:00
# include <shutdown.h>
2020-06-05 14:55:17 -04:00
# include <sync.h>
2017-11-09 21:57:53 -03:00
# include <timedata.h>
2019-06-17 03:56:52 -04:00
# include <torcontrol.h>
2017-11-09 21:57:53 -03:00
# include <txdb.h>
# include <txmempool.h>
2019-12-29 14:54:33 -03:00
# include <util/asmap.h>
2020-06-14 14:17:24 -04:00
# include <util/check.h>
2018-10-22 19:51:11 -03:00
# include <util/moneystr.h>
2020-06-06 13:28:47 -04:00
# include <util/string.h>
2019-06-17 03:56:52 -04:00
# include <util/system.h>
# include <util/threadnames.h>
# include <util/translation.h>
# include <validation.h>
2019-12-24 15:18:44 -03:00
2017-11-09 21:57:53 -03:00
# include <validationinterface.h>
2018-02-21 13:38:53 -03:00
# include <walletinitinterface.h>
2019-06-17 03:56:52 -04:00
2020-03-04 14:41:18 -03:00
# include <functional>
# include <set>
2013-04-13 02:13:08 -03:00
# include <stdint.h>
2014-05-11 09:29:16 -04:00
# include <stdio.h>
2021-01-27 04:04:34 -03:00
# include <thread>
# include <vector>
2011-05-14 14:10:21 -04:00
2012-04-15 17:10:54 -03:00
# ifndef WIN32
2019-02-01 19:40:36 -03:00
# include <attributes.h>
# include <cerrno>
2012-04-15 17:10:54 -03:00
# include <signal.h>
2018-07-25 05:33:22 -04:00
# include <sys/stat.h>
2012-03-18 19:14:03 -03:00
# endif
2011-10-07 11:46:56 -03:00
2014-08-29 16:52:41 -04:00
# include <boost/algorithm/string/replace.hpp>
2019-11-11 12:53:03 -03:00
# include <boost/signals2/signal.hpp>
2013-04-13 02:13:08 -03:00
2014-11-18 14:06:32 -03:00
# if ENABLE_ZMQ
2018-08-24 21:42:03 -03:00
# include <zmq/zmqabstractnotifier.h>
2017-11-09 21:57:53 -03:00
# include <zmq/zmqnotificationinterface.h>
2018-06-29 10:10:01 -04:00
# include <zmq/zmqrpc.h>
2014-11-18 14:06:32 -03:00
# endif
2015-06-27 16:21:41 -03:00
static const bool DEFAULT_PROXYRANDOMIZE = true ;
static const bool DEFAULT_REST_ENABLE = false ;
static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false ;
2011-06-26 13:23:24 -04:00
2013-04-25 19:46:47 -03:00
# ifdef WIN32
// Win32 LevelDB doesn't use filedescriptors, and the ones used for
2015-04-28 11:48:28 -03:00
// accessing block files don't count towards the fd_set size limit
2013-04-25 19:46:47 -03:00
// anyway.
# define MIN_CORE_FILEDESCRIPTORS 0
# else
# define MIN_CORE_FILEDESCRIPTORS 150
# endif
2019-12-24 15:18:44 -03:00
static const char * DEFAULT_ASMAP_FILENAME = " ip_asn.map " ;
2019-02-14 17:53:03 -03:00
/**
* The PID file facilities .
*/
static const char * BITCOIN_PID_FILENAME = " bitcoind.pid " ;
2020-08-21 14:13:40 -04:00
static fs : : path GetPidFile ( const ArgsManager & args )
2019-02-14 17:53:03 -03:00
{
2020-08-21 14:38:01 -04:00
return AbsPathForConfigVal ( fs : : path ( args . GetArg ( " -pid " , BITCOIN_PID_FILENAME ) ) ) ;
2019-02-14 17:53:03 -03:00
}
2020-11-26 06:05:59 -03:00
[[nodiscard]] static bool CreatePidFile ( const ArgsManager & args )
2019-02-14 17:53:03 -03:00
{
2020-08-21 14:13:40 -04:00
fsbridge : : ofstream file { GetPidFile ( args ) } ;
2019-02-14 17:53:03 -03:00
if ( file ) {
2019-02-25 06:00:34 -03:00
# ifdef WIN32
2019-06-13 09:43:24 -04:00
tfm : : format ( file , " %d \n " , GetCurrentProcessId ( ) ) ;
2019-02-25 06:00:34 -03:00
# else
2019-06-13 09:43:24 -04:00
tfm : : format ( file , " %d \n " , getpid ( ) ) ;
2019-02-25 06:00:34 -03:00
# endif
2019-02-14 17:53:03 -03:00
return true ;
} else {
2020-08-21 14:13:40 -04:00
return InitError ( strprintf ( _ ( " Unable to create the PID file '%s': %s " ) , GetPidFile ( args ) . string ( ) , std : : strerror ( errno ) ) ) ;
2019-02-14 17:53:03 -03:00
}
}
2011-05-14 14:10:21 -04:00
//////////////////////////////////////////////////////////////////////////////
//
// Shutdown
//
2013-03-09 14:02:57 -03: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 15:17:40 -04:00
// signal handler sets ShutdownRequested(), which makes main thread's
2017-06-28 12:24:41 -04: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 14:02:57 -03: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 15:17:40 -04:00
// ShutdownRequested() getting set, and then does the normal Qt
2013-03-23 19:14:12 -03:00
// shutdown thing.
2013-03-09 14:02:57 -03:00
//
2016-08-30 17:41:56 -03:00
static std : : unique_ptr < ECCVerifyHandle > globalVerifyHandle ;
2012-07-06 10:33:34 -04:00
2020-06-06 08:23:05 -04:00
static std : : thread g_load_block ;
2019-09-17 19:28:03 -03: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 03:53:17 -03:00
{
InterruptHTTPServer ( ) ;
InterruptHTTPRPC ( ) ;
InterruptRPC ( ) ;
InterruptREST ( ) ;
2015-09-08 12:48:45 -03:00
InterruptTorControl ( ) ;
2018-02-07 19:20:16 -03:00
InterruptMapPort ( ) ;
2019-09-17 19:59:36 -03:00
if ( node . connman )
node . connman - > Interrupt ( ) ;
2017-12-08 16:29:59 -03:00
if ( g_txindex ) {
g_txindex - > Interrupt ( ) ;
}
2018-08-30 02:15:50 -03:00
ForEachBlockFilterIndex ( [ ] ( BlockFilterIndex & index ) { 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 03:53:17 -03:00
}
2019-09-17 18:04:39 -03:00
void Shutdown ( NodeContext & node )
2011-05-14 14:10:21 -04:00
{
2020-06-05 14:55:17 -04:00
static Mutex g_shutdown_mutex ;
TRY_LOCK ( g_shutdown_mutex , lock_shutdown ) ;
if ( ! lock_shutdown ) return ;
2014-06-27 08:41:11 -04:00
LogPrintf ( " %s: In progress... \n " , __func__ ) ;
2020-08-21 14:13:40 -04:00
Assert ( node . args ) ;
2012-06-24 11:03:57 -04:00
2017-02-23 04:38:41 -03:00
/// Note: Shutdown() must be able to handle cases in which initialization failed part of the way,
2014-09-18 09:08:43 -03: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 03:07:54 -04: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 03:53:17 -03:00
StopHTTPRPC ( ) ;
StopREST ( ) ;
StopRPC ( ) ;
StopHTTPServer ( ) ;
2019-09-17 18:04:39 -03:00
for ( const auto & client : node . chain_clients ) {
2017-09-28 15:13:29 -03:00
client - > flush ( ) ;
}
2018-02-07 19:20:16 -03:00
StopMapPort ( ) ;
2017-09-07 15:26:20 -03:00
// Because these depend on each-other, we make sure that neither can be
// using the other before destroying them.
2020-08-29 05:31:11 -04:00
if ( node . peerman ) UnregisterValidationInterface ( node . peerman . get ( ) ) ;
2020-03-28 11:44:53 -03:00
// Follow the lock order requirements:
2020-09-01 16:32:09 -04:00
// * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraFullOutboundCount
2020-03-28 11:44:53 -03:00
// which locks cs_vNodes.
// * ProcessMessage locks cs_main and g_cs_orphans before indirectly calling ForEachNode which
// locks cs_vNodes.
// * CConnman::Stop calls DeleteNode, which calls FinalizeNode, which locks cs_main and calls
// EraseOrphansFor, which locks g_cs_orphans.
//
// Thus the implicit locking order requirement is: (1) cs_main, (2) g_cs_orphans, (3) cs_vNodes.
if ( node . connman ) {
node . connman - > StopThreads ( ) ;
LOCK2 ( : : cs_main , : : g_cs_orphans ) ;
node . connman - > StopNodes ( ) ;
}
2016-04-16 15:47:18 -03:00
2015-08-25 15:12:08 -03:00
StopTorControl ( ) ;
2018-01-24 23:15:56 -03:00
// After everything has been shut down, but before things get flushed, stop the
2021-01-27 04:04:34 -03:00
// CScheduler/checkqueue, scheduler and load block thread.
2020-02-27 23:02:10 -03:00
if ( node . scheduler ) node . scheduler - > stop ( ) ;
2020-06-06 08:23:05 -04:00
if ( g_load_block . joinable ( ) ) g_load_block . join ( ) ;
2020-08-21 02:24:05 -04:00
StopScriptCheckWorkerThreads ( ) ;
2018-01-24 23:15:56 -03: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 05:31:11 -04:00
node . peerman . reset ( ) ;
2019-09-17 19:59:36 -03:00
node . connman . reset ( ) ;
node . banman . reset ( ) ;
2018-08-06 12:08:35 -04:00
2020-07-19 03:07:54 -04:00
if ( node . mempool & & node . mempool - > IsLoaded ( ) & & node . args - > GetArg ( " -persistmempool " , DEFAULT_PERSIST_MEMPOOL ) ) {
DumpMempool ( * node . mempool ) ;
2017-03-09 19:12:25 -03:00
}
2014-03-17 09:19:54 -03:00
2020-09-10 09:27:36 -03:00
// Drop transactions we were still watching, and record fee estimations.
if ( node . fee_estimator ) node . fee_estimator - > Flush ( ) ;
2014-03-17 09:19:54 -03:00
2018-05-02 11:02:48 -03: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 ) ;
2020-04-18 08:05:52 -04:00
for ( CChainState * chainstate : node . chainman - > GetAll ( ) ) {
2019-12-12 12:48:28 -03: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 17:07:46 -03:00
// Stop and delete all indexes only after flushing background callbacks.
if ( g_txindex ) {
g_txindex - > Stop ( ) ;
g_txindex . reset ( ) ;
}
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 14:02:57 -03:00
LOCK ( cs_main ) ;
2020-04-18 08:05:52 -04:00
for ( CChainState * chainstate : node . chainman - > GetAll ( ) ) {
2019-12-12 12:48:28 -03: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 07:38:35 -03:00
}
2017-08-09 11:08:22 -04:00
pblocktree . reset ( ) ;
2011-05-14 14:10:21 -04:00
}
2019-09-17 18:04:39 -03:00
for ( const auto & client : node . chain_clients ) {
2017-09-28 15:13:29 -03:00
client - > stop ( ) ;
}
2014-11-18 14:06:32 -03:00
# if ENABLE_ZMQ
2018-06-29 09:16:31 -04:00
if ( g_zmq_notification_interface ) {
UnregisterValidationInterface ( g_zmq_notification_interface ) ;
delete g_zmq_notification_interface ;
g_zmq_notification_interface = nullptr ;
2014-11-18 14:06:32 -03:00
}
# endif
2019-09-17 18:04:39 -03:00
node . chain_clients . clear ( ) ;
2014-10-19 22:17:01 -03:00
UnregisterAllValidationInterfaces ( ) ;
2017-01-19 18:49:22 -03:00
GetMainSignals ( ) . UnregisterBackgroundSignalScheduler ( ) ;
2015-07-28 15:11:20 -03:00
globalVerifyHandle . reset ( ) ;
Update key.cpp to use new libsecp256k1
libsecp256k1's API changed, so update key.cpp to use it.
Libsecp256k1 now has explicit context objects, which makes it completely thread-safe.
In turn, keep an explicit context object in key.cpp, which is explicitly initialized
destroyed. This is not really pretty now, but it's more efficient than the static
initialized object in key.cpp (which made for example bitcoin-tx slow, as for most of
its calls, libsecp256k1 wasn't actually needed).
This also brings in the new blinding support in libsecp256k1. By passing in a random
seed, temporary variables during the elliptic curve computations are altered, in such
a way that if an attacker does not know the blind, observing the internal operations
leaks less information about the keys used. This was implemented by Greg Maxwell.
2015-04-22 18:28:26 -03:00
ECC_Stop ( ) ;
2020-07-19 14:30:46 -04:00
node . mempool . reset ( ) ;
2020-07-28 13:12:50 -04:00
node . fee_estimator . reset ( ) ;
2020-04-18 08:05:52 -04:00
node . chainman = nullptr ;
2020-02-12 16:08:28 -03:00
node . scheduler . reset ( ) ;
2020-04-04 16:50:40 -03:00
try {
2020-08-21 14:13:40 -04:00
if ( ! fs : : remove ( GetPidFile ( * node . args ) ) ) {
2020-04-04 16: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 ) ) ;
}
2020-08-21 14:13:40 -04:00
node . args = nullptr ;
2014-06-27 08:41:11 -04:00
LogPrintf ( " %s: done \n " , __func__ ) ;
2011-05-14 14:10:21 -04:00
}
2014-11-30 22:39:44 -03:00
/**
2017-03-22 17:29:41 -03: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-11-30 22:39:44 -03:00
*/
2018-04-30 12:31:11 -03:00
# ifndef WIN32
2017-03-22 17:29:41 -03:00
static void HandleSIGTERM ( int )
2011-05-14 14:10:21 -04:00
{
2018-05-16 15:17:40 -04:00
StartShutdown ( ) ;
2011-05-14 14:10:21 -04:00
}
2017-03-22 17:29:41 -03:00
static void HandleSIGHUP ( int )
2012-03-02 16:31:16 -03:00
{
2019-01-25 17:54:49 -03:00
LogInstance ( ) . m_reopen_file = true ;
2012-03-02 16:31:16 -03:00
}
2018-04-30 12:31:11 -03:00
# else
static BOOL WINAPI consoleCtrlHandler ( DWORD dwCtrlType )
{
2018-05-16 15:17:40 -04:00
StartShutdown ( ) ;
2018-04-30 12:31:11 -03:00
Sleep ( INFINITE ) ;
return true ;
}
# endif
2011-05-14 14:10:21 -04:00
2017-03-22 17:29:41 -03: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 01:36:37 -04:00
sigaction ( signal , & sa , nullptr ) ;
2017-03-22 17:29:41 -03:00
}
# endif
2019-03-29 15:11:43 -03:00
static boost : : signals2 : : connection rpc_notify_block_change_connection ;
2018-05-02 12:14:48 -03:00
static void OnRPCStarted ( )
2016-09-01 22:55:21 -03:00
{
2020-03-04 14:48:32 -03:00
rpc_notify_block_change_connection = uiInterface . NotifyBlockTip_connect ( std : : bind ( RPCNotifyBlockChange , std : : placeholders : : _2 ) ) ;
2016-09-01 22:55:21 -03:00
}
2012-05-11 09:28:59 -04:00
2018-05-02 12:14:48 -03:00
static void OnRPCStopped ( )
2014-10-19 05:46:17 -03:00
{
2019-03-29 15:11:43 -03:00
rpc_notify_block_change_connection . disconnect ( ) ;
2020-03-04 14:48:32 -03:00
RPCNotifyBlockChange ( nullptr ) ;
2018-04-04 01:53:07 -03:00
g_best_block_cv . notify_all ( ) ;
2016-12-25 17:19:40 -03:00
LogPrint ( BCLog : : RPC , " RPC stopped. \n " ) ;
2014-10-19 05:46:17 -03:00
}
2020-04-08 19:47:56 -04:00
void SetupServerArgs ( NodeContext & node )
2012-05-13 05:36:10 -04:00
{
2020-04-08 19:47:56 -04:00
assert ( ! node . args ) ;
node . args = & gArgs ;
2020-07-19 03:31:51 -04:00
ArgsManager & argsman = * node . args ;
2020-04-08 19:47:56 -04:00
2020-08-21 14:13:40 -04:00
SetupHelpOptions ( argsman ) ;
2020-07-19 03:47:05 -04: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 15:57:52 -03:00
2015-05-21 22:50:01 -03:00
const auto defaultBaseParams = CreateBaseChainParams ( CBaseChainParams : : MAIN ) ;
const auto testnetBaseParams = CreateBaseChainParams ( CBaseChainParams : : TESTNET ) ;
2020-09-25 08:55:40 -03:00
const auto signetBaseParams = CreateBaseChainParams ( CBaseChainParams : : SIGNET ) ;
2018-08-20 20:46:34 -03:00
const auto regtestBaseParams = CreateBaseChainParams ( CBaseChainParams : : REGTEST ) ;
2020-09-24 10:11:27 -03:00
const auto defaultChainParams = CreateChainParams ( argsman , CBaseChainParams : : MAIN ) ;
const auto testnetChainParams = CreateChainParams ( argsman , CBaseChainParams : : TESTNET ) ;
const auto signetChainParams = CreateChainParams ( argsman , CBaseChainParams : : SIGNET ) ;
const auto regtestChainParams = CreateChainParams ( argsman , CBaseChainParams : : REGTEST ) ;
2015-02-04 05:11:49 -03:00
2018-06-11 17:23:13 -04:00
// Hidden Options
2019-02-06 15:57:52 -03:00
std : : vector < std : : string > hidden_args = {
2018-09-20 17:41:08 -03:00
" -dbcrashratio " , " -forcecompactdb " ,
2018-06-11 17:23:13 -04:00
// GUI args. These will be overwritten by SetupUIArgs for the GUI
2019-10-12 13:49:29 -03:00
" -choosedatadir " , " -lang=<lang> " , " -min " , " -resetguisettings " , " -splash " , " -uiplatform " } ;
2018-06-11 17:23:13 -04:00
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -version " , " Print version and exit " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2019-07-05 12:30:15 -04:00
# if HAVE_SYSTEM
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -alertnotify=<cmd> " , " Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2019-03-14 07:30:37 -03:00
# endif
2020-09-25 08: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 03:47:05 -04:00
argsman . AddArg ( " -blocksdir=<dir> " , " Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-12-10 07:39:37 -03: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 12:30:15 -04:00
# if HAVE_SYSTEM
2020-07-19 03:47:05 -04: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 07:30:37 -03:00
# endif
2020-07-19 03:47:05 -04: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 ) ;
argsman . AddArg ( " -conf=<file> " , strprintf ( " Specify path to read-only configuration file. Relative paths will be prefixed by datadir location. (default: %s) " , BITCOIN_CONF_FILENAME ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
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 ( " -debuglogfile=<file> " , strprintf ( " Specify location of debug log file. Relative paths will be prefixed by a net-specific datadir location. (-nodebuglogfile to disable; default: %s) " , DEFAULT_DEBUGLOGFILE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -feefilter " , strprintf ( " Tell other nodes to filter invs to us by our mempool min fee (default: %u) " , DEFAULT_FEEFILTER ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , 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 ) ;
argsman . AddArg ( " -loadblock=<file> " , " Imports blocks from external file on startup " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -maxmempool=<n> " , strprintf ( " Keep the transaction memory pool below <n> megabytes (default: %u) " , DEFAULT_MAX_MEMPOOL_SIZE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -maxorphantx=<n> " , strprintf ( " Keep at most <n> unconnectable transactions in memory (default: %u) " , DEFAULT_MAX_ORPHAN_TRANSACTIONS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -mempoolexpiry=<n> " , strprintf ( " Do not keep transactions in the mempool longer than <n> hours (default: %u) " , DEFAULT_MEMPOOL_EXPIRY ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-09-25 08: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 03:47:05 -04: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 05:06:32 -04:00
- GetNumCores ( ) , MAX_SCRIPTCHECK_THREADS , DEFAULT_SCRIPTCHECK_THREADS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-07-19 03:47:05 -04: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 ) ;
argsman . AddArg ( " -prune=<n> " , strprintf ( " Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks, and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex and -rescan. "
2015-05-04 13:46:33 -03: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 05:06:32 -04: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 ) ;
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -reindex " , " Rebuild chain state and block index from the blk*.dat files on disk " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
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 ) ;
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 12:38:36 -03:00
# if HAVE_SYSTEM
argsman . AddArg ( " -startupnotify=<cmd> " , " Execute command on startup. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
# endif
2015-09-11 18:31:30 -03:00
# ifndef WIN32
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -sysperms " , " Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2018-06-11 17:23:13 -04:00
# else
hidden_args . emplace_back ( " -sysperms " ) ;
2014-06-04 07:16:07 -04:00
# endif
2020-07-19 03:47:05 -04: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-30 02:15:50 -03: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 05:06:32 -04:00
ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -addnode=<ip> " , " Add a node to connect to and attempt to keep the connection open (see the `addnode` RPC command help for more info). This option can be specified multiple times to add multiple nodes. " , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY , OptionsCategory : : CONNECTION ) ;
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 12: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 ) ;
2020-07-19 03:47:05 -04: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 ) ;
2020-09-05 12:51:33 -04:00
argsman . AddArg ( " -dnsseed " , strprintf ( " Query for peer addresses via DNS lookup, if low on addresses (default: %u unless -connect used) " , DEFAULT_DNSSEED ) , ArgsManager : : ALLOW_BOOL , OptionsCategory : : CONNECTION ) ;
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -externalip=<ip> " , " Specify your own public address " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2020-09-05 12:51:33 -04:00
argsman . AddArg ( " -fixedseeds " , strprintf ( " Allow fixed seeds if DNS seeds don't provide peers (default: %u) " , DEFAULT_FIXEDSEEDS ) , ArgsManager : : ALLOW_BOOL , OptionsCategory : : CONNECTION ) ;
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -forcednsseed " , strprintf ( " Always query for peer addresses via DNS lookup (default: %u) " , DEFAULT_FORCEDNSSEED ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -listen " , " Accept connections from outside (default: 1 if no -proxy or -connect) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2020-08-01 09:10:26 -04:00
argsman . AddArg ( " -listenonion " , strprintf ( " Automatically create Tor onion service (default: %d) " , DEFAULT_LISTEN_ONION ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -maxconnections=<n> " , strprintf ( " Maintain at most <n> connections to peers (default: %u) " , DEFAULT_MAX_PEER_CONNECTIONS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
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 ) ;
argsman . AddArg ( " -maxtimeadjustment " , strprintf ( " Maximum allowed median peer time offset adjustment. Local perspective of time may be influenced by peers forward or backward by this amount. (default: %u seconds) " , DEFAULT_MAX_TIME_ADJUSTMENT ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -maxuploadtarget=<n> " , strprintf ( " Tries to keep outbound traffic under the given target (in MiB per 24h). Limit does not apply to peers with 'download' permission. 0 = no limit (default: %d) " , DEFAULT_MAX_UPLOAD_TARGET ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2020-08-01 09:10:26 -04: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 ) ;
2021-02-01 19:48:16 -03:00
argsman . AddArg ( " -onlynet=<net> " , " Make outgoing connections only through network <net> ( " + Join ( GetNetworkNames ( ) , " , " ) + " ). Incoming connections are not affected by this option. This option can be specified multiple times to allow multiple networks. Warning: if it is used with ipv4 or ipv6 but not onion and the -onion or -proxy option is set, then outbound onion connections will still be made; use -noonion or -onion=0 to disable outbound onion connections in this case. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2020-07-19 03:47:05 -04: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 ) ;
argsman . AddArg ( " -permitbaremultisig " , strprintf ( " Relay non-P2SH multisig (default: %u) " , DEFAULT_PERMIT_BAREMULTISIG ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2020-12-15 22:37:32 -03: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. " , defaultChainParams - > GetDefaultPort ( ) , testnetChainParams - > GetDefaultPort ( ) , signetChainParams - > GetDefaultPort ( ) , regtestChainParams - > GetDefaultPort ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY , OptionsCategory : : CONNECTION ) ;
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -proxy=<ip:port> " , " Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
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 ) ;
argsman . AddArg ( " -networkactive " , " Enable all P2P network activity (default: 1). Can be changed by the setnetworkactive RPC command " , ArgsManager : : ALLOW_BOOL , OptionsCategory : : CONNECTION ) ;
2021-02-03 15:20:30 -03: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 03:47:05 -04: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 05:36:10 -04:00
# ifdef USE_UPNP
# if USE_UPNP
2020-07-19 03:47:05 -04: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 05:36:10 -04:00
# else
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -upnp " , strprintf ( " Use UPnP to map the listening port (default: %u) " , 0 ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2013-10-11 18:09:59 -03:00
# endif
2018-06-11 17:23:13 -04:00
# else
hidden_args . emplace_back ( " -upnp " ) ;
2012-05-13 05:36:10 -04:00
# endif
2020-02-22 21:12:19 -03:00
# ifdef USE_NATPMP
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_BOOL , OptionsCategory : : CONNECTION ) ;
# else
hidden_args . emplace_back ( " -natpmp " ) ;
# endif // USE_NATPMP
2020-07-19 03:47:05 -04: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 11:07:25 -04: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 00:31:41 -04:00
2020-07-19 03:47:05 -04: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 11:07:25 -04:00
" CIDR-notated network (e.g. 1.2.3.0/24). Uses the same permissions as "
2019-08-23 00:31:41 -04:00
" -whitebind. Can be specified multiple times. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2014-02-03 03:23:20 -03:00
2020-07-19 03:31:51 -04:00
g_wallet_init_interface . AddWalletOptions ( argsman ) ;
2014-02-03 03:23:20 -03:00
2014-11-18 14:06:32 -03:00
# if ENABLE_ZMQ
2020-07-19 03:47:05 -04: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 03:47:05 -04: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 17:23:13 -04: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 21:42:03 -03: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 14:06:32 -03:00
# endif
2020-07-19 03:47:05 -04: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 ) ;
argsman . AddArg ( " -checkmempool=<n> " , strprintf ( " Run checks every <n> transactions (default: %u, regtest: %u) " , defaultChainParams - > DefaultConsistencyChecks ( ) , regtestChainParams - > DefaultConsistencyChecks ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2020-06-10 19:57:58 -04: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 03:47:05 -04: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 ) ;
argsman . AddArg ( " -limitancestorsize=<n> " , strprintf ( " Do not accept transactions whose size with all in-mempool ancestors exceeds <n> kilobytes (default: %u) " , DEFAULT_ANCESTOR_SIZE_LIMIT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
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 ) ;
argsman . AddArg ( " -limitdescendantsize=<n> " , strprintf ( " Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u). " , DEFAULT_DESCENDANT_SIZE_LIMIT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -addrmantest " , " Allows to test address relay on localhost " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2020-07-13 14:00:03 -04:00
argsman . AddArg ( " -capturemessages " , " Capture all P2P messages to disk " , ArgsManager : : ALLOW_BOOL | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -debug=<category> " , " Output debugging information (default: -nodebug, supplying <category> is optional). "
2021-02-01 17:33:31 -03:00
" If <category> is not supplied or if <category> = 1, output all debugging information. <category> can be: " + LogInstance ( ) . LogCategoriesString ( ) + " . This option can be specified multiple times to output multiple categories. " ,
2020-04-16 11:12:14 -04:00
ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
2021-02-01 17:33:31 -03:00
argsman . AddArg ( " -debugexclude=<category> " , strprintf ( " Exclude debugging information for a category. Can be used in conjunction with -debug=1 to output debug logs for all categories except the specified category. This option can be specified multiple times to exclude multiple categories. " ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -logips " , strprintf ( " Include IP addresses in debug output (default: %u) " , DEFAULT_LOGIPS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -logtimestamps " , strprintf ( " Prepend debug output with timestamp (default: %u) " , DEFAULT_LOGTIMESTAMPS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
2020-04-16 08:22:12 -04:00
# ifdef HAVE_THREAD_LOCAL
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -logthreadnames " , strprintf ( " Prepend debug output with name of the originating thread (only available on platforms supporting thread_local) (default: %u) " , DEFAULT_LOGTHREADNAMES ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
2020-04-16 08:22:12 -04:00
# else
hidden_args . emplace_back ( " -logthreadnames " ) ;
# endif
2020-08-25 16:22:28 -04:00
argsman . AddArg ( " -logsourcelocations " , strprintf ( " Prepend debug output with name of the originating source location (source file, line number and function name) (default: %u) " , DEFAULT_LOGSOURCELOCATIONS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -logtimemicros " , strprintf ( " Add microsecond precision to debug timestamps (default: %u) " , DEFAULT_LOGTIMEMICROS ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -mocktime=<n> " , " Replace actual time with " + UNIX_EPOCH_TIME + " (default: 0) " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -maxsigcachesize=<n> " , strprintf ( " Limit sum of signature cache and script execution cache sizes to <n> MiB (default: %u) " , DEFAULT_MAX_SIG_CACHE_SIZE ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -maxtipage=<n> " , strprintf ( " Maximum tip age in seconds to consider node in initial block download (default: %u) " , DEFAULT_MAX_TIP_AGE ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -printpriority " , strprintf ( " Log transaction fee per kB when mining blocks (default: %u) " , DEFAULT_PRINTPRIORITY ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -printtoconsole " , " Send trace/debug info to console (default: 1 when no -daemon. To disable logging to file, set -nodebuglogfile) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -shrinkdebugfile " , " Shrink debug.log file on client startup (default: 1 when no -debug) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -uacomment=<cmt> " , " Append comment to the user agent string " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
2018-04-28 17:54:58 -03:00
2020-07-19 03:31:51 -04:00
SetupChainParamsBaseOptions ( argsman ) ;
2018-04-28 17:54:58 -03:00
2020-07-19 03:47:05 -04: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 ) ;
argsman . AddArg ( " -incrementalrelayfee=<amt> " , strprintf ( " Fee rate (in %s/kB) used to define cost of relay, used for mempool limiting and BIP 125 replacement. (default: %s) " , CURRENCY_UNIT , FormatMoney ( DEFAULT_INCREMENTAL_RELAY_FEE ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : NODE_RELAY ) ;
argsman . AddArg ( " -dustrelayfee=<amt> " , strprintf ( " Fee rate (in %s/kB) used to define dust, the value of an output such that it will cost more than its value in fees at this fee rate to spend it. (default: %s) " , CURRENCY_UNIT , FormatMoney ( DUST_RELAY_TX_FEE ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : NODE_RELAY ) ;
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 ) ;
argsman . AddArg ( " -minrelaytxfee=<amt> " , strprintf ( " Fees (in %s/kB) 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 05:06:32 -04:00
CURRENCY_UNIT , FormatMoney ( DEFAULT_MIN_RELAY_TX_FEE ) ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : NODE_RELAY ) ;
2020-07-19 03:47:05 -04: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 ) ;
argsman . AddArg ( " -blockmintxfee=<amt> " , strprintf ( " Set lowest fee rate (in %s/kB) for transactions to be included in block creation. (default: %s) " , CURRENCY_UNIT , FormatMoney ( DEFAULT_BLOCK_MIN_TX_FEE ) ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : BLOCK_CREATION ) ;
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 ) ;
argsman . AddArg ( " -rpcbind=<addr>[:port] " , " Bind to given address to listen for JSON-RPC connections. Do not expose the RPC server to untrusted networks such as the public internet! This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost) " , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY | ArgsManager : : SENSITIVE , OptionsCategory : : RPC ) ;
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 08: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 03:47:05 -04: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 ) ;
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_BOOL , OptionsCategory : : RPC ) ;
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 20:40:51 -03:00
2018-06-11 17:23:13 -04:00
# if HAVE_DECL_DAEMON
2020-07-19 03:47:05 -04:00
argsman . AddArg ( " -daemon " , " Run in the background as a daemon and accept commands " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2018-06-11 17:23:13 -04:00
# else
hidden_args . emplace_back ( " -daemon " ) ;
# endif
// Add the hidden options
2020-07-19 03:47:05 -04:00
argsman . AddHiddenArgs ( hidden_args ) ;
2012-05-13 05:36:10 -04:00
}
2014-06-10 10:02:46 -04:00
std : : string LicenseInfo ( )
{
2016-06-16 04:10:03 -04:00
const std : : string URL_SOURCE_CODE = " <https://github.com/bitcoin/bitcoin> " ;
2016-06-11 23:11:24 -04:00
2019-06-28 14:09:58 -04:00
return CopyrightHolders ( strprintf ( _ ( " Copyright (C) %i-%i " ) . translated , 2009 , COPYRIGHT_YEAR ) + " " ) + " \n " +
2014-06-10 10:02:46 -04:00
" \n " +
2016-06-16 04:10:03 -04:00
strprintf ( _ ( " Please contribute if you find %s useful. "
2019-06-28 14:09:58 -04:00
" Visit %s for further information about the software. " ) . translated ,
2020-04-01 09:28:35 -03:00
PACKAGE_NAME , " < " PACKAGE_URL " > " ) +
2016-06-16 04:10:03 -04:00
" \n " +
2019-06-28 14:09:58 -04:00
strprintf ( _ ( " The source code is available from %s. " ) . translated ,
2016-06-16 04:10:03 -04:00
URL_SOURCE_CODE ) +
2014-06-10 10:02:46 -04:00
" \n " +
2016-06-16 04:10:03 -04:00
" \n " +
2019-06-28 14:09:58 -04:00
_ ( " This is experimental software. " ) . translated + " \n " +
2019-10-26 10:14:14 -03:00
strprintf ( _ ( " Distributed under the MIT software license, see the accompanying file %s or %s " ) . translated , " COPYING " , " <https://opensource.org/licenses/MIT> " ) +
2014-06-10 10:02:46 -04:00
" \n " ;
}
2016-07-22 09:57:25 -04:00
static bool fHaveGenesis = false ;
2017-11-03 08:49:16 -03:00
static Mutex g_genesis_wait_mutex ;
static std : : condition_variable g_genesis_wait_cv ;
2016-07-22 09:57:25 -04:00
2020-03-04 14:41:18 -03:00
static void BlockNotifyGenesisWait ( const CBlockIndex * pBlockIndex )
2016-07-22 09:57:25 -04:00
{
2017-08-07 01:36:37 -04:00
if ( pBlockIndex ! = nullptr ) {
2016-07-22 09:57:25 -04:00
{
2017-11-03 08:49:16 -03:00
LOCK ( g_genesis_wait_mutex ) ;
2016-07-22 09:57:25 -04:00
fHaveGenesis = true ;
}
2017-11-03 08:49:16 -03:00
g_genesis_wait_cv . notify_all ( ) ;
2016-07-22 09:57:25 -04:00
}
}
2012-10-22 17:45:26 -03:00
struct CImportingNow
{
CImportingNow ( ) {
assert ( fImporting = = false ) ;
fImporting = true ;
}
~ CImportingNow ( ) {
assert ( fImporting = = true ) ;
fImporting = false ;
}
} ;
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 16:27:44 -03:00
// If we're using -prune with -reindex, then delete block files that will be ignored by the
// reindex. Since reindexing works by starting at block file 0 and looping until a blockfile
2015-06-02 16:24:53 -03:00
// is missing, do the same here to delete any later block files after a gap. Also delete all
// rev files since they'll be rewritten by the reindex anyway. This ensures that vinfoBlockFile
// is in sync with what's actually on disk by the time we start downloading, so that pruning
// works correctly.
2018-05-02 12:14:48 -03:00
static void CleanupBlockRevFiles ( )
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 16:27:44 -03:00
{
2017-03-01 13:05:50 -03:00
std : : map < std : : string , fs : : path > mapBlockFiles ;
2015-06-02 16:24:53 -03:00
// Glob all blk?????.dat and rev?????.dat files from the blocks directory.
// Remove the rev files immediately and insert the blk file paths into an
// ordered map keyed by block file index.
LogPrintf ( " Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune \n " ) ;
2018-03-09 01:12:43 -03:00
fs : : path blocksdir = GetBlocksDir ( ) ;
2017-03-01 13:05:50 -03:00
for ( fs : : directory_iterator it ( blocksdir ) ; it ! = fs : : directory_iterator ( ) ; it + + ) {
2017-10-13 18:23:52 -03:00
if ( fs : : is_regular_file ( * it ) & &
2015-06-02 16:24:53 -03:00
it - > path ( ) . filename ( ) . string ( ) . length ( ) = = 12 & &
it - > path ( ) . filename ( ) . string ( ) . substr ( 8 , 4 ) = = " .dat " )
{
if ( it - > path ( ) . filename ( ) . string ( ) . substr ( 0 , 3 ) = = " blk " )
mapBlockFiles [ it - > path ( ) . filename ( ) . string ( ) . substr ( 3 , 5 ) ] = it - > path ( ) ;
else if ( it - > path ( ) . filename ( ) . string ( ) . substr ( 0 , 3 ) = = " rev " )
remove ( it - > path ( ) ) ;
}
}
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 16:27:44 -03:00
2015-06-02 16:24:53 -03:00
// Remove all block files that aren't part of a contiguous set starting at
// zero by walking the ordered map (keys are block file indices) by
// keeping a separate counter. Once we hit a gap (or if 0 doesn't exist)
// start removing block files.
int nContigCounter = 0 ;
2018-05-15 18:41:53 -04:00
for ( const std : : pair < const std : : string , fs : : path > & item : mapBlockFiles ) {
2015-06-02 16:24:53 -03:00
if ( atoi ( item . first ) = = nContigCounter ) {
nContigCounter + + ;
continue ;
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 16:27:44 -03:00
}
2015-06-02 16:24:53 -03:00
remove ( item . second ) ;
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 16:27:44 -03:00
}
}
2020-09-28 12:38:36 -03: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
2020-08-21 14:13:40 -04:00
static void ThreadImport ( ChainstateManager & chainman , std : : vector < fs : : path > vImportFiles , const ArgsManager & args )
2013-03-07 00:31:26 -03:00
{
2015-04-17 09:40:24 -03:00
const CChainParams & chainparams = Params ( ) ;
2018-03-06 14:50:20 -03:00
ScheduleBatchPriority ( ) ;
2016-11-04 15:34:36 -03:00
{
2016-04-20 10:45:41 -03:00
CImportingNow imp ;
2012-10-21 16:23:13 -03:00
// -reindex
if ( fReindex ) {
int nFile = 0 ;
2013-03-07 00:31:26 -03:00
while ( true ) {
2019-01-06 16:46:30 -03:00
FlatFilePos pos ( nFile , 0 ) ;
2019-01-06 16:06:31 -03:00
if ( ! fs : : exists ( GetBlockPosFilename ( pos ) ) )
2014-09-08 14:29:14 -03:00
break ; // No block files left to reindex
2012-10-21 16:23:13 -03:00
FILE * file = OpenBlockFile ( pos , true ) ;
if ( ! file )
2014-09-08 14:29:14 -03:00
break ; // This error is logged in OpenBlockFile
2013-09-18 07:38:08 -03:00
LogPrintf ( " Reindexing block file blk%05u.dat... \n " , ( unsigned int ) nFile ) ;
2020-08-25 17:17:22 -04:00
: : ChainstateActive ( ) . LoadExternalBlockFile ( chainparams , file , & pos ) ;
2020-04-27 15:36:05 -04:00
if ( ShutdownRequested ( ) ) {
LogPrintf ( " Shutdown requested. Exit %s \n " , __func__ ) ;
return ;
}
2012-10-21 16:23:13 -03:00
nFile + + ;
}
2013-03-07 00:31:26 -03:00
pblocktree - > WriteReindexing ( false ) ;
fReindex = false ;
2013-09-18 07:38:08 -03:00
LogPrintf ( " Reindexing finished \n " ) ;
2013-03-07 00:31:26 -03:00
// To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked):
2017-07-06 19:57:20 -04:00
LoadGenesisBlock ( chainparams ) ;
2012-10-22 17:45:26 -03:00
}
2012-10-21 16:23:13 -03:00
// -loadblock=
2017-06-01 21:18:57 -04:00
for ( const fs : : path & path : vImportFiles ) {
2017-03-01 13:28:39 -03:00
FILE * file = fsbridge : : fopen ( path , " rb " ) ;
2012-10-21 16:23:13 -03:00
if ( file ) {
2014-02-08 07:35:02 -03:00
LogPrintf ( " Importing blocks file %s... \n " , path . string ( ) ) ;
2020-08-25 17:17:22 -04:00
: : ChainstateActive ( ) . LoadExternalBlockFile ( chainparams , file ) ;
2020-04-27 15:36:05 -04:00
if ( ShutdownRequested ( ) ) {
LogPrintf ( " Shutdown requested. Exit %s \n " , __func__ ) ;
return ;
}
2014-02-08 07:35:02 -03:00
} else {
LogPrintf ( " Warning: Could not open blocks file %s \n " , path . string ( ) ) ;
2012-10-21 16:23:13 -03:00
}
}
2014-05-07 14:10:48 -04:00
2016-04-20 10:45:41 -03:00
// scan for better chains in the block chain database, that are not yet connected in the active best chain
2020-01-29 11:57:56 -03:00
// We can't hold cs_main during ActivateBestChain even though we're accessing
2020-04-18 08:05:52 -04:00
// the chainman unique_ptrs since ABC requires us not to be holding cs_main, so retrieve
2020-01-29 11:57:56 -03:00
// the relevant pointers before the ABC call.
2020-04-18 08:05:52 -04:00
for ( CChainState * chainstate : WITH_LOCK ( : : cs_main , return chainman . GetAll ( ) ) ) {
2020-01-29 11:57:56 -03:00
BlockValidationState state ;
if ( ! chainstate - > ActivateBestChain ( state , chainparams , nullptr ) ) {
LogPrintf ( " Failed to connect best block (%s) \n " , state . ToString ( ) ) ;
StartShutdown ( ) ;
return ;
}
2016-04-20 10:45:41 -03:00
}
2020-08-21 14:38:01 -04:00
if ( args . GetBoolArg ( " -stopafterblockimport " , DEFAULT_STOPAFTERBLOCKIMPORT ) ) {
2014-05-07 14:10:48 -04:00
LogPrintf ( " Stopping after block import \n " ) ;
StartShutdown ( ) ;
2018-02-12 08:17:36 -03:00
return ;
2014-05-07 14:10:48 -04:00
}
2016-11-04 15:34:36 -03:00
} // End scope of CImportingNow
2020-07-19 03:07:54 -04:00
chainman . ActiveChainstate ( ) . LoadMempool ( args ) ;
2012-10-22 17:45:26 -03:00
}
2014-06-02 19:21:03 -04:00
/** Sanity checks
* Ensure that Bitcoin is running in a usable environment with all
* necessary library support .
*/
2018-09-13 14:36:41 -03:00
static bool InitSanityCheck ( )
2014-06-02 19:21:03 -04:00
{
2020-04-11 11:48:04 -04:00
if ( ! ECC_InitSanityCheck ( ) ) {
return InitError ( Untranslated ( " Elliptic curve cryptography sanity check failure. Aborting. " ) ) ;
2014-06-02 19:21:03 -04:00
}
2017-02-22 04:02:50 -03:00
2014-06-13 19:23:01 -04:00
if ( ! glibc_sanity_test ( ) | | ! glibcxx_sanity_test ( ) )
return false ;
2014-06-02 19:21:03 -04:00
2017-02-22 04:02:50 -03:00
if ( ! Random_SanityCheck ( ) ) {
2020-04-11 11:48:04 -04:00
return InitError ( Untranslated ( " OS cryptographic RNG sanity check failure. Aborting. " ) ) ;
2017-02-22 04:02:50 -03:00
}
2017-01-16 17:01:37 -03:00
if ( ! ChronoSanityCheck ( ) ) {
return InitError ( Untranslated ( " Clock epoch mismatch. Aborting. " ) ) ;
}
2014-06-02 19:21:03 -04:00
return true ;
}
2020-06-18 15:19:26 -04:00
static bool AppInitServers ( const util : : Ref & context , 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 03:53:17 -03:00
{
2020-08-21 14:13:40 -04:00
const ArgsManager & args = * Assert ( node . args ) ;
2016-09-01 22:55:21 -03: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 03:53:17 -03:00
RPCServer : : OnStopped ( & OnRPCStopped ) ;
2015-08-28 11:55:16 -03: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 03:53:17 -03:00
return false ;
2018-07-27 02:22:42 -04:00
StartRPC ( ) ;
2020-06-18 15:19:26 -04:00
node . rpc_interruption_point = RpcInterruptionPoint ;
2020-04-17 11:28:45 -04:00
if ( ! StartHTTPRPC ( context ) )
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 03:53:17 -03:00
return false ;
2020-08-21 14:38:01 -04:00
if ( args . GetBoolArg ( " -rest " , DEFAULT_REST_ENABLE ) ) StartREST ( context ) ;
2018-07-27 02:22:42 -04: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 03:53:17 -03:00
return true ;
}
2015-10-08 04:58:31 -03:00
// Parameter interaction based on rules
2020-08-21 14:13:40 -04:00
void InitParameterInteraction ( ArgsManager & args )
2015-10-08 04:58:31 -03:00
{
// when specifying an explicit binding address, you want to listen on it
// even when -connect or -proxy is specified
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -bind " ) ) {
if ( args . SoftSetBoolArg ( " -listen " , true ) )
2015-10-08 04:58:31 -03:00
LogPrintf ( " %s: parameter interaction: -bind set -> setting -listen=1 \n " , __func__ ) ;
}
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -whitebind " ) ) {
if ( args . SoftSetBoolArg ( " -listen " , true ) )
2015-10-08 04:58:31 -03:00
LogPrintf ( " %s: parameter interaction: -whitebind set -> setting -listen=1 \n " , __func__ ) ;
}
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -connect " ) ) {
2015-10-08 04:58:31 -03:00
// when only connecting to trusted nodes, do not seed via DNS, or listen by default
2020-08-21 14:38:01 -04:00
if ( args . SoftSetBoolArg ( " -dnsseed " , false ) )
2015-10-08 04:58:31 -03:00
LogPrintf ( " %s: parameter interaction: -connect set -> setting -dnsseed=0 \n " , __func__ ) ;
2020-08-21 14:38:01 -04:00
if ( args . SoftSetBoolArg ( " -listen " , false ) )
2015-10-08 04:58:31 -03:00
LogPrintf ( " %s: parameter interaction: -connect set -> setting -listen=0 \n " , __func__ ) ;
}
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -proxy " ) ) {
2015-10-08 04:58:31 -03:00
// to protect privacy, do not listen by default if a default proxy server is specified
2020-08-21 14:38:01 -04:00
if ( args . SoftSetBoolArg ( " -listen " , false ) )
2015-10-08 04:58:31 -03:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -listen=0 \n " , __func__ ) ;
2020-02-22 21:12:19 -03:00
// to protect privacy, do not map ports when a proxy is set. The user may still specify -listen=1
2015-10-08 04:58:31 -03:00
// to listen locally, so don't rely on this happening through -listen below.
2020-08-21 14:38:01 -04:00
if ( args . SoftSetBoolArg ( " -upnp " , false ) )
2015-10-08 04:58:31 -03:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -upnp=0 \n " , __func__ ) ;
2020-02-22 21:12:19 -03:00
if ( args . SoftSetBoolArg ( " -natpmp " , false ) ) {
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -natpmp=0 \n " , __func__ ) ;
}
2015-10-08 04:58:31 -03:00
// to protect privacy, do not discover addresses by default
2020-08-21 14:38:01 -04:00
if ( args . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 04:58:31 -03:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -discover=0 \n " , __func__ ) ;
}
2020-08-21 14:38:01 -04:00
if ( ! args . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) ) {
2015-10-08 04:58:31 -03:00
// do not map ports or try to retrieve public IP when not listening (pointless)
2020-08-21 14:38:01 -04:00
if ( args . SoftSetBoolArg ( " -upnp " , false ) )
2015-10-08 04:58:31 -03:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -upnp=0 \n " , __func__ ) ;
2020-02-22 21:12:19 -03:00
if ( args . SoftSetBoolArg ( " -natpmp " , false ) ) {
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -natpmp=0 \n " , __func__ ) ;
}
2020-08-21 14:38:01 -04:00
if ( args . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 04:58:31 -03:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -discover=0 \n " , __func__ ) ;
2020-08-21 14:38:01 -04:00
if ( args . SoftSetBoolArg ( " -listenonion " , false ) )
2015-10-08 04:58:31 -03:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -listenonion=0 \n " , __func__ ) ;
}
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -externalip " ) ) {
2015-10-08 04:58:31 -03:00
// if an explicit public IP is specified, do not try to find others
2020-08-21 14:38:01 -04:00
if ( args . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 04:58:31 -03:00
LogPrintf ( " %s: parameter interaction: -externalip set -> setting -discover=0 \n " , __func__ ) ;
}
2016-11-12 06:23:57 -03:00
// disable whitelistrelay in blocksonly mode
2020-08-21 14:38:01 -04:00
if ( args . GetBoolArg ( " -blocksonly " , DEFAULT_BLOCKSONLY ) ) {
if ( args . SoftSetBoolArg ( " -whitelistrelay " , false ) )
2015-11-25 20:00:23 -03:00
LogPrintf ( " %s: parameter interaction: -blocksonly=1 -> setting -whitelistrelay=0 \n " , __func__ ) ;
2015-10-08 05:01:29 -03:00
}
2015-11-25 20:00:23 -03:00
// Forcing relay from whitelisted hosts implies we will accept relays from them in the first place.
2020-08-21 14:38:01 -04:00
if ( args . GetBoolArg ( " -whitelistforcerelay " , DEFAULT_WHITELISTFORCERELAY ) ) {
if ( args . SoftSetBoolArg ( " -whitelistrelay " , true ) )
2015-11-25 20:00:23 -03:00
LogPrintf ( " %s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1 \n " , __func__ ) ;
}
2015-10-08 04:58:31 -03:00
}
2018-03-27 01:35:35 -03: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 14:13:40 -04:00
void InitLogging ( const ArgsManager & args )
2015-11-26 10:03:27 -03:00
{
2020-08-21 14:38:01 -04:00
LogInstance ( ) . m_print_to_file = ! args . IsArgNegated ( " -debuglogfile " ) ;
LogInstance ( ) . m_file_path = AbsPathForConfigVal ( args . GetArg ( " -debuglogfile " , DEFAULT_DEBUGLOGFILE ) ) ;
LogInstance ( ) . m_print_to_console = args . GetBoolArg ( " -printtoconsole " , ! args . GetBoolArg ( " -daemon " , false ) ) ;
LogInstance ( ) . m_log_timestamps = args . GetBoolArg ( " -logtimestamps " , DEFAULT_LOGTIMESTAMPS ) ;
LogInstance ( ) . m_log_time_micros = args . GetBoolArg ( " -logtimemicros " , DEFAULT_LOGTIMEMICROS ) ;
2020-04-16 08:22:12 -04:00
# ifdef HAVE_THREAD_LOCAL
2020-08-21 14:38:01 -04:00
LogInstance ( ) . m_log_threadnames = args . GetBoolArg ( " -logthreadnames " , DEFAULT_LOGTHREADNAMES ) ;
2020-04-16 08:22:12 -04:00
# endif
2020-08-25 16:22:28 -04:00
LogInstance ( ) . m_log_sourcelocations = args . GetBoolArg ( " -logsourcelocations " , DEFAULT_LOGSOURCELOCATIONS ) ;
2018-04-11 14:03:21 -03:00
2020-08-21 14:38:01 -04:00
fLogIPs = args . GetBoolArg ( " -logips " , DEFAULT_LOGIPS ) ;
2015-11-26 10:03:27 -03:00
2018-01-16 07:48:33 -03:00
std : : string version_string = FormatFullVersion ( ) ;
# ifdef DEBUG
version_string + = " (debug build) " ;
# else
version_string + = " (release build) " ;
# endif
2018-01-18 15:16:46 -03:00
LogPrintf ( PACKAGE_NAME " version %s \n " , version_string ) ;
2015-11-26 10:03:27 -03:00
}
2016-10-25 06:34:27 -03:00
namespace { // Variables internal to initialization process only
int nMaxConnections ;
int nUserMaxConnections ;
int nFD ;
2017-10-01 00:33:58 -03:00
ServiceFlags nLocalServices = ServiceFlags ( NODE_NETWORK | NODE_NETWORK_LIMITED ) ;
2018-11-15 20:30:26 -03:00
int64_t peer_connect_timeout ;
2019-12-06 17:47:55 -03:00
std : : set < BlockFilterType > g_enabled_filter_types ;
2016-10-25 06:34:27 -03:00
2017-05-31 16:21:25 -04:00
} // namespace
2016-10-25 06:34:27 -03:00
2017-02-24 20:20:03 -03: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 ( ) ;
} ;
2020-12-05 21:14:17 -03:00
bool AppInitBasicSetup ( const ArgsManager & args )
2011-05-14 14:10:21 -04:00
{
2012-05-21 10:47:29 -04:00
// ********************************************************* Step 1: setup
2011-05-14 14:10:21 -04:00
# ifdef _MSC_VER
2012-07-25 20:48:39 -04:00
// Turn off Microsoft heap dump noise
2011-05-14 14:10:21 -04:00
_CrtSetReportMode ( _CRT_WARN , _CRTDBG_MODE_FILE ) ;
2017-08-07 01:36:37 -04:00
_CrtSetReportFile ( _CRT_WARN , CreateFileA ( " NUL " , GENERIC_WRITE , 0 , nullptr , OPEN_EXISTING , 0 , 0 ) ) ;
2012-07-25 20:48:39 -04:00
// Disable confusing "helpful" text message on abort, Ctrl-C
2011-05-14 14:10:21 -04:00
_set_abort_behavior ( 0 , _WRITE_ABORT_MSG | _CALL_REPORTFAULT ) ;
# endif
2012-07-20 02:45:49 -04:00
# ifdef WIN32
2020-01-13 05:36:16 -03:00
// Enable heap terminate-on-corruption
HeapSetInformation ( nullptr , HeapEnableTerminationOnCorruption , nullptr , 0 ) ;
2011-05-14 14:10:21 -04:00
# endif
2020-12-08 17:49:06 -03:00
if ( ! InitShutdownState ( ) ) {
return InitError ( Untranslated ( " Initializing wait-for-shutdown state failed. " ) ) ;
}
2014-06-04 07:16:07 -04:00
2020-04-11 11:48:04 -04:00
if ( ! SetupNetworking ( ) ) {
return InitError ( Untranslated ( " Initializing networking failed. " ) ) ;
}
2015-09-02 11:18:16 -03:00
# ifndef WIN32
2020-08-21 14:38:01 -04:00
if ( ! args . GetBoolArg ( " -sysperms " , false ) ) {
2014-06-04 07:16:07 -04:00
umask ( 077 ) ;
}
2012-07-20 02:45:49 -04:00
2011-05-14 14:10:21 -04:00
// Clean shutdown on SIGTERM
2017-03-22 17:29:41 -03:00
registerSignalHandler ( SIGTERM , HandleSIGTERM ) ;
registerSignalHandler ( SIGINT , HandleSIGTERM ) ;
2012-03-02 16:31:16 -03:00
// Reopen debug.log on SIGHUP
2017-03-22 17:29:41 -03:00
registerSignalHandler ( SIGHUP , HandleSIGHUP ) ;
2013-05-05 01:37:03 -04:00
2015-09-14 20:39:12 -03:00
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
2013-05-05 01:37:03 -04:00
signal ( SIGPIPE , SIG_IGN ) ;
2018-04-30 12:31:11 -03:00
# else
SetConsoleCtrlHandler ( consoleCtrlHandler , true ) ;
2011-05-14 14:10:21 -04:00
# endif
2017-02-24 20:20:03 -03:00
std : : set_new_handler ( new_handler_terminate ) ;
2016-10-25 06:34:27 -03:00
return true ;
}
2011-05-14 14:10:21 -04:00
2020-08-21 14:13:40 -04:00
bool AppInitParameterInteraction ( const ArgsManager & args )
2016-10-25 06:34:27 -03:00
{
2015-04-09 10:58:34 -03:00
const CChainParams & chainparams = Params ( ) ;
2016-10-25 06:34:27 -03:00
// ********************************************************* Step 2: parameter interactions
2014-11-13 11:15:53 -03:00
2015-11-28 18:28:21 -03:00
// also see: InitParameterInteraction()
2014-02-14 13:33:07 -03:00
2020-06-01 04:05:15 -04:00
// Error if network-specific options (-addnode, -connect, etc) are
2019-03-19 17:37:39 -03:00
// specified in default section of config file, but not overridden
// on the command line or in this network's section of the config file.
2020-08-21 14:38:01 -04:00
std : : string network = args . GetChainName ( ) ;
2020-09-30 14:08:52 -03:00
if ( network = = CBaseChainParams : : SIGNET ) {
LogPrintf ( " Signet derived magic (message start): %s \n " , HexStr ( chainparams . MessageStart ( ) ) ) ;
}
2020-06-01 04:05:15 -04:00
bilingual_str errors ;
2020-08-21 14:38:01 -04:00
for ( const auto & arg : args . GetUnsuitableSectionOnlyArgs ( ) ) {
2020-06-01 04:05:15 -04:00
errors + = strprintf ( _ ( " Config setting for %s only applied on %s network when in [%s] section. " ) + Untranslated ( " \n " ) , arg , network , network ) ;
}
if ( ! errors . empty ( ) ) {
return InitError ( errors ) ;
2019-03-19 17:37:39 -03:00
}
// Warn if unrecognized section name are present in the config file.
2020-06-01 04:05:15 -04:00
bilingual_str warnings ;
2020-08-21 14:38:01 -04:00
for ( const auto & section : args . GetUnrecognizedSections ( ) ) {
2020-06-01 04:05:15 -04: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 17:37:39 -03:00
}
2018-10-05 15:04:08 -03:00
if ( ! fs : : is_directory ( GetBlocksDir ( ) ) ) {
2020-08-21 14:38:01 -04:00
return InitError ( strprintf ( _ ( " Specified blocks directory \" %s \" does not exist. " ) , args . GetArg ( " -blocksdir " , " " ) ) ) ;
2018-03-09 01:12:43 -03:00
}
2018-08-30 02:15:50 -03:00
// parse and validate enabled filter types
2020-08-21 14:38:01 -04:00
std : : string blockfilterindex_value = args . GetArg ( " -blockfilterindex " , DEFAULT_BLOCKFILTERINDEX ) ;
2018-08-30 02:15:50 -03:00
if ( blockfilterindex_value = = " " | | blockfilterindex_value = = " 1 " ) {
g_enabled_filter_types = AllBlockFilterTypes ( ) ;
} else if ( blockfilterindex_value ! = " 0 " ) {
2020-08-21 14:38:01 -04:00
const std : : vector < std : : string > names = args . GetArgs ( " -blockfilterindex " ) ;
2018-08-30 02:15:50 -03:00
for ( const auto & name : names ) {
BlockFilterType filter_type ;
if ( ! BlockFilterTypeByName ( name , filter_type ) ) {
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " Unknown -blockfilterindex value %s. " ) , name ) ) ;
2018-08-30 02:15:50 -03:00
}
2019-12-06 17:47:55 -03:00
g_enabled_filter_types . insert ( filter_type ) ;
2018-08-30 02:15:50 -03: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 14:38:01 -04: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
}
2016-09-19 10:52:48 -03:00
// if using block pruning, then disallow txindex
2020-08-21 14:38:01 -04:00
if ( args . GetArg ( " -prune " , 0 ) ) {
if ( args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) )
2020-04-11 11:48:04 -04:00
return InitError ( _ ( " Prune mode is incompatible with -txindex. " ) ) ;
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 16:27:44 -03:00
}
2015-11-14 09:46:23 -03:00
2017-06-01 06:34:02 -04:00
// -bind and -whitebind can't be set when not listening
2020-08-21 14:38:01 -04:00
size_t nUserBind = args . GetArgs ( " -bind " ) . size ( ) + args . GetArgs ( " -whitebind " ) . size ( ) ;
if ( nUserBind ! = 0 & & ! args . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) ) {
2020-04-11 11:48:04 -04:00
return InitError ( Untranslated ( " Cannot set -bind or -whitebind together with -listen=0 " ) ) ;
2017-06-01 06:34:02 -04:00
}
2014-11-16 08:19:23 -03:00
// Make sure enough file descriptors are available
2017-06-01 06:34:02 -04:00
int nBind = std : : max ( nUserBind , size_t ( 1 ) ) ;
2020-08-21 14:38:01 -04:00
nUserMaxConnections = args . GetArg ( " -maxconnections " , DEFAULT_MAX_PEER_CONNECTIONS ) ;
2016-10-25 06:34:27 -03:00
nMaxConnections = std : : max ( nUserMaxConnections , 0 ) ;
2014-11-16 08:19:23 -03:00
// Trim requested connection counts, to fit into system limitations
2018-06-19 09:39:52 -04:00
// <int> in std::min<int>(...) to work around FreeBSD compilation issue described in #2695
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 16:09:05 -03:00
# ifdef USE_POLL
int fd_max = nFD ;
# else
int fd_max = FD_SETSIZE ;
# endif
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 08:19:23 -03:00
if ( nFD < MIN_CORE_FILEDESCRIPTORS )
2020-04-11 11:48:04 -04: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 08:19:23 -03:00
if ( nMaxConnections < nUserMaxConnections )
2020-05-09 07:46:01 -04:00
InitWarning ( strprintf ( _ ( " Reducing -maxconnections from %d to %d, because of system limitations. " ) , nUserMaxConnections , nMaxConnections ) ) ;
2014-11-16 08:19:23 -03:00
2012-05-21 10:47:29 -04:00
// ********************************************************* Step 3: parameter-to-internal-flags
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -debug " ) ) {
2016-12-25 17:19:40 -03:00
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
2020-08-21 14:38:01 -04:00
const std : : vector < std : : string > categories = args . GetArgs ( " -debug " ) ;
2016-12-25 17:19:40 -03:00
2017-08-29 08:32:16 -03:00
if ( std : : none_of ( categories . begin ( ) , categories . end ( ) ,
[ ] ( std : : string cat ) { return cat = = " 0 " | | cat = = " none " ; } ) ) {
2016-12-25 17:19:40 -03:00
for ( const auto & cat : categories ) {
2019-01-25 17:54:49 -03:00
if ( ! LogInstance ( ) . EnableCategory ( cat ) ) {
2020-05-09 07:46:01 -04:00
InitWarning ( strprintf ( _ ( " Unsupported logging category %s=%s. " ) , " -debug " , cat ) ) ;
2016-12-25 17:19:40 -03:00
}
}
}
2016-11-29 21:50:49 -03:00
}
2013-10-08 07:09:40 -03:00
2017-04-02 20:56:03 -03:00
// Now remove the logging categories which were explicitly excluded
2020-08-21 14:38:01 -04:00
for ( const std : : string & cat : args . GetArgs ( " -debugexclude " ) ) {
2019-01-25 17:54:49 -03:00
if ( ! LogInstance ( ) . DisableCategory ( cat ) ) {
2020-05-09 07:46:01 -04:00
InitWarning ( strprintf ( _ ( " Unsupported logging category %s=%s. " ) , " -debugexclude " , cat ) ) ;
2017-06-26 21:10:39 -04:00
}
2017-04-02 20:56:03 -03:00
}
2020-08-21 14:38:01 -04:00
fCheckBlockIndex = args . GetBoolArg ( " -checkblockindex " , chainparams . DefaultConsistencyChecks ( ) ) ;
fCheckpointsEnabled = args . GetBoolArg ( " -checkpoints " , DEFAULT_CHECKPOINTS_ENABLED ) ;
2012-06-22 13:11:57 -04:00
2020-08-21 14:38:01 -04:00
hashAssumeValid = uint256S ( args . GetArg ( " -assumevalid " , chainparams . GetConsensus ( ) . defaultAssumeValid . GetHex ( ) ) ) ;
2017-01-06 08:49:59 -03:00
if ( ! hashAssumeValid . IsNull ( ) )
LogPrintf ( " Assuming ancestors of block %s have valid signatures. \n " , hashAssumeValid . GetHex ( ) ) ;
else
LogPrintf ( " Validating signatures for all blocks. \n " ) ;
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -minimumchainwork " ) ) {
const std : : string minChainWorkStr = args . GetArg ( " -minimumchainwork " , " " ) ;
2017-05-07 15:10:19 -03:00
if ( ! IsHexNumber ( minChainWorkStr ) ) {
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( Untranslated ( " Invalid non-hex (%s) minimum chain work value specified " ), minChainWorkStr)) ;
2017-05-07 15:10:19 -03:00
}
nMinimumChainWork = UintToArith256 ( uint256S ( minChainWorkStr ) ) ;
} else {
nMinimumChainWork = UintToArith256 ( chainparams . GetConsensus ( ) . nMinimumChainWork ) ;
}
LogPrintf ( " Setting nMinimumChainWork=%s \n " , nMinimumChainWork . GetHex ( ) ) ;
if ( nMinimumChainWork < UintToArith256 ( chainparams . GetConsensus ( ) . nMinimumChainWork ) ) {
LogPrintf ( " Warning: nMinimumChainWork set below default value of %s \n " , chainparams . GetConsensus ( ) . nMinimumChainWork . GetHex ( ) ) ;
}
2015-11-19 17:48:02 -03:00
// mempool limits
2020-08-21 14:38:01 -04:00
int64_t nMempoolSizeMax = args . GetArg ( " -maxmempool " , DEFAULT_MAX_MEMPOOL_SIZE ) * 1000000 ;
int64_t nMempoolSizeMin = args . GetArg ( " -limitdescendantsize " , DEFAULT_DESCENDANT_SIZE_LIMIT ) * 1000 * 40 ;
2015-11-19 17:48:02 -03:00
if ( nMempoolSizeMax < 0 | | nMempoolSizeMax < nMempoolSizeMin )
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " -maxmempool must be at least %d MB " ) , std : : ceil ( nMempoolSizeMin / 1000000.0 ) ) ) ;
2017-02-06 11:16:18 -03:00
// incremental relay fee sets the minimum feerate increase necessary for BIP 125 replacement in the mempool
2016-12-13 15:43:35 -03:00
// and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -incrementalrelayfee " ) ) {
2016-12-13 15:43:35 -03:00
CAmount n = 0 ;
2020-08-21 14:38:01 -04:00
if ( ! ParseMoney ( args . GetArg ( " -incrementalrelayfee " , " " ) , n ) )
return InitError ( AmountErrMsg ( " incrementalrelayfee " , args . GetArg ( " -incrementalrelayfee " , " " ) ) ) ;
2016-12-13 15:43:35 -03:00
incrementalRelayFee = CFeeRate ( n ) ;
}
2015-10-02 18:19:55 -03:00
2015-09-11 18:31:30 -03:00
// block pruning; get the amount of disk space (in MiB) to allot for block & undo files
2020-08-21 14:38:01 -04:00
int64_t nPruneArg = args . GetArg ( " -prune " , 0 ) ;
2016-11-29 14:39:19 -03:00
if ( nPruneArg < 0 ) {
2020-04-11 11:48:04 -04:00
return InitError ( _ ( " Prune cannot be configured with a negative value. " ) ) ;
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 16:27:44 -03:00
}
2016-11-29 14:39:19 -03:00
nPruneTarget = ( uint64_t ) nPruneArg * 1024 * 1024 ;
if ( nPruneArg = = 1 ) { // manual pruning: -prune=1
LogPrintf ( " Block pruning enabled. Use RPC call pruneblockchain(height) to manually prune block and undo files. \n " ) ;
nPruneTarget = std : : numeric_limits < uint64_t > : : max ( ) ;
fPruneMode = true ;
} else if ( nPruneTarget ) {
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 16:27:44 -03:00
if ( nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES ) {
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " Prune configured below the minimum of %d MiB. Please use a higher number. " ) , MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024 ) ) ;
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 16:27:44 -03:00
}
2019-01-14 08:40:00 -03:00
LogPrintf ( " Prune configured to target %u MiB on disk for block and undo files. \n " , nPruneTarget / 1024 / 1024 ) ;
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 16:27:44 -03:00
fPruneMode = true ;
}
2020-08-21 14:38:01 -04:00
nConnectTimeout = args . GetArg ( " -timeout " , DEFAULT_CONNECT_TIMEOUT ) ;
2018-11-15 20:30:26 -03:00
if ( nConnectTimeout < = 0 ) {
2014-09-25 04:01:54 -03:00
nConnectTimeout = DEFAULT_CONNECT_TIMEOUT ;
2018-11-15 20:30:26 -03:00
}
2020-08-21 14:38:01 -04:00
peer_connect_timeout = args . GetArg ( " -peertimeout " , DEFAULT_PEER_CONNECT_TIMEOUT ) ;
2018-11-15 20:30:26 -03:00
if ( peer_connect_timeout < = 0 ) {
2020-04-11 11:48:04 -04:00
return InitError ( Untranslated ( " peertimeout cannot be configured with a negative value. " ) ) ;
2018-11-15 20:30:26 -03:00
}
2012-05-21 10:47:29 -04:00
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -minrelaytxfee " ) ) {
2014-04-22 19:46:19 -03:00
CAmount n = 0 ;
2020-08-21 14:38:01 -04:00
if ( ! ParseMoney ( args . GetArg ( " -minrelaytxfee " , " " ) , n ) ) {
return InitError ( AmountErrMsg ( " minrelaytxfee " , args . GetArg ( " -minrelaytxfee " , " " ) ) ) ;
2017-01-19 23:48:10 -03:00
}
2020-11-02 09:42:21 -03:00
// High fee check is done afterward in CWallet::Create()
2016-01-07 21:14:09 -03:00
: : minRelayTxFee = CFeeRate ( n ) ;
2016-12-13 15:43:35 -03:00
} else if ( incrementalRelayFee > : : minRelayTxFee ) {
// Allow only setting incrementalRelayFee to control both
: : minRelayTxFee = incrementalRelayFee ;
LogPrintf ( " Increasing minrelaytxfee to %s to match incrementalrelayfee \n " , : : minRelayTxFee . ToString ( ) ) ;
2013-04-25 21:11:27 -03:00
}
2012-05-21 10:47:29 -04:00
2016-12-13 13:51:51 -03: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 14:38:01 -04:00
if ( args . IsArgSet ( " -blockmintxfee " ) ) {
2016-12-13 13:51:51 -03:00
CAmount n = 0 ;
2020-08-21 14:38:01 -04:00
if ( ! ParseMoney ( args . GetArg ( " -blockmintxfee " , " " ) , n ) )
return InitError ( AmountErrMsg ( " blockmintxfee " , args . GetArg ( " -blockmintxfee " , " " ) ) ) ;
2016-12-13 13:51:51 -03:00
}
2016-12-13 18:19:17 -03:00
// Feerate used to define dust. Shouldn't be changed lightly as old
// implementations may inadvertently create non-standard transactions
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -dustrelayfee " ) ) {
2016-12-13 18:19:17 -03:00
CAmount n = 0 ;
2020-08-21 14:38:01 -04:00
if ( ! ParseMoney ( args . GetArg ( " -dustrelayfee " , " " ) , n ) )
return InitError ( AmountErrMsg ( " dustrelayfee " , args . GetArg ( " -dustrelayfee " , " " ) ) ) ;
2016-12-13 18:19:17 -03:00
dustRelayFee = CFeeRate ( n ) ;
2013-04-25 21:11:27 -03:00
}
2012-05-21 10:47:29 -04:00
2020-08-21 14:38:01 -04:00
fRequireStandard = ! args . GetBoolArg ( " -acceptnonstdtxn " , ! chainparams . RequireStandard ( ) ) ;
2019-04-24 17:55:58 -04:00
if ( ! chainparams . IsTestChain ( ) & & ! fRequireStandard ) {
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( Untranslated ( " acceptnonstdtxn is not currently supported for %s chain " ) , chainparams . NetworkIDString ( ) ) ) ;
2019-04-24 17:55:58 -04:00
}
2020-08-21 14:38:01 -04:00
nBytesPerSigOp = args . GetArg ( " -bytespersigop " , nBytesPerSigOp ) ;
2015-06-24 00:36:22 -03:00
2018-04-13 10:05:55 -03:00
if ( ! g_wallet_init_interface . ParameterInteraction ( ) ) return false ;
2014-07-16 20:04:04 -04:00
2020-08-21 14:38:01 -04:00
fIsBareMultisigStd = args . GetBoolArg ( " -permitbaremultisig " , DEFAULT_PERMIT_BAREMULTISIG ) ;
fAcceptDatacarrier = args . GetBoolArg ( " -datacarrier " , DEFAULT_ACCEPT_DATACARRIER ) ;
nMaxDatacarrierBytes = args . GetArg ( " -datacarriersize " , nMaxDatacarrierBytes ) ;
2014-07-16 20:04:04 -04:00
2015-06-19 11:42:39 -03:00
// Option to startup with mocktime set (used for regression testing):
2020-08-21 14:38:01 -04:00
SetMockTime ( args . GetArg ( " -mocktime " , 0 ) ) ; // SetMockTime(0) is a no-op
2015-06-19 11:42:39 -03:00
2020-08-21 14:38:01 -04:00
if ( args . GetBoolArg ( " -peerbloomfilters " , DEFAULT_PEERBLOOMFILTERS ) )
2016-06-08 13:12:22 -04:00
nLocalServices = ServiceFlags ( nLocalServices | NODE_BLOOM ) ;
2015-08-21 01:15:27 -03:00
2020-08-21 14:38:01 -04:00
if ( args . GetArg ( " -rpcserialversion " , DEFAULT_RPC_SERIALIZE_VERSION ) < 0 )
2020-04-11 11:48:04 -04:00
return InitError ( Untranslated ( " rpcserialversion must be non-negative. " ) ) ;
2016-11-20 11:54:51 -03:00
2020-08-21 14:38:01 -04:00
if ( args . GetArg ( " -rpcserialversion " , DEFAULT_RPC_SERIALIZE_VERSION ) > 1 )
2020-04-11 11:48:04 -04:00
return InitError ( Untranslated ( " Unknown rpcserialversion requested. " ) ) ;
2016-12-06 04:26:32 -03:00
2020-08-21 14:38:01 -04:00
nMaxTipAge = args . GetArg ( " -maxtipage " , DEFAULT_MAX_TIP_AGE ) ;
2016-01-28 02:27:25 -03:00
2020-09-23 09:30:02 -03:00
if ( args . IsArgSet ( " -proxy " ) & & args . GetArg ( " -proxy " , " " ) . empty ( ) ) {
return InitError ( _ ( " No proxy server specified. Use -proxy=<ip> or -proxy=<ip:port>. " ) ) ;
}
2016-10-25 06:34:27 -03:00
return true ;
}
2016-07-25 17:22:37 -04:00
2016-10-25 07:03:22 -03:00
static bool LockDataDirectory ( bool probeOnly )
2016-10-25 06:34:27 -03:00
{
2012-05-21 10:47:29 -04:00
// Make sure only a single Bitcoin process is using the data directory.
2017-12-26 03:41:55 -03:00
fs : : path datadir = GetDataDir ( ) ;
2018-03-07 08:08:55 -03:00
if ( ! DirIsWritable ( datadir ) ) {
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " Cannot write to data directory '%s'; check permissions. " ) , datadir . string ( ) ) ) ;
2018-03-07 08:08:55 -03:00
}
2017-12-26 03:41:55 -03:00
if ( ! LockDirectory ( datadir , " .lock " , probeOnly ) ) {
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " Cannot obtain a lock on data directory %s. %s is probably already running. " ) , datadir . string ( ) , PACKAGE_NAME ) ) ;
2015-05-18 20:37:43 -03:00
}
2016-10-25 06:34:27 -03:00
return true ;
}
2016-10-25 07:03:22 -03:00
bool AppInitSanityChecks ( )
{
// ********************************************************* Step 4: sanity checks
// Initialize elliptic curve code
2017-07-14 02:26:04 -04:00
std : : string sha256_algo = SHA256AutoDetect ( ) ;
LogPrintf ( " Using the '%s' SHA256 implementation \n " , sha256_algo ) ;
2017-05-09 19:13:00 -03:00
RandomInit ( ) ;
2016-10-25 07:03:22 -03:00
ECC_Start ( ) ;
globalVerifyHandle . reset ( new ECCVerifyHandle ( ) ) ;
// Sanity check
if ( ! InitSanityCheck ( ) )
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " Initialization sanity check failed. %s is shutting down. " ) , PACKAGE_NAME ) ) ;
2016-10-25 07:03:22 -03:00
// Probe the data directory lock to give an early error message, if possible
2017-07-15 04:46:06 -04: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 07:03:22 -03:00
return LockDataDirectory ( true ) ;
}
2017-07-15 04:46:06 -04:00
bool AppInitLockDataDirectory ( )
2016-10-25 06:34:27 -03:00
{
2016-10-25 07:03:22 -03: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 04:46:06 -04:00
return true ;
}
2015-05-18 20:37:43 -03:00
2020-05-29 00:07:18 -04:00
bool AppInitInterfaces ( NodeContext & node )
{
node . chain = interfaces : : MakeChain ( node ) ;
// 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 ) ;
return true ;
}
2020-05-19 09:13:50 -04:00
bool AppInitMain ( const util : : Ref & context , NodeContext & node , interfaces : : BlockAndHeaderTipInfo * tip_info )
2017-07-15 04:46:06 -04:00
{
2020-08-21 14:13:40 -04:00
const ArgsManager & args = * Assert ( node . args ) ;
2017-07-15 04:46:06 -04:00
const CChainParams & chainparams = Params ( ) ;
// ********************************************************* Step 4a: application initialization
2020-08-21 14:13:40 -04:00
if ( ! CreatePidFile ( args ) ) {
2019-02-01 19:40:36 -03:00
// Detailed error printed inside CreatePidFile().
return false ;
}
2019-01-25 17:54:49 -03:00
if ( LogInstance ( ) . m_print_to_file ) {
2020-08-21 14:38:01 -04:00
if ( args . GetBoolArg ( " -shrinkdebugfile " , LogInstance ( ) . DefaultShrinkDebugFile ( ) ) ) {
2018-03-27 01:35:35 -03:00
// Do this first since it both loads a bunch of debug.log into memory,
// and because this needs to happen before any other debug.log printing
2019-01-25 17:54:49 -03:00
LogInstance ( ) . ShrinkDebugFile ( ) ;
2018-03-27 01:35:35 -03:00
}
2018-05-02 21:14:01 -03:00
}
if ( ! LogInstance ( ) . StartLogging ( ) ) {
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( Untranslated ( " Could not open debug log file %s " ) ,
2019-01-25 17:54:49 -03:00
LogInstance ( ) . m_file_path . string ( ) ) ) ;
2017-11-28 06:31:52 -03:00
}
2015-05-15 16:31:14 -03:00
2019-01-25 17:54:49 -03:00
if ( ! LogInstance ( ) . m_log_timestamps )
2018-02-28 12:46:31 -03:00
LogPrintf ( " Startup time: %s \n " , FormatISO8601DateTime ( GetTime ( ) ) ) ;
2014-01-16 12:15:27 -03:00
LogPrintf ( " Default data directory %s \n " , GetDefaultDataDir ( ) . string ( ) ) ;
2016-10-25 06:34:27 -03:00
LogPrintf ( " Using data directory %s \n " , GetDataDir ( ) . string ( ) ) ;
2018-08-24 19:03:01 -03:00
// Only log conf file usage message if conf file actually exists.
2020-08-21 14:38:01 -04:00
fs : : path config_file_path = GetConfigFile ( args . GetArg ( " -conf " , BITCOIN_CONF_FILENAME ) ) ;
2018-08-24 19:03:01 -03:00
if ( fs : : exists ( config_file_path ) ) {
LogPrintf ( " Config file: %s \n " , config_file_path . string ( ) ) ;
2020-08-21 14:38:01 -04:00
} else if ( args . IsArgSet ( " -conf " ) ) {
2018-08-24 19:03:01 -03:00
// Warn if no conf file exists at path provided by user
2020-05-09 07:46:01 -04:00
InitWarning ( strprintf ( _ ( " The specified config file %s does not exist \n " ) , config_file_path . string ( ) ) ) ;
2018-08-24 19:03:01 -03:00
} else {
// Not categorizing as "Warning" because it's the default behavior
LogPrintf ( " Config file: %s (not found, skipping) \n " , config_file_path . string ( ) ) ;
}
2020-01-20 12:32:42 -03:00
// Log the config arguments to debug.log
2020-08-21 14:38:01 -04:00
args . LogArgs ( ) ;
2020-01-20 12:32:42 -03:00
2016-12-11 01:39:26 -03:00
LogPrintf ( " Using at most %i automatic connections (%i file descriptors available) \n " , nMaxConnections , nFD ) ;
2011-05-14 14:10:21 -04:00
2018-01-18 15:15:00 -03:00
// Warn about relative -datadir path.
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -datadir " ) & & ! fs : : path ( args . GetArg ( " -datadir " , " " ) ) . is_absolute ( ) ) {
2018-04-05 11:17:32 -03:00
LogPrintf ( " Warning: relative datadir option '%s' specified, which will be interpreted relative to the " /* Continued */
2018-01-18 15:15:00 -03: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 " ,
2020-08-21 14:38:01 -04:00
args . GetArg ( " -datadir " , " " ) , fs : : current_path ( ) . string ( ) ) ;
2018-01-18 15:15:00 -03:00
}
2016-10-05 17:58:47 -03:00
InitSignatureCache ( ) ;
Cache full script execution results in addition to signatures
This adds a new CuckooCache in validation, caching whether all of a
transaction's scripts were valid with a given set of script flags.
Unlike previous attempts at caching an entire transaction's
validity, which have nearly universally introduced consensus
failures, this only caches the validity of a transaction's
scriptSigs. As these are pure functions of the transaction and
data it commits to, this should be much safer.
This is somewhat duplicative with the sigcache, as entries in the
new cache will also have several entries in the sigcache. However,
the sigcache is kept both as ATMP relies on it and because it
prevents malleability-based DoS attacks on the new higher-level
cache. Instead, the -sigcachesize option is re-used - cutting the
sigcache size in half and using the newly freed memory for the
script execution cache.
Transactions which match the script execution cache never even have
entries in the script check thread's workqueue created.
Note that the cache is indexed only on the script execution flags
and the transaction's witness hash. While this is sufficient to
make the CScriptCheck() calls pure functions, this introduces
dependancies on the mempool calculating things such as the
PrecomputedTransactionData object, filling the CCoinsViewCache, etc
in the exact same way as ConnectBlock. I belive this is a reasonable
assumption, but should be noted carefully.
In a rather naive benchmark (reindex-chainstate up to block 284k
with cuckoocache always returning true for contains(),
-assumevalid=0 and a very large dbcache), this connected blocks
~1.7x faster.
2017-04-11 17:46:39 -03:00
InitScriptExecutionCache ( ) ;
2016-10-05 17:58:47 -03:00
2020-08-21 14:38:01 -04:00
int script_threads = args . GetArg ( " -par " , DEFAULT_SCRIPTCHECK_THREADS ) ;
2019-11-02 18:14:38 -03: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 ) {
g_parallel_script_checks = true ;
2020-08-21 02:24:05 -04:00
StartScriptCheckWorkerThreads ( script_threads ) ;
2012-12-01 19:04:14 -03:00
}
2020-02-12 16:08:28 -03:00
assert ( ! node . scheduler ) ;
node . scheduler = MakeUnique < CScheduler > ( ) ;
2015-04-03 12:50:06 -03:00
// Start the lightweight task scheduler thread
2021-01-27 04:04:34 -03:00
node . scheduler - > m_service_thread = std : : thread ( [ & ] { TraceThread ( " scheduler " , [ & ] { node . scheduler - > serviceQueue ( ) ; } ) ; } ) ;
2015-04-03 12:50:06 -03:00
2019-10-29 15:55:59 -03:00
// Gather some entropy once per minute.
2020-02-12 16:08:28 -03:00
node . scheduler - > scheduleEvery ( [ ] {
2019-10-29 15:55:59 -03:00
RandAddPeriodic ( ) ;
2020-03-06 20:06:50 -03:00
} , std : : chrono : : minutes { 1 } ) ;
2019-10-29 15:55:59 -03:00
2020-02-12 16:08:28 -03:00
GetMainSignals ( ) . RegisterBackgroundSignalScheduler ( * node . scheduler ) ;
2017-01-19 18:49:22 -03:00
2017-11-03 17:28:18 -03: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 18:04:39 -03:00
for ( const auto & client : node . chain_clients ) {
2017-09-28 15:13:29 -03:00
client - > registerRpcs ( ) ;
}
2018-06-29 10:10:01 -04:00
# if ENABLE_ZMQ
RegisterZMQRPCCommands ( tableRPC ) ;
# endif
2017-11-03 17:28:18 -03:00
2014-10-29 14:08:31 -03: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 14:38:01 -04:00
if ( args . GetBoolArg ( " -server " , false ) ) {
2018-07-11 08:00:15 -04:00
uiInterface . InitMessage_connect ( SetRPCWarmupStatus ) ;
2020-06-18 15:19:26 -04:00
if ( ! AppInitServers ( context , node ) )
2020-04-11 11:48:04 -04:00
return InitError ( _ ( " Unable to start HTTP server. See debug log for details. " ) ) ;
2014-10-29 14:08:31 -03:00
}
2013-01-11 19:18:00 -03:00
// ********************************************************* Step 5: verify wallet database integrity
2019-09-17 18:04:39 -03:00
for ( const auto & client : node . chain_clients ) {
2017-09-28 15:13:29 -03:00
if ( ! client - > verify ( ) ) {
return false ;
}
}
2018-02-21 13:38:53 -03:00
2012-09-18 15:30:47 -03:00
// ********************************************************* Step 6: network initialization
2016-10-02 12:29:35 -03: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 10:47:29 -04:00
2020-09-06 14:37:13 -03:00
fListen = args . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) ;
fDiscover = args . GetBoolArg ( " -discover " , true ) ;
2020-10-22 06:56:38 -03:00
const bool ignores_incoming_txs { args . GetBoolArg ( " -blocksonly " , DEFAULT_BLOCKSONLY ) } ;
2020-09-06 14:37:13 -03:00
2019-09-17 19:59:36 -03:00
assert ( ! node . banman ) ;
2020-08-21 14:38:01 -04:00
node . banman = MakeUnique < BanMan > ( GetDataDir ( ) / " banlist.dat " , & uiInterface , args . GetArg ( " -bantime " , DEFAULT_MISBEHAVING_BANTIME ) ) ;
2019-09-17 19:59:36 -03:00
assert ( ! node . connman ) ;
2020-08-21 14:38:01 -04:00
node . connman = MakeUnique < CConnman > ( GetRand ( std : : numeric_limits < uint64_t > : : max ( ) ) , GetRand ( std : : numeric_limits < uint64_t > : : max ( ) ) , args . GetBoolArg ( " -networkactive " , true ) ) ;
2020-07-19 03:07:54 -04:00
2020-07-28 13:12:50 -04:00
assert ( ! node . fee_estimator ) ;
2020-09-06 14:37:13 -03:00
// Don't initialize fee estimation with old data if we don't relay transactions,
// as they would never get updated.
2020-10-22 06:56:38 -03:00
if ( ! ignores_incoming_txs ) node . fee_estimator = std : : make_unique < CBlockPolicyEstimator > ( ) ;
2020-07-28 13:12:50 -04:00
2020-01-24 16:00:57 -03:00
assert ( ! node . mempool ) ;
2020-10-20 15:42:47 -03:00
int check_ratio = std : : min < int > ( std : : max < int > ( args . GetArg ( " -checkmempool " , chainparams . DefaultConsistencyChecks ( ) ? 1 : 0 ) , 0 ) , 1000000 ) ;
2020-07-28 13:12:50 -04:00
node . mempool = std : : make_unique < CTxMemPool > ( node . fee_estimator . get ( ) , check_ratio ) ;
2020-07-19 03:07:54 -04:00
2020-04-18 08:05:52 -04:00
assert ( ! node . chainman ) ;
node . chainman = & g_chainman ;
2020-06-14 14:17:24 -04:00
ChainstateManager & chainman = * Assert ( node . chainman ) ;
2016-04-16 15:47:18 -03:00
2020-10-22 06:39:24 -03:00
assert ( ! node . peerman ) ;
2020-12-23 04:35:33 -03:00
node . peerman = PeerManager : : make ( chainparams , * node . connman , node . banman . get ( ) ,
* node . scheduler , chainman , * node . mempool , ignores_incoming_txs ) ;
2020-08-29 05:31:11 -04:00
RegisterValidationInterface ( node . peerman . get ( ) ) ;
2013-05-07 09:16:25 -04:00
2015-09-09 09:24:56 -03:00
// sanitize comments per BIP-0014, format user agent and check total size
2017-01-27 05:43:41 -03:00
std : : vector < std : : string > uacomments ;
2020-08-21 14:38:01 -04:00
for ( const std : : string & cmt : args . GetArgs ( " -uacomment " ) ) {
2017-06-26 21:10:39 -04:00
if ( cmt ! = SanitizeString ( cmt , SAFE_CHARS_UA_COMMENT ) )
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " User Agent comment (%s) contains unsafe characters . " ), cmt)) ;
2017-06-26 21:10:39 -04:00
uacomments . push_back ( cmt ) ;
2015-09-09 09:24:56 -03:00
}
strSubVersion = FormatSubVersion ( CLIENT_NAME , CLIENT_VERSION , uacomments ) ;
2015-07-31 13:05:42 -03:00
if ( strSubVersion . size ( ) > MAX_SUBVERSION_LENGTH ) {
2020-04-11 11:48:04 -04: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 13:05:42 -03:00
strSubVersion . size ( ) , MAX_SUBVERSION_LENGTH ) ) ;
}
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -onlynet " ) ) {
2012-05-21 10:47:29 -04:00
std : : set < enum Network > nets ;
2020-08-21 14:38:01 -04:00
for ( const std : : string & snet : args . GetArgs ( " -onlynet " ) ) {
2012-05-21 10:47:29 -04:00
enum Network net = ParseNetwork ( snet ) ;
if ( net = = NET_UNROUTABLE )
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " Unknown network specified in -onlynet: '%s' " ) , snet ) ) ;
2012-05-21 10:47:29 -04:00
nets . insert ( net ) ;
}
for ( int n = 0 ; n < NET_MAX ; n + + ) {
enum Network net = ( enum Network ) n ;
if ( ! nets . count ( net ) )
2019-01-09 21:41:37 -03:00
SetReachable ( net , false ) ;
2012-05-21 10:47:29 -04:00
}
}
2017-02-15 22:08:36 -03:00
// Check for host lookup allowed before parsing any network related parameters
2020-08-21 14:38:01 -04:00
fNameLookup = args . GetBoolArg ( " -dns " , DEFAULT_NAME_LOOKUP ) ;
2017-02-15 22:08:36 -03:00
2020-08-21 14:38:01 -04:00
bool proxyRandomize = args . GetBoolArg ( " -proxyrandomize " , DEFAULT_PROXYRANDOMIZE ) ;
2015-06-10 04:19:13 -03: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 14:38:01 -04:00
std : : string proxyArg = args . GetArg ( " -proxy " , " " ) ;
2019-01-09 21:41:37 -03:00
SetReachable ( NET_ONION , false ) ;
2015-06-10 04:19:13 -03:00
if ( proxyArg ! = " " & & proxyArg ! = " 0 " ) {
2017-02-15 22:08:36 -03:00
CService proxyAddr ;
2019-12-11 13:39:29 -03:00
if ( ! Lookup ( proxyArg , proxyAddr , 9050 , fNameLookup ) ) {
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " Invalid -proxy address or hostname: '%s' " ) , proxyArg ) ) ;
2017-02-15 22:08:36 -03:00
}
proxyType addrProxy = proxyType ( proxyAddr , proxyRandomize ) ;
2012-05-24 13:02:21 -04:00
if ( ! addrProxy . IsValid ( ) )
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " Invalid -proxy address or hostname: '%s' " ) , proxyArg ) ) ;
2012-05-24 13:02:21 -04:00
2014-11-23 20:12:50 -03:00
SetProxy ( NET_IPV4 , addrProxy ) ;
SetProxy ( NET_IPV6 , addrProxy ) ;
2018-07-02 05:37:59 -04:00
SetProxy ( NET_ONION , addrProxy ) ;
2014-06-11 07:20:59 -04:00
SetNameProxy ( addrProxy ) ;
2019-01-09 21:41:37 -03:00
SetReachable ( NET_ONION , true ) ; // by default, -proxy sets onion as reachable, unless -noonion later
2012-05-01 15:04:07 -04:00
}
2015-06-10 04:19:13 -03: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 14:38:01 -04:00
std : : string onionArg = args . GetArg ( " -onion " , " " ) ;
2015-06-10 04:19:13 -03:00
if ( onionArg ! = " " ) {
if ( onionArg = = " 0 " ) { // Handle -noonion/-onion=0
2019-01-09 21:41:37 -03:00
SetReachable ( NET_ONION , false ) ;
2015-06-10 04:19:13 -03:00
} else {
2017-02-15 22:08:36 -03:00
CService onionProxy ;
2019-12-11 13:39:29 -03:00
if ( ! Lookup ( onionArg , onionProxy , 9050 , fNameLookup ) ) {
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " Invalid -onion address or hostname: '%s' " ) , onionArg ) ) ;
2017-02-15 22:08:36 -03:00
}
proxyType addrOnion = proxyType ( onionProxy , proxyRandomize ) ;
2015-06-10 04:19:13 -03:00
if ( ! addrOnion . IsValid ( ) )
2020-04-11 11:48:04 -04:00
return InitError ( strprintf ( _ ( " Invalid -onion address or hostname: '%s' " ) , onionArg ) ) ;
2018-07-02 05:37:59 -04:00
SetProxy ( NET_ONION , addrOnion ) ;
2019-01-09 21:41:37 -03:00
SetReachable ( NET_ONION , true ) ;
2015-06-10 04:19:13 -03:00
}
2012-05-24 13:02:21 -04:00
}
2020-08-21 14:38:01 -04:00
for ( const std : : string & strAddr : args . GetArgs ( " -externalip " ) ) {
2017-06-26 21:10:39 -04:00
CService addrLocal ;
2019-12-11 13:39:29 -03:00
if ( Lookup ( strAddr , addrLocal , GetListenPort ( ) , fNameLookup ) & & addrLocal . IsValid ( ) )
2017-06-26 21:10:39 -04:00
AddLocal ( addrLocal , LOCAL_MANUAL ) ;
else
2020-06-05 08:26:16 -04:00
return InitError ( ResolveErrMsg ( " externalip " , strAddr ) ) ;
2012-05-21 10:47:29 -04:00
}
2020-01-29 12:38:25 -03:00
// Read asmap file if configured
2020-08-21 14:38:01 -04:00
if ( args . IsArgSet ( " -asmap " ) ) {
fs : : path asmap_path = fs : : path ( args . GetArg ( " -asmap " , " " ) ) ;
2020-01-29 12:38:25 -03:00
if ( asmap_path . empty ( ) ) {
asmap_path = DEFAULT_ASMAP_FILENAME ;
}
if ( ! asmap_path . is_absolute ( ) ) {
asmap_path = GetDataDir ( ) / asmap_path ;
}
if ( ! fs : : exists ( asmap_path ) ) {
2020-04-11 11:48:04 -04:00
InitError ( strprintf ( _ ( " Could not find asmap file %s " ) , asmap_path ) ) ;
2020-01-29 12:38:25 -03:00
return false ;
}
std : : vector < bool > asmap = CAddrMan : : DecodeAsmap ( asmap_path ) ;
if ( asmap . size ( ) = = 0 ) {
2020-04-11 11:48:04 -04:00
InitError ( strprintf ( _ ( " Could not parse asmap file %s " ) , asmap_path ) ) ;
2020-01-29 12:38:25 -03:00
return false ;
}
const uint256 asmap_version = SerializeHash ( asmap ) ;
node . connman - > SetAsmap ( std : : move ( asmap ) ) ;
LogPrintf ( " Using asmap version %s for IP bucketing \n " , asmap_version . ToString ( ) ) ;
} else {
LogPrintf ( " Using /16 prefix for IP bucketing \n " ) ;
}
2014-11-18 14:06:32 -03:00
# if ENABLE_ZMQ
2018-06-29 09:16:31 -04:00
g_zmq_notification_interface = CZMQNotificationInterface : : Create ( ) ;
2014-11-18 14:06:32 -03:00
2018-06-29 09:16:31 -04:00
if ( g_zmq_notification_interface ) {
RegisterValidationInterface ( g_zmq_notification_interface ) ;
2014-11-18 14:06:32 -03:00
}
# endif
2012-10-05 14:22:21 -03:00
// ********************************************************* Step 7: load block chain
2012-05-21 10:47:29 -04:00
2020-08-21 14:38:01 -04:00
fReindex = args . GetBoolArg ( " -reindex " , false ) ;
bool fReindexChainState = args . GetBoolArg ( " -reindex-chainstate " , false ) ;
2012-10-21 16:23:13 -03:00
2012-11-04 13:11:48 -03:00
// cache size calculations
2020-08-21 14:38:01 -04:00
int64_t nTotalCache = ( args . GetArg ( " -dbcache " , nDefaultDbCache ) < < 20 ) ;
2015-05-03 20:56:42 -03:00
nTotalCache = std : : max ( nTotalCache , nMinDbCache < < 20 ) ; // total cache cannot be less than nMinDbCache
2016-08-13 13:21:13 -04:00
nTotalCache = std : : min ( nTotalCache , nMaxDbCache < < 20 ) ; // total cache cannot be greater than nMaxDbcache
2017-12-08 16:29:59 -03:00
int64_t nBlockTreeDBCache = std : : min ( nTotalCache / 8 , nMaxBlockDBCache < < 20 ) ;
2012-11-04 13:11:48 -03:00
nTotalCache - = nBlockTreeDBCache ;
2020-08-21 14:38:01 -04:00
int64_t nTxIndexCache = std : : min ( nTotalCache / 8 , args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ? nMaxTxIndexCache < < 20 : 0 ) ;
2017-12-08 16:29:59 -03:00
nTotalCache - = nTxIndexCache ;
2018-08-30 02:15:50 -03:00
int64_t filter_index_cache = 0 ;
if ( ! g_enabled_filter_types . empty ( ) ) {
size_t n_indexes = g_enabled_filter_types . size ( ) ;
int64_t max_cache = std : : min ( nTotalCache / 8 , max_filter_index_cache < < 20 ) ;
filter_index_cache = max_cache / n_indexes ;
nTotalCache - = filter_index_cache * n_indexes ;
}
2015-05-03 20:56:42 -03:00
int64_t nCoinDBCache = std : : min ( nTotalCache / 2 , ( nTotalCache / 4 ) + ( 1 < < 23 ) ) ; // use 25%-50% of the remainder for disk cache
2016-06-27 09:39:28 -04:00
nCoinDBCache = std : : min ( nCoinDBCache , nMaxCoinsDBCache < < 20 ) ; // cap total coins db cache
2012-11-04 13:11:48 -03:00
nTotalCache - = nCoinDBCache ;
2019-09-16 16:01:12 -03:00
int64_t nCoinCacheUsage = nTotalCache ; // the rest goes to in-memory cache
2020-08-21 14:38:01 -04:00
int64_t nMempoolSizeMax = args . GetArg ( " -maxmempool " , DEFAULT_MAX_MEMPOOL_SIZE ) * 1000000 ;
2015-05-03 20:56:42 -03:00
LogPrintf ( " Cache configuration: \n " ) ;
2019-01-14 08:40:00 -03:00
LogPrintf ( " * Using %.1f MiB for block index database \n " , nBlockTreeDBCache * ( 1.0 / 1024 / 1024 ) ) ;
2020-08-21 14:38:01 -04:00
if ( args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ) {
2019-01-14 08:40:00 -03:00
LogPrintf ( " * Using %.1f MiB for transaction index database \n " , nTxIndexCache * ( 1.0 / 1024 / 1024 ) ) ;
2017-12-08 16:29:59 -03:00
}
2018-08-30 02:15:50 -03:00
for ( BlockFilterType filter_type : g_enabled_filter_types ) {
LogPrintf ( " * Using %.1f MiB for %s block filter index database \n " ,
filter_index_cache * ( 1.0 / 1024 / 1024 ) , BlockFilterTypeName ( filter_type ) ) ;
}
2019-01-14 08:40:00 -03:00
LogPrintf ( " * Using %.1f MiB for chain state database \n " , nCoinDBCache * ( 1.0 / 1024 / 1024 ) ) ;
LogPrintf ( " * Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space) \n " , nCoinCacheUsage * ( 1.0 / 1024 / 1024 ) , nMempoolSizeMax * ( 1.0 / 1024 / 1024 ) ) ;
2012-11-04 13:11:48 -03:00
2013-02-16 13:58:45 -03:00
bool fLoaded = false ;
2018-05-16 15:17:40 -04:00
while ( ! fLoaded & & ! ShutdownRequested ( ) ) {
2013-02-16 13:58:45 -03:00
bool fReset = fReindex ;
2019-12-12 12:48:28 -03:00
auto is_coinsview_empty = [ & ] ( CChainState * chainstate ) EXCLUSIVE_LOCKS_REQUIRED ( : : cs_main ) {
return fReset | | fReindexChainState | | chainstate - > CoinsTip ( ) . GetBestBlock ( ) . IsNull ( ) ;
} ;
2020-04-11 11:47:17 -04:00
bilingual_str strLoadError ;
2013-01-11 18:57:22 -03:00
2019-06-28 14:09:58 -04:00
uiInterface . InitMessage ( _ ( " Loading block index... " ) . translated ) ;
2012-07-06 10:33:34 -04:00
2013-02-16 13:58:45 -03:00
do {
2018-06-30 07:25:25 -04:00
const int64_t load_block_index_start_time = GetTimeMillis ( ) ;
2013-02-16 13:58:45 -03:00
try {
2019-02-13 20:39:32 -03:00
LOCK ( cs_main ) ;
2020-07-28 01:40:49 -04:00
chainman . InitializeChainstate ( * Assert ( node . mempool ) ) ;
2019-09-16 14:37:29 -03:00
chainman . m_total_coinstip_cache = nCoinCacheUsage ;
chainman . m_total_coinsdb_cache = nCoinDBCache ;
2020-08-25 15:23:57 -04:00
UnloadBlockIndex ( node . mempool . get ( ) , chainman ) ;
2019-07-24 13:23:48 -04:00
2018-02-11 08:14:08 -03:00
// new CBlockTreeDB tries to delete the existing file, which
// fails if it's still open from the previous loop. Close it first:
pblocktree . reset ( ) ;
2017-08-09 11:08:22 -04:00
pblocktree . reset ( new CBlockTreeDB ( nBlockTreeDBCache , false , fReset ) ) ;
2013-02-16 13:58:45 -03:00
2017-07-23 18:08:50 -04:00
if ( fReset ) {
2013-02-16 13:58:45 -03:00
pblocktree - > WriteReindexing ( true ) ;
2015-06-02 16:24:53 -03:00
//If we're reindexing in prune mode, wipe away unusable block files and all undo data files
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 16:27:44 -03:00
if ( fPruneMode )
2015-06-02 16:24:53 -03:00
CleanupBlockRevFiles ( ) ;
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 16:27:44 -03:00
}
2017-07-06 21:32:08 -04:00
2018-05-16 15:17:40 -04:00
if ( ShutdownRequested ( ) ) break ;
2013-02-16 13:58:45 -03:00
2017-12-08 16:29:59 -03:00
// LoadBlockIndex will load fHavePruned if we've ever removed a
// block file from disk.
2017-07-23 18:08:50 -04:00
// Note that it also sets fReindex based on the disk flag!
// From here on out fReindex and fReset mean something different!
2020-04-18 08:27:46 -04:00
if ( ! chainman . LoadBlockIndex ( chainparams ) ) {
2018-04-13 16:20:29 -03:00
if ( ShutdownRequested ( ) ) break ;
2020-04-11 11:47:17 -04:00
strLoadError = _ ( " Error loading block database " ) ;
2013-02-16 13:58:45 -03:00
break ;
}
2013-05-12 06:03:32 -04:00
// If the loaded chain has a wrong genesis, bail out immediately
// (we're likely using a testnet datadir, or the other way around).
2020-06-29 10:30:03 -04:00
if ( ! chainman . BlockIndex ( ) . empty ( ) & &
2020-08-25 17:39:57 -04:00
! g_chainman . m_blockman . LookupBlockIndex ( chainparams . GetConsensus ( ) . hashGenesisBlock ) ) {
2020-04-11 11:48:04 -04:00
return InitError ( _ ( " Incorrect or no genesis block found. Wrong datadir for network? " ) ) ;
2018-01-11 21:23:09 -03:00
}
2013-05-12 06:03:32 -04:00
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 16:27:44 -03:00
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
// in the past, but is now trying to run unpruned.
if ( fHavePruned & & ! fPruneMode ) {
2020-04-11 11:47:17 -04:00
strLoadError = _ ( " You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain " ) ;
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 16:27:44 -03:00
break ;
}
2017-07-06 21:32:08 -04:00
// At this point blocktree args are consistent with what's on disk.
2017-08-01 17:02:10 -04:00
// If we're not mid-reindex (based on disk + args), add a genesis block on disk
// (otherwise we use the one already on disk).
// This is called again in ThreadImport after the reindex completes.
2017-07-06 21:32:08 -04:00
if ( ! fReindex & & ! LoadGenesisBlock ( chainparams ) ) {
2020-04-11 11:47:17 -04:00
strLoadError = _ ( " Error initializing block database " ) ;
2017-07-06 21:32:08 -04:00
break ;
}
// At this point we're either in reindex or we've loaded a useful
2019-04-10 14:34:46 -04:00
// block tree into BlockIndex()!
2017-07-06 21:32:08 -04:00
2019-12-12 12:48:28 -03:00
bool failed_chainstate_init = false ;
2020-04-18 08:05:52 -04:00
for ( CChainState * chainstate : chainman . GetAll ( ) ) {
2019-12-12 12:48:28 -03:00
chainstate - > InitCoinsDB (
/* cache_size_bytes */ nCoinDBCache ,
/* in_memory */ false ,
/* should_wipe */ fReset | | fReindexChainState ) ;
chainstate - > CoinsErrorCatcher ( ) . AddReadErrCallback ( [ ] ( ) {
uiInterface . ThreadSafeMessageBox (
2020-04-11 11:47:17 -04:00
_ ( " Error reading from database, shutting down. " ) ,
2019-12-12 12:48:28 -03:00
" " , CClientUIInterface : : MSG_ERROR ) ;
} ) ;
// If necessary, upgrade from older database format.
// This is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
if ( ! chainstate - > CoinsDB ( ) . Upgrade ( ) ) {
2020-04-11 11:47:17 -04:00
strLoadError = _ ( " Error upgrading chainstate database " ) ;
2019-12-12 12:48:28 -03:00
failed_chainstate_init = true ;
break ;
}
2017-04-19 13:34:30 -03:00
2019-12-12 12:48:28 -03:00
// ReplayBlocks is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
if ( ! chainstate - > ReplayBlocks ( chainparams ) ) {
2020-04-11 11:47:17 -04:00
strLoadError = _ ( " Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate. " ) ;
2019-12-12 12:48:28 -03:00
failed_chainstate_init = true ;
2017-07-06 20:00:11 -04:00
break ;
}
2019-12-12 12:48:28 -03:00
// The on-disk coinsdb is now in a good state, create the cache
2019-09-16 16:01:12 -03:00
chainstate - > InitCoinsCache ( nCoinCacheUsage ) ;
2019-12-12 12:48:28 -03:00
assert ( chainstate - > CanFlushToDisk ( ) ) ;
if ( ! is_coinsview_empty ( chainstate ) ) {
// LoadChainTip initializes the chain based on CoinsTip()'s best block
if ( ! chainstate - > LoadChainTip ( chainparams ) ) {
2020-04-11 11:47:17 -04:00
strLoadError = _ ( " Error initializing block database " ) ;
2019-12-12 12:48:28 -03:00
failed_chainstate_init = true ;
break ; // out of the per-chainstate loop
}
assert ( chainstate - > m_chain . Tip ( ) ! = nullptr ) ;
}
}
if ( failed_chainstate_init ) {
break ; // out of the chainstate activation do-while
2017-07-06 20:00:11 -04:00
}
2019-02-13 20:39:32 -03:00
} catch ( const std : : exception & e ) {
LogPrintf ( " %s \n " , e . what ( ) ) ;
2020-04-11 11:47:17 -04:00
strLoadError = _ ( " Error opening block database " ) ;
2019-02-13 20:39:32 -03:00
break ;
}
2017-04-19 13:34:30 -03:00
2019-12-12 12:48:28 -03:00
bool failed_rewind { false } ;
2020-01-29 11:57:56 -03:00
// Can't hold cs_main while calling RewindBlockIndex, so retrieve the relevant
// chainstates beforehand.
2020-04-18 08:05:52 -04:00
for ( CChainState * chainstate : WITH_LOCK ( : : cs_main , return chainman . GetAll ( ) ) ) {
2019-12-12 12:48:28 -03:00
if ( ! fReset ) {
// Note that RewindBlockIndex MUST run even if we're about to -reindex-chainstate.
// It both disconnects blocks based on the chainstate, and drops block data in
// BlockIndex() based on lack of available witness data.
uiInterface . InitMessage ( _ ( " Rewinding blocks... " ) . translated ) ;
if ( ! chainstate - > RewindBlockIndex ( chainparams ) ) {
strLoadError = _ (
" Unable to rewind the database to a pre-fork state. "
2020-04-11 11:47:17 -04:00
" You will need to redownload the blockchain " ) ;
2019-12-12 12:48:28 -03:00
failed_rewind = true ;
break ; // out of the per-chainstate loop
}
2016-03-18 13:20:12 -03:00
}
2019-02-13 20:39:32 -03:00
}
2016-03-18 13:20:12 -03:00
2019-12-12 12:48:28 -03:00
if ( failed_rewind ) {
break ; // out of the chainstate activation do-while
}
bool failed_verification = false ;
2019-02-13 20:39:32 -03:00
try {
LOCK ( cs_main ) ;
2015-07-28 18:42:03 -03:00
2020-04-18 08:05:52 -04:00
for ( CChainState * chainstate : chainman . GetAll ( ) ) {
2019-12-12 12:48:28 -03:00
if ( ! is_coinsview_empty ( chainstate ) ) {
uiInterface . InitMessage ( _ ( " Verifying blocks... " ) . translated ) ;
2020-08-21 14:38:01 -04:00
if ( fHavePruned & & args . GetArg ( " -checkblocks " , DEFAULT_CHECKBLOCKS ) > MIN_BLOCKS_TO_KEEP ) {
2019-12-12 12:48:28 -03:00
LogPrintf ( " Prune: pruned datadir may not have more than %d blocks; only checking available blocks \n " ,
MIN_BLOCKS_TO_KEEP ) ;
}
const CBlockIndex * tip = chainstate - > m_chain . Tip ( ) ;
2020-03-04 14:48:32 -03:00
RPCNotifyBlockChange ( tip ) ;
2019-12-12 12:48:28 -03:00
if ( tip & & tip - > nTime > GetAdjustedTime ( ) + 2 * 60 * 60 ) {
strLoadError = _ ( " The block database contains a block which appears to be from the future. "
" This may be due to your computer's date and time being set incorrectly. "
2020-04-11 11:47:17 -04:00
" Only rebuild the block database if you are sure that your computer's date and time are correct " ) ;
2019-12-12 12:48:28 -03:00
failed_verification = true ;
break ;
}
// Only verify the DB of the active chainstate. This is fixed in later
// work when we allow VerifyDB to be parameterized by chainstate.
if ( & : : ChainstateActive ( ) = = chainstate & &
2020-08-21 14:38:01 -04:00
! CVerifyDB ( ) . VerifyDB (
2019-12-12 12:48:28 -03:00
chainparams , & chainstate - > CoinsDB ( ) ,
2020-08-21 14:38:01 -04:00
args . GetArg ( " -checklevel " , DEFAULT_CHECKLEVEL ) ,
args . GetArg ( " -checkblocks " , DEFAULT_CHECKBLOCKS ) ) ) {
2020-04-11 11:47:17 -04:00
strLoadError = _ ( " Corrupted block database detected " ) ;
2019-12-12 12:48:28 -03:00
failed_verification = true ;
break ;
}
2017-07-06 21:32:08 -04:00
}
2013-02-16 13:58:45 -03:00
}
2014-12-07 09:29:06 -03:00
} catch ( const std : : exception & e ) {
2016-12-25 17:19:40 -03:00
LogPrintf ( " %s \n " , e . what ( ) ) ;
2020-04-11 11:47:17 -04:00
strLoadError = _ ( " Error opening block database " ) ;
2019-12-12 12:48:28 -03:00
failed_verification = true ;
2013-02-16 13:58:45 -03:00
break ;
}
2013-01-03 11:29:07 -03:00
2019-12-12 12:48:28 -03:00
if ( ! failed_verification ) {
fLoaded = true ;
LogPrintf ( " block index %15dms \n " , GetTimeMillis ( ) - load_block_index_start_time ) ;
}
2013-02-16 13:58:45 -03:00
} while ( false ) ;
2018-05-16 15:17:40 -04:00
if ( ! fLoaded & & ! ShutdownRequested ( ) ) {
2013-02-16 13:58:45 -03:00
// first suggest a reindex
if ( ! fReset ) {
2016-06-24 10:35:21 -04:00
bool fRet = uiInterface . ThreadSafeQuestion (
2020-04-11 11:47:17 -04:00
strLoadError + Untranslated ( " . \n \n " ) + _ ( " Do you want to rebuild the block database now? " ) ,
strLoadError . original + " . \n Please restart with -reindex or -reindex-chainstate to recover. " ,
2013-02-16 13:58:45 -03:00
" " , CClientUIInterface : : MSG_ERROR | CClientUIInterface : : BTN_ABORT ) ;
if ( fRet ) {
fReindex = true ;
2018-05-16 15:17:40 -04:00
AbortShutdown ( ) ;
2013-02-16 13:58:45 -03:00
} else {
2013-09-18 07:38:08 -03:00
LogPrintf ( " Aborted block database rebuild. Exiting. \n " ) ;
2013-02-16 13:58:45 -03:00
return false ;
}
} else {
2020-04-11 11:48:04 -04:00
return InitError ( strLoadError ) ;
2013-02-16 13:58:45 -03:00
}
}
}
2012-04-18 08:30:24 -03:00
2013-12-16 19:36:22 -03: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 08:30:24 -03:00
// As the program has not fully started yet, Shutdown() is possibly overkill.
2018-05-16 15:17:40 -04:00
if ( ShutdownRequested ( ) ) {
2013-09-18 07:38:08 -03:00
LogPrintf ( " Shutdown requested. Exiting. \n " ) ;
2012-04-18 08:30:24 -03:00
return false ;
}
2011-05-14 14:10:21 -04:00
2017-12-08 16:29:59 -03:00
// ********************************************************* Step 8: start indexers
2020-08-21 14:38:01 -04:00
if ( args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ) {
2018-05-15 20:26:49 -04:00
g_txindex = MakeUnique < TxIndex > ( nTxIndexCache , false , fReindex ) ;
2017-12-08 16:29:59 -03:00
g_txindex - > Start ( ) ;
}
2018-08-30 02:15:50 -03:00
for ( const auto & filter_type : g_enabled_filter_types ) {
InitBlockFilterIndex ( filter_type , filter_index_cache , false , fReindex ) ;
GetBlockFilterIndex ( filter_type ) - > Start ( ) ;
}
2017-12-08 16:29:59 -03:00
// ********************************************************* Step 9: load wallet
2019-09-17 18:04:39 -03:00
for ( const auto & client : node . chain_clients ) {
2017-09-28 15:13:29 -03:00
if ( ! client - > load ( ) ) {
return false ;
}
}
2015-06-30 14:22:48 -03:00
2017-12-08 16:29:59 -03:00
// ********************************************************* Step 10: data directory maintenance
2015-06-30 14:22:48 -03:00
// if pruning, unset the service bit and perform the initial blockstore prune
// after any wallet rescanning has taken place.
if ( fPruneMode ) {
LogPrintf ( " Unsetting NODE_NETWORK on prune mode \n " ) ;
2016-06-08 13:12:22 -04:00
nLocalServices = ServiceFlags ( nLocalServices & ~ NODE_NETWORK ) ;
2015-06-30 14:22:48 -03:00
if ( ! fReindex ) {
2019-12-12 12:48:28 -03:00
LOCK ( cs_main ) ;
2020-04-18 08:05:52 -04:00
for ( CChainState * chainstate : chainman . GetAll ( ) ) {
2019-12-12 12:48:28 -03:00
uiInterface . InitMessage ( _ ( " Pruning blockstore... " ) . translated ) ;
chainstate - > PruneAndFlush ( ) ;
}
2015-06-30 14:22:48 -03:00
}
}
2019-05-20 14:59:07 -04:00
if ( chainparams . GetConsensus ( ) . SegwitHeight ! = std : : numeric_limits < int > : : max ( ) ) {
// Advertise witness capabilities.
// The option to not set NODE_WITNESS is only used in the tests and should be removed.
2015-11-16 20:20:49 -03:00
nLocalServices = ServiceFlags ( nLocalServices | NODE_WITNESS ) ;
}
2017-12-08 16:29:59 -03:00
// ********************************************************* Step 11: import blocks
2012-01-03 12:14:22 -03:00
2018-09-01 19:18:02 -03:00
if ( ! CheckDiskSpace ( GetDataDir ( ) ) ) {
2020-04-11 11:48:04 -04:00
InitError ( strprintf ( _ ( " Error: Disk space is low for %s " ) , GetDataDir ( ) ) ) ;
2016-07-22 10:01:51 -04:00
return false ;
2019-01-07 15:56:28 -03:00
}
2018-09-01 19:18:02 -03:00
if ( ! CheckDiskSpace ( GetBlocksDir ( ) ) ) {
2020-04-11 11:48:04 -04:00
InitError ( strprintf ( _ ( " Error: Disk space is low for %s " ) , GetBlocksDir ( ) ) ) ;
2019-01-07 15:56:28 -03:00
return false ;
}
2016-07-22 10:01:51 -04:00
2016-07-22 09:57:25 -04: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 15:11:43 -03:00
boost : : signals2 : : connection block_notify_genesis_wait_connection ;
2019-03-27 12:14:25 -03:00
if ( : : ChainActive ( ) . Tip ( ) = = nullptr ) {
2020-03-04 14:41:18 -03:00
block_notify_genesis_wait_connection = uiInterface . NotifyBlockTip_connect ( std : : bind ( BlockNotifyGenesisWait , std : : placeholders : : _2 ) ) ;
2016-07-22 09:57:25 -04:00
} else {
fHaveGenesis = true ;
}
2019-07-05 12:30:15 -04:00
# if HAVE_SYSTEM
2020-08-30 12:27:22 -04: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 ;
boost : : replace_all ( command , " %s " , pBlockIndex - > GetBlockHash ( ) . GetHex ( ) ) ;
std : : thread t ( runCommand , command ) ;
t . detach ( ) ; // thread runs free
} ) ;
2020-08-22 03:44:49 -04:00
}
2019-03-14 07:30:37 -03:00
# endif
2014-08-14 12:32:34 -04:00
2017-03-01 13:05:50 -03:00
std : : vector < fs : : path > vImportFiles ;
2020-08-21 14:38:01 -04:00
for ( const std : : string & strFile : args . GetArgs ( " -loadblock " ) ) {
2017-03-29 12:51:41 -03:00
vImportFiles . push_back ( strFile ) ;
2012-09-24 14:37:03 -03:00
}
2016-07-22 09:57:25 -04:00
2020-08-21 14:13:40 -04:00
g_load_block = std : : thread ( & TraceThread < std : : function < void ( ) > > , " loadblk " , [ = , & chainman , & args ] {
ThreadImport ( chainman , vImportFiles , args ) ;
} ) ;
2016-05-16 23:33:32 -04:00
// Wait for genesis block to be processed
2016-07-22 09:57:25 -04:00
{
2017-11-03 08:49:16 -03:00
WAIT_LOCK ( g_genesis_wait_mutex , lock ) ;
2018-02-06 15:32:53 -03:00
// We previously could hang here if StartShutdown() is called prior to
// ThreadImport getting started, so instead we just wait on a timer to
// check ShutdownRequested() regularly.
while ( ! fHaveGenesis & & ! ShutdownRequested ( ) ) {
2017-11-03 08:49:16 -03:00
g_genesis_wait_cv . wait_for ( lock , std : : chrono : : milliseconds ( 500 ) ) ;
2016-05-16 23:33:32 -04:00
}
2019-03-29 15:11:43 -03:00
block_notify_genesis_wait_connection . disconnect ( ) ;
2014-11-08 04:18:21 -03:00
}
2012-09-24 14:37:03 -03:00
2018-02-06 15:32:53 -03:00
if ( ShutdownRequested ( ) ) {
return false ;
}
2017-12-08 16:29:59 -03:00
// ********************************************************* Step 12: start node
2011-05-14 14:10:21 -04:00
2017-08-22 06:02:25 -03:00
int chain_active_height ;
2012-05-21 10:47:29 -04:00
//// debug print
2017-08-22 06:02:25 -03: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 09:13:50 -04:00
if ( tip_info ) {
tip_info - > block_height = chain_active_height ;
tip_info - > block_time = chainman . ActiveChain ( ) . Tip ( ) ? chainman . ActiveChain ( ) . Tip ( ) - > GetBlockTime ( ) : Params ( ) . GenesisBlock ( ) . GetBlockTime ( ) ;
tip_info - > verification_progress = GuessVerificationProgress ( Params ( ) . TxData ( ) , chainman . ActiveChain ( ) . Tip ( ) ) ;
}
if ( tip_info & & : : pindexBestHeader ) {
tip_info - > header_height = : : pindexBestHeader - > nHeight ;
tip_info - > header_time = : : pindexBestHeader - > GetBlockTime ( ) ;
}
2017-08-22 06:02:25 -03:00
}
LogPrintf ( " nBestHeight = %d \n " , chain_active_height ) ;
2021-01-02 06:25:05 -03:00
if ( node . peerman ) node . peerman - > SetBestHeight ( chain_active_height ) ;
2017-08-22 06:02:25 -03:00
2018-02-07 19:42:39 -03:00
Discover ( ) ;
2016-05-26 23:29:39 -04:00
2020-02-22 21:12:19 -03:00
// Map ports with UPnP or NAT-PMP.
StartMapPort ( args . GetBoolArg ( " -upnp " , DEFAULT_UPNP ) , gArgs . 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 14:55:06 -03:00
connOptions . m_max_outbound_full_relay = std : : min ( MAX_OUTBOUND_FULL_RELAY_CONNECTIONS , connOptions . nMaxConnections ) ;
2020-06-09 01:04:07 -04: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 01:39:26 -03: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 19:59:36 -03:00
connOptions . m_banman = node . banman . get ( ) ;
2020-08-29 05:31:11 -04:00
connOptions . m_msgproc = node . peerman . get ( ) ;
2020-08-21 14:38:01 -04:00
connOptions . nSendBufferMaxSize = 1000 * args . GetArg ( " -maxsendbuffer " , DEFAULT_MAXSENDBUFFER ) ;
connOptions . nReceiveFloodSize = 1000 * args . GetArg ( " -maxreceivebuffer " , DEFAULT_MAXRECEIVEBUFFER ) ;
connOptions . m_added_nodes = args . GetArgs ( " -addnode " ) ;
2016-05-26 23:53:08 -04:00
2020-10-24 05:38:56 -03:00
connOptions . nMaxOutboundLimit = 1024 * 1024 * args . GetArg ( " -maxuploadtarget " , DEFAULT_MAX_UPLOAD_TARGET ) ;
2018-11-15 20:30:26 -03:00
connOptions . m_peer_connect_timeout = peer_connect_timeout ;
2016-09-12 16:04:20 -03:00
2020-09-29 12:03:43 -03:00
for ( const std : : string & bind_arg : args . GetArgs ( " -bind " ) ) {
CService bind_addr ;
const size_t index = bind_arg . rfind ( ' = ' ) ;
if ( index = = std : : string : : npos ) {
if ( Lookup ( bind_arg , bind_addr , GetListenPort ( ) , false ) ) {
connOptions . vBinds . push_back ( bind_addr ) ;
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 ) ;
if ( Lookup ( truncated_bind_arg , bind_addr , BaseParams ( ) . OnionServiceTargetPort ( ) , false ) ) {
connOptions . onion_binds . push_back ( bind_addr ) ;
continue ;
}
}
2017-06-26 21:10:39 -04:00
}
2020-09-29 12:03:43 -03:00
return InitError ( ResolveErrMsg ( " bind " , bind_arg ) ) ;
2017-06-01 06:34:02 -04:00
}
2020-09-29 12:03:43 -03:00
if ( connOptions . onion_binds . empty ( ) ) {
connOptions . onion_binds . push_back ( DefaultOnionServiceTarget ( ) ) ;
}
if ( args . GetBoolArg ( " -listenonion " , DEFAULT_LISTEN_ONION ) ) {
const auto bind_addr = connOptions . onion_binds . front ( ) ;
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. " ) , bind_addr . ToStringIPPort ( ) ) ) ;
}
StartTorControl ( bind_addr ) ;
}
2020-08-21 14:38:01 -04:00
for ( const std : : string & strBind : args . GetArgs ( " -whitebind " ) ) {
2019-06-20 05:37:51 -04:00
NetWhitebindPermissions whitebind ;
2020-06-05 08:26:16 -04:00
bilingual_str error ;
if ( ! NetWhitebindPermissions : : TryParse ( strBind , whitebind , error ) ) return InitError ( error ) ;
2019-06-20 05:37:51 -04:00
connOptions . vWhiteBinds . push_back ( whitebind ) ;
2017-06-01 06:34:02 -04:00
}
2020-08-21 14:38:01 -04:00
for ( const auto & net : args . GetArgs ( " -whitelist " ) ) {
2019-06-20 05:37:51 -04:00
NetWhitelistPermissions subnet ;
2020-06-05 08:26:16 -04:00
bilingual_str error ;
if ( ! NetWhitelistPermissions : : TryParse ( net , subnet , error ) ) return InitError ( error ) ;
2017-06-26 21:10:39 -04:00
connOptions . vWhitelistedRange . push_back ( subnet ) ;
2017-06-01 05:07:08 -04:00
}
2020-08-21 14:38:01 -04:00
connOptions . vSeedNodes = args . GetArgs ( " -seednode " ) ;
2017-09-11 11:13:52 -03:00
2017-06-15 03:39:07 -04:00
// Initiate outbound connections unless connect=0
2020-08-21 14:38:01 -04:00
connOptions . m_use_addrman_outgoing = ! args . IsArgSet ( " -connect " ) ;
2017-06-15 03:39:07 -04:00
if ( ! connOptions . m_use_addrman_outgoing ) {
2020-08-21 14:38:01 -04:00
const auto connect = args . GetArgs ( " -connect " ) ;
2017-06-15 03:39:07 -04:00
if ( connect . size ( ) ! = 1 | | connect [ 0 ] ! = " 0 " ) {
connOptions . m_specified_outgoing = connect ;
}
}
2020-02-12 16:08:28 -03:00
if ( ! node . connman - > Start ( * node . scheduler , connOptions ) ) {
2017-06-01 06:34:02 -04:00
return false ;
}
2011-05-14 14:10:21 -04:00
2017-12-08 16:29:59 -03:00
// ********************************************************* Step 13: finished
2012-05-21 10:47:29 -04:00
2014-10-29 14:08:31 -03:00
SetRPCWarmupFinished ( ) ;
2019-06-28 14:09:58 -04:00
uiInterface . InitMessage ( _ ( " Done loading " ) . translated ) ;
2012-05-21 10:47:29 -04:00
2019-09-17 18:04:39 -03:00
for ( const auto & client : node . chain_clients ) {
2020-02-12 16:08:28 -03:00
client - > start ( * node . scheduler ) ;
2017-09-28 15:13:29 -03:00
}
2011-05-14 14:10:21 -04:00
2019-09-17 19:59:36 -03:00
BanMan * banman = node . banman . get ( ) ;
2020-02-12 16:08:28 -03:00
node . scheduler - > scheduleEvery ( [ banman ] {
2019-09-17 19:28:03 -03:00
banman - > DumpBanlist ( ) ;
2020-03-06 20:06:50 -03:00
} , DUMP_BANS_INTERVAL ) ;
2017-10-05 14:10:58 -03:00
2020-09-28 12:38:36 -03:00
# if HAVE_SYSTEM
StartupNotify ( args ) ;
# endif
2017-12-05 12:39:44 -03:00
return true ;
2011-05-14 14:10:21 -04:00
}