2011-05-14 20:10:21 +02:00
// Copyright (c) 2009-2010 Satoshi Nakamoto
2021-06-21 00:49:59 +02:00
// Copyright (c) 2009-2018 The Bitcoin Core developers
2021-04-20 21:33:02 +02:00
// Copyright (c) 2014-2021 The Dash Core developers
2014-12-01 02:39:44 +01:00
// Distributed under the MIT software license, see the accompanying
2012-05-18 16:02:28 +02:00
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2012-11-05 08:04:21 +01:00
2013-05-28 01:55:01 +02:00
# if defined(HAVE_CONFIG_H)
2020-03-19 23:46:56 +01:00
# include <config/dash-config.h>
2013-05-28 01:55:01 +02:00
# endif
2020-03-19 23:46:56 +01:00
# include <init.h>
# include <addrman.h>
# include <amount.h>
# include <base58.h>
# include <chain.h>
# include <chainparams.h>
# include <checkpoints.h>
2020-12-15 17:22:23 +01:00
# include <node/coinstats.h>
2020-03-19 23:46:56 +01:00
# include <compat/sanity.h>
# include <consensus/validation.h>
# include <fs.h>
2021-05-11 17:11:07 +02:00
# include <hash.h>
2020-03-19 23:46:56 +01:00
# include <httpserver.h>
# include <httprpc.h>
2021-05-25 12:48:04 +02:00
# include <index/txindex.h>
2020-03-19 23:46:56 +01:00
# include <key.h>
# include <validation.h>
# include <miner.h>
# include <netbase.h>
# include <net.h>
# include <net_processing.h>
# include <policy/feerate.h>
# include <policy/fees.h>
# include <policy/policy.h>
# include <rpc/server.h>
# include <rpc/register.h>
# include <rpc/blockchain.h>
# include <script/standard.h>
# include <script/sigcache.h>
# include <scheduler.h>
2021-06-21 00:49:59 +02:00
# include <shutdown.h>
2020-03-19 23:46:56 +01:00
# include <timedata.h>
# include <txdb.h>
# include <txmempool.h>
# include <torcontrol.h>
# include <ui_interface.h>
2021-06-27 08:33:13 +02:00
# include <util/asmap.h>
2021-06-25 08:07:28 +02:00
# include <util/error.h>
2021-06-27 08:33:13 +02:00
# include <util/moneystr.h>
2021-06-25 08:07:28 +02:00
# include <util/system.h>
2021-06-21 00:49:59 +02:00
# include <util/threadnames.h>
2021-06-25 08:07:28 +02:00
# include <util/validation.h>
2020-03-19 23:46:56 +01:00
# include <validationinterface.h>
2016-12-20 14:27:59 +01:00
2020-03-19 23:46:56 +01:00
# include <masternode/activemasternode.h>
2021-03-17 23:36:11 +01:00
# include <coinjoin/coinjoin-server.h>
2020-03-19 23:46:56 +01:00
# include <dsnotificationinterface.h>
# include <flat-database.h>
# include <governance/governance.h>
# include <masternode/masternode-meta.h>
# include <masternode/masternode-sync.h>
# include <masternode/masternode-utils.h>
# include <messagesigner.h>
# include <netfulfilledman.h>
# include <spork.h>
# include <warnings.h>
2020-04-18 11:59:40 +02:00
# include <walletinitinterface.h>
2016-12-20 14:27:59 +01:00
2020-03-19 23:46:56 +01:00
# include <evo/deterministicmns.h>
2021-04-16 05:41:16 +02:00
# include <llmq/quorums.h>
2020-03-19 23:46:56 +01:00
# include <llmq/quorums_init.h>
2020-09-25 18:19:58 +02:00
# include <llmq/quorums_blockprocessor.h>
2021-02-22 23:46:40 +01:00
# include <llmq/quorums_signing.h>
2021-02-01 17:10:19 +01:00
# include <llmq/quorums_utils.h>
2018-02-14 14:43:03 +01:00
2020-12-15 17:22:23 +01:00
# include <statsd_client.h>
2013-04-13 07:13:08 +02:00
# include <stdint.h>
2014-05-11 15:29:16 +02:00
# include <stdio.h>
2011-05-14 20:10:21 +02:00
2020-03-19 23:46:56 +01:00
# include <bls/bls.h>
2018-10-03 14:53:21 +02:00
2012-04-15 22:10:54 +02:00
# ifndef WIN32
# include <signal.h>
2018-07-25 11:33:22 +02:00
# include <sys/stat.h>
2012-03-18 23:14:03 +01:00
# endif
2011-10-07 16:46:56 +02:00
2016-01-28 06:27:25 +01:00
# include <boost/algorithm/string/classification.hpp>
2014-08-29 22:52:41 +02:00
# include <boost/algorithm/string/replace.hpp>
2016-01-28 06:27:25 +01:00
# include <boost/algorithm/string/split.hpp>
2015-03-26 16:20:59 +01:00
# include <boost/bind.hpp>
Split up util.cpp/h
Split up util.cpp/h into:
- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)
The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).
Breaks dependency of sha256.cpp on all the things pulled in by util.
2014-08-21 16:11:09 +02:00
# include <boost/thread.hpp>
2013-04-13 07:13:08 +02:00
# include <openssl/crypto.h>
2014-11-18 18:06:32 +01:00
# if ENABLE_ZMQ
2020-03-19 23:46:56 +01:00
# include <zmq/zmqnotificationinterface.h>
2018-07-09 17:05:14 +02:00
# include <zmq/zmqrpc.h>
2014-11-18 18:06:32 +01:00
# endif
2014-09-18 14:08:43 +02:00
bool fFeeEstimatesInitialized = false ;
2015-06-27 21:21:41 +02:00
static const bool DEFAULT_PROXYRANDOMIZE = true ;
static const bool DEFAULT_REST_ENABLE = false ;
static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false ;
2011-06-26 19:23:24 +02:00
2016-02-16 09:47:45 +01:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
std : : unique_ptr < CConnman > g_connman ;
2017-07-28 16:10:10 +02:00
std : : unique_ptr < PeerLogicValidation > peerLogic ;
2020-05-20 11:24:51 +02:00
# if !(ENABLE_WALLET)
class DummyWalletInit : public WalletInitInterface {
public :
2021-06-19 16:34:39 +02:00
void AddWalletOptions ( ) const override ;
2018-04-17 15:57:52 +02:00
bool ParameterInteraction ( ) const override { return true ; }
void RegisterRPC ( CRPCTable & ) const override { }
bool Verify ( ) const override { return true ; }
2018-04-10 01:08:00 +02:00
bool Open ( ) const override { LogPrintf ( " No wallet support compiled in! \n " ) ; return true ; }
2018-04-17 15:57:52 +02:00
void Start ( CScheduler & scheduler ) const override { }
void Flush ( ) const override { }
void Stop ( ) const override { }
void Close ( ) const override { }
2020-05-20 11:24:51 +02:00
2021-03-17 23:36:11 +01:00
// Dash Specific WalletInitInterface InitCoinJoinSettings
2018-04-17 15:57:52 +02:00
void AutoLockMasternodeCollaterals ( ) const override { }
2021-03-17 23:36:11 +01:00
void InitCoinJoinSettings ( ) const override { }
2018-04-17 15:57:52 +02:00
void InitKeePass ( ) const override { }
bool InitAutoBackup ( ) const override { return true ; }
2020-05-20 11:24:51 +02:00
} ;
2021-06-19 16:34:39 +02:00
void DummyWalletInit : : AddWalletOptions ( ) const
{
std : : vector < std : : string > opts = { " -createwalletbackups=<n> " , " -disablewallet " , " -instantsendnotify=<cmd> " ,
" -keypool=<n> " , " -rescan=<mode> " , " -salvagewallet " , " -spendzeroconfchange " , " -upgradewallet " ,
" -wallet=<path> " , " -walletbackupsdir=<dir> " , " -walletbroadcast " , " -walletdir=<dir> " ,
" -walletnotify=<cmd> " , " -zapwallettxes=<mode> " , " -discardfee=<amt> " , " -fallbackfee=<amt> " ,
" -mintxfee=<amt> " , " -paytxfee=<amt> " , " -txconfirmtarget=<n> " , " -hdseed=<hex> " , " -mnemonic=<text> " ,
" -mnemonicpassphrase=<text> " , " -usehd " , " -keepass " , " -keepassid=<id> " , " -keepasskey=<key> " ,
" -keepassname=<name> " , " -keepassport=<port> " , " -enablecoinjoin " , " -coinjoinamount=<n> " ,
" -coinjoinautostart " , " -coinjoindenomsgoal=<n> " , " -coinjoindenomshardcap=<n> " , " -coinjoinmultisession " ,
" -coinjoinrounds=<n> " , " -coinjoinsessions=<n> " , " -dblogsize=<n> " , " -flushwallet " , " -privdb " ,
" -walletrejectlongchains " } ;
gArgs . AddHiddenArgs ( opts ) ;
}
2018-04-17 15:57:52 +02:00
const WalletInitInterface & g_wallet_init_interface = DummyWalletInit ( ) ;
2020-05-20 11:24:51 +02:00
# endif
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
2019-08-06 05:08:33 +02:00
static CDSNotificationInterface * pdsNotificationInterface = nullptr ;
2016-03-02 22:20:04 +01:00
2013-04-26 00:46:47 +02:00
# ifdef WIN32
// Win32 LevelDB doesn't use filedescriptors, and the ones used for
2015-04-28 16:48:28 +02:00
// accessing block files don't count towards the fd_set size limit
2013-04-26 00:46:47 +02:00
// anyway.
# define MIN_CORE_FILEDESCRIPTORS 0
# else
# define MIN_CORE_FILEDESCRIPTORS 150
# endif
2014-03-17 13:19:54 +01:00
static const char * FEE_ESTIMATES_FILENAME = " fee_estimates.dat " ;
2013-01-07 16:35:31 +01:00
2021-05-11 17:11:07 +02:00
static const char * DEFAULT_ASMAP_FILENAME = " ip_asn.map " ;
2011-05-14 20:10:21 +02:00
//////////////////////////////////////////////////////////////////////////////
//
// Shutdown
//
2013-03-09 18:02:57 +01: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
2021-06-21 00:49:59 +02:00
// signal handler sets ShutdownRequested(), which makes main thread's
2017-09-12 21:08:03 +02: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 18:02:57 +01: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
2021-06-21 00:49:59 +02:00
// ShutdownRequested() getting set, and then does the normal Qt
2013-03-23 23:14:12 +01:00
// shutdown thing.
2013-03-09 18:02:57 +01:00
//
2016-05-26 07:26:21 +02:00
/**
* This is a minimally invasive approach to shutdown on LevelDB read errors from the
* chainstate , while keeping user interface out of the common library , which is shared
2020-06-11 10:39:04 +02:00
* between dashd , and dash - qt and non - server tools .
2016-05-26 07:26:21 +02:00
*/
2017-08-21 18:25:42 +02:00
class CCoinsViewErrorCatcher final : public CCoinsViewBacked
2015-01-24 18:31:19 +01:00
{
public :
2017-08-17 22:59:56 +02:00
explicit CCoinsViewErrorCatcher ( CCoinsView * view ) : CCoinsViewBacked ( view ) { }
2017-06-02 00:47:58 +02:00
bool GetCoin ( const COutPoint & outpoint , Coin & coin ) const override {
2015-01-24 18:31:19 +01:00
try {
2017-06-02 00:47:58 +02:00
return CCoinsViewBacked : : GetCoin ( outpoint , coin ) ;
2015-01-24 18:31:19 +01:00
} catch ( const std : : runtime_error & e ) {
uiInterface . ThreadSafeMessageBox ( _ ( " Error reading from database, shutting down. " ) , " " , CClientUIInterface : : MSG_ERROR ) ;
LogPrintf ( " Error reading from database: %s \n " , e . what ( ) ) ;
// Starting the shutdown sequence and returning false to the caller would be
// interpreted as 'entry not found' (as opposed to unable to read data), and
2015-02-11 05:24:38 +01:00
// could lead to invalid interpretation. Just exit immediately, as we can't
2015-01-24 18:31:19 +01:00
// continue anyway, and all writes should be atomic.
abort ( ) ;
}
}
// Writes do not need similar protection, as failure to write is handled by the caller.
} ;
2017-11-09 21:22:08 +01:00
static std : : unique_ptr < CCoinsViewErrorCatcher > pcoinscatcher ;
2016-09-02 09:56:16 +02:00
static std : : unique_ptr < ECCVerifyHandle > globalVerifyHandle ;
2012-07-06 16:33:34 +02:00
2018-01-30 12:34:11 +01:00
static boost : : thread_group threadGroup ;
static CScheduler scheduler ;
void Interrupt ( )
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
{
InterruptHTTPServer ( ) ;
InterruptHTTPRPC ( ) ;
InterruptRPC ( ) ;
InterruptREST ( ) ;
2015-09-08 17:48:45 +02:00
InterruptTorControl ( ) ;
2019-02-15 15:11:50 +01:00
llmq : : InterruptLLMQSystem ( ) ;
2020-06-13 20:21:30 +02:00
InterruptMapPort ( ) ;
2017-08-09 18:06:31 +02:00
if ( g_connman )
g_connman - > Interrupt ( ) ;
2021-05-25 12:48:04 +02:00
if ( g_txindex ) {
g_txindex - > Interrupt ( ) ;
}
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
}
2012-07-06 16:33:34 +02:00
2015-05-27 22:35:46 +02:00
/** Preparing steps before shutting down or restarting the wallet */
2015-05-28 23:09:14 +02:00
void PrepareShutdown ( )
2015-05-25 18:29:11 +02:00
{
2015-05-25 22:59:38 +02:00
LogPrintf ( " %s: In progress... \n " , __func__ ) ;
2015-05-25 18:29:11 +02:00
static CCriticalSection cs_Shutdown ;
TRY_LOCK ( cs_Shutdown , lockShutdown ) ;
if ( ! lockShutdown )
return ;
2019-01-07 10:55:35 +01:00
/// Note: Shutdown() must be able to handle cases in which initialization failed part of the way,
2015-05-25 18:29:11 +02:00
/// for example if the data directory was found to be locked.
/// Be sure that anything that writes files or flushes caches only does this if the respective
/// module was initialized.
2021-06-24 19:54:20 +02:00
util : : ThreadRename ( " shutoff " ) ;
2015-05-25 18:29:11 +02:00
mempool . AddTransactionsUpdated ( 1 ) ;
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
StopHTTPRPC ( ) ;
StopREST ( ) ;
StopRPC ( ) ;
StopHTTPServer ( ) ;
2019-02-17 12:39:43 +01:00
llmq : : StopLLMQSystem ( ) ;
2018-11-01 22:58:17 +01:00
// fRPCInWarmup should be `false` if we completed the loading sequence
// before a shutdown request was received
std : : string statusmessage ;
bool fRPCInWarmup = RPCIsInWarmup ( & statusmessage ) ;
2018-04-17 15:57:52 +02:00
g_wallet_init_interface . Flush ( ) ;
2020-06-13 20:21:30 +02:00
StopMapPort ( ) ;
2017-09-08 01:00:49 +02:00
// Because these depend on each-other, we make sure that neither can be
// using the other before destroying them.
2017-11-30 11:14:44 +01:00
if ( peerLogic ) UnregisterValidationInterface ( peerLogic . get ( ) ) ;
if ( g_connman ) g_connman - > Stop ( ) ;
2021-05-25 12:48:04 +02:00
if ( g_txindex ) g_txindex - > Stop ( ) ;
2016-04-10 08:31:32 +02:00
2020-06-13 20:21:30 +02:00
StopTorControl ( ) ;
2018-01-30 12:34:11 +01:00
// After everything has been shut down, but before things get flushed, stop the
// CScheduler/checkqueue threadGroup
threadGroup . interrupt_all ( ) ;
threadGroup . join_all ( ) ;
2021-06-16 15:03:04 +02:00
StopScriptCheckWorkerThreads ( ) ;
2018-01-30 12:34:11 +01:00
2020-03-26 13:24:31 +01:00
// After there are no more peers/RPC left to give us new data which may generate
// CValidationInterface callbacks, flush them...
GetMainSignals ( ) . FlushBackgroundCallbacks ( ) ;
2020-06-13 20:18:31 +02:00
if ( ! fRPCInWarmup ) {
2018-07-16 14:47:37 +02:00
// STORE DATA CACHES INTO SERIALIZED DAT FILES
2019-01-03 21:08:34 +01:00
CFlatDB < CMasternodeMetaMan > flatdb1 ( " mncache.dat " , " magicMasternodeCache " ) ;
flatdb1 . Dump ( mmetaman ) ;
2018-03-29 17:08:00 +02:00
CFlatDB < CNetFulfilledRequestManager > flatdb4 ( " netfulfilled.dat " , " magicFulfilledCache " ) ;
flatdb4 . Dump ( netfulfilledman ) ;
2018-08-13 22:21:21 +02:00
CFlatDB < CSporkManager > flatdb6 ( " sporks.dat " , " magicSporkCache " ) ;
flatdb6 . Dump ( sporkManager ) ;
2020-06-28 23:00:00 +02:00
if ( ! fDisableGovernance ) {
2020-06-13 20:18:31 +02:00
CFlatDB < CGovernanceManager > flatdb3 ( " governance.dat " , " magicGovernanceCache " ) ;
flatdb3 . Dump ( governance ) ;
}
2018-03-29 17:08:00 +02:00
}
2016-04-10 08:31:32 +02:00
2018-08-08 14:02:54 +02:00
// After the threads that potentially access these pointers have been stopped,
// destruct and reset all to nullptr.
peerLogic . reset ( ) ;
g_connman . reset ( ) ;
2021-05-25 12:48:04 +02:00
g_txindex . reset ( ) ;
2018-08-08 14:02:54 +02:00
2018-03-30 00:25:43 +02:00
if ( g_is_mempool_loaded & & gArgs . GetArg ( " -persistmempool " , DEFAULT_PERSIST_MEMPOOL ) ) {
2017-01-06 18:28:46 +01:00
DumpMempool ( ) ;
2017-05-03 09:23:39 +02:00
}
2015-05-25 18:29:11 +02:00
if ( fFeeEstimatesInitialized )
{
2018-02-08 22:05:00 +01:00
: : feeEstimator . FlushUnconfirmed ( ) ;
2017-04-06 20:19:21 +02:00
fs : : path est_path = GetDataDir ( ) / FEE_ESTIMATES_FILENAME ;
CAutoFile est_fileout ( fsbridge : : fopen ( est_path , " wb " ) , SER_DISK , CLIENT_VERSION ) ;
2015-05-25 18:29:11 +02:00
if ( ! est_fileout . IsNull ( ) )
2017-04-20 21:16:19 +02:00
: : feeEstimator . Write ( est_fileout ) ;
2015-05-25 18:29:11 +02:00
else
LogPrintf ( " %s: Failed to write fee estimates to %s \n " , __func__ , est_path . string ( ) ) ;
fFeeEstimatesInitialized = false ;
}
2018-05-03 12:38:00 +02:00
// FlushStateToDisk generates a ChainStateFlushed callback, which we should avoid missing
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
if ( pcoinsTip ! = nullptr ) {
FlushStateToDisk ( ) ;
}
2017-07-11 09:30:36 +02:00
2021-01-25 05:56:18 +01:00
// After there are no more peers/RPC left to give us new data which may generate
// CValidationInterface callbacks, flush them...
GetMainSignals ( ) . FlushBackgroundCallbacks ( ) ;
2017-07-11 09:30:36 +02: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.
2015-05-25 18:29:11 +02:00
{
LOCK ( cs_main ) ;
2019-08-06 05:08:33 +02:00
if ( pcoinsTip ! = nullptr ) {
2015-05-25 18:29:11 +02:00
FlushStateToDisk ( ) ;
}
2017-11-09 21:22:08 +01:00
pcoinsTip . reset ( ) ;
pcoinscatcher . reset ( ) ;
pcoinsdbview . reset ( ) ;
pblocktree . reset ( ) ;
2018-11-23 15:42:09 +01:00
llmq : : DestroyLLMQSystem ( ) ;
2017-11-09 21:22:08 +01:00
deterministicMNManager . reset ( ) ;
evoDb . reset ( ) ;
2015-05-25 18:29:11 +02:00
}
2018-04-17 15:57:52 +02:00
g_wallet_init_interface . Stop ( ) ;
2014-11-18 18:06:32 +01:00
# if ENABLE_ZMQ
2018-07-09 17:05:14 +02:00
if ( g_zmq_notification_interface ) {
UnregisterValidationInterface ( g_zmq_notification_interface ) ;
delete g_zmq_notification_interface ;
g_zmq_notification_interface = nullptr ;
2014-11-18 18:06:32 +01:00
}
# endif
2016-03-02 22:20:04 +01:00
if ( pdsNotificationInterface ) {
UnregisterValidationInterface ( pdsNotificationInterface ) ;
delete pdsNotificationInterface ;
2019-08-06 05:08:33 +02:00
pdsNotificationInterface = nullptr ;
2016-03-02 22:20:04 +01:00
}
2018-02-15 14:33:04 +01:00
if ( fMasternodeMode ) {
UnregisterValidationInterface ( activeMasternodeManager ) ;
}
2016-03-02 22:20:04 +01:00
2018-10-26 07:04:22 +02:00
// make sure to clean up BLS keys before global destructors are called (they have allocated from the secure memory pool)
activeMasternodeInfo . blsKeyOperator . reset ( ) ;
activeMasternodeInfo . blsPubKeyOperator . reset ( ) ;
2015-05-25 18:29:11 +02:00
# ifndef WIN32
2015-05-19 01:37:43 +02:00
try {
2017-04-06 20:19:21 +02:00
fs : : remove ( GetPidFile ( ) ) ;
} catch ( const fs : : filesystem_error & e ) {
2015-05-19 01:37:43 +02:00
LogPrintf ( " %s: Unable to remove pidfile: %s \n " , __func__ , e . what ( ) ) ;
}
2015-05-25 18:29:11 +02:00
# endif
UnregisterAllValidationInterfaces ( ) ;
2017-07-11 09:30:36 +02:00
GetMainSignals ( ) . UnregisterBackgroundSignalScheduler ( ) ;
2017-11-15 14:14:20 +01:00
GetMainSignals ( ) . UnregisterWithMempoolSignals ( mempool ) ;
2015-05-25 18:29:11 +02:00
}
2015-05-27 22:35:46 +02:00
/**
* Shutdown is split into 2 parts :
2015-05-28 23:09:14 +02:00
* Part 1 : shut down everything but the main wallet instance ( done in PrepareShutdown ( ) )
2015-05-27 22:35:46 +02:00
* Part 2 : delete wallet instance
*
2015-05-28 23:09:14 +02:00
* In case of a restart PrepareShutdown ( ) was already called before , but this method here gets
2015-05-27 22:35:46 +02:00
* called implicitly when the parent object is deleted . In this case we have to skip the
2015-05-28 23:09:14 +02:00
* PrepareShutdown ( ) part because it was already executed and just delete the wallet instance .
2015-05-27 22:35:46 +02:00
*/
2013-03-09 18:02:57 +01:00
void Shutdown ( )
2011-05-14 20:10:21 +02:00
{
2015-05-27 22:35:46 +02:00
// Shutdown part 1: prepare shutdown
2021-06-21 00:49:59 +02:00
if ( ! RestartRequested ( ) ) {
2015-05-28 23:09:14 +02:00
PrepareShutdown ( ) ;
2015-05-27 22:35:46 +02:00
}
2020-06-13 20:21:30 +02:00
// Shutdown part 2: delete wallet instance
2018-04-17 15:57:52 +02:00
g_wallet_init_interface . Close ( ) ;
2015-07-28 20:11:20 +02: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 23:28:26 +02:00
ECC_Stop ( ) ;
2014-06-27 14:41:11 +02:00
LogPrintf ( " %s: done \n " , __func__ ) ;
2011-05-14 20:10:21 +02:00
}
2014-12-01 02:39:44 +01:00
/**
2017-03-27 10:36:32 +02:00
* Signal handlers are very limited in what they are allowed to do .
* The execution context the handler is invoked in is not guaranteed ,
* so we restrict handler operations to just touching variables :
2014-12-01 02:39:44 +01:00
*/
2018-05-07 14:31:08 +02:00
# ifndef WIN32
2017-03-27 10:36:32 +02:00
static void HandleSIGTERM ( int )
2011-05-14 20:10:21 +02:00
{
2021-06-21 00:49:59 +02:00
StartShutdown ( ) ;
2011-05-14 20:10:21 +02:00
}
2017-03-27 10:36:32 +02:00
static void HandleSIGHUP ( int )
2012-03-02 20:31:16 +01:00
{
2018-05-01 04:13:30 +02:00
g_logger - > m_reopen_file = true ;
2012-03-02 20:31:16 +01:00
}
2018-05-07 14:31:08 +02:00
# else
static BOOL WINAPI consoleCtrlHandler ( DWORD dwCtrlType )
{
2021-06-21 00:49:59 +02:00
StartShutdown ( ) ;
2018-05-07 14:31:08 +02:00
Sleep ( INFINITE ) ;
return true ;
}
# endif
2011-05-14 20:10:21 +02:00
2017-03-27 10:36:32 +02: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 ;
2019-08-06 05:08:33 +02:00
sigaction ( signal , & sa , nullptr ) ;
2017-03-27 10:36:32 +02:00
}
# endif
2018-05-04 22:42:39 +02:00
static void OnRPCStarted ( )
2016-09-09 08:33:26 +02:00
{
2018-08-13 21:01:07 +02:00
uiInterface . NotifyBlockTip_connect ( & RPCNotifyBlockChange ) ;
2016-09-09 08:33:26 +02:00
}
2012-05-11 15:28:59 +02:00
2018-05-04 22:42:39 +02:00
static void OnRPCStopped ( )
2014-10-19 10:46:17 +02:00
{
2018-08-13 21:01:07 +02:00
uiInterface . NotifyBlockTip_disconnect ( & RPCNotifyBlockChange ) ;
2016-09-09 08:33:26 +02:00
RPCNotifyBlockChange ( false , nullptr ) ;
2018-04-13 03:13:49 +02:00
g_best_block_cv . notify_all ( ) ;
2019-05-22 23:51:39 +02:00
LogPrint ( BCLog : : RPC , " RPC stopped. \n " ) ;
2014-10-19 10:46:17 +02:00
}
2020-04-16 10:11:26 +02:00
std : : string GetSupportedSocketEventsStr ( )
{
std : : string strSupportedModes = " 'select' " ;
# ifdef USE_POLL
strSupportedModes + = " , 'poll' " ;
2020-04-07 17:58:38 +02:00
# endif
# ifdef USE_EPOLL
strSupportedModes + = " , 'epoll' " ;
2020-12-30 20:34:42 +01:00
# endif
# ifdef USE_KQUEUE
strSupportedModes + = " , 'kqueue' " ;
2020-04-16 10:11:26 +02:00
# endif
return strSupportedModes ;
}
2021-03-19 16:00:24 +01:00
void SetupServerArgs ( )
2012-05-13 11:36:10 +02:00
{
2017-05-09 09:29:12 +02:00
const auto defaultBaseParams = CreateBaseChainParams ( CBaseChainParams : : MAIN ) ;
const auto testnetBaseParams = CreateBaseChainParams ( CBaseChainParams : : TESTNET ) ;
const auto defaultChainParams = CreateChainParams ( CBaseChainParams : : MAIN ) ;
const auto testnetChainParams = CreateChainParams ( CBaseChainParams : : TESTNET ) ;
2021-02-22 23:46:40 +01:00
Consensus : : Params devnetConsensus = CreateChainParams ( CBaseChainParams : : DEVNET , true ) - > GetConsensus ( ) ;
Consensus : : LLMQParams devnetLLMQ = devnetConsensus . llmqs . at ( Consensus : : LLMQ_DEVNET ) ;
2021-04-10 22:36:31 +02:00
const auto regtestLLMQ = CreateChainParams ( CBaseChainParams : : REGTEST ) - > GetConsensus ( ) . llmqs . at ( Consensus : : LLMQ_TEST ) ;
2021-02-22 23:46:40 +01:00
2021-06-19 16:34:39 +02:00
// Hidden Options
std : : vector < std : : string > hidden_args = { " -rpcssl " , " -benchmark " , " -h " , " -help " , " -socks " , " -tor " , " -debugnet " , " -whitelistalwaysrelay " ,
" -blockminsize " , " -dbcrashratio " , " -forcecompactdb " ,
// GUI args. These will be overwritten by SetupUIArgs for the GUI
" -allowselfsignedrootcertificates " , " -choosedatadir " , " -lang=<lang> " , " -min " , " -resetguisettings " , " -rootcertificates=<file> " , " -splash " , " -uiplatform " } ;
2015-02-04 09:11:49 +01:00
2021-03-19 16:00:24 +01:00
// Set all of the args and their help
2014-06-17 09:13:52 +02:00
// When adding new options to the categories, please keep and ensure alphabetical ordering.
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -? " , " Print this help message and exit " , false , OptionsCategory : : OPTIONS ) ;
gArgs . 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) " , false , OptionsCategory : : OPTIONS ) ;
gArgs . 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) " , defaultChainParams - > GetConsensus ( ) . defaultAssumeValid . GetHex ( ) , testnetChainParams - > GetConsensus ( ) . defaultAssumeValid . GetHex ( ) ) , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -blocksdir=<dir> " , " Specify blocks directory (default: <datadir>/blocks) " , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -blocknotify=<cmd> " , " Execute command when the best block changes (%s in cmd is replaced by block hash) " , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -blockreconstructionextratxn=<n> " , strprintf ( " Extra transactions to keep in memory for compact block reconstructions (default: %u) " , DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN ) , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -blocksonly " , strprintf ( " Whether to operate in a blocks only mode (default: %u) " , DEFAULT_BLOCKSONLY ) , true , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -conf=<file> " , strprintf ( " Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s) " , BITCOIN_CONF_FILENAME ) , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -datadir=<dir> " , " Specify data directory " , false , OptionsCategory : : OPTIONS ) ;
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -dbbatchsize " , strprintf ( " Maximum database write batch size in bytes (default: %u) " , nDefaultDbBatchSize ) , true , OptionsCategory : : OPTIONS ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -dbcache=<n> " , strprintf ( " Set database cache size in megabytes (%d to %d, default: %d) " , nMinDbCache , nMaxDbCache , nDefaultDbCache ) , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -debuglogfile=<file> " , strprintf ( " Specify location of debug log file. Relative paths will be prefixed by a net-specific datadir location. (0 to disable; default: %s) " , DEFAULT_DEBUGLOGFILE ) , false , OptionsCategory : : OPTIONS ) ;
2018-05-09 06:31:11 +02:00
gArgs . AddArg ( " -includeconf=<file> " , " Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line) " , false , OptionsCategory : : OPTIONS ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -loadblock=<file> " , " Imports blocks from external blk000??.dat file on startup " , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -maxmempool=<n> " , strprintf ( " Keep the transaction memory pool below <n> megabytes (default: %u) " , DEFAULT_MAX_MEMPOOL_SIZE ) , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -maxorphantxsize=<n> " , strprintf ( " Maximum total size of all orphan transactions in megabytes (default: %u) " , DEFAULT_MAX_ORPHAN_TRANSACTIONS_SIZE ) , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -maxrecsigsage=<n> " , strprintf ( " Number of seconds to keep LLMQ recovery sigs (default: %u) " , llmq : : DEFAULT_MAX_RECOVERED_SIGS_AGE ) , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -mempoolexpiry=<n> " , strprintf ( " Do not keep transactions in the mempool longer than <n> hours (default: %u) " , DEFAULT_MEMPOOL_EXPIRY ) , false , OptionsCategory : : OPTIONS ) ;
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -minimumchainwork=<hex> " , strprintf ( " Minimum work assumed to exist on a valid chain in hex (default: %s, testnet: %s) " , defaultChainParams - > GetConsensus ( ) . nMinimumChainWork . GetHex ( ) , testnetChainParams - > GetConsensus ( ) . nMinimumChainWork . GetHex ( ) ) , true , OptionsCategory : : OPTIONS ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -par=<n> " , strprintf ( " Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d) " ,
2021-03-19 16:00:24 +01:00
- GetNumCores ( ) , MAX_SCRIPTCHECK_THREADS , DEFAULT_SCRIPTCHECK_THREADS ) , false , OptionsCategory : : OPTIONS ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -persistmempool " , strprintf ( " Whether to save the mempool on shutdown and load on restart (default: %u) " , DEFAULT_PERSIST_MEMPOOL ) , false , OptionsCategory : : OPTIONS ) ;
2014-09-20 10:56:25 +02:00
# ifndef WIN32
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -pid=<file> " , strprintf ( " Specify pid file. Relative paths will be prefixed by a net-specific datadir location. (default: %s) " , BITCOIN_PID_FILENAME ) , false , OptionsCategory : : OPTIONS ) ;
2021-06-19 16:34:39 +02:00
# else
hidden_args . emplace_back ( " -pid " ) ;
2014-09-20 10:56:25 +02:00
# endif
2021-03-19 18:23:58 +01:00
gArgs . 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, -rescan and -disablegovernance=false. "
2015-05-04 18:46:33 +02:00
" Warning: Reverting this setting requires re-downloading the entire blockchain. "
2021-03-19 18:23:58 +01: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 ) , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -syncmempool " , strprintf ( " Sync mempool from other nodes on start (default: %u) " , DEFAULT_SYNC_MEMPOOL ) , false , OptionsCategory : : OPTIONS ) ;
2015-09-11 23:31:30 +02:00
# ifndef WIN32
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -sysperms " , " Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality) " , false , OptionsCategory : : OPTIONS ) ;
2021-06-19 16:34:39 +02:00
# else
hidden_args . emplace_back ( " -sysperms " ) ;
2014-06-04 13:16:07 +02:00
# endif
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -version " , " Print version and exit " , false , OptionsCategory : : OPTIONS ) ;
gArgs . AddArg ( " -addressindex " , strprintf ( " Maintain a full address index, used to query for the balance, txids and unspent outputs for addresses (default: %u) " , DEFAULT_ADDRESSINDEX ) , false , OptionsCategory : : INDEXING ) ;
gArgs . AddArg ( " -reindex " , " Rebuild chain state and block index from the blk*.dat files on disk " , false , OptionsCategory : : INDEXING ) ;
gArgs . AddArg ( " -reindex-chainstate " , " Rebuild chain state from the currently indexed blocks " , false , OptionsCategory : : INDEXING ) ;
gArgs . AddArg ( " -spentindex " , strprintf ( " Maintain a full spent index, used to query the spending txid and input index for an outpoint (default: %u) " , DEFAULT_SPENTINDEX ) , false , OptionsCategory : : INDEXING ) ;
gArgs . AddArg ( " -timestampindex " , strprintf ( " Maintain a timestamp index for block hashes, used to query blocks hashes by a range of timestamps (default: %u) " , DEFAULT_TIMESTAMPINDEX ) , false , OptionsCategory : : INDEXING ) ;
gArgs . AddArg ( " -txindex " , strprintf ( " Maintain a full transaction index, used by the getrawtransaction rpc call (default: %u) " , DEFAULT_TXINDEX ) , false , OptionsCategory : : INDEXING ) ;
2021-05-18 18:30:48 +02:00
gArgs . 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 ) , false , OptionsCategory : : CONNECTION ) ;
2021-03-19 18:23:58 +01:00
gArgs . 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. " , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -allowprivatenet " , strprintf ( " Allow RFC1918 addresses to be relayed and connected to (default: %u) " , DEFAULT_ALLOWPRIVATENET ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -banscore=<n> " , strprintf ( " Threshold for disconnecting misbehaving peers (default: %u) " , DEFAULT_BANSCORE_THRESHOLD ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -bantime=<n> " , strprintf ( " Number of seconds to keep misbehaving peers from reconnecting (default: %u) " , DEFAULT_MISBEHAVING_BANTIME ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -bind=<addr> " , " Bind to given address and always listen on it. Use [host]:port notation for IPv6 " , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -connect=<ip> " , " Connect only to the specified node; -connect=0 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. " , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -discover " , " Discover own IP addresses (default: 1 when listening and no -externalip or -proxy) " , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -dns " , strprintf ( " Allow DNS lookups for -addnode, -seednode and -connect (default: %u) " , DEFAULT_NAME_LOOKUP ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -dnsseed " , " Query for peer addresses via DNS lookup, if low on addresses (default: 1 unless -connect used) " , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -enablebip61 " , strprintf ( " Send reject messages per BIP61 (default: %u) " , DEFAULT_ENABLE_BIP61 ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -externalip=<ip> " , " Specify your own public address " , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -forcednsseed " , strprintf ( " Always query for peer addresses via DNS lookup (default: %u) " , DEFAULT_FORCEDNSSEED ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -listen " , " Accept connections from outside (default: 1 if no -proxy or -connect) " , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -listenonion " , strprintf ( " Automatically create Tor hidden service (default: %d) " , DEFAULT_LISTEN_ONION ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -maxconnections=<n> " , strprintf ( " Maintain at most <n> connections to peers (temporary service connections excluded) (default: %u) " , DEFAULT_MAX_PEER_CONNECTIONS ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -maxreceivebuffer=<n> " , strprintf ( " Maximum per-connection receive buffer, <n>*1000 bytes (default: %u) " , DEFAULT_MAXRECEIVEBUFFER ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -maxsendbuffer=<n> " , strprintf ( " Maximum per-connection send buffer, <n>*1000 bytes (default: %u) " , DEFAULT_MAXSENDBUFFER ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . 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 ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -maxuploadtarget=<n> " , strprintf ( " Tries to keep outbound traffic under the given target (in MiB per 24h), 0 = no limit (default: %d) " , DEFAULT_MAX_UPLOAD_TARGET ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -onion=<ip:port> " , " Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: -proxy) " , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -onlynet=<net> " , " Make outgoing connections only through network <net> (ipv4, ipv6 or onion). Incoming connections are not affected by this option. This option can be specified multiple times to allow multiple networks. " , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -peerbloomfilters " , strprintf ( " Support filtering of blocks and transaction with bloom filters (default: %u) " , DEFAULT_PEERBLOOMFILTERS ) , false , OptionsCategory : : CONNECTION ) ;
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -peertimeout=<n> " , strprintf ( " Specify p2p connection timeout in seconds. This option determines the amount of time a peer may be inactive before the connection to it is dropped. (minimum: 1, default: %d) " , DEFAULT_PEER_CONNECT_TIMEOUT ) , false , OptionsCategory : : CONNECTION ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -permitbaremultisig " , strprintf ( " Relay non-P2SH multisig (default: %u) " , DEFAULT_PERMIT_BAREMULTISIG ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -port=<port> " , strprintf ( " Listen for connections on <port> (default: %u or testnet: %u) " , defaultChainParams - > GetDefaultPort ( ) , testnetChainParams - > GetDefaultPort ( ) ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -proxy=<ip:port> " , " Connect through SOCKS5 proxy " , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -proxyrandomize " , strprintf ( " Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u) " , DEFAULT_PROXYRANDOMIZE ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . 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. " , false , OptionsCategory : : CONNECTION ) ;
2021-04-10 22:36:31 +02:00
gArgs . AddArg ( " -socketevents=<mode> " , " Socket events mode, which must be one of 'select', 'poll', 'epoll' or 'kqueue', depending on your system (default: Linux - 'epoll', FreeBSD/Apple - 'kqueue', Windows - 'select') " , false , OptionsCategory : : CONNECTION ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -timeout=<n> " , strprintf ( " Specify connection timeout in milliseconds (minimum: 1, default: %d) " , DEFAULT_CONNECT_TIMEOUT ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -torcontrol=<ip>:<port> " , strprintf ( " Tor control port to use if onion listening enabled (default: %s) " , DEFAULT_TOR_CONTROL ) , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -torpassword=<pass> " , " Tor control port password (default: empty) " , false , OptionsCategory : : CONNECTION ) ;
2012-05-13 11:36:10 +02:00
# ifdef USE_UPNP
# if USE_UPNP
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -upnp " , " Use UPnP to map the listening port (default: 1 when listening and no -proxy) " , false , OptionsCategory : : CONNECTION ) ;
2012-05-13 11:36:10 +02:00
# else
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -upnp " , strprintf ( " Use UPnP to map the listening port (default: %u) " , 0 ) , false , OptionsCategory : : CONNECTION ) ;
2013-10-11 23:09:59 +02:00
# endif
2021-06-19 16:34:39 +02:00
# else
hidden_args . emplace_back ( " -upnp " ) ;
2012-05-13 11:36:10 +02:00
# endif
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -whitebind=<addr> " , " Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6 " , false , OptionsCategory : : CONNECTION ) ;
gArgs . AddArg ( " -whitelist=<IP address or network> " , " Whitelist peers connecting from the given IP address (e.g. 1.2.3.4) or CIDR notated network (e.g. 1.2.3.0/24). Can be specified multiple times. "
" Whitelisted peers cannot be DoS banned and their transactions are always relayed, even if they are already in the mempool, useful e.g. for a gateway " , false , OptionsCategory : : CONNECTION ) ;
2014-02-03 07:23:20 +01:00
2021-03-19 16:00:24 +01:00
g_wallet_init_interface . AddWalletOptions ( ) ;
2014-02-03 07:23:20 +01:00
2014-11-18 18:06:32 +01:00
# if ENABLE_ZMQ
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -zmqpubhashblock=<address> " , " Enable publish hash block in <address> " , false , OptionsCategory : : ZMQ ) ;
2021-06-19 16:34:39 +02:00
gArgs . AddArg ( " -zmqpubhashchainlock=<address> " , " Enable publish hash block (locked via ChainLocks) in <address> " , false , OptionsCategory : : ZMQ ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -zmqpubhashgovernanceobject=<address> " , " Enable publish hash of governance objects (like proposals) in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubhashgovernancevote=<address> " , " Enable publish hash of governance votes in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubhashinstantsenddoublespend=<address> " , " Enable publish transaction hashes of attempted InstantSend double spend in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubhashrecoveredsig=<address> " , " Enable publish message hash of recovered signatures (recovered by LLMQs) in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubhashtx=<address> " , " Enable publish hash transaction in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubhashtxlock=<address> " , " Enable publish hash transaction (locked via InstantSend) in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubrawblock=<address> " , " Enable publish raw block in <address> " , false , OptionsCategory : : ZMQ ) ;
2021-06-19 16:34:39 +02:00
gArgs . AddArg ( " -zmqpubrawchainlock=<address> " , " Enable publish raw block (locked via ChainLocks) in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubrawchainlocksig=<address> " , " Enable publish raw block (locked via ChainLocks) and CLSIG message in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubrawgovernancevote=<address> " , " Enable publish raw governance objects (like proposals) in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubrawgovernanceobject=<address> " , " Enable publish raw governance votes in <address> " , false , OptionsCategory : : ZMQ ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -zmqpubrawinstantsenddoublespend=<address> " , " Enable publish raw transactions of attempted InstantSend double spend in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubrawrecoveredsig=<address> " , " Enable publish raw recovered signatures (recovered by LLMQs) in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubrawtx=<address> " , " Enable publish raw transaction in <address> " , false , OptionsCategory : : ZMQ ) ;
gArgs . AddArg ( " -zmqpubrawtxlock=<address> " , " Enable publish raw transaction (locked via InstantSend) in <address> " , false , OptionsCategory : : ZMQ ) ;
2021-06-19 16:34:39 +02:00
gArgs . AddArg ( " -zmqpubrawtxlocksig=<address> " , " Enable publish raw transaction (locked via InstantSend) and ISLOCK in <address> " , false , OptionsCategory : : ZMQ ) ;
# else
hidden_args . emplace_back ( " -zmqpubhashblock=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubhashchainlock=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubhashgovernanceobject=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubhashgovernancevote=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubhashinstantsenddoublespend=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubhashrecoveredsig=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubhashtx=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubhashtxlock=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawblock=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawchainlock=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawchainlocksig=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawgovernancevote=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawgovernanceobject=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawinstantsenddoublespend=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawrecoveredsig=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawtx=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawtxlock=<address> " ) ;
hidden_args . emplace_back ( " -zmqpubrawtxlocksig=<address> " ) ;
2014-11-18 18:06:32 +01:00
# endif
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -checkblockindex " , strprintf ( " Do a full consistency check for mapBlockIndex, setBlockIndexCandidates, chainActive and mapBlocksUnlinked occasionally. (default: %u) " , defaultChainParams - > DefaultConsistencyChecks ( ) ) , true , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -checkblocks=<n> " , strprintf ( " How many blocks to check at startup (default: %u, 0 = all) " , DEFAULT_CHECKBLOCKS ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -checklevel=<n> " , strprintf ( " How thorough the block verification of -checkblocks is (0-4, default: %u) " , DEFAULT_CHECKLEVEL ) , true , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -checkmempool=<n> " , strprintf ( " Run checks every <n> transactions (default: %u) " , defaultChainParams - > DefaultConsistencyChecks ( ) ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -checkpoints " , strprintf ( " Disable expensive verification for known chain history (default: %u) " , DEFAULT_CHECKPOINTS_ENABLED ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -deprecatedrpc=<method> " , " Allows deprecated RPC method(s) to be used " , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -dropmessagestest=<n> " , " Randomly drop 1 of every <n> network messages " , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -limitancestorcount=<n> " , strprintf ( " Do not accept transactions if number of in-mempool ancestors is <n> or more (default: %u) " , DEFAULT_ANCESTOR_LIMIT ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -limitancestorsize=<n> " , strprintf ( " Do not accept transactions whose size with all in-mempool ancestors exceeds <n> kilobytes (default: %u) " , DEFAULT_ANCESTOR_SIZE_LIMIT ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -limitdescendantcount=<n> " , strprintf ( " Do not accept transactions if any ancestor would have <n> or more in-mempool descendants (default: %u) " , DEFAULT_DESCENDANT_LIMIT ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . 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 ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -stopafterblockimport " , strprintf ( " Stop running after importing blocks from disk (default: %u) " , DEFAULT_STOPAFTERBLOCKIMPORT ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -stopatheight " , strprintf ( " Stop running after reaching the given height in the main chain (default: %u) " , DEFAULT_STOPATHEIGHT ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -vbparams=<deployment>:<start>:<end>(:<window>:<threshold>) " , " Use given start/end times for specified version bits deployment (regtest-only). Specifying window and threshold is optional. " , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -watchquorums=<n> " , strprintf ( " Watch and validate quorum communication (default: %u) " , llmq : : DEFAULT_WATCH_QUORUMS ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -addrmantest " , " Allows to test address relay on localhost " , true , OptionsCategory : : DEBUG_TEST ) ;
2021-06-19 16:34:39 +02:00
gArgs . AddArg ( " -budgetparams=<masternode>:<budget>:<superblock> " , " Override masternode, budget and superblock start heights " , false , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -debug=<category> " , strprintf ( " Output debugging information (default: %u, supplying <category> is optional) " , 0 ) + " . " +
" If <category> is not supplied or if <category> = 1, output all debugging information. <category> can be: " + ListLogCategories ( ) + " . " , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . 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 one or more specified categories. " ) , false , OptionsCategory : : DEBUG_TEST ) ;
2021-06-19 16:34:39 +02:00
gArgs . AddArg ( " -dip3params=<activation>:<enforcement> " , " Override DIP3 activation and enforcement heights " , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -dip8params=<activation> " , " Override DIP8 activation height " , false , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -disablegovernance " , strprintf ( " Disable governance validation (0-1, default: %u) " , 0 ) , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -help-debug " , " Show all debugging options (usage: --help -help-debug) " , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -highsubsidyblocks=<n> " , strprintf ( " The number of blocks with a higher than normal subsidy to mine at the start of a devnet (default: %u) " , devnetConsensus . nHighSubsidyBlocks ) , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -highsubsidyfactor=<n> " , strprintf ( " The factor to multiply the normal block subsidy by while in the highsubsidyblocks window of a devnet (default: %u) " , devnetConsensus . nHighSubsidyFactor ) , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -llmqchainlocks=<quorum name> " , strprintf ( " Override the default LLMQ type used for ChainLocks on a devnet. Allows using ChainLocks with smaller LLMQs. (default: %s) " , devnetConsensus . llmqs . at ( devnetConsensus . llmqTypeChainLocks ) . name ) , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -llmqdevnetparams=<size:threshold> " , strprintf ( " Override the default LLMQ size for the LLMQ_DEVNET quorum (default: %u:%u) " , devnetLLMQ . size , devnetLLMQ . threshold ) , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -llmqinstantsend=<quorum name> " , strprintf ( " Override the default LLMQ type used for InstantSend on a devnet. Allows using InstantSend with smaller LLMQs. (default: %s) " , devnetConsensus . llmqs . at ( devnetConsensus . llmqTypeInstantSend ) . name ) , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -llmqtestparams=<size:threshold> " , strprintf ( " Override the default LLMQ size for the LLMQ_TEST quorum (default: %u:%u) " , regtestLLMQ . size , regtestLLMQ . threshold ) , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -logips " , strprintf ( " Include IP addresses in debug output (default: %u) " , DEFAULT_LOGIPS ) , false , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -logtimemicros " , strprintf ( " Add microsecond precision to debug timestamps (default: %u) " , DEFAULT_LOGTIMEMICROS ) , true , OptionsCategory : : DEBUG_TEST ) ;
2021-06-24 19:54:20 +02:00
gArgs . AddArg ( " -logtimestamps " , strprintf ( " Prepend debug output with timestamp (default: %u) " , DEFAULT_LOGTIMESTAMPS ) , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -logthreadnames " , strprintf ( " Prepend debug output with name of the originating thread (only available on platforms supporting thread_local) (default: %u) " , DEFAULT_LOGTHREADNAMES ) , true , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -maxsigcachesize=<n> " , strprintf ( " Limit sum of signature cache and script execution cache sizes to <n> MiB (default: %u) " , DEFAULT_MAX_SIG_CACHE_SIZE ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -maxtipage=<n> " , strprintf ( " Maximum tip age in seconds to consider node in initial block download (default: %u) " , DEFAULT_MAX_TIP_AGE ) , true , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -mocktime=<n> " , " Replace actual time with <n> seconds since epoch (default: 0) " , true , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -maxtxfee=<amt> " , strprintf ( " Maximum total fees (in %s) to use in a single wallet transaction or raw transaction; setting this too low may abort large transactions (default: %s) " ,
2021-03-19 16:00:24 +01:00
CURRENCY_UNIT , FormatMoney ( DEFAULT_TRANSACTION_MAXFEE ) ) , false , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -minimumdifficultyblocks=<n> " , strprintf ( " The number of blocks that can be mined with the minimum difficulty at the start of a devnet (default: %u) " , devnetConsensus . nMinimumDifficultyBlocks ) , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -minsporkkeys=<n> " , " Overrides minimum spork signers to change spork value. Only useful for regtest and devnet. Using this on mainnet or testnet will ban you. " , false , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -printpriority " , strprintf ( " Log transaction fee per kB when mining blocks (default: %u) " , DEFAULT_PRINTPRIORITY ) , true , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -printtoconsole " , " Send trace/debug info to console instead of debug.log file " , false , OptionsCategory : : DEBUG_TEST ) ;
2021-06-19 16:34:39 +02:00
gArgs . AddArg ( " -pushversion " , " Protocol version to report to other nodes " , false , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -shrinkdebugfile " , " Shrink debug.log file on client startup (default: 1 when no -debug) " , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -sporkaddr=<dashaddress> " , " Override spork address. Only useful for regtest and devnet. Using this on mainnet or testnet will ban you. " , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -sporkkey=<privatekey> " , " Set the private key to be used for signing spork messages. " , false , OptionsCategory : : DEBUG_TEST ) ;
gArgs . AddArg ( " -uacomment=<cmt> " , " Append comment to the user agent string " , false , OptionsCategory : : DEBUG_TEST ) ;
2021-03-19 16:00:24 +01:00
SetupChainParamsBaseOptions ( ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -llmq-data-recovery=<n> " , strprintf ( " Enable automated quorum data recovery (default: %u) " , llmq : : DEFAULT_ENABLE_QUORUM_DATA_RECOVERY ) , false , OptionsCategory : : MASTERNODE ) ;
2021-03-25 17:59:40 +01:00
gArgs . AddArg ( " -llmq-qvvec-sync=<quorum_name>:<mode> " , strprintf ( " Defines from which LLMQ type the masternode should sync quorum verification vectors. Can be used multiple times with different LLMQ types. <mode>: %d (sync always from all quorums of the type defined by <quorum_name>), %d (sync from all quorums of the type defined by <quorum_name> if a member of any of the quorums) " , ( int32_t ) llmq : : QvvecSyncMode : : Always , ( int32_t ) llmq : : QvvecSyncMode : : OnlyIfTypeMember ) , false , OptionsCategory : : MASTERNODE ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -masternodeblsprivkey=<hex> " , " Set the masternode BLS private key and enable the client to act as a masternode " , false , OptionsCategory : : MASTERNODE ) ;
gArgs . AddArg ( " -platform-user=<user> " , " Set the username for the \" platform user \" , a restricted user intended to be used by Dash Platform, to the specified username. " , false , OptionsCategory : : MASTERNODE ) ;
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -acceptnonstdtxn " , strprintf ( " Relay and mine \" non-standard \" transactions (%sdefault: %u) " , " testnet/regtest only; " , ! testnetChainParams - > RequireStandard ( ) ) , true , OptionsCategory : : NODE_RELAY ) ;
gArgs . AddArg ( " -dustrelayfee=<amt> " , strprintf ( " Fee rate (in %s/kB) used to defined 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 ) ) , true , OptionsCategory : : NODE_RELAY ) ;
gArgs . 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 ) ) , true , OptionsCategory : : NODE_RELAY ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -bytespersigop " , strprintf ( " Minimum bytes per sigop in transactions we relay and mine (default: %u) " , DEFAULT_BYTES_PER_SIGOP ) , false , OptionsCategory : : NODE_RELAY ) ;
gArgs . AddArg ( " -datacarrier " , strprintf ( " Relay and mine data carrier transactions (default: %u) " , DEFAULT_ACCEPT_DATACARRIER ) , false , OptionsCategory : : NODE_RELAY ) ;
gArgs . AddArg ( " -datacarriersize " , strprintf ( " Maximum size of data in data carrier transactions we relay and mine (default: %u) " , MAX_OP_RETURN_RELAY ) , false , OptionsCategory : : NODE_RELAY ) ;
gArgs . AddArg ( " -minrelaytxfee=<amt> " , strprintf ( " Fees (in %s/kB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s) " ,
2021-03-19 16:00:24 +01:00
CURRENCY_UNIT , FormatMoney ( DEFAULT_MIN_RELAY_TX_FEE ) ) , false , OptionsCategory : : NODE_RELAY ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -whitelistforcerelay " , strprintf ( " Force relay of transactions from whitelisted peers even if they violate local relay policy (default: %d) " , DEFAULT_WHITELISTFORCERELAY ) , false , OptionsCategory : : NODE_RELAY ) ;
gArgs . AddArg ( " -whitelistrelay " , strprintf ( " Accept relayed transactions received from whitelisted peers even when not relaying transactions (default: %d) " , DEFAULT_WHITELISTRELAY ) , false , OptionsCategory : : NODE_RELAY ) ;
2021-03-19 16:00:24 +01:00
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -blockmaxsize=<n> " , strprintf ( " Set maximum block size in bytes (default: %d) " , DEFAULT_BLOCK_MAX_SIZE ) , false , OptionsCategory : : BLOCK_CREATION ) ;
gArgs . 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 ) ) , false , OptionsCategory : : BLOCK_CREATION ) ;
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -blockversion=<n> " , " Override block version to test forking scenarios " , true , OptionsCategory : : BLOCK_CREATION ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -rest " , strprintf ( " Accept public REST requests (default: %u) " , DEFAULT_REST_ENABLE ) , false , OptionsCategory : : RPC ) ;
gArgs . 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 " , false , OptionsCategory : : RPC ) ;
gArgs . AddArg ( " -rpcauth=<userpw> " , " Username and hashed password for JSON-RPC connections. The field <userpw> comes in the format: <USERNAME>:<SALT>$<HASH>. A canonical python script is included in share/rpcuser. The client then connects normally using the rpcuser=<USERNAME>/rpcpassword=<PASSWORD> pair of arguments. This option can be specified multiple times " , false , OptionsCategory : : RPC ) ;
gArgs . AddArg ( " -rpcbind=<addr>[:port] " , " Bind to given address to listen for JSON-RPC connections. Do not expose the RPC server to untrusted networks such as the public internet! This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost, or if -rpcallowip has been specified, 0.0.0.0 and :: i.e., all addresses) " , false , OptionsCategory : : RPC ) ;
gArgs . AddArg ( " -rpccookiefile=<loc> " , " Location of the auth cookie. Relative paths will be prefixed by a net-specific datadir location. (default: data dir) " , false , OptionsCategory : : RPC ) ;
gArgs . AddArg ( " -rpcpassword=<pw> " , " Password for JSON-RPC connections " , false , OptionsCategory : : RPC ) ;
gArgs . AddArg ( " -rpcport=<port> " , strprintf ( " Listen for JSON-RPC connections on <port> (default: %u or testnet: %u) " , defaultBaseParams - > RPCPort ( ) , testnetBaseParams - > RPCPort ( ) ) , false , OptionsCategory : : RPC ) ;
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -rpcservertimeout=<n> " , strprintf ( " Timeout during HTTP requests (default: %d) " , DEFAULT_HTTP_SERVER_TIMEOUT ) , true , OptionsCategory : : RPC ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -rpcthreads=<n> " , strprintf ( " Set the number of threads to service RPC calls (default: %d) " , DEFAULT_HTTP_THREADS ) , false , OptionsCategory : : RPC ) ;
gArgs . AddArg ( " -rpcuser=<user> " , " Username for JSON-RPC connections " , false , OptionsCategory : : RPC ) ;
2021-03-19 16:00:24 +01:00
gArgs . AddArg ( " -rpcworkqueue=<n> " , strprintf ( " Set the depth of the work queue to service RPC calls (default: %d) " , DEFAULT_HTTP_WORKQUEUE ) , true , OptionsCategory : : RPC ) ;
2021-03-19 18:23:58 +01:00
gArgs . AddArg ( " -server " , " Accept command line and JSON-RPC commands " , false , OptionsCategory : : RPC ) ;
gArgs . AddArg ( " -statsenabled " , strprintf ( " Publish internal stats to statsd (default: %u) " , DEFAULT_STATSD_ENABLE ) , false , OptionsCategory : : STATSD ) ;
gArgs . AddArg ( " -statshost=<ip> " , strprintf ( " Specify statsd host (default: %s) " , DEFAULT_STATSD_HOST ) , false , OptionsCategory : : STATSD ) ;
gArgs . AddArg ( " -statshostname=<ip> " , strprintf ( " Specify statsd host name (default: %s) " , DEFAULT_STATSD_HOSTNAME ) , false , OptionsCategory : : STATSD ) ;
gArgs . AddArg ( " -statsport=<port> " , strprintf ( " Specify statsd port (default: %u) " , DEFAULT_STATSD_PORT ) , false , OptionsCategory : : STATSD ) ;
gArgs . AddArg ( " -statsns=<ns> " , strprintf ( " Specify additional namespace prefix (default: %s) " , DEFAULT_STATSD_NAMESPACE ) , false , OptionsCategory : : STATSD ) ;
gArgs . AddArg ( " -statsperiod=<seconds> " , strprintf ( " Specify the number of seconds between periodic measurements (default: %d) " , DEFAULT_STATSD_PERIOD ) , false , OptionsCategory : : STATSD ) ;
2021-06-19 16:34:39 +02:00
# if HAVE_DECL_DAEMON
gArgs . AddArg ( " -daemon " , " Run in the background as a daemon and accept commands " , false , OptionsCategory : : OPTIONS ) ;
# else
hidden_args . emplace_back ( " -daemon " ) ;
# endif
2018-05-30 19:42:58 +02:00
2021-06-19 16:34:39 +02:00
// Add the hidden options
gArgs . AddHiddenArgs ( hidden_args ) ;
2012-05-13 11:36:10 +02:00
}
2014-06-10 16:02:46 +02:00
std : : string LicenseInfo ( )
{
2016-06-16 10:53:23 +02:00
const std : : string URL_SOURCE_CODE = " <https://github.com/dashpay/dash> " ;
const std : : string URL_WEBSITE = " <https://dash.org> " ;
2016-08-15 15:36:28 +02:00
2017-12-11 15:20:11 +01:00
return CopyrightHolders ( _ ( " Copyright (C) " ) , 2014 , COPYRIGHT_YEAR ) + " \n " +
2015-04-03 00:51:08 +02:00
" \n " +
2016-06-16 10:53:23 +02:00
strprintf ( _ ( " Please contribute if you find %s useful. "
" Visit %s for further information about the software. " ) ,
PACKAGE_NAME , URL_WEBSITE ) +
" \n " +
strprintf ( _ ( " The source code is available from %s. " ) ,
URL_SOURCE_CODE ) +
2014-06-10 16:02:46 +02:00
" \n " +
2016-06-16 10:53:23 +02:00
" \n " +
_ ( " This is experimental software. " ) + " \n " +
2016-08-15 15:36:28 +02:00
strprintf ( _ ( " Distributed under the MIT software license, see the accompanying file %s or %s " ) , " COPYING " , " <https://opensource.org/licenses/MIT> " ) + " \n " +
2014-06-10 16:02:46 +02:00
" \n " +
2016-08-15 15:36:28 +02:00
strprintf ( _ ( " This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit %s and cryptographic software written by Eric Young and UPnP software written by Thomas Bernard. " ) , " <https://www.openssl.org> " ) +
2014-06-10 16:02:46 +02:00
" \n " ;
}
2015-11-26 15:48:26 +01:00
static void BlockNotifyCallback ( bool initialSync , const CBlockIndex * pBlockIndex )
2014-08-14 18:32:34 +02:00
{
2015-11-26 15:48:26 +01:00
if ( initialSync | | ! pBlockIndex )
return ;
2019-06-24 18:44:27 +02:00
std : : string strCmd = gArgs . GetArg ( " -blocknotify " , " " ) ;
2017-10-04 14:53:26 +02:00
if ( ! strCmd . empty ( ) ) {
boost : : replace_all ( strCmd , " %s " , pBlockIndex - > GetBlockHash ( ) . GetHex ( ) ) ;
2020-06-13 20:21:30 +02:00
std : : thread t ( runCommand , strCmd ) ;
t . detach ( ) ; // thread runs free
2017-10-04 14:53:26 +02:00
}
2014-08-14 18:32:34 +02:00
}
2016-08-04 12:21:59 +02:00
static bool fHaveGenesis = false ;
2021-06-04 21:26:33 +02:00
static Mutex g_genesis_wait_mutex ;
static std : : condition_variable g_genesis_wait_cv ;
2016-08-04 12:21:59 +02:00
static void BlockNotifyGenesisWait ( bool , const CBlockIndex * pBlockIndex )
{
2019-08-06 05:08:33 +02:00
if ( pBlockIndex ! = nullptr ) {
2016-08-04 12:21:59 +02:00
{
2021-06-04 21:26:33 +02:00
LOCK ( g_genesis_wait_mutex ) ;
2016-08-04 12:21:59 +02:00
fHaveGenesis = true ;
}
2021-06-04 21:26:33 +02:00
g_genesis_wait_cv . notify_all ( ) ;
2016-08-04 12:21:59 +02:00
}
}
2012-10-22 22:45:26 +02: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 20:27:44 +01: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 21:24:53 +02: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-04 22:42:39 +02: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 20:27:44 +01:00
{
2017-04-06 20:19:21 +02:00
std : : map < std : : string , fs : : path > mapBlockFiles ;
2015-06-02 21:24:53 +02: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-27 21:04:22 +02:00
fs : : path blocksdir = GetBlocksDir ( ) ;
2017-04-06 20:19:21 +02:00
for ( fs : : directory_iterator it ( blocksdir ) ; it ! = fs : : directory_iterator ( ) ; it + + ) {
2017-10-18 16:34:54 +02:00
if ( fs : : is_regular_file ( * it ) & &
2015-06-02 21:24:53 +02: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 20:27:44 +01:00
2015-06-02 21:24:53 +02: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 ;
2020-07-07 18:46:21 +02:00
for ( const std : : pair < const std : : string , fs : : path > & item : mapBlockFiles ) {
2015-06-02 21:24:53 +02: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 20:27:44 +01:00
}
2015-06-02 21:24:53 +02: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 20:27:44 +01:00
}
}
2018-05-04 22:42:39 +02:00
static void ThreadImport ( std : : vector < fs : : path > vImportFiles )
2013-03-07 04:31:26 +01:00
{
2015-04-17 14:40:24 +02:00
const CChainParams & chainparams = Params ( ) ;
2021-06-24 19:54:20 +02:00
util : : ThreadRename ( " loadblk " ) ;
2018-04-07 19:24:47 +02:00
ScheduleBatchPriority ( ) ;
2016-11-16 10:11:35 +01:00
{
2017-07-10 16:41:14 +02:00
CImportingNow imp ;
2012-10-21 21:23:13 +02:00
// -reindex
if ( fReindex ) {
int nFile = 0 ;
2013-03-07 04:31:26 +01:00
while ( true ) {
2012-12-03 10:14:54 +01:00
CDiskBlockPos pos ( nFile , 0 ) ;
2017-04-06 20:19:21 +02:00
if ( ! fs : : exists ( GetBlockPosFilename ( pos , " blk " ) ) )
2014-09-08 19:29:14 +02:00
break ; // No block files left to reindex
2012-10-21 21:23:13 +02:00
FILE * file = OpenBlockFile ( pos , true ) ;
if ( ! file )
2014-09-08 19:29:14 +02:00
break ; // This error is logged in OpenBlockFile
2013-09-18 12:38:08 +02:00
LogPrintf ( " Reindexing block file blk%05u.dat... \n " , ( unsigned int ) nFile ) ;
2015-04-17 14:40:24 +02:00
LoadExternalBlockFile ( chainparams , file , & pos ) ;
2012-10-21 21:23:13 +02:00
nFile + + ;
}
2013-03-07 04:31:26 +01:00
pblocktree - > WriteReindexing ( false ) ;
fReindex = false ;
2013-09-18 12:38:08 +02:00
LogPrintf ( " Reindexing finished \n " ) ;
2013-03-07 04:31:26 +01:00
// To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked):
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
LoadGenesisBlock ( chainparams ) ;
2012-10-22 22:45:26 +02:00
}
// hardcoded $DATADIR/bootstrap.dat
2017-04-06 20:19:21 +02:00
fs : : path pathBootstrap = GetDataDir ( ) / " bootstrap.dat " ;
if ( fs : : exists ( pathBootstrap ) ) {
FILE * file = fsbridge : : fopen ( pathBootstrap , " rb " ) ;
2012-10-22 22:45:26 +02:00
if ( file ) {
2017-04-06 20:19:21 +02:00
fs : : path pathBootstrapOld = GetDataDir ( ) / " bootstrap.dat.old " ;
2013-09-18 12:38:08 +02:00
LogPrintf ( " Importing bootstrap.dat... \n " ) ;
2015-04-17 14:40:24 +02:00
LoadExternalBlockFile ( chainparams , file ) ;
2012-10-22 22:45:26 +02:00
RenameOver ( pathBootstrap , pathBootstrapOld ) ;
2014-02-08 11:35:02 +01:00
} else {
LogPrintf ( " Warning: Could not open bootstrap file %s \n " , pathBootstrap . string ( ) ) ;
2012-10-22 22:45:26 +02:00
}
}
2012-10-21 21:23:13 +02:00
// -loadblock=
2019-07-05 09:06:28 +02:00
for ( const fs : : path & path : vImportFiles ) {
2017-04-06 20:19:21 +02:00
FILE * file = fsbridge : : fopen ( path , " rb " ) ;
2012-10-21 21:23:13 +02:00
if ( file ) {
2014-02-08 11:35:02 +01:00
LogPrintf ( " Importing blocks file %s... \n " , path . string ( ) ) ;
2015-04-17 14:40:24 +02:00
LoadExternalBlockFile ( chainparams , file ) ;
2014-02-08 11:35:02 +01:00
} else {
LogPrintf ( " Warning: Could not open blocks file %s \n " , path . string ( ) ) ;
2012-10-21 21:23:13 +02:00
}
}
2014-05-07 20:10:48 +02:00
2017-07-10 16:41:14 +02:00
// scan for better chains in the block chain database, that are not yet connected in the active best chain
CValidationState state ;
if ( ! ActivateBestChain ( state , chainparams ) ) {
2019-04-30 14:48:21 +02:00
LogPrintf ( " Failed to connect best block (%s) \n " , FormatStateMessage ( state ) ) ;
2017-07-10 16:41:14 +02:00
StartShutdown ( ) ;
2018-02-15 14:31:07 +01:00
return ;
2017-07-10 16:41:14 +02:00
}
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -stopafterblockimport " , DEFAULT_STOPAFTERBLOCKIMPORT ) ) {
2014-05-07 20:10:48 +02:00
LogPrintf ( " Stopping after block import \n " ) ;
StartShutdown ( ) ;
2018-02-15 14:31:07 +01:00
return ;
2014-05-07 20:10:48 +02:00
}
2016-11-16 10:11:35 +01:00
} // End scope of CImportingNow
2018-09-12 13:13:17 +02:00
// force UpdatedBlockTip to initialize nCachedBlockHeight for DS, MN payments and budgets
// but don't call it directly to prevent triggering of other listeners like zmq etc.
// GetMainSignals().UpdatedBlockTip(chainActive.Tip());
pdsNotificationInterface - > InitializeCurrentBlockTip ( ) ;
2019-11-22 19:12:57 +01:00
{
// Get all UTXOs for each MN collateral in one go so that we can fill coin cache early
2021-03-26 13:11:11 +01:00
// and reduce further locking overhead for cs_main in other parts of code including GUI
2019-11-22 19:12:57 +01:00
LogPrintf ( " Filling coin cache with masternode UTXOs... \n " ) ;
LOCK ( cs_main ) ;
int64_t nStart = GetTimeMillis ( ) ;
auto mnList = deterministicMNManager - > GetListAtChainTip ( ) ;
mnList . ForEachMN ( false , [ & ] ( const CDeterministicMNCPtr & dmn ) {
Coin coin ;
GetUTXOCoin ( dmn - > collateralOutpoint , coin ) ;
} ) ;
LogPrintf ( " Filling coin cache with masternode UTXOs: done in %dms \n " , GetTimeMillis ( ) - nStart ) ;
}
2019-03-25 07:14:57 +01:00
if ( fMasternodeMode ) {
2019-04-25 17:39:04 +02:00
assert ( activeMasternodeManager ) ;
2020-03-20 17:11:54 +01:00
const CBlockIndex * pindexTip ;
{
LOCK ( cs_main ) ;
pindexTip = chainActive . Tip ( ) ;
}
activeMasternodeManager - > Init ( pindexTip ) ;
2018-10-26 07:03:33 +02:00
}
2018-04-17 15:57:52 +02:00
g_wallet_init_interface . AutoLockMasternodeCollaterals ( ) ;
2018-10-25 16:29:50 +02:00
2019-06-24 18:44:27 +02:00
if ( gArgs . GetArg ( " -persistmempool " , DEFAULT_PERSIST_MEMPOOL ) ) {
2017-05-03 09:23:39 +02:00
LoadMempool ( ) ;
}
2021-06-21 00:49:59 +02:00
g_is_mempool_loaded = ! ShutdownRequested ( ) ;
2012-10-22 22:45:26 +02:00
}
2020-12-15 17:22:23 +01:00
void PeriodicStats ( )
{
assert ( gArgs . GetBoolArg ( " -statsenabled " , DEFAULT_STATSD_ENABLE ) ) ;
CCoinsStats stats ;
FlushStateToDisk ( ) ;
if ( GetUTXOStats ( pcoinsdbview . get ( ) , stats ) ) {
statsClient . gauge ( " utxoset.tx " , stats . nTransactions , 1.0f ) ;
statsClient . gauge ( " utxoset.txOutputs " , stats . nTransactionOutputs , 1.0f ) ;
statsClient . gauge ( " utxoset.dbSizeBytes " , stats . nDiskSize , 1.0f ) ;
statsClient . gauge ( " utxoset.blockHeight " , stats . nHeight , 1.0f ) ;
statsClient . gauge ( " utxoset.totalAmount " , ( double ) stats . nTotalAmount / ( double ) COIN , 1.0f ) ;
} else {
// something went wrong
LogPrintf ( " %s: GetUTXOStats failed \n " , __func__ ) ;
}
// short version of GetNetworkHashPS(120, -1);
CBlockIndex * tip ;
{
LOCK ( cs_main ) ;
tip = chainActive . Tip ( ) ;
assert ( tip ) ;
}
CBlockIndex * pindex = tip ;
int64_t minTime = pindex - > GetBlockTime ( ) ;
int64_t maxTime = minTime ;
for ( int i = 0 ; i < 120 & & pindex - > pprev ! = nullptr ; i + + ) {
pindex = pindex - > pprev ;
int64_t time = pindex - > GetBlockTime ( ) ;
minTime = std : : min ( time , minTime ) ;
maxTime = std : : max ( time , maxTime ) ;
}
arith_uint256 workDiff = tip - > nChainWork - pindex - > nChainWork ;
int64_t timeDiff = maxTime - minTime ;
double nNetworkHashPS = workDiff . getdouble ( ) / timeDiff ;
2021-01-08 20:45:57 +01:00
statsClient . gaugeDouble ( " network.hashesPerSecond " , nNetworkHashPS ) ;
statsClient . gaugeDouble ( " network.terahashesPerSecond " , nNetworkHashPS / 1e12 ) ;
statsClient . gaugeDouble ( " network.petahashesPerSecond " , nNetworkHashPS / 1e15 ) ;
statsClient . gaugeDouble ( " network.exahashesPerSecond " , nNetworkHashPS / 1e18 ) ;
2020-12-15 17:22:23 +01:00
// No need for cs_main, we never use null tip here
2021-01-08 20:45:57 +01:00
statsClient . gaugeDouble ( " network.difficulty " , ( double ) GetDifficulty ( tip ) ) ;
statsClient . gauge ( " transactions.txCacheSize " , pcoinsTip - > GetCacheSize ( ) , 1.0f ) ;
statsClient . gauge ( " transactions.totalTransactions " , tip - > nChainTx , 1.0f ) ;
2020-12-15 17:22:23 +01:00
statsClient . gauge ( " transactions.mempool.totalTransactions " , mempool . size ( ) , 1.0f ) ;
statsClient . gauge ( " transactions.mempool.totalTxBytes " , ( int64_t ) mempool . GetTotalTxSize ( ) , 1.0f ) ;
statsClient . gauge ( " transactions.mempool.memoryUsageBytes " , ( int64_t ) mempool . DynamicMemoryUsage ( ) , 1.0f ) ;
statsClient . gauge ( " transactions.mempool.minFeePerKb " , mempool . GetMinFee ( gArgs . GetArg ( " -maxmempool " , DEFAULT_MAX_MEMPOOL_SIZE ) * 1000000 ) . GetFeePerK ( ) , 1.0f ) ;
}
2014-06-03 01:21:03 +02:00
/** Sanity checks
2016-07-29 07:30:19 +02:00
* Ensure that Dash Core is running in a usable environment with all
2014-06-03 01:21:03 +02:00
* necessary library support .
*/
2018-05-04 22:42:39 +02:00
static bool InitSanityCheck ( void )
2014-06-03 01:21:03 +02:00
{
if ( ! ECC_InitSanityCheck ( ) ) {
2015-07-28 20:11:20 +02:00
InitError ( " Elliptic curve cryptography sanity check failure. Aborting. " ) ;
2014-06-03 01:21:03 +02:00
return false ;
}
2017-03-01 12:40:06 +01:00
2014-06-14 01:23:01 +02:00
if ( ! glibc_sanity_test ( ) | | ! glibcxx_sanity_test ( ) )
return false ;
2014-06-03 01:21:03 +02:00
2018-12-10 06:04:48 +01:00
if ( ! BLSInit ( ) ) {
return false ;
}
2017-03-01 12:40:06 +01:00
if ( ! Random_SanityCheck ( ) ) {
InitError ( " OS cryptographic RNG sanity check failure. Aborting. " ) ;
return false ;
}
2014-06-03 01:21:03 +02:00
return true ;
}
2018-05-04 22:42:39 +02:00
static bool AppInitServers ( )
2011-05-14 20:10:21 +02:00
{
2016-09-09 08:33:26 +02:00
RPCServer : : OnStarted ( & OnRPCStarted ) ;
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
RPCServer : : OnStopped ( & OnRPCStopped ) ;
2015-08-28 16:55:16 +02:00
if ( ! InitHTTPServer ( ) )
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
return false ;
2021-06-29 12:46:52 +02:00
StartRPC ( ) ;
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
if ( ! StartHTTPRPC ( ) )
return false ;
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -rest " , DEFAULT_REST_ENABLE ) & & ! StartREST ( ) )
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
return false ;
2021-06-29 12:46:52 +02:00
StartHTTPServer ( ) ;
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
return true ;
}
2014-06-04 13:16:07 +02:00
2015-10-08 09:58:31 +02:00
// Parameter interaction based on rules
void InitParameterInteraction ( )
{
// when specifying an explicit binding address, you want to listen on it
// even when -connect or -proxy is specified
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -bind " ) ) {
if ( gArgs . SoftSetBoolArg ( " -listen " , true ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -bind set -> setting -listen=1 \n " , __func__ ) ;
2014-06-04 13:16:07 +02:00
}
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -whitebind " ) ) {
if ( gArgs . SoftSetBoolArg ( " -listen " , true ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -whitebind set -> setting -listen=1 \n " , __func__ ) ;
2012-05-24 19:02:21 +02:00
}
2012-05-21 16:47:29 +02:00
2017-05-15 07:30:09 +02:00
if ( gArgs . IsArgSet ( " -connect " ) ) {
2012-05-24 19:02:21 +02:00
// when only connecting to trusted nodes, do not seed via DNS, or listen by default
2019-06-24 18:44:27 +02:00
if ( gArgs . SoftSetBoolArg ( " -dnsseed " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -connect set -> setting -dnsseed=0 \n " , __func__ ) ;
2019-06-24 18:44:27 +02:00
if ( gArgs . SoftSetBoolArg ( " -listen " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -connect set -> setting -listen=0 \n " , __func__ ) ;
2012-05-24 19:02:21 +02:00
}
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -proxy " ) ) {
2014-01-27 11:26:30 +01:00
// to protect privacy, do not listen by default if a default proxy server is specified
2019-06-24 18:44:27 +02:00
if ( gArgs . SoftSetBoolArg ( " -listen " , false ) )
2015-05-18 11:21:32 +02:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -listen=0 \n " , __func__ ) ;
// to protect privacy, do not use UPNP when a proxy is set. The user may still specify -listen=1
// to listen locally, so don't rely on this happening through -listen below.
2019-06-24 18:44:27 +02:00
if ( gArgs . SoftSetBoolArg ( " -upnp " , false ) )
2015-05-18 11:21:32 +02:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -upnp=0 \n " , __func__ ) ;
2014-07-21 08:32:25 +02:00
// to protect privacy, do not discover addresses by default
2019-06-24 18:44:27 +02:00
if ( gArgs . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -discover=0 \n " , __func__ ) ;
2012-05-24 19:02:21 +02:00
}
2019-06-24 18:44:27 +02:00
if ( ! gArgs . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) ) {
2012-05-24 19:02:21 +02:00
// do not map ports or try to retrieve public IP when not listening (pointless)
2019-06-24 18:44:27 +02:00
if ( gArgs . SoftSetBoolArg ( " -upnp " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -upnp=0 \n " , __func__ ) ;
2019-06-24 18:44:27 +02:00
if ( gArgs . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -discover=0 \n " , __func__ ) ;
2019-06-24 18:44:27 +02:00
if ( gArgs . SoftSetBoolArg ( " -listenonion " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -listenonion=0 \n " , __func__ ) ;
2012-05-21 16:47:29 +02:00
}
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -externalip " ) ) {
2012-05-24 19:02:21 +02:00
// if an explicit public IP is specified, do not try to find others
2019-06-24 18:44:27 +02:00
if ( gArgs . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -externalip set -> setting -discover=0 \n " , __func__ ) ;
2012-05-24 19:02:21 +02:00
}
2016-11-23 07:17:47 +01:00
// disable whitelistrelay in blocksonly mode
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -blocksonly " , DEFAULT_BLOCKSONLY ) ) {
if ( gArgs . SoftSetBoolArg ( " -whitelistrelay " , false ) )
2015-11-26 00:00:23 +01:00
LogPrintf ( " %s: parameter interaction: -blocksonly=1 -> setting -whitelistrelay=0 \n " , __func__ ) ;
2015-10-08 10:01:29 +02:00
}
2015-11-26 00:00:23 +01:00
// Forcing relay from whitelisted hosts implies we will accept relays from them in the first place.
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -whitelistforcerelay " , DEFAULT_WHITELISTFORCERELAY ) ) {
if ( gArgs . SoftSetBoolArg ( " -whitelistrelay " , true ) )
2015-11-26 00:00:23 +01:00
LogPrintf ( " %s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1 \n " , __func__ ) ;
2014-02-14 17:33:07 +01:00
}
2020-07-09 01:28:30 +02:00
if ( gArgs . GetBoolArg ( " -litemode " , false ) ) {
if ( gArgs . SoftSetBoolArg ( " -disablegovernance " , true ) ) {
LogPrintf ( " %s: parameter interaction: -litemode=true -> setting -disablegovernance=true \n " , __func__ ) ;
}
}
2020-07-29 15:27:45 +02:00
int64_t nPruneArg = gArgs . GetArg ( " -prune " , 0 ) ;
if ( nPruneArg > 0 ) {
2020-07-09 01:28:30 +02:00
if ( gArgs . SoftSetBoolArg ( " -disablegovernance " , true ) ) {
2020-07-29 15:27:45 +02:00
LogPrintf ( " %s: parameter interaction: -prune=%d -> setting -disablegovernance=true \n " , __func__ , nPruneArg ) ;
2020-07-09 01:28:30 +02:00
}
if ( gArgs . SoftSetBoolArg ( " -txindex " , false ) ) {
2020-07-29 15:27:45 +02:00
LogPrintf ( " %s: parameter interaction: -prune=%d -> setting -txindex=false \n " , __func__ , nPruneArg ) ;
2020-07-09 01:28:30 +02:00
}
}
2017-12-12 02:24:24 +01:00
// Make sure additional indexes are recalculated correctly in VerifyDB
// (we must reconnect blocks whenever we disconnect them for these indexes to work)
bool fAdditionalIndexes =
2019-06-24 18:44:27 +02:00
gArgs . GetBoolArg ( " -addressindex " , DEFAULT_ADDRESSINDEX ) | |
gArgs . GetBoolArg ( " -spentindex " , DEFAULT_SPENTINDEX ) | |
gArgs . GetBoolArg ( " -timestampindex " , DEFAULT_TIMESTAMPINDEX ) ;
2017-12-12 02:24:24 +01:00
2019-06-24 18:44:27 +02:00
if ( fAdditionalIndexes & & gArgs . GetArg ( " -checklevel " , DEFAULT_CHECKLEVEL ) < 4 ) {
gArgs . ForceSetArg ( " -checklevel " , " 4 " ) ;
2017-12-12 02:24:24 +01:00
LogPrintf ( " %s: parameter interaction: additional indexes -> setting -checklevel=4 \n " , __func__ ) ;
}
Merge #11862: Network specific conf sections
c25321f Add config changes to release notes (Anthony Towns)
5e3cbe0 [tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns)
005ad26 ArgsManager: special handling for -regtest and -testnet (Anthony Towns)
608415d [tests] Unit tests for network-specific config entries (Anthony Towns)
68797e2 ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns)
d1fc4d9 ArgsManager: limit some options to only apply on mainnet when in default section (Anthony Towns)
8a9817d [tests] Use regtest section in functional tests configs (Anthony Towns)
30f9407 [tests] Unit tests for config file sections (Anthony Towns)
95eb66d ArgsManager: support config file sections (Anthony Towns)
4d34fcc ArgsManager: drop m_negated_args (Anthony Towns)
3673ca3 ArgsManager: keep command line and config file arguments separate (Anthony Towns)
Pull request description:
The weekly meeting on [2017-12-07](http://www.erisian.com.au/meetbot/bitcoin-core-dev/2017/bitcoin-core-dev.2017-12-07-19.00.log.html) discussed allowing options to bitcoin to have some sensitivity to what network is in use. @theuni suggested having sections in the config file:
<cfields> an alternative to that would be sections in a config file. and on the
cmdline they'd look like namespaces. so, [testnet] port=5. or -testnet::port=5.
This approach is (more or less) supported by `boost::program_options::detail::config_file_iterator` -- when it sees a `[testnet]` section with `port=5`, it will treat that the same as "testnet.port=5". So `[testnet] port=5` (or `testnet.port=5` without the section header) in bitcoin.conf and `-testnet.port=5` on the command line.
The other aspect to this question is possibly limiting some options so that there is no possibility of accidental cross-contamination across networks. For example, if you're using a particular wallet.dat on mainnet, you may not want to accidentally use the same wallet on testnet and risk reusing keys.
I've set this up so that the `-addnode` and `-wallet` options are `NETWORK_ONLY`, so that if you have a bitcoin.conf:
wallet=/secret/wallet.dat
upnp=1
and you run `bitcoind -testnet` or `bitcoind -regtest`, then the `wallet=` setting will be ignored, and should behave as if your bitcoin.conf had specified:
upnp=1
[main]
wallet=/secret/wallet.dat
For any `NETWORK_ONLY` options, if you're using `-testnet` or `-regtest`, you'll have to add the prefix to any command line options. This was necessary for `multiwallet.py` for instance.
I've left the "default" options as taking precedence over network specific ones, which might be backwards. So if you have:
maxmempool=200
[regtest]
maxmempool=100
your maxmempool will still be 200 on regtest. The advantage of doing it this way is that if you have `[regtest] maxmempool=100` in bitcoin.conf, and then say `bitcoind -regtest -maxmempool=200`, the same result is probably in line with what you expect...
The other thing to note is that I'm using the chain names from `chainparamsbase.cpp` / `ChainNameFromCommandLine`, so the sections are `[main]`, `[test]` and `[regtest]`; not `[mainnet]` or `[testnet]` as might be expected.
Thoughts? Ping @MeshCollider @laanwj @jonasschnelli @morcos
Tree-SHA512: f00b5eb75f006189987e5c15e154a42b66ee251777768c1e185d764279070fcb7c41947d8794092b912a03d985843c82e5189871416995436a6260520fb7a4db
2020-04-29 14:50:51 +02:00
2020-12-09 21:29:31 +01:00
if ( gArgs . IsArgSet ( " -masternodeblsprivkey " ) & & gArgs . SoftSetBoolArg ( " -disablewallet " , true ) ) {
LogPrintf ( " %s: parameter interaction: -masternodeblsprivkey set -> setting -disablewallet=1 \n " , __func__ ) ;
}
Merge #11862: Network specific conf sections
c25321f Add config changes to release notes (Anthony Towns)
5e3cbe0 [tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns)
005ad26 ArgsManager: special handling for -regtest and -testnet (Anthony Towns)
608415d [tests] Unit tests for network-specific config entries (Anthony Towns)
68797e2 ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns)
d1fc4d9 ArgsManager: limit some options to only apply on mainnet when in default section (Anthony Towns)
8a9817d [tests] Use regtest section in functional tests configs (Anthony Towns)
30f9407 [tests] Unit tests for config file sections (Anthony Towns)
95eb66d ArgsManager: support config file sections (Anthony Towns)
4d34fcc ArgsManager: drop m_negated_args (Anthony Towns)
3673ca3 ArgsManager: keep command line and config file arguments separate (Anthony Towns)
Pull request description:
The weekly meeting on [2017-12-07](http://www.erisian.com.au/meetbot/bitcoin-core-dev/2017/bitcoin-core-dev.2017-12-07-19.00.log.html) discussed allowing options to bitcoin to have some sensitivity to what network is in use. @theuni suggested having sections in the config file:
<cfields> an alternative to that would be sections in a config file. and on the
cmdline they'd look like namespaces. so, [testnet] port=5. or -testnet::port=5.
This approach is (more or less) supported by `boost::program_options::detail::config_file_iterator` -- when it sees a `[testnet]` section with `port=5`, it will treat that the same as "testnet.port=5". So `[testnet] port=5` (or `testnet.port=5` without the section header) in bitcoin.conf and `-testnet.port=5` on the command line.
The other aspect to this question is possibly limiting some options so that there is no possibility of accidental cross-contamination across networks. For example, if you're using a particular wallet.dat on mainnet, you may not want to accidentally use the same wallet on testnet and risk reusing keys.
I've set this up so that the `-addnode` and `-wallet` options are `NETWORK_ONLY`, so that if you have a bitcoin.conf:
wallet=/secret/wallet.dat
upnp=1
and you run `bitcoind -testnet` or `bitcoind -regtest`, then the `wallet=` setting will be ignored, and should behave as if your bitcoin.conf had specified:
upnp=1
[main]
wallet=/secret/wallet.dat
For any `NETWORK_ONLY` options, if you're using `-testnet` or `-regtest`, you'll have to add the prefix to any command line options. This was necessary for `multiwallet.py` for instance.
I've left the "default" options as taking precedence over network specific ones, which might be backwards. So if you have:
maxmempool=200
[regtest]
maxmempool=100
your maxmempool will still be 200 on regtest. The advantage of doing it this way is that if you have `[regtest] maxmempool=100` in bitcoin.conf, and then say `bitcoind -regtest -maxmempool=200`, the same result is probably in line with what you expect...
The other thing to note is that I'm using the chain names from `chainparamsbase.cpp` / `ChainNameFromCommandLine`, so the sections are `[main]`, `[test]` and `[regtest]`; not `[mainnet]` or `[testnet]` as might be expected.
Thoughts? Ping @MeshCollider @laanwj @jonasschnelli @morcos
Tree-SHA512: f00b5eb75f006189987e5c15e154a42b66ee251777768c1e185d764279070fcb7c41947d8794092b912a03d985843c82e5189871416995436a6260520fb7a4db
2020-04-29 14:50:51 +02:00
// Warn if network-specific options (-addnode, -connect, etc) are
// specified in default section of config file, but not overridden
// on the command line or in this network's section of the config file.
gArgs . WarnForSectionOnlyArgs ( ) ;
2015-10-08 09:58:31 +02:00
}
2016-01-07 09:12:12 +01:00
static std : : string ResolveErrMsg ( const char * const optname , const std : : string & strBind )
{
return strprintf ( _ ( " Cannot resolve -%s address: '%s' " ) , optname , strBind ) ;
}
2018-04-17 17:07:19 +02: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 .
*/
2015-11-26 14:03:27 +01:00
void InitLogging ( )
{
2018-05-01 04:13:30 +02:00
g_logger - > m_print_to_file = ! gArgs . IsArgNegated ( " -debuglogfile " ) ;
g_logger - > m_file_path = AbsPathForConfigVal ( gArgs . GetArg ( " -debuglogfile " , DEFAULT_DEBUGLOGFILE ) ) ;
g_logger - > m_print_to_console = gArgs . GetBoolArg ( " -printtoconsole " , ! gArgs . GetBoolArg ( " -daemon " , false ) ) ;
g_logger - > m_log_timestamps = gArgs . GetBoolArg ( " -logtimestamps " , DEFAULT_LOGTIMESTAMPS ) ;
g_logger - > m_log_time_micros = gArgs . GetBoolArg ( " -logtimemicros " , DEFAULT_LOGTIMEMICROS ) ;
2021-06-24 19:54:20 +02:00
g_logger - > m_log_threadnames = gArgs . GetBoolArg ( " -logthreadnames " , DEFAULT_LOGTHREADNAMES ) ;
2018-05-01 04:13:30 +02:00
2019-06-24 18:44:27 +02:00
fLogIPs = gArgs . GetBoolArg ( " -logips " , DEFAULT_LOGIPS ) ;
2015-11-26 14:03:27 +01:00
2018-01-29 11:12:08 +01:00
std : : string version_string = FormatFullVersion ( ) ;
# ifdef DEBUG
version_string + = " (debug build) " ;
# else
version_string + = " (release build) " ;
# endif
LogPrintf ( PACKAGE_NAME " version %s \n " , version_string ) ;
2015-11-26 14:03:27 +01:00
}
2016-12-01 01:07:21 +01:00
namespace { // Variables internal to initialization process only
int nMaxConnections ;
int nUserMaxConnections ;
int nFD ;
2017-12-09 08:34:31 +01:00
ServiceFlags nLocalServices = ServiceFlags ( NODE_NETWORK | NODE_NETWORK_LIMITED ) ;
2018-12-04 12:06:35 +01:00
int64_t peer_connect_timeout ;
2016-12-01 01:07:21 +01:00
2017-06-26 13:37:42 +02:00
} // namespace
2016-12-01 01:07:21 +01:00
2017-02-28 11:37:00 +01: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 ( ) ;
} ;
2016-12-01 01:07:21 +01:00
bool AppInitBasicSetup ( )
2011-05-14 20:10:21 +02:00
{
2012-05-21 16:47:29 +02:00
// ********************************************************* Step 1: setup
2011-05-14 20:10:21 +02:00
# ifdef _MSC_VER
2012-07-26 02:48:39 +02:00
// Turn off Microsoft heap dump noise
2011-05-14 20:10:21 +02:00
_CrtSetReportMode ( _CRT_WARN , _CRTDBG_MODE_FILE ) ;
2019-08-06 05:08:33 +02:00
_CrtSetReportFile ( _CRT_WARN , CreateFileA ( " NUL " , GENERIC_WRITE , 0 , nullptr , OPEN_EXISTING , 0 , 0 ) ) ;
2012-07-26 02:48:39 +02:00
// Disable confusing "helpful" text message on abort, Ctrl-C
2011-05-14 20:10:21 +02:00
_set_abort_behavior ( 0 , _WRITE_ABORT_MSG | _CALL_REPORTFAULT ) ;
# endif
2012-07-20 08:45:49 +02:00
# ifdef WIN32
// Enable Data Execution Prevention (DEP)
// Minimum supported OS versions: WinXP SP3, WinVista >= SP1, Win Server 2008
// A failure is non-critical and needs no further attention!
# ifndef PROCESS_DEP_ENABLE
2013-10-01 09:47:16 +02:00
// We define this here, because GCCs winbase.h limits this to _WIN32_WINNT >= 0x0601 (Windows 7),
// which is not correct. Can be removed, when GCCs winbase.h is fixed!
2012-07-20 08:45:49 +02:00
# define PROCESS_DEP_ENABLE 0x00000001
# endif
typedef BOOL ( WINAPI * PSETPROCDEPPOL ) ( DWORD ) ;
PSETPROCDEPPOL setProcDEPPol = ( PSETPROCDEPPOL ) GetProcAddress ( GetModuleHandleA ( " Kernel32.dll " ) , " SetProcessDEPPolicy " ) ;
2019-08-06 05:08:33 +02:00
if ( setProcDEPPol ! = nullptr ) setProcDEPPol ( PROCESS_DEP_ENABLE ) ;
2011-05-14 20:10:21 +02:00
# endif
2014-06-04 13:16:07 +02:00
2015-09-02 16:18:16 +02:00
if ( ! SetupNetworking ( ) )
2015-10-22 18:09:19 +02:00
return InitError ( " Initializing networking failed " ) ;
2015-09-02 16:18:16 +02:00
# ifndef WIN32
2019-06-24 18:44:27 +02:00
if ( ! gArgs . GetBoolArg ( " -sysperms " , false ) ) {
2014-06-04 13:16:07 +02:00
umask ( 077 ) ;
}
2012-07-20 08:45:49 +02:00
2011-05-14 20:10:21 +02:00
// Clean shutdown on SIGTERM
2017-03-27 10:36:32 +02:00
registerSignalHandler ( SIGTERM , HandleSIGTERM ) ;
registerSignalHandler ( SIGINT , HandleSIGTERM ) ;
2012-03-02 20:31:16 +01:00
// Reopen debug.log on SIGHUP
2017-03-27 10:36:32 +02:00
registerSignalHandler ( SIGHUP , HandleSIGHUP ) ;
2013-05-05 07:37:03 +02:00
2015-09-15 01:39:12 +02:00
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
2013-05-05 07:37:03 +02:00
signal ( SIGPIPE , SIG_IGN ) ;
2018-05-07 14:31:08 +02:00
# else
SetConsoleCtrlHandler ( consoleCtrlHandler , true ) ;
2011-05-14 20:10:21 +02:00
# endif
2017-02-28 11:37:00 +01:00
std : : set_new_handler ( new_handler_terminate ) ;
2016-12-01 01:07:21 +01:00
return true ;
}
2011-05-14 20:10:21 +02:00
2016-12-01 01:07:21 +01:00
bool AppInitParameterInteraction ( )
{
2015-04-09 15:58:34 +02:00
const CChainParams & chainparams = Params ( ) ;
2016-12-01 01:07:21 +01:00
// ********************************************************* Step 2: parameter interactions
2014-11-13 15:15:53 +01:00
2015-11-28 22:28:21 +01:00
// also see: InitParameterInteraction()
2014-02-14 17:33:07 +01:00
2019-01-16 13:28:54 +01:00
if ( ! fs : : is_directory ( GetBlocksDir ( ) ) ) {
2018-07-27 20:38:45 +02:00
return InitError ( strprintf ( _ ( " Specified blocks directory \" %s \" does not exist. " ) , gArgs . GetArg ( " -blocksdir " , " " ) . c_str ( ) ) ) ;
2018-03-27 21:04:22 +02:00
}
2020-07-09 01:28:30 +02:00
// if using block pruning, then disallow txindex and require disabling governance validation
2019-06-24 18:44:27 +02:00
if ( gArgs . GetArg ( " -prune " , 0 ) ) {
if ( gArgs . GetBoolArg ( " -txindex " , DEFAULT_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 20:27:44 +01:00
return InitError ( _ ( " Prune mode is incompatible with -txindex. " ) ) ;
2020-07-09 01:28:30 +02:00
if ( ! gArgs . GetBoolArg ( " -disablegovernance " , false ) ) {
return InitError ( _ ( " Prune mode is incompatible with -disablegovernance=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 20:27:44 +01:00
}
2015-11-20 15:03:57 +01:00
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -devnet " ) ) {
2017-12-20 12:45:01 +01:00
// Require setting of ports when running devnet
2019-06-24 18:44:27 +02:00
if ( gArgs . GetArg ( " -listen " , DEFAULT_LISTEN ) & & ! gArgs . IsArgSet ( " -port " ) ) {
2017-12-20 12:45:01 +01:00
return InitError ( _ ( " -port must be specified when -devnet and -listen are specified " ) ) ;
2017-05-15 07:30:09 +02:00
}
2019-06-24 18:44:27 +02:00
if ( gArgs . GetArg ( " -server " , false ) & & ! gArgs . IsArgSet ( " -rpcport " ) ) {
2017-12-20 12:45:01 +01:00
return InitError ( _ ( " -rpcport must be specified when -devnet and -server are specified " ) ) ;
2017-05-15 07:30:09 +02:00
}
2019-06-23 18:33:05 +02:00
if ( gArgs . GetArgs ( " -devnet " ) . size ( ) > 1 ) {
2017-12-20 12:45:01 +01:00
return InitError ( _ ( " -devnet can only be specified once " ) ) ;
2017-05-15 07:30:09 +02:00
}
2017-12-20 12:45:01 +01:00
}
2019-06-24 18:44:27 +02:00
fAllowPrivateNet = gArgs . GetBoolArg ( " -allowprivatenet " , DEFAULT_ALLOWPRIVATENET ) ;
2017-12-20 12:45:01 +01:00
2017-06-26 14:42:46 +02:00
// -bind and -whitebind can't be set when not listening
2017-06-27 14:22:54 +02:00
size_t nUserBind = gArgs . GetArgs ( " -bind " ) . size ( ) + gArgs . GetArgs ( " -whitebind " ) . size ( ) ;
2017-06-26 14:42:46 +02:00
if ( nUserBind ! = 0 & & ! gArgs . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) ) {
return InitError ( " Cannot set -bind or -whitebind together with -listen=0 " ) ;
}
2013-04-26 00:46:47 +02:00
// Make sure enough file descriptors are available
2017-06-26 14:42:46 +02:00
int nBind = std : : max ( nUserBind , size_t ( 1 ) ) ;
2019-06-24 18:44:27 +02:00
nUserMaxConnections = gArgs . GetArg ( " -maxconnections " , DEFAULT_MAX_PEER_CONNECTIONS ) ;
2016-12-01 01:07:21 +01:00
nMaxConnections = std : : max ( nUserMaxConnections , 0 ) ;
2014-11-16 12:19:23 +01:00
// Trim requested connection counts, to fit into system limitations
2018-06-27 10:39:41 +02:00
// <int> in std::min<int>(...) to work around FreeBSD compilation issue described in #2695
2017-01-06 16:47:05 +01:00
nFD = RaiseFileDescriptorLimit ( nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS ) ;
2018-11-13 20:09:05 +01:00
# ifdef USE_POLL
int fd_max = nFD ;
# else
int fd_max = FD_SETSIZE ;
# endif
nMaxConnections = std : : max ( std : : min < int > ( nMaxConnections , fd_max - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS ) , 0 ) ;
2013-04-26 00:46:47 +02:00
if ( nFD < MIN_CORE_FILEDESCRIPTORS )
return InitError ( _ ( " Not enough file descriptors available. " ) ) ;
2017-01-06 16:47:05 +01:00
nMaxConnections = std : : min ( nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS , nMaxConnections ) ;
2014-11-16 12:19:23 +01:00
if ( nMaxConnections < nUserMaxConnections )
InitWarning ( strprintf ( _ ( " Reducing -maxconnections from %d to %d, because of system limitations. " ) , nUserMaxConnections , nMaxConnections ) ) ;
2013-04-26 00:46:47 +02:00
2012-05-21 16:47:29 +02:00
// ********************************************************* Step 3: parameter-to-internal-flags
2017-05-15 07:30:09 +02:00
if ( gArgs . IsArgSet ( " -debug " ) ) {
2019-05-22 23:51:39 +02:00
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
2017-05-15 07:30:09 +02:00
const std : : vector < std : : string > categories = gArgs . GetArgs ( " -debug " ) ;
2019-05-22 23:51:39 +02:00
2017-11-30 09:32:35 +01:00
if ( std : : none_of ( categories . begin ( ) , categories . end ( ) ,
[ ] ( std : : string cat ) { return cat = = " 0 " | | cat = = " none " ; } ) ) {
2019-05-22 23:51:39 +02:00
for ( const auto & cat : categories ) {
2018-05-01 04:13:30 +02:00
if ( ! g_logger - > EnableCategory ( cat ) ) {
2019-05-22 23:51:39 +02:00
InitWarning ( strprintf ( _ ( " Unsupported logging category %s=%s. " ) , " -debug " , cat ) ) ;
}
}
}
}
// Now remove the logging categories which were explicitly excluded
2017-06-27 14:22:54 +02:00
for ( const std : : string & cat : gArgs . GetArgs ( " -debugexclude " ) ) {
2018-05-01 04:13:30 +02:00
if ( ! g_logger - > DisableCategory ( cat ) ) {
InitWarning ( strprintf ( _ ( " Unsupported logging category %s=%s. " ) , " -debugexclude " , cat ) ) ;
2019-05-22 23:51:39 +02:00
}
2016-12-27 19:11:21 +01:00
}
2013-10-08 12:09:40 +02:00
2014-06-27 14:41:11 +02:00
// Check for -debugnet
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -debugnet " , false ) )
2015-10-22 18:09:19 +02:00
InitWarning ( _ ( " Unsupported argument -debugnet ignored, use -debug=net. " ) ) ;
2014-06-16 08:48:32 +02:00
// Check for -socks - as this is a privacy risk to continue, exit here
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -socks " ) )
2015-10-22 18:09:19 +02:00
return InitError ( _ ( " Unsupported argument -socks found. Setting SOCKS version isn't possible anymore, only SOCKS5 proxies are supported. " ) ) ;
2014-05-05 20:32:56 +02:00
// Check for -tor - as this is a privacy risk to continue, exit here
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -tor " , false ) )
2015-10-22 18:09:19 +02:00
return InitError ( _ ( " Unsupported argument -tor found, use -onion. " ) ) ;
2013-10-08 12:09:40 +02:00
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -benchmark " , false ) )
2015-10-22 18:09:19 +02:00
InitWarning ( _ ( " Unsupported argument -benchmark ignored, use -debug=bench. " ) ) ;
2014-07-26 22:49:17 +02:00
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -whitelistalwaysrelay " , false ) )
2015-11-26 00:00:23 +01:00
InitWarning ( _ ( " Unsupported argument -whitelistalwaysrelay ignored, use -whitelistrelay and/or -whitelistforcerelay. " ) ) ;
2014-07-26 22:49:17 +02:00
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -blockminsize " ) )
2016-07-18 08:23:38 +02:00
InitWarning ( " Unsupported argument -blockminsize ignored. " ) ;
2015-03-13 17:25:34 +01:00
// Checkmempool and checkblockindex default to true in regtest mode
2019-06-24 18:44:27 +02:00
int ratio = std : : min < int > ( std : : max < int > ( gArgs . GetArg ( " -checkmempool " , chainparams . DefaultConsistencyChecks ( ) ? 1 : 0 ) , 0 ) , 1000000 ) ;
2015-10-07 23:34:55 +02:00
if ( ratio ! = 0 ) {
mempool . setSanityCheck ( 1.0 / ratio ) ;
}
2019-06-24 18:44:27 +02:00
fCheckBlockIndex = gArgs . GetBoolArg ( " -checkblockindex " , chainparams . DefaultConsistencyChecks ( ) ) ;
fCheckpointsEnabled = gArgs . GetBoolArg ( " -checkpoints " , DEFAULT_CHECKPOINTS_ENABLED ) ;
2012-06-22 19:11:57 +02:00
2019-06-24 18:44:27 +02:00
hashAssumeValid = uint256S ( gArgs . GetArg ( " -assumevalid " , chainparams . GetConsensus ( ) . defaultAssumeValid . GetHex ( ) ) ) ;
2017-08-23 16:21:08 +02:00
if ( ! hashAssumeValid . IsNull ( ) )
LogPrintf ( " Assuming ancestors of block %s have valid signatures. \n " , hashAssumeValid . GetHex ( ) ) ;
else
LogPrintf ( " Validating signatures for all blocks. \n " ) ;
2017-09-06 18:49:43 +02:00
if ( gArgs . IsArgSet ( " -minimumchainwork " ) ) {
const std : : string minChainWorkStr = gArgs . GetArg ( " -minimumchainwork " , " " ) ;
if ( ! IsHexNumber ( minChainWorkStr ) ) {
return InitError ( strprintf ( " Invalid non-hex (%s) minimum chain work value specified " , minChainWorkStr)) ;
}
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 21:48:02 +01:00
// mempool limits
2019-06-24 18:44:27 +02:00
int64_t nMempoolSizeMax = gArgs . GetArg ( " -maxmempool " , DEFAULT_MAX_MEMPOOL_SIZE ) * 1000000 ;
int64_t nMempoolSizeMin = gArgs . GetArg ( " -limitdescendantsize " , DEFAULT_DESCENDANT_SIZE_LIMIT ) * 1000 * 40 ;
2015-11-19 21:48:02 +01:00
if ( nMempoolSizeMax < 0 | | nMempoolSizeMax < nMempoolSizeMin )
2015-11-27 16:44:30 +01:00
return InitError ( strprintf ( _ ( " -maxmempool must be at least %d MB " ) , std : : ceil ( nMempoolSizeMin / 1000000.0 ) ) ) ;
2019-01-03 10:18:47 +01:00
// incremental relay fee sets the minimum feerate increase necessary for BIP 125 replacement in the mempool
2017-01-16 19:32:51 +01:00
// and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -incrementalrelayfee " ) )
2017-01-16 19:32:51 +01:00
{
CAmount n = 0 ;
2019-06-24 18:44:27 +02:00
if ( ! ParseMoney ( gArgs . GetArg ( " -incrementalrelayfee " , " " ) , n ) )
return InitError ( AmountErrMsg ( " incrementalrelayfee " , gArgs . GetArg ( " -incrementalrelayfee " , " " ) ) ) ;
2017-01-16 19:32:51 +01:00
incrementalRelayFee = CFeeRate ( n ) ;
}
2012-06-22 19:11:57 +02:00
2015-09-11 23:31:30 +02:00
// block pruning; get the amount of disk space (in MiB) to allot for block & undo files
2019-06-24 18:44:27 +02:00
int64_t nPruneArg = gArgs . GetArg ( " -prune " , 0 ) ;
2017-01-11 14:16:11 +01:00
if ( nPruneArg < 0 ) {
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 20:27:44 +01:00
return InitError ( _ ( " Prune cannot be configured with a negative value. " ) ) ;
}
2017-01-11 14:16:11 +01: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 ) {
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -regtest " , false ) ) {
2019-05-21 15:52:59 +02:00
// we use 1MB blocks to test this on regtest
if ( nPruneTarget < 550 * 1024 * 1024 ) {
return InitError ( strprintf ( _ ( " Prune configured below the minimum of %d MiB. Please use a higher number. " ) , 550 ) ) ;
}
} else {
if ( nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES ) {
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 20:27:44 +01:00
}
LogPrintf ( " Prune configured to target %uMiB on disk for block and undo files. \n " , nPruneTarget / 1024 / 1024 ) ;
fPruneMode = true ;
}
2019-06-24 18:44:27 +02:00
nConnectTimeout = gArgs . GetArg ( " -timeout " , DEFAULT_CONNECT_TIMEOUT ) ;
2018-12-04 12:06:35 +01:00
if ( nConnectTimeout < = 0 ) {
2014-09-25 09:01:54 +02:00
nConnectTimeout = DEFAULT_CONNECT_TIMEOUT ;
2018-12-04 12:06:35 +01:00
}
peer_connect_timeout = gArgs . GetArg ( " -peertimeout " , DEFAULT_PEER_CONNECT_TIMEOUT ) ;
if ( peer_connect_timeout < = 0 ) {
return InitError ( " peertimeout cannot be configured with a negative value. " ) ;
}
2012-05-21 16:47:29 +02:00
2017-06-24 10:11:18 +02:00
if ( gArgs . IsArgSet ( " -minrelaytxfee " ) ) {
2014-04-23 00:46:19 +02:00
CAmount n = 0 ;
2019-06-24 18:44:27 +02:00
if ( ! ParseMoney ( gArgs . GetArg ( " -minrelaytxfee " , " " ) , n ) ) {
return InitError ( AmountErrMsg ( " minrelaytxfee " , gArgs . GetArg ( " -minrelaytxfee " , " " ) ) ) ;
2019-03-14 15:44:42 +01:00
}
2017-08-02 13:19:28 +02:00
// High fee check is done afterward in WalletParameterInteraction()
2016-09-26 13:55:04 +02:00
: : minRelayTxFee = CFeeRate ( n ) ;
2017-01-16 19:32:51 +01: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 ( ) ) ;
}
// Sanity check argument for min fee for including tx in block
// TODO: Harmonize which arguments need sanity checking and where that happens
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -blockmintxfee " ) )
2017-01-16 19:32:51 +01:00
{
CAmount n = 0 ;
2019-06-24 18:44:27 +02:00
if ( ! ParseMoney ( gArgs . GetArg ( " -blockmintxfee " , " " ) , n ) )
return InitError ( AmountErrMsg ( " blockmintxfee " , gArgs . GetArg ( " -blockmintxfee " , " " ) ) ) ;
2017-01-16 19:32:51 +01:00
}
// Feerate used to define dust. Shouldn't be changed lightly as old
// implementations may inadvertently create non-standard transactions
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -dustrelayfee " ) )
2017-01-16 19:32:51 +01:00
{
CAmount n = 0 ;
2018-03-05 22:35:50 +01:00
if ( ! ParseMoney ( gArgs . GetArg ( " -dustrelayfee " , " " ) , n ) )
2019-06-24 18:44:27 +02:00
return InitError ( AmountErrMsg ( " dustrelayfee " , gArgs . GetArg ( " -dustrelayfee " , " " ) ) ) ;
2017-01-16 19:32:51 +01:00
dustRelayFee = CFeeRate ( n ) ;
2013-04-26 02:11:27 +02:00
}
2012-05-21 16:47:29 +02:00
2019-06-24 18:44:27 +02:00
fRequireStandard = ! gArgs . GetBoolArg ( " -acceptnonstdtxn " , ! chainparams . RequireStandard ( ) ) ;
Backport compact blocks functionality from bitcoin (#1966)
* Merge #8068: Compact Blocks
48efec8 Fix some minor compact block issues that came up in review (Matt Corallo)
ccd06b9 Elaborate bucket size math (Pieter Wuille)
0d4cb48 Use vTxHashes to optimize InitData significantly (Matt Corallo)
8119026 Provide a flat list of txid/terators to txn in CTxMemPool (Matt Corallo)
678ee97 Add BIP 152 to implemented BIPs list (Matt Corallo)
56ba516 Add reconstruction debug logging (Matt Corallo)
2f34a2e Get our "best three" peers to announce blocks using cmpctblocks (Matt Corallo)
927f8ee Add ability to fetch CNode by NodeId (Matt Corallo)
d25cd3e Add receiver-side protocol implementation for CMPCTBLOCK stuff (Matt Corallo)
9c837d5 Add sender-side protocol implementation for CMPCTBLOCK stuff (Matt Corallo)
00c4078 Add protocol messages for short-ids blocks (Matt Corallo)
e3b2222 Add some blockencodings tests (Matt Corallo)
f4f8f14 Add TestMemPoolEntryHelper::FromTx version for CTransaction (Matt Corallo)
85ad31e Add partial-block block encodings API (Matt Corallo)
5249dac Add COMPACTSIZE wrapper similar to VARINT for serialization (Matt Corallo)
cbda71c Move context-required checks from CheckBlockHeader to Contextual... (Matt Corallo)
7c29ec9 If AcceptBlockHeader returns true, pindex will be set. (Matt Corallo)
96806c3 Stop trimming when mapTx is empty (Pieter Wuille)
* Merge #8408: Prevent fingerprinting, disk-DoS with compact blocks
1d06e49 Ignore CMPCTBLOCK messages for pruned blocks (Suhas Daftuar)
1de2a46 Ignore GETBLOCKTXN requests for unknown blocks (Suhas Daftuar)
* Merge #8418: Add tests for compact blocks
45c7ddd Add p2p test for BIP 152 (compact blocks) (Suhas Daftuar)
9a22a6c Add support for compactblocks to mininode (Suhas Daftuar)
a8689fd Tests: refactor compact size serialization in mininode (Suhas Daftuar)
9c8593d Implement SipHash in Python (Pieter Wuille)
56c87e9 Allow changing BIP9 parameters on regtest (Suhas Daftuar)
* Merge #8505: Trivial: Fix typos in various files
1aacfc2 various typos (leijurv)
* Merge #8449: [Trivial] Do not shadow local variable, cleanup
a159f25 Remove redundand (and shadowing) declaration (Pavel Janík)
cce3024 Do not shadow local variable, cleanup (Pavel Janík)
* Merge #8739: [qa] Fix broken sendcmpct test in p2p-compactblocks.py
157254a Fix broken sendcmpct test in p2p-compactblocks.py (Suhas Daftuar)
* Merge #8854: [qa] Fix race condition in p2p-compactblocks test
b5fd666 [qa] Fix race condition in p2p-compactblocks test (Suhas Daftuar)
* Merge #8393: Support for compact blocks together with segwit
27acfc1 [qa] Update p2p-compactblocks.py for compactblocks v2 (Suhas Daftuar)
422fac6 [qa] Add support for compactblocks v2 to mininode (Suhas Daftuar)
f5b9b8f [qa] Fix bug in mininode witness deserialization (Suhas Daftuar)
6aa28ab Use cmpctblock type 2 for segwit-enabled transfer (Pieter Wuille)
be7555f Fix overly-prescriptive p2p-segwit test for new fetch logic (Matt Corallo)
06128da Make GetFetchFlags always request witness objects from witness peers (Matt Corallo)
* Merge #8882: [qa] Fix race conditions in p2p-compactblocks.py and sendheaders.py
b55d941 [qa] Fix race condition in sendheaders.py (Suhas Daftuar)
6976db2 [qa] Another attempt to fix race condition in p2p-compactblocks.py (Suhas Daftuar)
* Merge #8904: [qa] Fix compact block shortids for a test case
4cdece4 [qa] Fix compact block shortids for a test case (Dagur Valberg Johannsson)
* Merge #8637: Compact Block Tweaks (rebase of #8235)
3ac6de0 Align constant names for maximum compact block / blocktxn depth (Pieter Wuille)
b2e93a3 Add cmpctblock to debug help list (instagibbs)
fe998e9 More agressively filter compact block requests (Matt Corallo)
02a337d Dont remove a "preferred" cmpctblock peer if they provide a block (Matt Corallo)
* Merge #8975: Chainparams: Trivial: In AppInit2(), s/Params()/chainparams/
6f2f639 Chainparams: Trivial: In AppInit2(), s/Params()/chainparams/ (Jorge Timón)
* Merge #8968: Don't hold cs_main when calling ProcessNewBlock from a cmpctblock
72ca7d9 Don't hold cs_main when calling ProcessNewBlock from a cmpctblock (Matt Corallo)
* Merge #8995: Add missing cs_main lock to ::GETBLOCKTXN processing
dfe7906 Add missing cs_main lock to ::GETBLOCKTXN processing (Matt Corallo)
* Merge #8515: A few mempool removal optimizations
0334430 Add some missing includes (Pieter Wuille)
4100499 Return shared_ptr<CTransaction> from mempool removes (Pieter Wuille)
51f2783 Make removed and conflicted arguments optional to remove (Pieter Wuille)
f48211b Bypass removeRecursive in removeForReorg (Pieter Wuille)
* Merge #9026: Fix handling of invalid compact blocks
d4833ff Bump the protocol version to distinguish new banning behavior. (Suhas Daftuar)
88c3549 Fix compact block handling to not ban if block is invalid (Suhas Daftuar)
c93beac [qa] Test that invalid compactblocks don't result in ban (Suhas Daftuar)
* Merge #9039: Various serialization simplifcations and optimizations
d59a518 Use fixed preallocation instead of costly GetSerializeSize (Pieter Wuille)
25a211a Add optimized CSizeComputer serializers (Pieter Wuille)
a2929a2 Make CSerAction's ForRead() constexpr (Pieter Wuille)
a603925 Avoid -Wshadow errors (Pieter Wuille)
5284721 Get rid of nType and nVersion (Pieter Wuille)
657e05a Make GetSerializeSize a wrapper on top of CSizeComputer (Pieter Wuille)
fad9b66 Make nType and nVersion private and sometimes const (Pieter Wuille)
c2c5d42 Make streams' read and write return void (Pieter Wuille)
50e8a9c Remove unused ReadVersion and WriteVersion (Pieter Wuille)
* Merge #9058: Fixes for p2p-compactblocks.py test timeouts on travis (#8842)
dac53b5 Modify getblocktxn handler not to drop requests for old blocks (Russell Yanofsky)
55bfddc [qa] Fix stale data bug in test_compactblocks_not_at_tip (Russell Yanofsky)
47e9659 [qa] Fix bug in compactblocks v2 merge (Russell Yanofsky)
* Merge #9160: [trivial] Fix hungarian variable name
ec34648 [trivial] Fix hungarian variable name (Russell Yanofsky)
* Merge #9159: [qa] Wait for specific block announcement in p2p-compactblocks
dfa44d1 [qa] Wait for specific block announcement in p2p-compactblocks (Russell Yanofsky)
* Merge #9125: Make CBlock a vector of shared_ptr of CTransactions
b4e4ba4 Introduce convenience type CTransactionRef (Pieter Wuille)
1662b43 Make CBlock::vtx a vector of shared_ptr<CTransaction> (Pieter Wuille)
da60506 Add deserializing constructors to CTransaction and CMutableTransaction (Pieter Wuille)
0e85204 Add serialization for unique_ptr and shared_ptr (Pieter Wuille)
* Merge #8872: Remove block-request logic from INV message processing
037159c Remove block-request logic from INV message processing (Matt Corallo)
3451203 [qa] Respond to getheaders and do not assume a getdata on inv (Matt Corallo)
d768f15 [qa] Make comptool push blocks instead of relying on inv-fetch (mrbandrews)
* Merge #9199: Always drop the least preferred HB peer when adding a new one.
ca8549d Always drop the least preferred HB peer when adding a new one. (Gregory Maxwell)
* Merge #9233: Fix some typos
15fa95d Fix some typos (fsb4000)
* Merge #9260: Mrs Peacock in The Library with The Candlestick (killed main.{h,cpp})
76faa3c Rename the remaining main.{h,cpp} to validation.{h,cpp} (Matt Corallo)
e736772 Move network-msg-processing code out of main to its own file (Matt Corallo)
87c35f5 Remove orphan state wipe from UnloadBlockIndex. (Matt Corallo)
* Merge #9014: Fix block-connection performance regression
dd0df81 Document ConnectBlock connectTrace postconditions (Matt Corallo)
2d6e561 Switch pblock in ProcessNewBlock to a shared_ptr (Matt Corallo)
2736c44 Make the optional pblock in ActivateBestChain a shared_ptr (Matt Corallo)
ae4db44 Create a shared_ptr for the block we're connecting in ActivateBCS (Matt Corallo)
fd9d890 Keep blocks as shared_ptrs, instead of copying txn in ConnectTip (Matt Corallo)
6fdd43b Add struct to track block-connect-time-generated info for callbacks (Matt Corallo)
* Merge #9240: Remove txConflicted
a874ab5 remove internal tracking of mempool conflicts for reporting to wallet (Alex Morcos)
bf663f8 remove external usage of mempool conflict tracking (Alex Morcos)
* Merge #9344: Do not run functions with necessary side-effects in assert()
da9cdd2 Do not run functions with necessary side-effects in assert() (Gregory Maxwell)
* Merge #9273: Remove unused CDiskBlockPos* argument from ProcessNewBlock
a13fa4c Remove unused CDiskBlockPos* argument from ProcessNewBlock (Matt Corallo)
* Merge #9352: Attempt reconstruction from all compact block announcements
813ede9 [qa] Update compactblocks test for multi-peer reconstruction (Suhas Daftuar)
7017298 Allow compactblock reconstruction when block is in flight (Suhas Daftuar)
* Merge #9252: Release cs_main before calling ProcessNewBlock, or processing headers (cmpctblock handling)
bd02bdd Release cs_main before processing cmpctblock as header (Suhas Daftuar)
680b0c0 Release cs_main before calling ProcessNewBlock (cmpctblock handling) (Suhas Daftuar)
* Merge #9283: A few more CTransactionRef optimizations
91335ba Remove unused MakeTransactionRef overloads (Pieter Wuille)
6713f0f Make FillBlock consume txn_available to avoid shared_ptr copies (Pieter Wuille)
62607d7 Convert COrphanTx to keep a CTransactionRef (Pieter Wuille)
c44e4c4 Make AcceptToMemoryPool take CTransactionRef (Pieter Wuille)
* Merge #9375: Relay compact block messages prior to full block connection
02ee4eb Make most_recent_compact_block a pointer to a const (Matt Corallo)
73666ad Add comment to describe callers to ActivateBestChain (Matt Corallo)
962f7f0 Call ActivateBestChain without cs_main/with most_recent_block (Matt Corallo)
0df777d Use a temp pindex to avoid a const_cast in ProcessNewBlockHeaders (Matt Corallo)
c1ae4fc Avoid holding cs_most_recent_block while calling ReadBlockFromDisk (Matt Corallo)
9eb67f5 Ensure we meet the BIP 152 old-relay-types response requirements (Matt Corallo)
5749a85 Cache most-recently-connected compact block (Matt Corallo)
9eaec08 Cache most-recently-announced block's shared_ptr (Matt Corallo)
c802092 Relay compact block messages prior to full block connection (Matt Corallo)
6987219 Add a CValidationInterface::NewPoWValidBlock callback (Matt Corallo)
180586f Call AcceptBlock with the block's shared_ptr instead of CBlock& (Matt Corallo)
8baaba6 [qa] Avoid race in preciousblock test. (Matt Corallo)
9a0b2f4 [qa] Make compact blocks test construction using fetch methods (Matt Corallo)
8017547 Make CBlockIndex*es in net_processing const (Matt Corallo)
* Merge #9486: Make peer=%d log prints consistent
e6111b2 Make peer id logging consistent ("peer=%d" instead of "peer %d") (Matt Corallo)
* Merge #9400: Set peers as HB peers upon full block validation
d4781ac Set peers as HB peers upon full block validation (Gregory Sanders)
* Merge #9499: Use recent-rejects, orphans, and recently-replaced txn for compact-block-reconstruction
c594580 Add braces around AddToCompactExtraTransactions (Matt Corallo)
1ccfe9b Clarify comment about mempool/extra conflicts (Matt Corallo)
fac4c78 Make PartiallyDownloadedBlock::InitData's second param const (Matt Corallo)
b55b416 Add extra_count lower bound to compact reconstruction debug print (Matt Corallo)
863edb4 Consider all (<100k memusage) txn for compact-block-extra-txn cache (Matt Corallo)
7f8c8ca Consider all orphan txn for compact-block-extra-txn cache (Matt Corallo)
93380c5 Use replaced transactions in compact block reconstruction (Matt Corallo)
1531652 Keep shared_ptrs to recently-replaced txn for compact blocks (Matt Corallo)
edded80 Make ATMP optionally return the CTransactionRefs it replaced (Matt Corallo)
c735540 Move ORPHAN constants from validation.h to net_processing.h (Matt Corallo)
* Merge #9587: Do not shadow local variable named `tx`.
44f2baa Do not shadow local variable named `tx`. (Pavel Janík)
* Merge #9510: [trivial] Fix typos in comments
cc16d99 [trivial] Fix typos in comments (practicalswift)
* Merge #9604: [Trivial] add comment about setting peer as HB peer.
dd5b011 [Trivial] add comment about setting peer as HB peer. (John Newbery)
* Fix using of AcceptToMemoryPool in PrivateSend code
* add `override`
* fSupportsDesiredCmpctVersion
* bring back tx ressurection in DisconnectTip
* Fix delayed headers
* Remove unused CConnman::FindNode overload
* Fix typos and comments
* Fix minor code differences
* Don't use rejection cache for corrupted transactions
Partly based on https://github.com/bitcoin/bitcoin/pull/8525
* Backport missed cs_main locking changes
Missed from https://github.com/bitcoin/bitcoin/commit/58a215ce8c13b900cf982c39f8ee4879290d1a95
* Backport missed comments and mapBlockSource.emplace call
Missed from two commits:
https://github.com/bitcoin/bitcoin/commit/88c35491ab19f9afdf9b3fa9356a072f70ef2f55
https://github.com/bitcoin/bitcoin/commit/7c98ce584ec23bcddcba8cdb33efa6547212f6ef
* Add CheckPeerHeaders() helper and check in (nCount == 0) too
2018-04-11 13:06:01 +02:00
if ( chainparams . RequireStandard ( ) & & ! fRequireStandard )
2015-06-24 05:36:22 +02:00
return InitError ( strprintf ( " acceptnonstdtxn is not currently supported for %s chain " , chainparams . NetworkIDString ( ) ) ) ;
2019-06-24 18:44:27 +02:00
nBytesPerSigOp = gArgs . GetArg ( " -bytespersigop " , nBytesPerSigOp ) ;
2015-06-24 05:36:22 +02:00
2018-04-17 15:57:52 +02:00
if ( ! g_wallet_init_interface . ParameterInteraction ( ) ) return false ;
2014-07-17 02:04:04 +02:00
2019-06-24 18:44:27 +02:00
fIsBareMultisigStd = gArgs . GetBoolArg ( " -permitbaremultisig " , DEFAULT_PERMIT_BAREMULTISIG ) ;
fAcceptDatacarrier = gArgs . GetBoolArg ( " -datacarrier " , DEFAULT_ACCEPT_DATACARRIER ) ;
nMaxDatacarrierBytes = gArgs . GetArg ( " -datacarriersize " , nMaxDatacarrierBytes ) ;
2012-05-21 16:47:29 +02:00
2015-06-19 16:42:39 +02:00
// Option to startup with mocktime set (used for regression testing):
2019-06-24 18:44:27 +02:00
SetMockTime ( gArgs . GetArg ( " -mocktime " , 0 ) ) ; // SetMockTime(0) is a no-op
2015-06-19 16:42:39 +02:00
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -peerbloomfilters " , DEFAULT_PEERBLOOMFILTERS ) )
2017-07-05 05:45:23 +02:00
nLocalServices = ServiceFlags ( nLocalServices | NODE_BLOOM ) ;
2015-08-21 06:15:27 +02:00
2019-06-24 18:44:27 +02:00
nMaxTipAge = gArgs . GetArg ( " -maxtipage " , DEFAULT_MAX_TIP_AGE ) ;
2016-01-18 11:55:52 +01:00
2017-06-06 10:08:14 +02:00
if ( gArgs . IsArgSet ( " -vbparams " ) ) {
// Allow overriding version bits parameters for testing
2018-02-08 09:02:47 +01:00
if ( ! chainparams . MineBlocksOnDemand ( ) ) {
2017-06-06 10:08:14 +02:00
return InitError ( " Version bits parameters may only be overridden on regtest. " ) ;
2016-07-25 23:22:37 +02:00
}
2017-06-06 10:08:14 +02:00
for ( const std : : string & strDeployment : gArgs . GetArgs ( " -vbparams " ) ) {
2016-07-25 23:22:37 +02:00
std : : vector < std : : string > vDeploymentParams ;
2017-05-15 07:30:09 +02:00
boost : : split ( vDeploymentParams , strDeployment , boost : : is_any_of ( " : " ) ) ;
2020-09-12 16:33:12 +02:00
if ( vDeploymentParams . size ( ) ! = 3 & & vDeploymentParams . size ( ) ! = 5 & & vDeploymentParams . size ( ) ! = 7 ) {
return InitError ( " Version bits parameters malformed, expecting deployment:start:end or deployment:start:end:window:threshold or deployment:start:end:window:thresholdstart:thresholdmin:falloffcoeff " ) ;
2016-07-25 23:22:37 +02:00
}
2020-09-12 16:33:12 +02:00
int64_t nStartTime , nTimeout , nWindowSize = - 1 , nThresholdStart = - 1 , nThresholdMin = - 1 , nFalloffCoeff = - 1 ;
2016-07-25 23:22:37 +02:00
if ( ! ParseInt64 ( vDeploymentParams [ 1 ] , & nStartTime ) ) {
return InitError ( strprintf ( " Invalid nStartTime (%s) " , vDeploymentParams[1])) ;
}
if ( ! ParseInt64 ( vDeploymentParams [ 2 ] , & nTimeout ) ) {
return InitError ( strprintf ( " Invalid nTimeout (%s) " , vDeploymentParams[2])) ;
}
2020-12-15 03:48:00 +01:00
if ( vDeploymentParams . size ( ) > = 5 ) {
2019-01-23 17:36:51 +01:00
if ( ! ParseInt64 ( vDeploymentParams [ 3 ] , & nWindowSize ) ) {
return InitError ( strprintf ( " Invalid nWindowSize (%s) " , vDeploymentParams[3])) ;
}
2020-09-12 16:33:12 +02:00
if ( ! ParseInt64 ( vDeploymentParams [ 4 ] , & nThresholdStart ) ) {
return InitError ( strprintf ( " Invalid nThresholdStart (%s) " , vDeploymentParams[4])) ;
}
}
if ( vDeploymentParams . size ( ) = = 7 ) {
if ( ! ParseInt64 ( vDeploymentParams [ 5 ] , & nThresholdMin ) ) {
return InitError ( strprintf ( " Invalid nThresholdMin (%s) " , vDeploymentParams[5])) ;
}
if ( ! ParseInt64 ( vDeploymentParams [ 6 ] , & nFalloffCoeff ) ) {
return InitError ( strprintf ( " Invalid nFalloffCoeff (%s) " , vDeploymentParams[6])) ;
2019-01-23 17:36:51 +01:00
}
}
2016-07-25 23:22:37 +02:00
bool found = false ;
2016-08-03 11:05:16 +02:00
for ( int j = 0 ; j < ( int ) Consensus : : MAX_VERSION_BITS_DEPLOYMENTS ; + + j )
2016-07-25 23:22:37 +02:00
{
2016-08-03 11:05:16 +02:00
if ( vDeploymentParams [ 0 ] . compare ( VersionBitsDeploymentInfo [ j ] . name ) = = 0 ) {
2020-09-12 16:33:12 +02:00
UpdateVersionBitsParameters ( Consensus : : DeploymentPos ( j ) , nStartTime , nTimeout , nWindowSize , nThresholdStart , nThresholdMin , nFalloffCoeff ) ;
2016-07-25 23:22:37 +02:00
found = true ;
2020-09-12 16:33:12 +02:00
LogPrintf ( " Setting version bits activation parameters for %s to start=%ld, timeout=%ld, window=%ld, thresholdstart=%ld, thresholdmin=%ld, falloffcoeff=%ld \n " ,
vDeploymentParams [ 0 ] , nStartTime , nTimeout , nWindowSize , nThresholdStart , nThresholdMin , nFalloffCoeff ) ;
2016-07-25 23:22:37 +02:00
break ;
}
}
if ( ! found ) {
return InitError ( strprintf ( " Invalid deployment (%s) " , vDeploymentParams[0])) ;
}
}
}
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -dip3params " ) ) {
2021-03-26 13:11:11 +01:00
// Allow overriding dip3 parameters for testing
2019-04-25 17:39:04 +02:00
if ( ! chainparams . MineBlocksOnDemand ( ) ) {
return InitError ( " DIP3 parameters may only be overridden on regtest. " ) ;
}
2019-06-24 18:44:27 +02:00
std : : string strDIP3Params = gArgs . GetArg ( " -dip3params " , " " ) ;
2019-04-25 17:39:04 +02:00
std : : vector < std : : string > vDIP3Params ;
boost : : split ( vDIP3Params , strDIP3Params , boost : : is_any_of ( " : " ) ) ;
if ( vDIP3Params . size ( ) ! = 2 ) {
return InitError ( " DIP3 parameters malformed, expecting DIP3ActivationHeight:DIP3EnforcementHeight " ) ;
}
int nDIP3ActivationHeight , nDIP3EnforcementHeight ;
if ( ! ParseInt32 ( vDIP3Params [ 0 ] , & nDIP3ActivationHeight ) ) {
return InitError ( strprintf ( " Invalid nDIP3ActivationHeight (%s) " , vDIP3Params[0])) ;
}
if ( ! ParseInt32 ( vDIP3Params [ 1 ] , & nDIP3EnforcementHeight ) ) {
return InitError ( strprintf ( " Invalid nDIP3EnforcementHeight (%s) " , vDIP3Params[1])) ;
}
2017-05-09 09:29:12 +02:00
UpdateDIP3Parameters ( nDIP3ActivationHeight , nDIP3EnforcementHeight ) ;
2019-01-23 17:36:51 +01:00
}
2020-12-28 12:21:01 +01:00
if ( gArgs . IsArgSet ( " -dip8params " ) ) {
// Allow overriding dip8 activation height for testing
if ( ! chainparams . MineBlocksOnDemand ( ) ) {
return InitError ( " DIP8 activation height may only be overridden on regtest. " ) ;
}
UpdateDIP8Parameters ( gArgs . GetArg ( " -dip8params " , Params ( ) . GetConsensus ( ) . DIP0008Height ) ) ;
}
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -budgetparams " ) ) {
2018-08-11 00:36:17 +02:00
// Allow overriding budget parameters for testing
if ( ! chainparams . MineBlocksOnDemand ( ) ) {
return InitError ( " Budget parameters may only be overridden on regtest. " ) ;
}
2019-06-24 18:44:27 +02:00
std : : string strBudgetParams = gArgs . GetArg ( " -budgetparams " , " " ) ;
2018-08-11 00:36:17 +02:00
std : : vector < std : : string > vBudgetParams ;
boost : : split ( vBudgetParams , strBudgetParams , boost : : is_any_of ( " : " ) ) ;
if ( vBudgetParams . size ( ) ! = 3 ) {
return InitError ( " Budget parameters malformed, expecting masternodePaymentsStartBlock:budgetPaymentsStartBlock:superblockStartBlock " ) ;
}
int nMasternodePaymentsStartBlock , nBudgetPaymentsStartBlock , nSuperblockStartBlock ;
if ( ! ParseInt32 ( vBudgetParams [ 0 ] , & nMasternodePaymentsStartBlock ) ) {
return InitError ( strprintf ( " Invalid nMasternodePaymentsStartBlock (%s) " , vBudgetParams[0])) ;
}
if ( ! ParseInt32 ( vBudgetParams [ 1 ] , & nBudgetPaymentsStartBlock ) ) {
return InitError ( strprintf ( " Invalid nBudgetPaymentsStartBlock (%s) " , vBudgetParams[1])) ;
}
if ( ! ParseInt32 ( vBudgetParams [ 2 ] , & nSuperblockStartBlock ) ) {
return InitError ( strprintf ( " Invalid nSuperblockStartBlock (%s) " , vBudgetParams[2])) ;
}
2017-05-09 09:29:12 +02:00
UpdateBudgetParameters ( nMasternodePaymentsStartBlock , nBudgetPaymentsStartBlock , nSuperblockStartBlock ) ;
2018-08-11 00:36:17 +02:00
}
2018-10-25 09:16:38 +02:00
if ( chainparams . NetworkIDString ( ) = = CBaseChainParams : : DEVNET ) {
2019-06-24 18:44:27 +02:00
int nMinimumDifficultyBlocks = gArgs . GetArg ( " -minimumdifficultyblocks " , chainparams . GetConsensus ( ) . nMinimumDifficultyBlocks ) ;
int nHighSubsidyBlocks = gArgs . GetArg ( " -highsubsidyblocks " , chainparams . GetConsensus ( ) . nHighSubsidyBlocks ) ;
int nHighSubsidyFactor = gArgs . GetArg ( " -highsubsidyfactor " , chainparams . GetConsensus ( ) . nHighSubsidyFactor ) ;
2018-10-25 09:16:38 +02:00
UpdateDevnetSubsidyAndDiffParams ( nMinimumDifficultyBlocks , nHighSubsidyBlocks , nHighSubsidyFactor ) ;
2019-06-24 18:44:27 +02:00
} else if ( gArgs . IsArgSet ( " -minimumdifficultyblocks " ) | | gArgs . IsArgSet ( " -highsubsidyblocks " ) | | gArgs . IsArgSet ( " -highsubsidyfactor " ) ) {
2018-10-25 09:16:38 +02:00
return InitError ( " Difficulty and subsidy parameters may only be overridden on devnet. " ) ;
}
2019-02-05 15:46:05 +01:00
if ( chainparams . NetworkIDString ( ) = = CBaseChainParams : : DEVNET ) {
2021-01-21 21:29:14 +01:00
std : : string strLLMQTypeChainLocks = gArgs . GetArg ( " -llmqchainlocks " , Params ( ) . GetConsensus ( ) . llmqs . at ( Params ( ) . GetConsensus ( ) . llmqTypeChainLocks ) . name ) ;
std : : string strLLMQTypeInstantSend = gArgs . GetArg ( " -llmqinstantsend " , Params ( ) . GetConsensus ( ) . llmqs . at ( Params ( ) . GetConsensus ( ) . llmqTypeInstantSend ) . name ) ;
Consensus : : LLMQType llmqTypeChainLocks = Consensus : : LLMQ_NONE ;
Consensus : : LLMQType llmqTypeInstantSend = Consensus : : LLMQ_NONE ;
2019-02-05 15:46:05 +01:00
for ( const auto & p : Params ( ) . GetConsensus ( ) . llmqs ) {
2021-01-21 21:29:14 +01:00
if ( p . second . name = = strLLMQTypeChainLocks ) {
llmqTypeChainLocks = p . first ;
}
if ( p . second . name = = strLLMQTypeInstantSend ) {
llmqTypeInstantSend = p . first ;
2019-02-05 15:46:05 +01:00
}
}
2021-01-21 21:29:14 +01:00
if ( llmqTypeChainLocks = = Consensus : : LLMQ_NONE ) {
2019-02-05 15:46:05 +01:00
return InitError ( " Invalid LLMQ type specified for -llmqchainlocks. " ) ;
}
2021-01-21 21:29:14 +01:00
if ( llmqTypeInstantSend = = Consensus : : LLMQ_NONE ) {
return InitError ( " Invalid LLMQ type specified for -llmqinstantsend. " ) ;
}
UpdateDevnetLLMQChainLocks ( llmqTypeChainLocks ) ;
UpdateDevnetLLMQInstantSend ( llmqTypeInstantSend ) ;
2019-06-24 18:44:27 +02:00
} else if ( gArgs . IsArgSet ( " -llmqchainlocks " ) ) {
2019-02-05 15:46:05 +01:00
return InitError ( " LLMQ type for ChainLocks can only be overridden on devnet. " ) ;
2021-01-21 21:29:14 +01:00
} else if ( gArgs . IsArgSet ( " -llmqinstantsend " ) ) {
return InitError ( " LLMQ type for InstantSend can only be overridden on devnet. " ) ;
2019-02-05 15:46:05 +01:00
}
2020-02-25 17:06:10 +01:00
if ( chainparams . NetworkIDString ( ) = = CBaseChainParams : : DEVNET ) {
if ( gArgs . IsArgSet ( " -llmqdevnetparams " ) ) {
std : : string s = gArgs . GetArg ( " -llmqdevnetparams " , " " ) ;
std : : vector < std : : string > v ;
boost : : split ( v , s , boost : : is_any_of ( " : " ) ) ;
int size , threshold ;
if ( v . size ( ) ! = 2 | | ! ParseInt32 ( v [ 0 ] , & size ) | | ! ParseInt32 ( v [ 1 ] , & threshold ) ) {
return InitError ( " Invalid -llmqdevnetparams specified " ) ;
}
UpdateLLMQDevnetParams ( size , threshold ) ;
}
} else if ( gArgs . IsArgSet ( " -llmqdevnetparams " ) ) {
return InitError ( " LLMQ devnet params can only be overridden on devnet. " ) ;
}
2020-01-07 13:49:51 +01:00
if ( chainparams . NetworkIDString ( ) = = CBaseChainParams : : REGTEST ) {
if ( gArgs . IsArgSet ( " -llmqtestparams " ) ) {
std : : string s = gArgs . GetArg ( " -llmqtestparams " , " " ) ;
std : : vector < std : : string > v ;
boost : : split ( v , s , boost : : is_any_of ( " : " ) ) ;
int size , threshold ;
if ( v . size ( ) ! = 2 | | ! ParseInt32 ( v [ 0 ] , & size ) | | ! ParseInt32 ( v [ 1 ] , & threshold ) ) {
return InitError ( " Invalid -llmqtestparams specified " ) ;
}
UpdateLLMQTestParams ( size , threshold ) ;
}
} else if ( gArgs . IsArgSet ( " -llmqtestparams " ) ) {
return InitError ( " LLMQ test params can only be overridden on regtest. " ) ;
}
2021-02-01 17:10:19 +01:00
try {
const bool fRecoveryEnabled { llmq : : CLLMQUtils : : QuorumDataRecoveryEnabled ( ) } ;
2021-03-16 23:50:41 +01:00
const bool fQuorumVvecRequestsEnabled { llmq : : CLLMQUtils : : GetEnabledQuorumVvecSyncEntries ( ) . size ( ) > 0 } ;
2021-02-01 17:10:19 +01:00
if ( ! fRecoveryEnabled & & fQuorumVvecRequestsEnabled ) {
InitWarning ( " -llmq-qvvec-sync set but recovery is disabled due to -llmq-data-recovery=0 " ) ;
}
} catch ( const std : : invalid_argument & e ) {
return InitError ( e . what ( ) ) ;
}
2019-09-30 15:34:13 +02:00
if ( gArgs . IsArgSet ( " -maxorphantx " ) ) {
InitWarning ( " -maxorphantx is not supported anymore. Use -maxorphantxsize instead. " ) ;
}
2019-11-11 10:21:45 +01:00
if ( gArgs . IsArgSet ( " -masternode " ) ) {
InitWarning ( _ ( " -masternode option is deprecated and ignored, specifying -masternodeblsprivkey is enough to start this node as a masternode. " ) ) ;
}
2020-03-12 11:32:39 +01:00
if ( gArgs . IsArgSet ( " -masternodeblsprivkey " ) ) {
2020-03-31 07:21:12 +02:00
if ( ! gArgs . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) & & Params ( ) . RequireRoutableExternalIP ( ) ) {
2020-03-12 11:32:39 +01:00
return InitError ( " Masternode must accept connections from outside, set -listen=1 " ) ;
}
if ( ! gArgs . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ) {
return InitError ( " Masternode must have transaction index enabled, set -txindex=1 " ) ;
}
if ( ! gArgs . GetBoolArg ( " -peerbloomfilters " , DEFAULT_PEERBLOOMFILTERS ) ) {
return InitError ( " Masternode must have bloom filters enabled, set -peerbloomfilters=1 " ) ;
}
if ( gArgs . GetArg ( " -prune " , 0 ) > 0 ) {
return InitError ( " Masternode must have no pruning enabled, set -prune=0 " ) ;
}
if ( gArgs . GetArg ( " -maxconnections " , DEFAULT_MAX_PEER_CONNECTIONS ) < DEFAULT_MAX_PEER_CONNECTIONS ) {
return InitError ( strprintf ( " Masternode must be able to handle at least %d connections, set -maxconnections=%d " , DEFAULT_MAX_PEER_CONNECTIONS , DEFAULT_MAX_PEER_CONNECTIONS ) ) ;
}
2020-06-28 23:00:00 +02:00
if ( gArgs . GetBoolArg ( " -disablegovernance " , false ) ) {
return InitError ( _ ( " You can not disable governance validation on a masternode. " ) ) ;
2020-03-12 11:32:39 +01:00
}
}
2020-07-27 09:33:29 +02:00
if ( gArgs . IsArgSet ( " -litemode " ) ) {
InitWarning ( _ ( " -litemode is deprecated. " ) + ( gArgs . GetBoolArg ( " -litemode " , false ) ? ( " " + _ ( " Its replacement -disablegovernance has been forced instead. " ) ) : ( " " + _ ( " It has been replaced by -disablegovernance. " ) ) ) ) ;
gArgs . ForceRemoveArg ( " -litemode " ) ;
}
2020-07-09 01:28:30 +02:00
fDisableGovernance = gArgs . GetBoolArg ( " -disablegovernance " , false ) ;
LogPrintf ( " fDisableGovernance %d \n " , fDisableGovernance ) ;
if ( fDisableGovernance ) {
InitWarning ( _ ( " You are starting with governance validation disabled. " ) + ( fPruneMode ? " " + _ ( " This is expected because you are running a pruned node. " ) : " " ) ) ;
}
2016-12-01 01:07:21 +01:00
return true ;
}
2012-05-21 16:47:29 +02:00
2016-12-01 01:07:21 +01:00
static bool LockDataDirectory ( bool probeOnly )
{
2016-07-29 07:30:19 +02:00
// Make sure only a single Dash Core process is using the data directory.
2018-01-16 10:54:13 +01:00
fs : : path datadir = GetDataDir ( ) ;
2018-03-22 14:57:46 +01:00
if ( ! DirIsWritable ( datadir ) ) {
return InitError ( strprintf ( _ ( " Cannot write to data directory '%s'; check permissions. " ) , datadir . string ( ) ) ) ;
}
2018-01-16 10:54:13 +01:00
if ( ! LockDirectory ( datadir , " .lock " , probeOnly ) ) {
return InitError ( strprintf ( _ ( " Cannot obtain a lock on data directory %s. %s is probably already running. " ) , datadir . string ( ) , _ ( PACKAGE_NAME ) ) ) ;
2015-05-19 01:37:43 +02:00
}
2016-12-01 01:07:21 +01:00
return true ;
}
bool AppInitSanityChecks ( )
{
// ********************************************************* Step 4: sanity checks
// Initialize elliptic curve code
2017-07-20 20:16:28 +02:00
std : : string sha256_algo = SHA256AutoDetect ( ) ;
LogPrintf ( " Using the '%s' SHA256 implementation \n " , sha256_algo ) ;
2017-06-14 15:22:08 +02:00
RandomInit ( ) ;
2016-12-01 01:07:21 +01:00
ECC_Start ( ) ;
globalVerifyHandle . reset ( new ECCVerifyHandle ( ) ) ;
// Sanity check
if ( ! InitSanityCheck ( ) )
return InitError ( strprintf ( _ ( " Initialization sanity check failed. %s is shutting down. " ) , _ ( PACKAGE_NAME ) ) ) ;
// Probe the data directory lock to give an early error message, if possible
2017-07-17 17:12:00 +02:00
// We cannot hold the data directory lock here, as the forking for daemon() hasn't yet happened,
// and a fork will cause weird behavior to it.
2016-12-01 01:07:21 +01:00
return LockDataDirectory ( true ) ;
}
2017-07-17 17:12:00 +02:00
bool AppInitLockDataDirectory ( )
2016-12-01 01:07:21 +01: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-17 17:12:00 +02:00
return true ;
}
2015-07-03 07:55:45 +02:00
2018-01-30 12:34:11 +01:00
bool AppInitMain ( )
2017-07-17 17:12:00 +02:00
{
const CChainParams & chainparams = Params ( ) ;
// ********************************************************* Step 4a: application initialization
2014-09-20 10:56:25 +02:00
# ifndef WIN32
CreatePidFile ( GetPidFile ( ) , getpid ( ) ) ;
# endif
2018-05-01 04:13:30 +02:00
if ( g_logger - > m_print_to_file ) {
if ( gArgs . GetBoolArg ( " -shrinkdebugfile " , g_logger - > DefaultShrinkDebugFile ( ) ) ) {
2018-04-17 17:07:19 +02: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
2018-05-01 04:13:30 +02:00
g_logger - > ShrinkDebugFile ( ) ;
2018-04-17 17:07:19 +02:00
}
2021-06-08 04:19:35 +02:00
}
if ( ! g_logger - > StartLogging ( ) ) {
return InitError ( strprintf ( " Could not open debug log file %s " ,
g_logger - > m_file_path . string ( ) ) ) ;
2017-12-04 18:30:25 +01:00
}
2015-05-15 21:31:14 +02:00
2018-05-01 04:13:30 +02:00
if ( ! g_logger - > m_log_timestamps )
2018-03-10 14:08:15 +01:00
LogPrintf ( " Startup time: %s \n " , FormatISO8601DateTime ( GetTime ( ) ) ) ;
2014-01-16 16:15:27 +01:00
LogPrintf ( " Default data directory %s \n " , GetDefaultDataDir ( ) . string ( ) ) ;
2016-12-01 01:07:21 +01:00
LogPrintf ( " Using data directory %s \n " , GetDataDir ( ) . string ( ) ) ;
2018-09-10 15:37:20 +02:00
// Only log conf file usage message if conf file actually exists.
fs : : path config_file_path = GetConfigFile ( gArgs . GetArg ( " -conf " , BITCOIN_CONF_FILENAME ) ) ;
if ( fs : : exists ( config_file_path ) ) {
LogPrintf ( " Config file: %s \n " , config_file_path . string ( ) ) ;
} else if ( gArgs . IsArgSet ( " -conf " ) ) {
// Warn if no conf file exists at path provided by user
InitWarning ( strprintf ( _ ( " The specified config file %s does not exist \n " ) , config_file_path . string ( ) ) ) ;
} else {
// Not categorizing as "Warning" because it's the default behavior
LogPrintf ( " Config file: %s (not found, skipping) \n " , config_file_path . string ( ) ) ;
}
2017-01-06 16:47:05 +01:00
LogPrintf ( " Using at most %i automatic connections (%i file descriptors available) \n " , nMaxConnections , nFD ) ;
2011-05-14 20:10:21 +02:00
2018-01-19 17:44:27 +01:00
// Warn about relative -datadir path.
if ( gArgs . IsArgSet ( " -datadir " ) & & ! fs : : path ( gArgs . GetArg ( " -datadir " , " " ) ) . is_absolute ( ) ) {
2018-04-08 11:03:56 +02:00
LogPrintf ( " Warning: relative datadir option '%s' specified, which will be interpreted relative to the " /* Continued */
2018-01-19 17:44:27 +01:00
" current working directory '%s'. This is fragile, because if Dash Core 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 Dash Core is started while in a temporary directory. \n " ,
gArgs . GetArg ( " -datadir " , " " ) , fs : : current_path ( ) . string ( ) ) ;
}
2016-12-15 02:48:56 +01:00
InitSignatureCache ( ) ;
2017-06-29 20:04:07 +02:00
InitScriptExecutionCache ( ) ;
2016-12-15 02:48:56 +01:00
2019-11-02 22:13:06 +01:00
int script_threads = gArgs . GetArg ( " -par " , DEFAULT_SCRIPTCHECK_THREADS ) ;
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 ;
2021-06-16 15:03:04 +02:00
StartScriptCheckWorkerThreads ( script_threads ) ;
2012-12-01 23:04:14 +01:00
}
2018-09-30 19:01:33 +02:00
std : : vector < std : : string > vSporkAddresses ;
2017-05-15 07:30:09 +02:00
if ( gArgs . IsArgSet ( " -sporkaddr " ) ) {
vSporkAddresses = gArgs . GetArgs ( " -sporkaddr " ) ;
2018-09-30 19:01:33 +02:00
} else {
vSporkAddresses = Params ( ) . SporkAddresses ( ) ;
}
for ( const auto & address : vSporkAddresses ) {
if ( ! sporkManager . SetSporkAddress ( address ) ) {
return InitError ( _ ( " Invalid spork address specified with -sporkaddr " ) ) ;
}
}
2018-03-02 14:15:04 +01:00
2019-06-24 18:44:27 +02:00
int minsporkkeys = gArgs . GetArg ( " -minsporkkeys " , Params ( ) . MinSporkKeys ( ) ) ;
2018-09-30 19:01:33 +02:00
if ( ! sporkManager . SetMinSporkKeys ( minsporkkeys ) ) {
return InitError ( _ ( " Invalid minimum number of spork signers specified with -minsporkkeys " ) ) ;
}
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -sporkkey " ) ) { // spork priv key
if ( ! sporkManager . SetPrivKey ( gArgs . GetArg ( " -sporkkey " , " " ) ) ) {
2015-02-09 20:28:29 +01:00
return InitError ( _ ( " Unable to sign spork message, wrong key? " ) ) ;
2018-09-30 19:01:33 +02:00
}
2014-12-28 02:08:45 +01:00
}
2015-04-03 17:50:06 +02:00
// Start the lightweight task scheduler thread
CScheduler : : Function serviceLoop = boost : : bind ( & CScheduler : : serviceQueue , & scheduler ) ;
threadGroup . create_thread ( boost : : bind ( & TraceThread < CScheduler : : Function > , " scheduler " , serviceLoop ) ) ;
2017-07-11 09:30:36 +02:00
GetMainSignals ( ) . RegisterBackgroundSignalScheduler ( scheduler ) ;
2017-11-15 14:14:20 +01:00
GetMainSignals ( ) . RegisterWithMempoolSignals ( mempool ) ;
2017-07-11 09:30:36 +02:00
2021-01-14 20:39:34 +01:00
tableRPC . InitPlatformRestrictions ( ) ;
2017-11-23 22:06:00 +01: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 ) ;
2018-04-17 15:57:52 +02:00
g_wallet_init_interface . RegisterRPC ( tableRPC ) ;
2018-07-09 17:05:14 +02:00
# if ENABLE_ZMQ
RegisterZMQRPCCommands ( tableRPC ) ;
# endif
2017-11-23 22:06:00 +01:00
2014-10-29 18:08:31 +01:00
/* Start the RPC server already. It will be started in "warmup" mode
* and not really process calls already ( but it will signify connections
* that the server is there and will be ready later ) . Warmup mode will
* be disabled when initialisation is finished .
*/
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -server " , false ) )
2014-10-29 18:08:31 +01:00
{
2018-08-13 21:01:07 +02:00
uiInterface . InitMessage_connect ( SetRPCWarmupStatus ) ;
2018-01-30 12:34:11 +01:00
if ( ! AppInitServers ( ) )
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
return InitError ( _ ( " Unable to start HTTP server. See debug log for details. " ) ) ;
2014-10-29 18:08:31 +01:00
}
2014-12-28 02:08:45 +01:00
2020-04-18 11:59:40 +02:00
// ********************************************************* Step 5: verify wallet database integrity
2012-09-18 20:30:47 +02:00
2018-04-17 15:57:52 +02:00
if ( ! g_wallet_init_interface . InitAutoBackup ( ) ) return false ;
if ( ! g_wallet_init_interface . Verify ( ) ) return false ;
2014-12-26 12:53:29 +01:00
2016-09-21 12:27:47 +02:00
// Initialize KeePass Integration
2018-04-17 15:57:52 +02:00
g_wallet_init_interface . InitKeePass ( ) ;
2012-09-18 20:30:47 +02:00
// ********************************************************* Step 6: network initialization
2017-08-01 17:11:32 +02:00
// Note that we absolutely cannot open any actual connections
// until the very end ("start node") as the UTXO/block state
// is not yet setup and may end up being set up twice if we
// need to reindex later.
2012-05-21 16:47:29 +02:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
assert ( ! g_connman ) ;
2016-09-19 17:05:35 +02:00
g_connman = std : : unique_ptr < CConnman > ( new CConnman ( GetRand ( std : : numeric_limits < uint64_t > : : max ( ) ) , GetRand ( std : : numeric_limits < uint64_t > : : max ( ) ) ) ) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
CConnman & connman = * g_connman ;
2018-07-14 05:07:19 +02:00
peerLogic . reset ( new PeerLogicValidation ( & connman , scheduler , gArgs . GetBoolArg ( " -enablebip61 " , DEFAULT_ENABLE_BIP61 ) ) ) ;
2017-07-28 16:10:10 +02:00
RegisterValidationInterface ( peerLogic . get ( ) ) ;
2013-05-07 15:16:25 +02:00
2015-09-09 14:24:56 +02:00
// sanitize comments per BIP-0014, format user agent and check total size
2017-01-30 13:13:07 +01:00
std : : vector < std : : string > uacomments ;
2017-12-20 12:45:01 +01:00
if ( chainparams . NetworkIDString ( ) = = CBaseChainParams : : DEVNET ) {
// Add devnet name to user agent. This allows to disconnect nodes immediately if they don't belong to our own devnet
2020-04-29 12:16:37 +02:00
uacomments . push_back ( strprintf ( " devnet=%s " , gArgs . GetDevNetName ( ) ) ) ;
2017-12-20 12:45:01 +01:00
}
2017-06-27 14:22:54 +02:00
for ( const std : : string & cmt : gArgs . GetArgs ( " -uacomment " ) ) {
if ( cmt ! = SanitizeString ( cmt , SAFE_CHARS_UA_COMMENT ) )
return InitError ( strprintf ( _ ( " User Agent comment (%s) contains unsafe characters . " ), cmt)) ;
uacomments . push_back ( cmt ) ;
2015-09-09 14:24:56 +02:00
}
strSubVersion = FormatSubVersion ( CLIENT_NAME , CLIENT_VERSION , uacomments ) ;
2015-07-31 18:05:42 +02:00
if ( strSubVersion . size ( ) > MAX_SUBVERSION_LENGTH ) {
2015-10-22 18:09:19 +02:00
return InitError ( strprintf ( _ ( " Total length of network version string (%i) exceeds maximum length (%i). Reduce the number or size of uacomments. " ) ,
2015-07-31 18:05:42 +02:00
strSubVersion . size ( ) , MAX_SUBVERSION_LENGTH ) ) ;
}
2017-05-15 07:30:09 +02:00
if ( gArgs . IsArgSet ( " -onlynet " ) ) {
2012-05-21 16:47:29 +02:00
std : : set < enum Network > nets ;
2019-07-05 09:06:28 +02:00
for ( const std : : string & snet : gArgs . GetArgs ( " -onlynet " ) ) {
2012-05-21 16:47:29 +02:00
enum Network net = ParseNetwork ( snet ) ;
if ( net = = NET_UNROUTABLE )
2014-01-16 16:15:27 +01:00
return InitError ( strprintf ( _ ( " Unknown network specified in -onlynet: '%s' " ) , snet ) ) ;
2012-05-21 16:47:29 +02:00
nets . insert ( net ) ;
}
for ( int n = 0 ; n < NET_MAX ; n + + ) {
enum Network net = ( enum Network ) n ;
if ( ! nets . count ( net ) )
SetLimited ( net ) ;
}
}
2017-03-03 16:10:16 +01:00
// Check for host lookup allowed before parsing any network related parameters
2019-06-24 18:44:27 +02:00
fNameLookup = gArgs . GetBoolArg ( " -dns " , DEFAULT_NAME_LOOKUP ) ;
2017-03-03 16:10:16 +01:00
2019-06-24 18:44:27 +02:00
bool proxyRandomize = gArgs . GetBoolArg ( " -proxyrandomize " , DEFAULT_PROXYRANDOMIZE ) ;
2015-06-10 09:19:13 +02:00
// -proxy sets a proxy for all outgoing network traffic
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
2019-06-24 18:44:27 +02:00
std : : string proxyArg = gArgs . GetArg ( " -proxy " , " " ) ;
2020-04-16 07:21:49 +02:00
SetLimited ( NET_ONION ) ;
2015-06-10 09:19:13 +02:00
if ( proxyArg ! = " " & & proxyArg ! = " 0 " ) {
2017-03-03 16:10:16 +01:00
CService proxyAddr ;
if ( ! Lookup ( proxyArg . c_str ( ) , proxyAddr , 9050 , fNameLookup ) ) {
return InitError ( strprintf ( _ ( " Invalid -proxy address or hostname: '%s' " ) , proxyArg ) ) ;
}
proxyType addrProxy = proxyType ( proxyAddr , proxyRandomize ) ;
2012-05-24 19:02:21 +02:00
if ( ! addrProxy . IsValid ( ) )
2017-03-03 16:10:16 +01:00
return InitError ( strprintf ( _ ( " Invalid -proxy address or hostname: '%s' " ) , proxyArg ) ) ;
2012-05-24 19:02:21 +02:00
2014-11-24 00:12:50 +01:00
SetProxy ( NET_IPV4 , addrProxy ) ;
SetProxy ( NET_IPV6 , addrProxy ) ;
2020-04-16 07:21:49 +02:00
SetProxy ( NET_ONION , addrProxy ) ;
2014-06-11 13:20:59 +02:00
SetNameProxy ( addrProxy ) ;
2020-04-16 07:21:49 +02:00
SetLimited ( NET_ONION , false ) ; // by default, -proxy sets onion as reachable, unless -noonion later
2012-05-01 21:04:07 +02:00
}
2015-06-10 09:19:13 +02:00
// -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
// -noonion (or -onion=0) disables connecting to .onion entirely
// An empty string is used to not override the onion proxy (in which case it defaults to -proxy set above, or none)
2019-06-24 18:44:27 +02:00
std : : string onionArg = gArgs . GetArg ( " -onion " , " " ) ;
2015-06-10 09:19:13 +02:00
if ( onionArg ! = " " ) {
if ( onionArg = = " 0 " ) { // Handle -noonion/-onion=0
2020-04-16 07:21:49 +02:00
SetLimited ( NET_ONION ) ; // set onions as unreachable
2015-06-10 09:19:13 +02:00
} else {
2017-03-03 16:10:16 +01:00
CService onionProxy ;
if ( ! Lookup ( onionArg . c_str ( ) , onionProxy , 9050 , fNameLookup ) ) {
return InitError ( strprintf ( _ ( " Invalid -onion address or hostname: '%s' " ) , onionArg ) ) ;
}
proxyType addrOnion = proxyType ( onionProxy , proxyRandomize ) ;
2015-06-10 09:19:13 +02:00
if ( ! addrOnion . IsValid ( ) )
2017-03-03 16:10:16 +01:00
return InitError ( strprintf ( _ ( " Invalid -onion address or hostname: '%s' " ) , onionArg ) ) ;
2020-04-16 07:21:49 +02:00
SetProxy ( NET_ONION , addrOnion ) ;
SetLimited ( NET_ONION , false ) ;
2015-06-10 09:19:13 +02:00
}
2012-05-24 19:02:21 +02:00
}
// see Step 2: parameter interactions for more information about these
2019-06-24 18:44:27 +02:00
fListen = gArgs . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) ;
fDiscover = gArgs . GetBoolArg ( " -discover " , true ) ;
fRelayTxes = ! gArgs . GetBoolArg ( " -blocksonly " , DEFAULT_BLOCKSONLY ) ;
2012-05-17 04:11:19 +02:00
2017-06-27 14:22:54 +02:00
for ( const std : : string & strAddr : gArgs . GetArgs ( " -externalip " ) ) {
CService addrLocal ;
if ( Lookup ( strAddr . c_str ( ) , addrLocal , GetListenPort ( ) , fNameLookup ) & & addrLocal . IsValid ( ) )
AddLocal ( addrLocal , LOCAL_MANUAL ) ;
else
return InitError ( ResolveErrMsg ( " externalip " , strAddr ) ) ;
2012-05-21 16:47:29 +02:00
}
2021-05-18 18:30:48 +02:00
// Read asmap file if configured
if ( gArgs . IsArgSet ( " -asmap " ) ) {
fs : : path asmap_path = fs : : path ( gArgs . GetArg ( " -asmap " , " " ) ) ;
if ( asmap_path . empty ( ) ) {
asmap_path = DEFAULT_ASMAP_FILENAME ;
}
if ( ! asmap_path . is_absolute ( ) ) {
asmap_path = GetDataDir ( ) / asmap_path ;
}
if ( ! fs : : exists ( asmap_path ) ) {
InitError ( strprintf ( _ ( " Could not find asmap file %s " ) , asmap_path ) ) ;
return false ;
}
std : : vector < bool > asmap = CAddrMan : : DecodeAsmap ( asmap_path ) ;
if ( asmap . size ( ) = = 0 ) {
InitError ( strprintf ( _ ( " Could not parse asmap file %s " ) , asmap_path ) ) ;
return false ;
}
const uint256 asmap_version = SerializeHash ( asmap ) ;
2020-01-29 22:55:40 +01:00
g_connman - > SetAsmap ( std : : move ( asmap ) ) ;
2021-05-18 18:30:48 +02:00
LogPrintf ( " Using asmap version %s for IP bucketing \n " , asmap_version . ToString ( ) ) ;
} else {
LogPrintf ( " Using /16 prefix for IP bucketing \n " ) ;
}
2014-11-18 18:06:32 +01:00
# if ENABLE_ZMQ
2018-07-09 17:05:14 +02:00
g_zmq_notification_interface = CZMQNotificationInterface : : Create ( ) ;
2014-11-18 18:06:32 +01:00
2018-07-09 17:05:14 +02:00
if ( g_zmq_notification_interface ) {
RegisterValidationInterface ( g_zmq_notification_interface ) ;
2014-11-18 18:06:32 +01:00
}
# endif
2016-03-02 22:20:04 +01:00
2017-09-19 16:51:38 +02:00
pdsNotificationInterface = new CDSNotificationInterface ( connman ) ;
2016-03-02 22:20:04 +01:00
RegisterValidationInterface ( pdsNotificationInterface ) ;
2016-09-19 16:46:18 +02:00
uint64_t nMaxOutboundLimit = 0 ; //unlimited unless -maxuploadtarget is set
uint64_t nMaxOutboundTimeframe = MAX_UPLOAD_TIMEFRAME ;
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -maxuploadtarget " ) ) {
nMaxOutboundLimit = gArgs . GetArg ( " -maxuploadtarget " , DEFAULT_MAX_UPLOAD_TARGET ) * 1024 * 1024 ;
2015-09-02 17:03:27 +02:00
}
2014-11-18 18:06:32 +01:00
2020-07-09 01:28:30 +02:00
// ********************************************************* Step 7a: Load sporks
2018-12-20 14:31:23 +01:00
2020-06-13 20:18:31 +02:00
uiInterface . InitMessage ( _ ( " Loading sporks cache... " ) ) ;
CFlatDB < CSporkManager > flatdb6 ( " sporks.dat " , " magicSporkCache " ) ;
if ( ! flatdb6 . Load ( sporkManager ) ) {
return InitError ( _ ( " Failed to load sporks cache from " ) + " \n " + ( GetDataDir ( ) / " sporks.dat " ) . string ( ) ) ;
2018-12-20 14:31:23 +01:00
}
// ********************************************************* Step 7b: load block chain
2012-05-21 16:47:29 +02:00
2019-06-24 18:44:27 +02:00
fReindex = gArgs . GetBoolArg ( " -reindex " , false ) ;
bool fReindexChainState = gArgs . GetBoolArg ( " -reindex-chainstate " , false ) ;
2012-10-21 21:23:13 +02:00
2012-11-04 17:11:48 +01:00
// cache size calculations
2019-06-24 18:44:27 +02:00
int64_t nTotalCache = ( gArgs . GetArg ( " -dbcache " , nDefaultDbCache ) < < 20 ) ;
2015-05-04 01:56:42 +02:00
nTotalCache = std : : max ( nTotalCache , nMinDbCache < < 20 ) ; // total cache cannot be less than nMinDbCache
2016-08-17 12:50:28 +02:00
nTotalCache = std : : min ( nTotalCache , nMaxDbCache < < 20 ) ; // total cache cannot be greater than nMaxDbcache
2021-05-25 12:48:04 +02:00
int64_t nBlockTreeDBCache = std : : min ( nTotalCache / 8 , nMaxBlockDBCache < < 20 ) ;
2012-11-04 17:11:48 +01:00
nTotalCache - = nBlockTreeDBCache ;
2021-05-25 12:48:04 +02:00
int64_t nTxIndexCache = std : : min ( nTotalCache / 8 , gArgs . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ? nMaxTxIndexCache < < 20 : 0 ) ;
nTotalCache - = nTxIndexCache ;
2015-05-04 01:56:42 +02:00
int64_t nCoinDBCache = std : : min ( nTotalCache / 2 , ( nTotalCache / 4 ) + ( 1 < < 23 ) ) ; // use 25%-50% of the remainder for disk cache
2016-07-06 07:46:41 +02:00
nCoinDBCache = std : : min ( nCoinDBCache , nMaxCoinsDBCache < < 20 ) ; // cap total coins db cache
2012-11-04 17:11:48 +01:00
nTotalCache - = nCoinDBCache ;
2015-05-04 01:56:42 +02:00
nCoinCacheUsage = nTotalCache ; // the rest goes to in-memory cache
2019-06-24 18:44:27 +02:00
int64_t nMempoolSizeMax = gArgs . GetArg ( " -maxmempool " , DEFAULT_MAX_MEMPOOL_SIZE ) * 1000000 ;
2018-05-24 14:28:23 +02:00
int64_t nEvoDbCache = 1024 * 1024 * 16 ; // TODO
2015-05-04 01:56:42 +02:00
LogPrintf ( " Cache configuration: \n " ) ;
LogPrintf ( " * Using %.1fMiB for block index database \n " , nBlockTreeDBCache * ( 1.0 / 1024 / 1024 ) ) ;
2021-05-25 12:48:04 +02:00
if ( gArgs . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ) {
LogPrintf ( " * Using %.1fMiB for transaction index database \n " , nTxIndexCache * ( 1.0 / 1024 / 1024 ) ) ;
}
2015-05-04 01:56:42 +02:00
LogPrintf ( " * Using %.1fMiB for chain state database \n " , nCoinDBCache * ( 1.0 / 1024 / 1024 ) ) ;
2017-01-05 22:46:10 +01:00
LogPrintf ( " * Using %.1fMiB for in-memory UTXO set (plus up to %.1fMiB of unused mempool space) \n " , nCoinCacheUsage * ( 1.0 / 1024 / 1024 ) , nMempoolSizeMax * ( 1.0 / 1024 / 1024 ) ) ;
2012-11-04 17:11:48 +01:00
2013-02-16 17:58:45 +01:00
bool fLoaded = false ;
2018-05-13 22:57:12 +02:00
int64_t nStart = GetTimeMillis ( ) ;
2021-06-21 00:49:59 +02:00
while ( ! fLoaded & & ! ShutdownRequested ( ) ) {
2013-02-16 17:58:45 +01:00
bool fReset = fReindex ;
std : : string strLoadError ;
2013-01-11 22:57:22 +01:00
2013-02-16 17:58:45 +01:00
uiInterface . InitMessage ( _ ( " Loading block index... " ) ) ;
2012-07-06 16:33:34 +02:00
2018-03-13 19:04:28 +01:00
LOCK ( cs_main ) ;
2013-02-16 17:58:45 +01:00
do {
2018-07-05 18:07:21 +02:00
const int64_t load_block_index_start_time = GetTimeMillis ( ) ;
2013-02-16 17:58:45 +01:00
try {
UnloadBlockIndex ( ) ;
2017-11-09 21:22:08 +01:00
pcoinsTip . reset ( ) ;
pcoinsdbview . reset ( ) ;
pcoinscatcher . reset ( ) ;
2018-02-12 10:11:28 +01: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-11-09 21:22:08 +01:00
pblocktree . reset ( new CBlockTreeDB ( nBlockTreeDBCache , false , fReset ) ) ;
2018-11-23 15:42:09 +01:00
llmq : : DestroyLLMQSystem ( ) ;
2020-03-16 20:06:21 +01:00
// Same logic as above with pblocktree
evoDb . reset ( ) ;
2017-11-09 21:22:08 +01:00
evoDb . reset ( new CEvoDB ( nEvoDbCache , false , fReset | | fReindexChainState ) ) ;
2020-03-16 20:06:21 +01:00
deterministicMNManager . reset ( ) ;
2017-11-09 21:22:08 +01:00
deterministicMNManager . reset ( new CDeterministicMNManager ( * evoDb ) ) ;
2018-05-24 14:28:23 +02:00
2020-06-09 05:53:16 +02:00
llmq : : InitLLMQSystem ( * evoDb , false , fReset | | fReindexChainState ) ;
2013-02-16 17:58:45 +01:00
2017-08-07 08:57:45 +02:00
if ( fReset ) {
2013-02-16 17:58:45 +01:00
pblocktree - > WriteReindexing ( true ) ;
2015-06-02 21:24:53 +02: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 20:27:44 +01:00
if ( fPruneMode )
2015-06-02 21:24:53 +02: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 20:27:44 +01:00
}
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
2021-06-21 00:49:59 +02:00
if ( ShutdownRequested ( ) ) break ;
2013-02-16 17:58:45 +01:00
2021-05-25 12:48:04 +02:00
// LoadBlockIndex will load fHavePruned if we've ever removed a
// block file from disk.
2017-08-07 08:57:45 +02:00
// Note that it also sets fReindex based on the disk flag!
// From here on out fReindex and fReset mean something different!
2016-11-02 21:09:24 +01:00
if ( ! LoadBlockIndex ( chainparams ) ) {
2013-02-16 17:58:45 +01:00
strLoadError = _ ( " Error loading block database " ) ;
break ;
}
2021-05-25 12:48:04 +02:00
if ( ! fDisableGovernance & & ! gArgs . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX )
2020-03-12 11:32:49 +01:00
& & chainparams . NetworkIDString ( ) ! = CBaseChainParams : : REGTEST ) { // TODO remove this when pruning is fixed. See https://github.com/dashpay/dash/pull/1817 and https://github.com/dashpay/dash/pull/1743
2020-06-28 23:00:00 +02:00
return InitError ( _ ( " Transaction index can't be disabled with governance validation enabled. Either start with -disablegovernance command line switch or enable transaction index. " ) ) ;
2020-03-12 11:32:49 +01:00
}
2013-05-12 12:03:32 +02:00
// If the loaded chain has a wrong genesis, bail out immediately
// (we're likely using a testnet datadir, or the other way around).
2018-03-13 19:04:28 +01:00
if ( ! mapBlockIndex . empty ( ) & & ! LookupBlockIndex ( chainparams . GetConsensus ( ) . hashGenesisBlock ) ) {
2013-05-12 12:03:32 +02:00
return InitError ( _ ( " Incorrect or no genesis block found. Wrong datadir for network? " ) ) ;
2018-03-13 19:04:28 +01:00
}
2013-05-12 12:03:32 +02:00
2018-02-01 18:05:35 +01:00
if ( ! chainparams . GetConsensus ( ) . hashDevnetGenesisBlock . IsNull ( ) & & ! mapBlockIndex . empty ( ) & & mapBlockIndex . count ( chainparams . GetConsensus ( ) . hashDevnetGenesisBlock ) = = 0 )
2017-12-20 12:45:01 +01:00
return InitError ( _ ( " Incorrect or no devnet genesis block found. Wrong datadir for devnet specified? " ) ) ;
2019-10-31 18:30:42 +01:00
// Check for changed -addressindex state
if ( fAddressIndex ! = gArgs . GetBoolArg ( " -addressindex " , DEFAULT_ADDRESSINDEX ) ) {
strLoadError = _ ( " You need to rebuild the database using -reindex to change -addressindex " ) ;
break ;
}
// Check for changed -timestampindex state
if ( fTimestampIndex ! = gArgs . GetBoolArg ( " -timestampindex " , DEFAULT_TIMESTAMPINDEX ) ) {
strLoadError = _ ( " You need to rebuild the database using -reindex to change -timestampindex " ) ;
break ;
}
// Check for changed -spentindex state
if ( fSpentIndex ! = gArgs . GetBoolArg ( " -spentindex " , DEFAULT_SPENTINDEX ) ) {
strLoadError = _ ( " You need to rebuild the database using -reindex to change -spentindex " ) ;
break ;
}
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 20:27:44 +01: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 ) {
strLoadError = _ ( " You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain " ) ;
break ;
}
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
// At this point blocktree args are consistent with what's on disk.
2017-08-07 08:57:45 +02: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.
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
if ( ! fReindex & & ! LoadGenesisBlock ( chainparams ) ) {
strLoadError = _ ( " Error initializing block database " ) ;
break ;
}
// At this point we're either in reindex or we've loaded a useful
// block tree into mapBlockIndex!
2017-11-09 21:22:08 +01:00
pcoinsdbview . reset ( new CCoinsViewDB ( nCoinDBCache , false , fReset | | fReindexChainState ) ) ;
pcoinscatcher . reset ( new CCoinsViewErrorCatcher ( pcoinsdbview . get ( ) ) ) ;
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
// If necessary, upgrade from older database format.
// This is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
if ( ! pcoinsdbview - > Upgrade ( ) ) {
strLoadError = _ ( " Error upgrading chainstate database " ) ;
break ;
}
// ReplayBlocks is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
2017-11-09 21:22:08 +01:00
if ( ! ReplayBlocks ( chainparams , pcoinsdbview . get ( ) ) ) {
2017-06-28 18:24:32 +02:00
strLoadError = _ ( " Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate. " ) ;
break ;
}
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
// The on-disk coinsdb is now in a good state, create the cache
2017-11-09 21:22:08 +01:00
pcoinsTip . reset ( new CCoinsViewCache ( pcoinscatcher . get ( ) ) ) ;
2017-06-28 18:24:32 +02:00
2020-05-11 14:33:21 +02:00
// flush evodb
if ( ! evoDb - > CommitRootTransaction ( ) ) {
strLoadError = _ ( " Failed to commit EvoDB " ) ;
break ;
}
2017-08-07 08:57:45 +02:00
bool is_coinsview_empty = fReset | | fReindexChainState | | pcoinsTip - > GetBestBlock ( ) . IsNull ( ) ;
if ( ! is_coinsview_empty ) {
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
// LoadChainTip sets chainActive based on pcoinsTip's best block
if ( ! LoadChainTip ( chainparams ) ) {
strLoadError = _ ( " Error initializing block database " ) ;
break ;
}
assert ( chainActive . Tip ( ) ! = NULL ) ;
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 20:27:44 +01:00
}
2015-07-28 23:42:03 +02:00
2020-09-25 18:19:58 +02:00
if ( is_coinsview_empty & & ! evoDb - > IsEmpty ( ) ) {
// EvoDB processed some blocks earlier but we have no blocks anymore, something is wrong
strLoadError = _ ( " Error initializing block database " ) ;
break ;
}
if ( ! deterministicMNManager - > UpgradeDBIfNeeded ( ) | | ! llmq : : quorumBlockProcessor - > UpgradeDB ( ) ) {
2020-06-11 19:52:58 +02:00
strLoadError = _ ( " Error upgrading evo database " ) ;
break ;
}
2019-09-22 16:28:59 +02:00
2017-08-07 08:57:45 +02:00
if ( ! is_coinsview_empty ) {
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
uiInterface . InitMessage ( _ ( " Verifying blocks... " ) ) ;
if ( fHavePruned & & gArgs . GetArg ( " -checkblocks " , DEFAULT_CHECKBLOCKS ) > MIN_BLOCKS_TO_KEEP ) {
2020-06-12 07:01:11 +02:00
LogPrintf ( " Prune: pruned datadir may not have more than %d blocks; only checking available blocks \n " ,
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
MIN_BLOCKS_TO_KEEP ) ;
}
2018-03-13 19:04:28 +01:00
CBlockIndex * tip = chainActive . Tip ( ) ;
RPCNotifyBlockChange ( true , tip ) ;
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. "
" Only rebuild the block database if you are sure that your computer's date and time are correct " ) ;
break ;
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
}
2017-11-09 21:22:08 +01:00
if ( ! CVerifyDB ( ) . VerifyDB ( chainparams , pcoinsdbview . get ( ) , gArgs . GetArg ( " -checklevel " , DEFAULT_CHECKLEVEL ) ,
Merge #10758: Fix some chainstate-init-order bugs.
c0025d0 Fix segfault when shutting down before fully loading (Matt Corallo)
1385697 Order chainstate init more logically. (Matt Corallo)
ff3a219 Call RewindBlockIndex even if we're about to run -reindex-chainstate (Matt Corallo)
b0f3249 More user-friendly error message if UTXO DB runs ahead of block DB (Matt Corallo)
eda888e Fix some LoadChainTip-related init-order bugs. (Matt Corallo)
Pull request description:
This does a number of things to clean up chainstate init order,
fixing some issues as it goes:
* Order chainstate init more logically - first all of the
blocktree-related loading, then coinsdb, then
pcoinsTip/chainActive. Only create objects as needed.
* More clearly document exactly what is and isn't called in
-reindex and -reindex-chainstate both with comments noting
calls as no-ops and by adding if guards.
* Move the writing of fTxIndex to LoadBlockIndex - this fixes a
bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where
InitBlockIndex was writing to fTxIndex which had not yet been
checked (because LoadChainTip hadn't yet initialized the
chainActive, which would otherwise have resulted in
InitBlockIndex being a NOP), allowing you to modify -txindex
without reindex, potentially corrupting your chainstate!
* Rename InitBlockIndex to LoadGenesisBlock, which is now a more
natural name for it. Also check mapBlockIndex instead of
chainActive, fixing a bug where we'd write the genesis block out
on every start.
* Move LoadGenesisBlock further down in init. This is a more logical
location for it, as it is after all of the blockindex-related
loading and checking, but before any of the UTXO-related loading
and checking.
* Give LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.
* Calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
* Move all of the VerifyDB()-related stuff into a -reindex +
-reindex-chainstate if guard. It couldn't do anything useful
as chainActive.Tip() would be null at this point anyway.
Tree-SHA512: 3c96ee7ed44f4130bee3479a40c5cd99a619fda5e309c26d60b54feab9f6ec60fabab8cf47a049c9cf15e88999b2edb7f16cbe6819e97273560b201a89d90762
2017-08-01 12:49:22 +02:00
gArgs . GetArg ( " -checkblocks " , DEFAULT_CHECKBLOCKS ) ) ) {
strLoadError = _ ( " Corrupted block database detected " ) ;
break ;
}
2021-01-21 17:18:25 +01:00
ResetBlockFailureFlags ( nullptr ) ;
2013-02-16 17:58:45 +01:00
}
2014-12-07 13:29:06 +01:00
} catch ( const std : : exception & e ) {
2019-05-22 23:51:39 +02:00
LogPrintf ( " %s \n " , e . what ( ) ) ;
2013-02-16 17:58:45 +01:00
strLoadError = _ ( " Error opening block database " ) ;
break ;
}
2013-01-03 15:29:07 +01:00
2013-02-16 17:58:45 +01:00
fLoaded = true ;
2018-07-05 18:07:21 +02:00
LogPrintf ( " block index %15dms \n " , GetTimeMillis ( ) - load_block_index_start_time ) ;
2013-02-16 17:58:45 +01:00
} while ( false ) ;
2021-06-21 00:49:59 +02:00
if ( ! fLoaded & & ! ShutdownRequested ( ) ) {
2013-02-16 17:58:45 +01:00
// first suggest a reindex
if ( ! fReset ) {
2017-09-09 09:04:02 +02:00
bool fRet = uiInterface . ThreadSafeQuestion (
2013-05-13 08:26:29 +02:00
strLoadError + " . \n \n " + _ ( " Do you want to rebuild the block database now? " ) ,
2017-09-09 09:04:02 +02:00
strLoadError + " . \n Please restart with -reindex or -reindex-chainstate to recover. " ,
2013-02-16 17:58:45 +01:00
" " , CClientUIInterface : : MSG_ERROR | CClientUIInterface : : BTN_ABORT ) ;
if ( fRet ) {
fReindex = true ;
2021-06-21 00:49:59 +02:00
AbortShutdown ( ) ;
2013-02-16 17:58:45 +01:00
} else {
2013-09-18 12:38:08 +02:00
LogPrintf ( " Aborted block database rebuild. Exiting. \n " ) ;
2013-02-16 17:58:45 +01:00
return false ;
}
} else {
return InitError ( strLoadError ) ;
}
}
}
2012-04-18 13:30:24 +02:00
2013-12-16 23:36:22 +01:00
// As LoadBlockIndex can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit.
2012-04-18 13:30:24 +02:00
// As the program has not fully started yet, Shutdown() is possibly overkill.
2021-06-21 00:49:59 +02:00
if ( ShutdownRequested ( ) ) {
2013-09-18 12:38:08 +02:00
LogPrintf ( " Shutdown requested. Exiting. \n " ) ;
2012-04-18 13:30:24 +02:00
return false ;
}
2011-05-14 20:10:21 +02:00
2017-04-06 20:19:21 +02:00
fs : : path est_path = GetDataDir ( ) / FEE_ESTIMATES_FILENAME ;
CAutoFile est_filein ( fsbridge : : fopen ( est_path , " rb " ) , SER_DISK , CLIENT_VERSION ) ;
2014-06-27 14:41:11 +02:00
// Allowed to fail as this file IS missing on first startup.
2014-10-20 12:45:50 +02:00
if ( ! est_filein . IsNull ( ) )
2017-04-20 21:16:19 +02:00
: : feeEstimator . Read ( est_filein ) ;
2014-09-18 14:08:43 +02:00
fFeeEstimatesInitialized = true ;
2012-02-20 20:50:26 +01:00
2021-05-25 12:48:04 +02:00
// ********************************************************* Step 8: start indexers
if ( gArgs . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ) {
2018-06-07 17:59:30 +02:00
g_txindex = MakeUnique < TxIndex > ( nTxIndexCache , false , fReindex ) ;
2021-05-25 12:48:04 +02:00
g_txindex - > Start ( ) ;
}
// ********************************************************* Step 9: load wallet
2018-04-17 15:57:52 +02:00
if ( ! g_wallet_init_interface . Open ( ) ) return false ;
2015-06-30 19:22:48 +02:00
2020-01-04 12:21:00 +01:00
// As InitLoadWallet can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit.
2021-06-21 00:49:59 +02:00
if ( ShutdownRequested ( ) )
2020-01-04 12:21:00 +01:00
{
LogPrintf ( " Shutdown requested. Exiting. \n " ) ;
return false ;
}
2021-05-25 12:48:04 +02:00
// ********************************************************* Step 10: data directory maintenance
2020-01-04 12:21:00 +01:00
2018-11-01 22:58:01 +01:00
2015-06-30 19:22:48 +02: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 " ) ;
2017-07-05 05:45:23 +02:00
nLocalServices = ServiceFlags ( nLocalServices & ~ NODE_NETWORK ) ;
2015-06-30 19:22:48 +02:00
if ( ! fReindex ) {
2015-10-19 20:43:04 +02:00
uiInterface . InitMessage ( _ ( " Pruning blockstore... " ) ) ;
2015-06-30 19:22:48 +02:00
PruneAndFlush ( ) ;
}
}
2020-01-04 12:21:00 +01:00
// As PruneAndFlush can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit.
2021-06-21 00:49:59 +02:00
if ( ShutdownRequested ( ) )
2020-01-04 12:21:00 +01:00
{
LogPrintf ( " Shutdown requested. Exiting. \n " ) ;
return false ;
}
2019-03-25 07:14:57 +01:00
// ********************************************************* Step 10a: Prepare Masternode related stuff
2019-11-11 10:21:45 +01:00
fMasternodeMode = false ;
std : : string strMasterNodeBLSPrivKey = gArgs . GetArg ( " -masternodeblsprivkey " , " " ) ;
if ( ! strMasterNodeBLSPrivKey . empty ( ) ) {
auto binKey = ParseHex ( strMasterNodeBLSPrivKey ) ;
2020-12-15 00:26:30 +01:00
CBLSSecretKey keyOperator ( binKey ) ;
2019-11-11 10:21:45 +01:00
if ( ! keyOperator . IsValid ( ) ) {
return InitError ( _ ( " Invalid masternodeblsprivkey. Please see documentation. " ) ) ;
}
fMasternodeMode = true ;
activeMasternodeInfo . blsKeyOperator = std : : make_unique < CBLSSecretKey > ( keyOperator ) ;
activeMasternodeInfo . blsPubKeyOperator = std : : make_unique < CBLSPublicKey > ( activeMasternodeInfo . blsKeyOperator - > GetPublicKey ( ) ) ;
LogPrintf ( " MASTERNODE: \n " ) ;
LogPrintf ( " blsPubKeyOperator: %s \n " , keyOperator . GetPublicKey ( ) . ToString ( ) ) ;
}
2015-07-16 12:00:16 +02:00
2018-01-26 02:11:01 +01:00
if ( fMasternodeMode ) {
2019-03-25 07:14:57 +01:00
// Create and register activeMasternodeManager, will init later in ThreadImport
2019-01-03 21:08:34 +01:00
activeMasternodeManager = new CActiveMasternodeManager ( ) ;
2018-02-15 14:33:04 +01:00
RegisterValidationInterface ( activeMasternodeManager ) ;
2016-10-25 15:46:38 +02:00
}
2018-10-21 21:45:16 +02:00
if ( activeMasternodeInfo . blsKeyOperator = = nullptr ) {
activeMasternodeInfo . blsKeyOperator = std : : make_unique < CBLSSecretKey > ( ) ;
}
if ( activeMasternodeInfo . blsPubKeyOperator = = nullptr ) {
activeMasternodeInfo . blsPubKeyOperator = std : : make_unique < CBLSPublicKey > ( ) ;
}
2021-03-17 23:36:11 +01:00
// ********************************************************* Step 10b: setup CoinJoin
2018-11-01 22:58:01 +01:00
2021-03-17 23:36:11 +01:00
g_wallet_init_interface . InitCoinJoinSettings ( ) ;
CCoinJoin : : InitStandardDenominations ( ) ;
2016-05-30 08:22:08 +02:00
2019-07-09 16:50:08 +02:00
// ********************************************************* Step 10b: Load cache data
2016-05-30 08:22:08 +02:00
// LOAD SERIALIZED DAT FILES INTO DATA CACHES FOR INTERNAL USE
2020-06-13 20:18:31 +02:00
bool fLoadCacheFiles = ! ( fReindex | | fReindexChainState ) ;
2020-01-10 11:24:21 +01:00
{
LOCK ( cs_main ) ;
// was blocks/chainstate deleted?
if ( chainActive . Tip ( ) = = nullptr ) {
fLoadCacheFiles = false ;
}
}
fs : : path pathDB = GetDataDir ( ) ;
std : : string strDBName ;
strDBName = " mncache.dat " ;
uiInterface . InitMessage ( _ ( " Loading masternode cache... " ) ) ;
CFlatDB < CMasternodeMetaMan > flatdb1 ( strDBName , " magicMasternodeCache " ) ;
if ( fLoadCacheFiles ) {
2019-01-03 21:08:34 +01:00
if ( ! flatdb1 . Load ( mmetaman ) ) {
2018-03-29 17:08:00 +02:00
return InitError ( _ ( " Failed to load masternode cache from " ) + " \n " + ( pathDB / strDBName ) . string ( ) ) ;
}
2020-01-10 11:24:21 +01:00
} else {
CMasternodeMetaMan mmetamanTmp ;
if ( ! flatdb1 . Dump ( mmetamanTmp ) ) {
return InitError ( _ ( " Failed to clear masternode cache at " ) + " \n " + ( pathDB / strDBName ) . string ( ) ) ;
}
}
2018-03-29 17:08:00 +02:00
2020-01-10 11:24:21 +01:00
strDBName = " governance.dat " ;
uiInterface . InitMessage ( _ ( " Loading governance cache... " ) ) ;
CFlatDB < CGovernanceManager > flatdb3 ( strDBName , " magicGovernanceCache " ) ;
2020-06-28 23:00:00 +02:00
if ( fLoadCacheFiles & & ! fDisableGovernance ) {
2019-01-03 10:17:43 +01:00
if ( ! flatdb3 . Load ( governance ) ) {
return InitError ( _ ( " Failed to load governance cache from " ) + " \n " + ( pathDB / strDBName ) . string ( ) ) ;
2016-12-26 16:33:28 +01:00
}
2019-01-03 10:17:43 +01:00
governance . InitOnLoad ( ) ;
2020-01-10 11:24:21 +01:00
} else {
CGovernanceManager governanceTmp ;
if ( ! flatdb3 . Dump ( governanceTmp ) ) {
return InitError ( _ ( " Failed to clear governance cache at " ) + " \n " + ( pathDB / strDBName ) . string ( ) ) ;
}
}
2016-05-30 08:22:08 +02:00
2020-01-10 11:24:21 +01:00
strDBName = " netfulfilled.dat " ;
uiInterface . InitMessage ( _ ( " Loading fulfilled requests cache... " ) ) ;
CFlatDB < CNetFulfilledRequestManager > flatdb4 ( strDBName , " magicFulfilledCache " ) ;
if ( fLoadCacheFiles ) {
2018-03-29 17:08:00 +02:00
if ( ! flatdb4 . Load ( netfulfilledman ) ) {
return InitError ( _ ( " Failed to load fulfilled requests cache from " ) + " \n " + ( pathDB / strDBName ) . string ( ) ) ;
2016-12-26 16:33:28 +01:00
}
2020-01-10 11:24:21 +01:00
} else {
CNetFulfilledRequestManager netfulfilledmanTmp ;
if ( ! flatdb4 . Dump ( netfulfilledmanTmp ) ) {
return InitError ( _ ( " Failed to clear fulfilled requests cache at " ) + " \n " + ( pathDB / strDBName ) . string ( ) ) ;
}
2016-11-16 16:37:40 +01:00
}
2016-05-30 08:22:08 +02:00
2019-07-09 16:50:08 +02:00
// ********************************************************* Step 10c: schedule Dash-specific tasks
2018-07-16 14:47:37 +02:00
2020-12-09 21:23:36 +01:00
scheduler . scheduleEvery ( std : : bind ( & CNetFulfilledRequestManager : : DoMaintenance , std : : ref ( netfulfilledman ) ) , 60 * 1000 ) ;
scheduler . scheduleEvery ( std : : bind ( & CMasternodeSync : : DoMaintenance , std : : ref ( masternodeSync ) , std : : ref ( * g_connman ) ) , 1 * 1000 ) ;
scheduler . scheduleEvery ( std : : bind ( & CMasternodeUtils : : DoMaintenance , std : : ref ( * g_connman ) ) , 1 * 1000 ) ;
2018-07-16 14:47:37 +02:00
2020-06-28 23:00:00 +02:00
if ( ! fDisableGovernance ) {
2020-12-09 21:23:36 +01:00
scheduler . scheduleEvery ( std : : bind ( & CGovernanceManager : : DoMaintenance , std : : ref ( governance ) , std : : ref ( * g_connman ) ) , 60 * 5 * 1000 ) ;
2019-06-27 22:24:43 +02:00
}
if ( fMasternodeMode ) {
2021-03-17 23:36:11 +01:00
scheduler . scheduleEvery ( std : : bind ( & CCoinJoinServer : : DoMaintenance , std : : ref ( coinJoinServer ) , std : : ref ( * g_connman ) ) , 1 * 1000 ) ;
2018-07-16 14:47:37 +02:00
}
2014-12-09 02:17:57 +01:00
2020-12-15 17:22:23 +01:00
if ( gArgs . GetBoolArg ( " -statsenabled " , DEFAULT_STATSD_ENABLE ) ) {
int nStatsPeriod = std : : min ( std : : max ( ( int ) gArgs . GetArg ( " -statsperiod " , DEFAULT_STATSD_PERIOD ) , MIN_STATSD_PERIOD ) , MAX_STATSD_PERIOD ) ;
scheduler . scheduleEvery ( PeriodicStats , nStatsPeriod * 1000 ) ;
}
2019-02-17 12:39:43 +01:00
llmq : : StartLLMQSystem ( ) ;
2019-03-25 07:14:57 +01:00
// ********************************************************* Step 11: import blocks
2019-01-09 15:31:32 +01:00
if ( ! CheckDiskSpace ( /* additional_bytes */ 0 , /* blocks_dir */ false ) ) {
InitError ( strprintf ( _ ( " Error: Disk space is low for %s " ) , GetDataDir ( ) ) ) ;
2019-03-25 07:14:57 +01:00
return false ;
2019-01-09 15:31:32 +01:00
}
if ( ! CheckDiskSpace ( /* additional_bytes */ 0 , /* blocks_dir */ true ) ) {
InitError ( strprintf ( _ ( " Error: Disk space is low for %s " ) , GetBlocksDir ( ) ) ) ;
return false ;
}
2019-03-25 07:14:57 +01: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-08-06 05:08:33 +02:00
if ( chainActive . Tip ( ) = = nullptr ) {
2018-08-13 21:01:07 +02:00
uiInterface . NotifyBlockTip_connect ( BlockNotifyGenesisWait ) ;
2019-03-25 07:14:57 +01:00
} else {
fHaveGenesis = true ;
}
2019-06-24 18:44:27 +02:00
if ( gArgs . IsArgSet ( " -blocknotify " ) )
2018-08-13 21:01:07 +02:00
uiInterface . NotifyBlockTip_connect ( BlockNotifyCallback ) ;
2019-03-25 07:14:57 +01:00
2017-04-06 20:19:21 +02:00
std : : vector < fs : : path > vImportFiles ;
2017-06-27 14:22:54 +02:00
for ( const std : : string & strFile : gArgs . GetArgs ( " -loadblock " ) ) {
vImportFiles . push_back ( strFile ) ;
2019-03-25 07:14:57 +01:00
}
threadGroup . create_thread ( boost : : bind ( & ThreadImport , vImportFiles ) ) ;
// Wait for genesis block to be processed
{
2021-06-04 21:26:33 +02:00
WAIT_LOCK ( g_genesis_wait_mutex , lock ) ;
2018-02-08 08:40:55 +01: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 ( ) ) {
2021-06-04 21:26:33 +02:00
g_genesis_wait_cv . wait_for ( lock , std : : chrono : : milliseconds ( 500 ) ) ;
2019-03-25 07:14:57 +01:00
}
2018-08-13 21:01:07 +02:00
uiInterface . NotifyBlockTip_disconnect ( BlockNotifyGenesisWait ) ;
2019-03-25 07:14:57 +01:00
}
2020-01-04 12:21:00 +01:00
// As importing blocks can take several minutes, it's possible the user
// requested to kill the GUI during one of the last operations. If so, exit.
2018-02-08 08:40:55 +01:00
if ( ShutdownRequested ( ) ) {
2020-01-04 12:21:00 +01:00
LogPrintf ( " Shutdown requested. Exiting. \n " ) ;
return false ;
}
2016-05-30 08:22:08 +02:00
// ********************************************************* Step 12: start node
2011-05-14 20:10:21 +02:00
2017-10-05 15:03:09 +02:00
int chain_active_height ;
2012-05-21 16:47:29 +02:00
//// debug print
2017-10-05 15:03:09 +02:00
{
LOCK ( cs_main ) ;
LogPrintf ( " mapBlockIndex.size() = %u \n " , mapBlockIndex . size ( ) ) ;
chain_active_height = chainActive . Height ( ) ;
}
LogPrintf ( " chainActive.Height() = %d \n " , chain_active_height ) ;
2019-06-24 18:44:27 +02:00
if ( gArgs . GetBoolArg ( " -listenonion " , DEFAULT_LISTEN_ONION ) )
2020-06-13 20:21:30 +02:00
StartTorControl ( ) ;
2015-08-25 20:12:08 +02:00
2020-06-13 20:21:30 +02:00
Discover ( ) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
// Map ports with UPnP
2020-06-13 20:21:30 +02:00
if ( gArgs . GetBoolArg ( " -upnp " , DEFAULT_UPNP ) ) {
StartMapPort ( ) ;
}
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
CConnman : : Options connOptions ;
connOptions . nLocalServices = nLocalServices ;
connOptions . nMaxConnections = nMaxConnections ;
connOptions . nMaxOutbound = std : : min ( MAX_OUTBOUND_CONNECTIONS , connOptions . nMaxConnections ) ;
2017-01-06 16:47:05 +01:00
connOptions . nMaxAddnode = MAX_ADDNODE_CONNECTIONS ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
connOptions . nMaxFeeler = 1 ;
2017-10-05 15:03:09 +02:00
connOptions . nBestHeight = chain_active_height ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
connOptions . uiInterface = & uiInterface ;
2017-09-08 01:00:49 +02:00
connOptions . m_msgproc = peerLogic . get ( ) ;
2019-06-24 18:44:27 +02:00
connOptions . nSendBufferMaxSize = 1000 * gArgs . GetArg ( " -maxsendbuffer " , DEFAULT_MAXSENDBUFFER ) ;
connOptions . nReceiveFloodSize = 1000 * gArgs . GetArg ( " -maxreceivebuffer " , DEFAULT_MAXRECEIVEBUFFER ) ;
2017-09-22 23:58:52 +02:00
connOptions . m_added_nodes = gArgs . GetArgs ( " -addnode " ) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
2016-09-19 16:46:18 +02:00
connOptions . nMaxOutboundTimeframe = nMaxOutboundTimeframe ;
connOptions . nMaxOutboundLimit = nMaxOutboundLimit ;
2018-12-04 12:06:35 +01:00
connOptions . m_peer_connect_timeout = peer_connect_timeout ;
2016-09-19 16:46:18 +02:00
2017-06-27 14:22:54 +02:00
for ( const std : : string & strBind : gArgs . GetArgs ( " -bind " ) ) {
CService addrBind ;
if ( ! Lookup ( strBind . c_str ( ) , addrBind , GetListenPort ( ) , false ) ) {
return InitError ( ResolveErrMsg ( " bind " , strBind ) ) ;
2017-06-26 14:42:46 +02:00
}
2017-06-27 14:22:54 +02:00
connOptions . vBinds . push_back ( addrBind ) ;
2017-06-26 14:42:46 +02:00
}
2017-06-27 14:22:54 +02:00
for ( const std : : string & strBind : gArgs . GetArgs ( " -whitebind " ) ) {
CService addrBind ;
if ( ! Lookup ( strBind . c_str ( ) , addrBind , 0 , false ) ) {
return InitError ( ResolveErrMsg ( " whitebind " , strBind ) ) ;
}
if ( addrBind . GetPort ( ) = = 0 ) {
return InitError ( strprintf ( _ ( " Need to specify a port with -whitebind: '%s' " ) , strBind ) ) ;
2017-06-26 14:42:46 +02:00
}
2017-06-27 14:22:54 +02:00
connOptions . vWhiteBinds . push_back ( addrBind ) ;
2017-06-26 14:42:46 +02:00
}
2017-06-27 14:22:54 +02:00
for ( const auto & net : gArgs . GetArgs ( " -whitelist " ) ) {
CSubNet subnet ;
LookupSubNet ( net . c_str ( ) , subnet ) ;
if ( ! subnet . IsValid ( ) )
return InitError ( strprintf ( _ ( " Invalid netmask specified in -whitelist: '%s' " ) , net ) ) ;
connOptions . vWhitelistedRange . push_back ( subnet ) ;
2017-06-26 14:42:46 +02:00
}
2017-09-22 23:58:52 +02:00
connOptions . vSeedNodes = gArgs . GetArgs ( " -seednode " ) ;
2017-09-06 01:54:31 +02:00
// Initiate outbound connections unless connect=0
connOptions . m_use_addrman_outgoing = ! gArgs . IsArgSet ( " -connect " ) ;
if ( ! connOptions . m_use_addrman_outgoing ) {
const auto connect = gArgs . GetArgs ( " -connect " ) ;
if ( connect . size ( ) ! = 1 | | connect [ 0 ] ! = " 0 " ) {
connOptions . m_specified_outgoing = connect ;
}
}
2020-04-16 10:11:26 +02:00
std : : string strSocketEventsMode = gArgs . GetArg ( " -socketevents " , DEFAULT_SOCKETEVENTS ) ;
if ( strSocketEventsMode = = " select " ) {
connOptions . socketEventsMode = CConnman : : SOCKETEVENTS_SELECT ;
# ifdef USE_POLL
} else if ( strSocketEventsMode = = " poll " ) {
connOptions . socketEventsMode = CConnman : : SOCKETEVENTS_POLL ;
2020-04-07 17:58:38 +02:00
# endif
# ifdef USE_EPOLL
} else if ( strSocketEventsMode = = " epoll " ) {
connOptions . socketEventsMode = CConnman : : SOCKETEVENTS_EPOLL ;
2020-12-30 20:34:42 +01:00
# endif
# ifdef USE_KQUEUE
} else if ( strSocketEventsMode = = " kqueue " ) {
connOptions . socketEventsMode = CConnman : : SOCKETEVENTS_KQUEUE ;
2020-04-16 10:11:26 +02:00
# endif
} else {
return InitError ( strprintf ( _ ( " Invalid -socketevents ('%s') specified . Only these modes are supported : % s " ), strSocketEventsMode, GetSupportedSocketEventsStr())) ;
}
2017-06-26 14:42:46 +02:00
if ( ! connman . Start ( scheduler , connOptions ) ) {
return false ;
}
2011-05-14 20:10:21 +02:00
2016-04-10 08:31:32 +02:00
// ********************************************************* Step 13: finished
2012-05-21 16:47:29 +02:00
2014-10-29 18:08:31 +01:00
SetRPCWarmupFinished ( ) ;
2012-05-21 16:47:29 +02:00
uiInterface . InitMessage ( _ ( " Done loading " ) ) ;
2018-04-17 15:57:52 +02:00
g_wallet_init_interface . Start ( scheduler ) ;
2011-05-14 20:10:21 +02:00
2017-12-12 10:27:45 +01:00
return true ;
2011-05-14 20:10:21 +02:00
}