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
2023-01-12 22:26:21 +01:00
// Copyright (c) 2014-2023 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)
2022-08-02 18:34:58 +02:00
# include <config/bitcoin-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>
2019-01-21 18:45:59 +01:00
# include <banman.h>
2020-03-19 23:46:56 +01:00
# include <base58.h>
2021-08-12 09:04:28 +02:00
# include <blockfilter.h>
2020-03-19 23:46:56 +01:00
# include <chain.h>
# include <chainparams.h>
2022-10-22 19:18:03 +02:00
# include <context.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>
2018-11-09 15:36:34 +01:00
# include <interfaces/chain.h>
2021-08-12 09:04:28 +02:00
# include <index/blockfilterindex.h>
2021-05-25 12:48:04 +02:00
# include <index/txindex.h>
2022-04-16 08:24:42 +02:00
# include <interfaces/node.h>
2020-03-19 23:46:56 +01:00
# include <key.h>
2022-02-26 13:19:13 +01:00
# include <mapport.h>
2020-03-19 23:46:56 +01:00
# include <miner.h>
# include <net.h>
Merge #16248: Make whitebind/whitelist permissions more flexible
c5b404e8f1973afe071a07c63ba1038eefe13f0f Add functional tests for flexible whitebind/list (nicolas.dorier)
d541fa391844f658bd7035659b5b16695733dd56 Replace the use of fWhitelisted by permission checks (nicolas.dorier)
ecd5cf7ea4c3644a30092100ffc399e30e193275 Do not disconnect peer for asking mempool if it has NO_BAN permission (nicolas.dorier)
e5b26deaaa6842f7dd7c4537ede000f965ea0189 Make whitebind/whitelist permissions more flexible (nicolas.dorier)
Pull request description:
# Motivation
In 0.19, bloom filter will be disabled by default. I tried to make [a PR](https://github.com/bitcoin/bitcoin/pull/16176) to enable bloom filter for whitelisted peers regardless of `-peerbloomfilters`.
Bloom filter have non existent privacy and server can omit filter's matches. However, both problems are completely irrelevant when you connect to your own node. If you connect to your own node, bloom filters are the most bandwidth efficient way to synchronize your light client without the need of some middleware like Electrum.
It is also a superior alternative to BIP157 as it does not require to maintain an additional index and it would work well on pruned nodes.
When I attempted to allow bloom filters for whitelisted peer, my proposal has been NACKed in favor of [a more flexible approach](https://github.com/bitcoin/bitcoin/pull/16176#issuecomment-500762907) which should allow node operator to set fine grained permissions instead of a global `whitelisted` attribute.
Doing so will also make follow up idea very easy to implement in a backward compatible way.
# Implementation details
The PR propose a new format for `--white{list,bind}`. I added a way to specify permissions granted to inbound connection matching `white{list,bind}`.
The following permissions exists:
* ForceRelay
* Relay
* NoBan
* BloomFilter
* Mempool
Example:
* `-whitelist=bloomfilter@127.0.0.1/32`.
* `-whitebind=bloomfilter,relay,noban@127.0.0.1:10020`.
If no permissions are specified, `NoBan | Mempool` is assumed. (making this PR backward compatible)
When we receive an inbound connection, we calculate the effective permissions for this peer by fetching the permissions granted from `whitelist` and add to it the permissions granted from `whitebind`.
To keep backward compatibility, if no permissions are specified in `white{list,bind}` (e.g. `--whitelist=127.0.0.1`) then parameters `-whitelistforcerelay` and `-whiterelay` will add the permissions `ForceRelay` and `Relay` to the inbound node.
`-whitelistforcerelay` and `-whiterelay` are ignored if the permissions flags are explicitly set in `white{bind,list}`.
# Follow up idea
Based on this PR, other changes become quite easy to code in a trivially review-able, backward compatible way:
* Changing `connect` at rpc and config file level to understand the permissions flags.
* Changing the permissions of a peer at RPC level.
ACKs for top commit:
laanwj:
re-ACK c5b404e8f1973afe071a07c63ba1038eefe13f0f
Tree-SHA512: adfefb373d09e68cae401247c8fc64034e305694cdef104bdcdacb9f1704277bd53b18f52a2427a5cffdbc77bda410d221aed252bc2ece698ffbb9cf1b830577
2019-08-14 16:35:54 +02:00
# include <net_permissions.h>
2020-03-19 23:46:56 +01:00
# include <net_processing.h>
2022-03-24 05:13:51 +01:00
# include <netbase.h>
2022-04-05 11:09:41 +02:00
# include <node/context.h>
2020-03-19 23:46:56 +01:00
# include <policy/feerate.h>
# include <policy/fees.h>
# include <policy/policy.h>
2021-11-16 16:19:47 +01:00
# include <policy/settings.h>
2020-03-19 23:46:56 +01:00
# include <rpc/blockchain.h>
2022-03-24 05:13:51 +01:00
# include <rpc/register.h>
# include <rpc/server.h>
2018-11-09 15:36:34 +01:00
# include <rpc/util.h>
2020-03-19 23:46:56 +01:00
# include <scheduler.h>
2022-03-24 05:13:51 +01:00
# include <script/sigcache.h>
# include <script/standard.h>
2021-06-21 00:49:59 +02:00
# include <shutdown.h>
2020-03-19 23:46:56 +01:00
# include <timedata.h>
2022-03-24 05:13:51 +01:00
# include <torcontrol.h>
2020-03-19 23:46:56 +01:00
# include <txdb.h>
# include <txmempool.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>
2022-12-20 17:18:10 +01:00
# include <util/strencodings.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>
2022-03-24 05:13:51 +01:00
# include <util/translation.h>
2021-06-25 08:07:28 +02:00
# include <util/validation.h>
2022-02-26 13:19:13 +01:00
# include <validation.h>
2020-03-19 23:46:56 +01:00
# include <validationinterface.h>
2016-12-20 14:27:59 +01:00
2021-10-01 21:19:08 +02:00
# include <masternode/node.h>
2022-04-07 17:32:40 +02:00
# ifdef ENABLE_WALLET
# include <coinjoin/client.h>
# include <coinjoin/options.h>
# endif // ENABLE_WALLET
2021-10-01 21:19:08 +02:00
# include <coinjoin/server.h>
2020-03-19 23:46:56 +01:00
# include <dsnotificationinterface.h>
# include <flat-database.h>
# include <governance/governance.h>
2021-10-01 21:19:08 +02:00
# include <masternode/meta.h>
# include <masternode/sync.h>
# include <masternode/utils.h>
2020-03-19 23:46:56 +01:00
# include <messagesigner.h>
# include <netfulfilledman.h>
# include <spork.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-10-02 19:32:24 +02:00
# include <llmq/blockprocessor.h>
2022-09-22 13:14:48 +02:00
# include <llmq/chainlocks.h>
2022-11-07 19:09:44 +01:00
# include <llmq/context.h>
2022-09-22 13:14:48 +02:00
# include <llmq/instantsend.h>
2022-04-16 16:46:04 +02:00
# include <llmq/quorums.h>
2022-04-19 08:08:57 +02:00
# include <llmq/dkgsessionmgr.h>
2021-10-02 19:32:24 +02:00
# include <llmq/signing.h>
2022-04-16 16:46:04 +02:00
# include <llmq/snapshot.h>
2021-10-02 19:32:24 +02:00
# include <llmq/utils.h>
2022-09-22 13:14:48 +02:00
# include <llmq/signing_shares.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>
refactor: remove the g_evoDb global; use NodeContext and locals (#5058)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
globals should be avoided to avoid annoying lifetime / nullptr /
initialization issues
## What was done?
<!--- Describe your changes in detail -->
removed a global, g_evoDB
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
make check
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [ ] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
2022-12-10 18:58:17 +01:00
# include <memory>
2019-12-06 21:47:55 +01:00
# include <set>
2022-12-25 09:25:19 +01:00
# include <thread>
# include <vector>
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
2021-09-06 14:23:00 +02:00
# include <attributes.h>
# include <cerrno>
2012-04-15 22:10:54 +02:00
# 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
2020-03-19 17:09:15 +01:00
# include <boost/signals2/signal.hpp>
2014-11-18 18:06:32 +01:00
# if ENABLE_ZMQ
2021-09-08 18:39:06 +02:00
# include <zmq/zmqabstractnotifier.h>
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
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
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
2021-05-11 17:11:07 +02:00
static const char * DEFAULT_ASMAP_FILENAME = " ip_asn.map " ;
2021-09-06 14:23:00 +02:00
/**
* The PID file facilities .
*/
static const char * BITCOIN_PID_FILENAME = " dashd.pid " ;
2022-05-21 11:30:27 +02:00
static fs : : path GetPidFile ( const ArgsManager & args )
2021-09-06 14:23:00 +02:00
{
2022-05-21 11:30:27 +02:00
return AbsPathForConfigVal ( fs : : path ( args . GetArg ( " -pid " , BITCOIN_PID_FILENAME ) ) ) ;
2021-09-06 14:23:00 +02:00
}
2022-05-21 11:30:27 +02:00
[[nodiscard]] static bool CreatePidFile ( const ArgsManager & args )
2021-09-06 14:23:00 +02:00
{
2022-05-21 11:30:27 +02:00
fsbridge : : ofstream file { GetPidFile ( args ) } ;
2021-09-06 14:23:00 +02:00
if ( file ) {
Merge #15456: Enable PID file creation on WIN
3f5ad622e5fe0781a70bee9e3322b23c2352e956 Enable PID file creation on Windows - Add available WIN PID function - Consider WIN32 in each relevant case - Add new preprocessor definitions to suppress warning - Update error message for generic OS (riordant)
Pull request description:
# Introduction
As discussed with @laanwj on IRC:
- PID file creation was never enabled for Windows, as the `pid_t` filetype is not available for it. However, the WIN32 API contains the header [`Processthreadsapi.h`](https://github.com/CodeShark/x86_64-w64-mingw32/blob/master/include/processthreadsapi.h) which in turn contains the function [`GetCurrentProcessId()`](https://docs.microsoft.com/en-gb/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocessid). ~~This function is called at a higher level by [`_getpid()`](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getpid?view=vs-2017)~~ EDIT: `_getpid()` is not available to the MSVC compiler used in the AppVeyor build. As a result, I have changed the function call to`GetCurrentProcessId()`, which performs the same function and is available to both MinGW & MSVC.
This allows one to capture the PID in Windows, without any additional includes - the above function is already available.
- Within this PR, I have added a separate line that calls `GetCurrentProcessId()` in the case of a WIN compilation, and the usual `getpid()` otherwise. All code blocks processing PID file logic that avoid WIN32 have been changed to consider it. I have also updated the preprocessor definitions in `libbitcoin_server.vcxproj.in` to suppress a warning related to `std::strerror` for the MSVC build, that was causing the AppVeyor build to fail (see @fanquake comment below).
# Rationale
- Consistency between OS's running Bitcoin
- Applications which build off of `bitcoind`, such as novel front-end clients, often need access to the PID in order to control the daemon. Instead of designing some alternate way of doing this for one system, it should be consistent between all of them.
In collaboration with @joernroeder
Tree-SHA512: 22fcbf866e99115d12ed29716e68d200d4c118ae2f7b188b7705dc0cf5f0cd0ce5fb18f772744c6238eecd9e6d0922c615e2f0e12a7fe7c810062a79d97aa6a2
2019-02-25 13:12:44 +01:00
# ifdef WIN32
tfm : : format ( file , " %d \n " , GetCurrentProcessId ( ) ) ;
# else
2021-10-24 12:51:47 +02:00
tfm : : format ( file , " %d \n " , getpid ( ) ) ;
Merge #15456: Enable PID file creation on WIN
3f5ad622e5fe0781a70bee9e3322b23c2352e956 Enable PID file creation on Windows - Add available WIN PID function - Consider WIN32 in each relevant case - Add new preprocessor definitions to suppress warning - Update error message for generic OS (riordant)
Pull request description:
# Introduction
As discussed with @laanwj on IRC:
- PID file creation was never enabled for Windows, as the `pid_t` filetype is not available for it. However, the WIN32 API contains the header [`Processthreadsapi.h`](https://github.com/CodeShark/x86_64-w64-mingw32/blob/master/include/processthreadsapi.h) which in turn contains the function [`GetCurrentProcessId()`](https://docs.microsoft.com/en-gb/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocessid). ~~This function is called at a higher level by [`_getpid()`](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getpid?view=vs-2017)~~ EDIT: `_getpid()` is not available to the MSVC compiler used in the AppVeyor build. As a result, I have changed the function call to`GetCurrentProcessId()`, which performs the same function and is available to both MinGW & MSVC.
This allows one to capture the PID in Windows, without any additional includes - the above function is already available.
- Within this PR, I have added a separate line that calls `GetCurrentProcessId()` in the case of a WIN compilation, and the usual `getpid()` otherwise. All code blocks processing PID file logic that avoid WIN32 have been changed to consider it. I have also updated the preprocessor definitions in `libbitcoin_server.vcxproj.in` to suppress a warning related to `std::strerror` for the MSVC build, that was causing the AppVeyor build to fail (see @fanquake comment below).
# Rationale
- Consistency between OS's running Bitcoin
- Applications which build off of `bitcoind`, such as novel front-end clients, often need access to the PID in order to control the daemon. Instead of designing some alternate way of doing this for one system, it should be consistent between all of them.
In collaboration with @joernroeder
Tree-SHA512: 22fcbf866e99115d12ed29716e68d200d4c118ae2f7b188b7705dc0cf5f0cd0ce5fb18f772744c6238eecd9e6d0922c615e2f0e12a7fe7c810062a79d97aa6a2
2019-02-25 13:12:44 +01:00
# endif
2021-09-06 14:23:00 +02:00
return true ;
} else {
2022-05-21 11:30:27 +02:00
return InitError ( strprintf ( _ ( " Unable to create the PID file '%s': %s " ) , GetPidFile ( args ) . string ( ) , std : : strerror ( errno ) ) ) ;
2021-09-06 14:23:00 +02:00
}
}
2021-05-11 17:11:07 +02:00
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-09-02 09:56:16 +02:00
static std : : unique_ptr < ECCVerifyHandle > globalVerifyHandle ;
2012-07-06 16:33:34 +02:00
2020-06-06 14:23:05 +02:00
static std : : thread g_load_block ;
2022-04-05 11:09:41 +02:00
void Interrupt ( NodeContext & node )
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
{
InterruptHTTPServer ( ) ;
InterruptHTTPRPC ( ) ;
InterruptRPC ( ) ;
InterruptREST ( ) ;
2015-09-08 17:48:45 +02:00
InterruptTorControl ( ) ;
2022-11-07 19:09:44 +01:00
if ( node . llmq_ctx ) {
node . llmq_ctx - > Interrupt ( ) ;
}
2020-06-13 20:21:30 +02:00
InterruptMapPort ( ) ;
2022-04-05 11:09:41 +02:00
if ( node . connman )
node . connman - > Interrupt ( ) ;
2021-05-25 12:48:04 +02:00
if ( g_txindex ) {
g_txindex - > Interrupt ( ) ;
}
2021-08-12 09:04:28 +02:00
ForEachBlockFilterIndex ( [ ] ( BlockFilterIndex & index ) { index . Interrupt ( ) ; } ) ;
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 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 */
2022-04-05 11:09:41 +02:00
void PrepareShutdown ( NodeContext & node )
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 ;
2022-05-21 11:30:27 +02:00
Assert ( node . args ) ;
2015-05-25 18:29:11 +02:00
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 " ) ;
2020-09-07 09:47:14 +02:00
if ( node . mempool ) node . mempool - > AddTransactionsUpdated ( 1 ) ;
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
StopHTTPRPC ( ) ;
StopREST ( ) ;
StopRPC ( ) ;
StopHTTPServer ( ) ;
2022-11-07 19:09:44 +01:00
if ( node . llmq_ctx ) node . llmq_ctx - > Stop ( ) ;
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 ) ;
2022-04-05 11:09:41 +02:00
for ( const auto & client : node . chain_clients ) {
2018-11-09 15:36:34 +01:00
client - > 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.
2022-04-05 11:09:41 +02:00
if ( node . peer_logic ) UnregisterValidationInterface ( node . peer_logic . get ( ) ) ;
if ( node . connman ) node . connman - > 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
2020-06-06 14:23:05 +02:00
// CScheduler/checkqueue, threadGroup and load block thread.
2022-01-09 18:03:26 +01:00
if ( node . scheduler ) node . scheduler - > stop ( ) ;
2020-06-06 14:23:05 +02:00
if ( g_load_block . joinable ( ) ) g_load_block . join ( ) ;
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 " ) ;
2022-08-26 23:52:53 +02:00
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 " ) ;
2022-08-26 23:52:53 +02:00
flatdb3 . Dump ( * : : governance ) ;
2020-06-13 20:18:31 +02:00
}
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.
2022-04-05 11:09:41 +02:00
node . peer_logic . reset ( ) ;
node . connman . reset ( ) ;
node . banman . reset ( ) ;
2018-08-08 14:02:54 +02:00
2020-09-07 09:47:14 +02:00
if ( node . mempool & & node . mempool - > IsLoaded ( ) & & node . args - > GetArg ( " -persistmempool " , DEFAULT_PERSIST_MEMPOOL ) ) {
DumpMempool ( * node . mempool ) ;
2017-05-03 09:23:39 +02:00
}
2015-05-25 18:29:11 +02:00
2023-02-22 08:53:20 +01:00
// Drop transactions we were still watching, and record fee estimations.
if ( node . fee_estimator ) node . fee_estimator - > Flush ( ) ;
2015-05-25 18:29:11 +02:00
2018-05-03 12:38:00 +02:00
// FlushStateToDisk generates a ChainStateFlushed callback, which we should avoid missing
2022-05-05 20:07:00 +02:00
if ( node . chainman ) {
2019-07-24 17:45:04 +02:00
LOCK ( cs_main ) ;
2022-05-05 20:07:00 +02:00
for ( CChainState * chainstate : node . chainman - > GetAll ( ) ) {
2022-04-03 16:41:38 +02:00
if ( chainstate - > CanFlushToDisk ( ) ) {
chainstate - > ForceFlushStateToDisk ( ) ;
}
2019-07-24 17:45:04 +02: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
}
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 ( ) ;
refactor: begin to de-globalize masternodeSync (#5103)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
minimizing global uses
## What was done?
<!--- Describe your changes in detail -->
Started the deglobalization, a future PR should be done to continue this
deglobalization
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have added or updated relevant unit/integration/functional/e2e
tests
- [x] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [x] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-01-04 21:37:20 +01:00
// After all scheduled tasks have been flushed, destroy pointers
// and reset all to nullptr.
: : coinJoinServer . reset ( ) ;
# ifdef ENABLE_WALLET
: : coinJoinClientQueueManager . reset ( ) ;
# endif // ENABLE_WALLET
: : governance . reset ( ) ;
: : sporkManager . reset ( ) ;
: : masternodeSync . reset ( ) ;
2020-01-22 10:30:00 +01:00
// Stop and delete all indexes only after flushing background callbacks.
if ( g_txindex ) {
g_txindex - > Stop ( ) ;
g_txindex . reset ( ) ;
}
ForEachBlockFilterIndex ( [ ] ( BlockFilterIndex & index ) { index . Stop ( ) ; } ) ;
DestroyAllBlockFilterIndexes ( ) ;
2017-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.
2022-05-05 20:07:00 +02:00
if ( node . chainman ) {
2015-05-25 18:29:11 +02:00
LOCK ( cs_main ) ;
2022-05-05 20:07:00 +02:00
for ( CChainState * chainstate : node . chainman - > GetAll ( ) ) {
2022-04-03 16:41:38 +02:00
if ( chainstate - > CanFlushToDisk ( ) ) {
chainstate - > ForceFlushStateToDisk ( ) ;
chainstate - > ResetCoinsViews ( ) ;
}
2015-05-25 18:29:11 +02:00
}
2017-11-09 21:22:08 +01:00
pblocktree . reset ( ) ;
2022-11-07 19:09:44 +01:00
if ( node . llmq_ctx ) {
node . llmq_ctx . reset ( ) ;
}
2022-04-16 16:46:04 +02:00
llmq : : quorumSnapshotManager . reset ( ) ;
2017-11-09 21:22:08 +01:00
deterministicMNManager . reset ( ) ;
refactor: remove the g_evoDb global; use NodeContext and locals (#5058)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
globals should be avoided to avoid annoying lifetime / nullptr /
initialization issues
## What was done?
<!--- Describe your changes in detail -->
removed a global, g_evoDB
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
make check
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [ ] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
2022-12-10 18:58:17 +01:00
node . evodb . reset ( ) ;
2015-05-25 18:29:11 +02:00
}
2022-04-05 11:09:41 +02:00
for ( const auto & client : node . chain_clients ) {
2018-11-09 15:36:34 +01:00
client - > 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 ) {
2022-08-26 23:52:53 +02:00
UnregisterValidationInterface ( activeMasternodeManager . get ( ) ) ;
activeMasternodeManager . reset ( ) ;
2018-02-15 14:33:04 +01:00
}
2016-03-02 22:20:04 +01:00
2021-07-26 17:52:52 +02:00
{
LOCK ( activeMasternodeInfoCs ) ;
// 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 ( ) ;
}
2018-10-26 07:04:22 +02:00
2022-04-05 11:09:41 +02:00
node . chain_clients . clear ( ) ;
2015-05-25 18:29:11 +02:00
UnregisterAllValidationInterfaces ( ) ;
2017-07-11 09:30:36 +02:00
GetMainSignals ( ) . UnregisterBackgroundSignalScheduler ( ) ;
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
*/
2022-04-05 11:09:41 +02:00
void Shutdown ( NodeContext & node )
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 ( ) ) {
2022-04-05 11:09:41 +02:00
PrepareShutdown ( node ) ;
2015-05-27 22:35:46 +02:00
}
2020-06-13 20:21:30 +02:00
// Shutdown part 2: delete wallet instance
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 ( ) ;
2020-09-07 09:47:14 +02:00
node . mempool . reset ( ) ;
2023-02-22 08:53:20 +01:00
node . fee_estimator . reset ( ) ;
2022-05-05 20:07:00 +02:00
node . chainman = nullptr ;
2022-01-09 18:03:26 +01:00
node . scheduler . reset ( ) ;
2022-05-21 09:27:47 +02:00
try {
2022-05-21 11:30:27 +02:00
if ( ! fs : : remove ( GetPidFile ( * node . args ) ) ) {
2022-05-21 09:27:47 +02:00
LogPrintf ( " %s: Unable to remove PID file: File does not exist \n " , __func__ ) ;
}
} catch ( const fs : : filesystem_error & e ) {
LogPrintf ( " %s: Unable to remove PID file: %s \n " , __func__ , fsbridge : : get_filesystem_error_message ( e ) ) ;
}
2022-05-21 11:30:27 +02:00
node . args = nullptr ;
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
{
2019-02-04 20:26:02 +01:00
LogInstance ( ) . 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
2019-04-23 19:02:18 +02:00
static boost : : signals2 : : connection rpc_notify_block_change_connection ;
2018-05-04 22:42:39 +02:00
static void OnRPCStarted ( )
2016-09-09 08:33:26 +02:00
{
2019-04-23 19:02:18 +02:00
rpc_notify_block_change_connection = 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
{
2019-04-23 19:02:18 +02:00
rpc_notify_block_change_connection . disconnect ( ) ;
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 ;
}
2022-05-29 21:49:04 +02:00
void SetupServerArgs ( NodeContext & node )
2012-05-13 11:36:10 +02:00
{
2022-05-29 21:49:04 +02:00
assert ( ! node . args ) ;
node . args = & gArgs ;
2022-05-21 10:27:30 +02:00
ArgsManager & argsman = * node . args ;
2022-05-29 21:49:04 +02:00
2022-05-21 11:30:27 +02:00
SetupHelpOptions ( argsman ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -help-debug " , " Print help message with debugging options and exit " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
2022-05-21 10:12:13 +02:00
2017-05-09 09:29:12 +02:00
const auto defaultBaseParams = CreateBaseChainParams ( CBaseChainParams : : MAIN ) ;
const auto testnetBaseParams = CreateBaseChainParams ( CBaseChainParams : : TESTNET ) ;
2018-09-04 12:45:48 +02:00
const auto regtestBaseParams = CreateBaseChainParams ( CBaseChainParams : : REGTEST ) ;
2017-05-09 09:29:12 +02:00
const auto defaultChainParams = CreateChainParams ( CBaseChainParams : : MAIN ) ;
const auto testnetChainParams = CreateChainParams ( CBaseChainParams : : TESTNET ) ;
2018-09-04 12:45:48 +02:00
const auto regtestChainParams = CreateChainParams ( CBaseChainParams : : REGTEST ) ;
2021-02-22 23:46:40 +01:00
2021-06-19 16:34:39 +02:00
// Hidden Options
2022-05-21 10:12:13 +02:00
std : : vector < std : : string > hidden_args = { " -dbcrashratio " , " -forcecompactdb " , " -printcrashinfo " ,
2021-06-19 16:34:39 +02:00
// GUI args. These will be overwritten by SetupUIArgs for the GUI
2022-04-25 11:01:47 +02:00
" -choosedatadir " , " -lang=<lang> " , " -min " , " -resetguisettings " , " -splash " , " -uiplatform " } ;
2021-06-19 16:34:39 +02:00
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.
2022-05-21 09:57:28 +02:00
# if HAVE_SYSTEM
2022-02-21 08:16:29 +01:00
argsman . AddArg ( " -alertnotify=<cmd> " , " Execute command when an alert is raised (%s in cmd is replaced by message) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2022-05-21 09:33:04 +02:00
# endif
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -assumevalid=<hex> " , strprintf ( " If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: %s, testnet: %s) " , defaultChainParams - > GetConsensus ( ) . defaultAssumeValid . GetHex ( ) , testnetChainParams - > GetConsensus ( ) . defaultAssumeValid . GetHex ( ) ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -blocksdir=<dir> " , " Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2022-05-21 09:57:28 +02:00
# if HAVE_SYSTEM
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -blocknotify=<cmd> " , " Execute command when the best block changes (%s in cmd is replaced by block hash) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2022-05-21 09:33:04 +02:00
# endif
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -blockreconstructionextratxn=<n> " , strprintf ( " Extra transactions to keep in memory for compact block reconstructions (default: %u) " , DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-07-11 10:22:44 +02:00
argsman . AddArg ( " -blocksonly " , strprintf ( " Whether to reject transactions from network peers. Automatic broadcast and rebroadcast of any transactions from inbound peers is disabled, unless the peer has the 'forcerelay' permission. RPC transactions are not affected. (default: %u) " , DEFAULT_BLOCKSONLY ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-07-23 18:39:18 +02:00
argsman . AddArg ( " -conf=<file> " , strprintf ( " Specify path to read-only configuration file. Relative paths will be prefixed by datadir location. (default: %s) " , BITCOIN_CONF_FILENAME ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -datadir=<dir> " , " Specify data directory " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -dbbatchsize " , strprintf ( " Maximum database write batch size in bytes (default: %u) " , nDefaultDbBatchSize ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -dbcache=<n> " , strprintf ( " Maximum database cache size <n> MiB (%d to %d, default: %d). In addition, unused mempool memory is shared for this cache (see -maxmempool). " , nMinDbCache , nMaxDbCache , nDefaultDbCache ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -debuglogfile=<file> " , strprintf ( " Specify location of debug log file. Relative paths will be prefixed by a net-specific datadir location. (-nodebuglogfile to disable; default: %s) " , DEFAULT_DEBUGLOGFILE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -includeconf=<file> " , " Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2019-11-05 19:25:06 +01:00
argsman . AddArg ( " -loadblock=<file> " , " Imports blocks from external file on startup " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -maxmempool=<n> " , strprintf ( " Keep the transaction memory pool below <n> megabytes (default: %u) " , DEFAULT_MAX_MEMPOOL_SIZE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -maxorphantxsize=<n> " , strprintf ( " Maximum total size of all orphan transactions in megabytes (default: %u) " , DEFAULT_MAX_ORPHAN_TRANSACTIONS_SIZE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -maxrecsigsage=<n> " , strprintf ( " Number of seconds to keep LLMQ recovery sigs (default: %u) " , llmq : : DEFAULT_MAX_RECOVERED_SIGS_AGE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -mempoolexpiry=<n> " , strprintf ( " Do not keep transactions in the mempool longer than <n> hours (default: %u) " , DEFAULT_MEMPOOL_EXPIRY ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . 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 ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -par=<n> " , strprintf ( " Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d) " ,
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
- GetNumCores ( ) , MAX_SCRIPTCHECK_THREADS , DEFAULT_SCRIPTCHECK_THREADS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -persistmempool " , strprintf ( " Whether to save the mempool on shutdown and load on restart (default: %u) " , DEFAULT_PERSIST_MEMPOOL ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -pid=<file> " , strprintf ( " Specify pid file. Relative paths will be prefixed by a net-specific datadir location. (default: %s) " , BITCOIN_PID_FILENAME ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -prune=<n> " , strprintf ( " Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks, and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex, -rescan and -disablegovernance=false. "
2015-05-04 18:46:33 +02:00
" Warning: Reverting this setting requires re-downloading the entire blockchain. "
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +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 ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2020-07-23 18:39:18 +02:00
argsman . AddArg ( " -settings=<file> " , strprintf ( " Specify path to dynamic settings data file. Can be disabled with -nosettings. File is written at runtime and not meant to be edited by users (use %s instead for custom settings). Relative paths will be prefixed by datadir location. (default: %s) " , BITCOIN_CONF_FILENAME , BITCOIN_SETTINGS_FILENAME ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -syncmempool " , strprintf ( " Sync mempool from other nodes on start (default: %u) " , DEFAULT_SYNC_MEMPOOL ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2015-09-11 23:31:30 +02:00
# ifndef WIN32
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -sysperms " , " Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2021-06-19 16:34:39 +02:00
# else
hidden_args . emplace_back ( " -sysperms " ) ;
2014-06-04 13:16:07 +02:00
# endif
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -version " , " Print version and exit " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
argsman . AddArg ( " -addressindex " , strprintf ( " Maintain a full address index, used to query for the balance, txids and unspent outputs for addresses (default: %u) " , DEFAULT_ADDRESSINDEX ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : INDEXING ) ;
argsman . AddArg ( " -reindex " , " Rebuild chain state and block index from the blk*.dat files on disk " , ArgsManager : : ALLOW_ANY , OptionsCategory : : INDEXING ) ;
argsman . AddArg ( " -reindex-chainstate " , " Rebuild chain state from the currently indexed blocks. When in pruning mode or if blocks on disk might be corrupted, use full -reindex instead. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : INDEXING ) ;
argsman . AddArg ( " -spentindex " , strprintf ( " Maintain a full spent index, used to query the spending txid and input index for an outpoint (default: %u) " , DEFAULT_SPENTINDEX ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : INDEXING ) ;
argsman . AddArg ( " -timestampindex " , strprintf ( " Maintain a timestamp index for block hashes, used to query blocks hashes by a range of timestamps (default: %u) " , DEFAULT_TIMESTAMPINDEX ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : INDEXING ) ;
argsman . AddArg ( " -txindex " , strprintf ( " Maintain a full transaction index, used by the getrawtransaction rpc call (default: %u) " , DEFAULT_TXINDEX ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : INDEXING ) ;
argsman . AddArg ( " -blockfilterindex=<type> " ,
2021-08-12 09:04:28 +02:00
strprintf ( " Maintain an index of compact filters by block (default: %s, values: %s). " , DEFAULT_BLOCKFILTERINDEX , ListBlockFilterTypes ( ) ) +
" If <type> is not supplied or if <type> = 1, indexes for all known types are enabled. " ,
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -asmap=<file> " , strprintf ( " Specify asn mapping used for bucketing of the peers (default: %s). Relative paths will be prefixed by the net-specific datadir location. " , DEFAULT_ASMAP_FILENAME ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -addnode=<ip> " , " Add a node to connect to and attempt to keep the connection open (see the `addnode` RPC command help for more info). This option can be specified multiple times to add multiple nodes. " , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -allowprivatenet " , strprintf ( " Allow RFC1918 addresses to be relayed and connected to (default: %u) " , DEFAULT_ALLOWPRIVATENET ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2022-06-10 11:16:05 +02:00
argsman . AddArg ( " -banscore=<n> " , strprintf ( " Threshold for disconnecting and discouraging misbehaving peers (default: %u) " , DEFAULT_BANSCORE_THRESHOLD ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -bantime=<n> " , strprintf ( " Default duration (in seconds) of manually configured bans (default: %u) " , DEFAULT_MISBEHAVING_BANTIME ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -bind=<addr> " , " Bind to given address and always listen on it. Use [host]:port notation for IPv6 " , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -connect=<ip> " , " Connect only to the specified node; -noconnect disables automatic connections (the rules for this peer are the same as for -addnode). This option can be specified multiple times to connect to multiple nodes. " , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -discover " , " Discover own IP addresses (default: 1 when listening and no -externalip or -proxy) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -dns " , strprintf ( " Allow DNS lookups for -addnode, -seednode and -connect (default: %u) " , DEFAULT_NAME_LOOKUP ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -dnsseed " , " Query for peer addresses via DNS lookup, if low on addresses (default: 1 unless -connect used) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -externalip=<ip> " , " Specify your own public address " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -forcednsseed " , strprintf ( " Always query for peer addresses via DNS lookup (default: %u) " , DEFAULT_FORCEDNSSEED ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -listen " , " Accept connections from outside (default: 1 if no -proxy or -connect) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -listenonion " , strprintf ( " Automatically create Tor hidden service (default: %d) " , DEFAULT_LISTEN_ONION ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -maxconnections=<n> " , strprintf ( " Maintain at most <n> connections to peers (temporary service connections excluded) (default: %u) " , DEFAULT_MAX_PEER_CONNECTIONS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -maxreceivebuffer=<n> " , strprintf ( " Maximum per-connection receive buffer, <n>*1000 bytes (default: %u) " , DEFAULT_MAXRECEIVEBUFFER ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -maxsendbuffer=<n> " , strprintf ( " Maximum per-connection send buffer, <n>*1000 bytes (default: %u) " , DEFAULT_MAXSENDBUFFER ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -maxtimeadjustment " , strprintf ( " Maximum allowed median peer time offset adjustment. Local perspective of time may be influenced by peers forward or backward by this amount. (default: %u seconds) " , DEFAULT_MAX_TIME_ADJUSTMENT ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -maxuploadtarget=<n> " , strprintf ( " Tries to keep outbound traffic under the given target (in MiB per 24h), 0 = no limit (default: %d) " , DEFAULT_MAX_UPLOAD_TARGET ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -onion=<ip:port> " , " Use separate SOCKS5 proxy to reach peers via Tor hidden services, set -noonion to disable (default: -proxy) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . 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. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -peerblockfilters " , strprintf ( " Serve compact block filters to peers per BIP 157 (default: %u) " , DEFAULT_PEERBLOCKFILTERS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -peerbloomfilters " , strprintf ( " Support filtering of blocks and transaction with bloom filters (default: %u) " , DEFAULT_PEERBLOOMFILTERS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . 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 ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -permitbaremultisig " , strprintf ( " Relay non-P2SH multisig (default: %u) " , DEFAULT_PERMIT_BAREMULTISIG ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -port=<port> " , strprintf ( " Listen for connections on <port> (default: %u, testnet: %u, regtest: %u) " , defaultChainParams - > GetDefaultPort ( ) , testnetChainParams - > GetDefaultPort ( ) , regtestChainParams - > GetDefaultPort ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -proxy=<ip:port> " , " Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -proxyrandomize " , strprintf ( " Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u) " , DEFAULT_PROXYRANDOMIZE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -seednode=<ip> " , " Connect to a node to retrieve peer addresses, and disconnect. This option can be specified multiple times to connect to multiple nodes. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -socketevents=<mode> " , " Socket events mode, which must be one of 'select', 'poll', 'epoll' or 'kqueue', depending on your system (default: Linux - 'epoll', FreeBSD/Apple - 'kqueue', Windows - 'select') " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -timeout=<n> " , strprintf ( " Specify connection timeout in milliseconds (minimum: 1, default: %d) " , DEFAULT_CONNECT_TIMEOUT ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
argsman . AddArg ( " -torcontrol=<ip>:<port> " , strprintf ( " Tor control port to use if onion listening enabled (default: %s) " , DEFAULT_TOR_CONTROL ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2020-01-30 23:10:50 +01:00
argsman . AddArg ( " -torpassword=<pass> " , " Tor control port password (default: empty) " , ArgsManager : : ALLOW_ANY | ArgsManager : : SENSITIVE , OptionsCategory : : CONNECTION ) ;
2012-05-13 11:36:10 +02:00
# ifdef USE_UPNP
# if USE_UPNP
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -upnp " , " Use UPnP to map the listening port (default: 1 when listening and no -proxy) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2012-05-13 11:36:10 +02:00
# else
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -upnp " , strprintf ( " Use UPnP to map the listening port (default: %u) " , 0 ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2013-10-11 23:09:59 +02:00
# endif
2021-06-19 16:34:39 +02:00
# else
hidden_args . emplace_back ( " -upnp " ) ;
2012-05-13 11:36:10 +02:00
# endif
2022-02-26 13:19:13 +01:00
# ifdef USE_NATPMP
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -natpmp " , strprintf ( " Use NAT-PMP to map the listening port (default: %s) " , DEFAULT_NATPMP ? " 1 when listening and no -proxy " : " 0 " ) , ArgsManager : : ALLOW_BOOL , OptionsCategory : : CONNECTION ) ;
2022-02-26 13:19:13 +01:00
# else
hidden_args . emplace_back ( " -natpmp " ) ;
# endif // USE_NATPMP
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -whitebind=<[permissions@]addr> " , " Bind to given address and whitelist peers connecting to it. "
2019-08-26 15:21:56 +02:00
" Use [host]:port notation for IPv6. Allowed permissions are bloomfilter (allow requesting BIP37 filtered blocks and transactions), "
" noban (do not ban for misbehavior), "
2020-02-26 18:44:25 +01:00
" forcerelay (relay transactions that are already in the mempool; implies relay), "
2019-08-26 15:21:56 +02:00
" relay (relay even in -blocksonly mode), "
" and mempool (allow requesting BIP35 mempool contents). "
" Specify multiple permissions separated by commas (default: noban,mempool,relay). Can be specified multiple times. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -whitelist=<[permissions@]IP address or network> " , " Whitelist peers connecting from the given IP address (e.g. 1.2.3.4) or "
2019-08-26 15:21:56 +02:00
" CIDR notated network(e.g. 1.2.3.0/24). Uses same permissions as "
" -whitebind. Can be specified multiple times. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CONNECTION ) ;
2014-02-03 07:23:20 +01:00
2022-05-21 10:27:30 +02:00
g_wallet_init_interface . AddWalletOptions ( argsman ) ;
2014-02-03 07:23:20 +01:00
2014-11-18 18:06:32 +01:00
# if ENABLE_ZMQ
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -zmqpubhashblock=<address> " , " Enable publish hash block in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashchainlock=<address> " , " Enable publish hash block (locked via ChainLocks) in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashgovernanceobject=<address> " , " Enable publish hash of governance objects (like proposals) in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashgovernancevote=<address> " , " Enable publish hash of governance votes in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashinstantsenddoublespend=<address> " , " Enable publish transaction hashes of attempted InstantSend double spend in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashrecoveredsig=<address> " , " Enable publish message hash of recovered signatures (recovered by LLMQs) in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashtx=<address> " , " Enable publish hash transaction in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashtxlock=<address> " , " Enable publish hash transaction (locked via InstantSend) in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawblock=<address> " , " Enable publish raw block in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawchainlock=<address> " , " Enable publish raw block (locked via ChainLocks) in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawchainlocksig=<address> " , " Enable publish raw block (locked via ChainLocks) and CLSIG message in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawgovernancevote=<address> " , " Enable publish raw governance objects (like proposals) in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawgovernanceobject=<address> " , " Enable publish raw governance votes in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawinstantsenddoublespend=<address> " , " Enable publish raw transactions of attempted InstantSend double spend in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawrecoveredsig=<address> " , " Enable publish raw recovered signatures (recovered by LLMQs) in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawtx=<address> " , " Enable publish raw transaction in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawtxlock=<address> " , " Enable publish raw transaction (locked via InstantSend) in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawtxlocksig=<address> " , " Enable publish raw transaction (locked via InstantSend) and ISLOCK in <address> " , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashblockhwm=<n> " , strprintf ( " Set publish hash block outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashchainlockhwm=<n> " , strprintf ( " Set publish hash chain lock outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashgovernanceobjecthwm=<n> " , strprintf ( " Set publish hash governance object outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashgovernancevotehwm=<n> " , strprintf ( " Set publish hash governance vote outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashinstantsenddoublespendhwm=<n> " , strprintf ( " Set publish hash InstantSend double spend outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashrecoveredsighwm=<n> " , strprintf ( " Set publish hash recovered signature outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashtxhwm=<n> " , strprintf ( " Set publish hash transaction outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubhashtxlockhwm=<n> " , strprintf ( " Set publish hash transaction lock outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawblockhwm=<n> " , strprintf ( " Set publish raw block outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawchainlockhwm=<n> " , strprintf ( " Set publish raw chain lock outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawchainlocksighwm=<n> " , strprintf ( " Set publish raw chain lock signature outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawgovernanceobjecthwm=<n> " , strprintf ( " Set publish raw governance object outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawgovernancevotehwm=<n> " , strprintf ( " Set publish raw governance vote outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawinstantsenddoublespendhwm=<n> " , strprintf ( " Set publish raw InstantSend double spend outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawrecoveredsighwm=<n> " , strprintf ( " Set publish raw recovered signature outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawtxhwm=<n> " , strprintf ( " Set publish raw transaction outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawtxlockhwm=<n> " , strprintf ( " Set publish raw transaction lock outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
argsman . AddArg ( " -zmqpubrawtxlocksighwm=<n> " , strprintf ( " Set publish raw transaction lock signature outbound message high water mark (default: %d) " , CZMQAbstractNotifier : : DEFAULT_ZMQ_SNDHWM ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : ZMQ ) ;
2021-06-19 16:34:39 +02:00
# 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> " ) ;
2021-09-08 18:39:06 +02:00
hidden_args . emplace_back ( " -zmqpubhashblockhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubhashchainlockhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubhashgovernanceobjecthwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubhashgovernancevotehwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubhashinstantsenddoublespendhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubhashrecoveredsighwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubhashtxhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubhashtxlockhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawblockhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawchainlockhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawchainlocksighwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawgovernanceobjecthwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawgovernancevotehwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawinstantsenddoublespendhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawrecoveredsighwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawtxhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawtxlockhwm=<n> " ) ;
hidden_args . emplace_back ( " -zmqpubrawtxlocksighwm=<n> " ) ;
2014-11-18 18:06:32 +01:00
# endif
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -checkblockindex " , strprintf ( " Do a consistency check for the block tree, and occasionally. (default: %u, regtest: %u) " , defaultChainParams - > DefaultConsistencyChecks ( ) , regtestChainParams - > DefaultConsistencyChecks ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -checkblocks=<n> " , strprintf ( " How many blocks to check at startup (default: %u, 0 = all) " , DEFAULT_CHECKBLOCKS ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -checklevel=<n> " , strprintf ( " How thorough the block verification of -checkblocks is: "
2018-09-15 12:01:20 +02:00
" level 0 reads the blocks from disk, "
" level 1 verifies block validity, "
" level 2 verifies undo data, "
" level 3 checks disconnection of tip blocks, "
" and level 4 tries to reconnect the blocks, "
" each level includes the checks of the previous levels "
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
" (0-4, default: %u) " , DEFAULT_CHECKLEVEL ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -checkmempool=<n> " , strprintf ( " Run checks every <n> transactions (default: %u, regtest: %u) " , defaultChainParams - > DefaultConsistencyChecks ( ) , regtestChainParams - > DefaultConsistencyChecks ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -checkpoints " , strprintf ( " Enable rejection of any forks from the known historical chain until block 1450000 (default: %u) " , DEFAULT_CHECKPOINTS_ENABLED ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -deprecatedrpc=<method> " , " Allows deprecated RPC method(s) to be used " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -dropmessagestest=<n> " , " Randomly drop 1 of every <n> network messages " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -limitancestorcount=<n> " , strprintf ( " Do not accept transactions if number of in-mempool ancestors is <n> or more (default: %u) " , DEFAULT_ANCESTOR_LIMIT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -limitancestorsize=<n> " , strprintf ( " Do not accept transactions whose size with all in-mempool ancestors exceeds <n> kilobytes (default: %u) " , DEFAULT_ANCESTOR_SIZE_LIMIT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -limitdescendantcount=<n> " , strprintf ( " Do not accept transactions if any ancestor would have <n> or more in-mempool descendants (default: %u) " , DEFAULT_DESCENDANT_LIMIT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -limitdescendantsize=<n> " , strprintf ( " Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u). " , DEFAULT_DESCENDANT_SIZE_LIMIT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -stopafterblockimport " , strprintf ( " Stop running after importing blocks from disk (default: %u) " , DEFAULT_STOPAFTERBLOCKIMPORT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -stopatheight " , strprintf ( " Stop running after reaching the given height in the main chain (default: %u) " , DEFAULT_STOPATHEIGHT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -watchquorums=<n> " , strprintf ( " Watch and validate quorum communication (default: %u) " , llmq : : DEFAULT_WATCH_QUORUMS ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -addrmantest " , " Allows to test address relay on localhost " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -debug=<category> " , " Output debugging information (default: -nodebug, supplying <category> is optional). "
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
" If <category> is not supplied or if <category> = 1, output all debugging information. <category> can be: " + ListLogCategories ( ) + " . " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -debugexclude=<category> " , strprintf ( " Exclude debugging information for a category. Can be used in conjunction with -debug=1 to output debug logs for all categories except one or more specified categories. " ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -disablegovernance " , strprintf ( " Disable governance validation (0-1, default: %u) " , 0 ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -logips " , strprintf ( " Include IP addresses in debug output (default: %u) " , DEFAULT_LOGIPS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -logtimemicros " , strprintf ( " Add microsecond precision to debug timestamps (default: %u) " , DEFAULT_LOGTIMEMICROS ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -logtimestamps " , strprintf ( " Prepend debug output with timestamp (default: %u) " , DEFAULT_LOGTIMESTAMPS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -logthreadnames " , strprintf ( " Prepend debug output with name of the originating thread (only available on platforms supporting thread_local) (default: %u) " , DEFAULT_LOGTHREADNAMES ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -maxsigcachesize=<n> " , strprintf ( " Limit sum of signature cache and script execution cache sizes to <n> MiB (default: %u) " , DEFAULT_MAX_SIG_CACHE_SIZE ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -maxtipage=<n> " , strprintf ( " Maximum tip age in seconds to consider node in initial block download (default: %u) " , DEFAULT_MAX_TIP_AGE ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
Merge #17617: doc: unify unix epoch time descriptions
d94d34f05f4ae3efa07de409489d68bbcc216346 doc: update developer notes wrt unix epoch time (Jon Atack)
e2f32cb5c5c7f2b1d1fc7003587b6573fb59526a qa: unify unix epoch time descriptions (Jon Atack)
Pull request description:
Closes #17613.
Updated call sites: mocktime, getblockheader, getblock, pruneblockchain,
getchaintxstats, getblocktemplate, setmocktime, getpeerinfo, setban,
getnodeaddresses, getrawtransaction, importmulti, listtransactions,
listsinceblock, gettransaction, getwalletinfo, getaddressinfo
Commands for testing manually:
```
bitcoind -help-debug | grep -A1 mocktime
bitcoin-cli help getblockheader
bitcoin-cli help getblock
bitcoin-cli help pruneblockchain
bitcoin-cli help getchaintxstats
bitcoin-cli help getblocktemplate
bitcoin-cli help setmocktime
bitcoin-cli help getpeerinfo
bitcoin-cli help setban
bitcoin-cli help getnodeaddresses
bitcoin-cli help getrawtransaction
bitcoin-cli help importmulti
bitcoin-cli help listtransactions
bitcoin-cli help listsinceblock
bitcoin-cli help gettransaction
bitcoin-cli help getwalletinfo
bitcoin-cli help getaddressinfo
```
ACKs for top commit:
laanwj:
re-ACK d94d34f05f4ae3efa07de409489d68bbcc216346
Tree-SHA512: 060713ea4e20ab72c580f06c5c7e3ef344ad9c2c9cb034987d980a54e3ed2ac0268eb3929806daa5caa7797c45f5305254fd499767db7f22862212cf77acf236
2019-12-13 10:53:37 +01:00
argsman . AddArg ( " -mocktime=<n> " , " Replace actual time with " + UNIX_EPOCH_TIME + " (default: 0) " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -minsporkkeys=<n> " , " Overrides minimum spork signers to change spork value. Only useful for regtest and devnet. Using this on mainnet or testnet will ban you. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -printpriority " , strprintf ( " Log transaction fee per kB when mining blocks (default: %u) " , DEFAULT_PRINTPRIORITY ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -printtoconsole " , " Send trace/debug info to console (default: 1 when no -daemon. To disable logging to file, set -nodebuglogfile) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -pushversion " , " Protocol version to report to other nodes " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -shrinkdebugfile " , " Shrink debug.log file on client startup (default: 1 when no -debug) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -sporkaddr=<dashaddress> " , " Override spork address. Only useful for regtest and devnet. Using this on mainnet or testnet will ban you. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -sporkkey=<privatekey> " , " Set the private key to be used for signing spork messages. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
argsman . AddArg ( " -uacomment=<cmt> " , " Append comment to the user agent string " , ArgsManager : : ALLOW_ANY , OptionsCategory : : DEBUG_TEST ) ;
SetupChainParamsBaseOptions ( argsman ) ;
argsman . AddArg ( " -llmq-data-recovery=<n> " , strprintf ( " Enable automated quorum data recovery (default: %u) " , llmq : : DEFAULT_ENABLE_QUORUM_DATA_RECOVERY ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : MASTERNODE ) ;
argsman . AddArg ( " -llmq-qvvec-sync=<quorum_name>:<mode> " , strprintf ( " Defines from which LLMQ type the masternode should sync quorum verification vectors. Can be used multiple times with different LLMQ types. <mode>: %d (sync always from all quorums of the type defined by <quorum_name>), %d (sync from all quorums of the type defined by <quorum_name> if a member of any of the quorums) " , ( int32_t ) llmq : : QvvecSyncMode : : Always , ( int32_t ) llmq : : QvvecSyncMode : : OnlyIfTypeMember ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : MASTERNODE ) ;
argsman . AddArg ( " -masternodeblsprivkey=<hex> " , " Set the masternode BLS private key and enable the client to act as a masternode " , ArgsManager : : ALLOW_ANY , OptionsCategory : : MASTERNODE ) ;
argsman . 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. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : MASTERNODE ) ;
argsman . AddArg ( " -acceptnonstdtxn " , strprintf ( " Relay and mine \" non-standard \" transactions (%sdefault: %u) " , " testnet/regtest only; " , ! testnetChainParams - > RequireStandard ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : NODE_RELAY ) ;
argsman . AddArg ( " -dustrelayfee=<amt> " , strprintf ( " Fee rate (in %s/kB) used to define dust, the value of an output such that it will cost more than its value in fees at this fee rate to spend it. (default: %s) " , CURRENCY_UNIT , FormatMoney ( DUST_RELAY_TX_FEE ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : NODE_RELAY ) ;
argsman . AddArg ( " -incrementalrelayfee=<amt> " , strprintf ( " Fee rate (in %s/kB) used to define cost of relay, used for mempool limiting and BIP 125 replacement. (default: %s) " , CURRENCY_UNIT , FormatMoney ( DEFAULT_INCREMENTAL_RELAY_FEE ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : NODE_RELAY ) ;
argsman . AddArg ( " -bytespersigop " , strprintf ( " Equivalent bytes per sigop in transactions for relay and mining (default: %u) " , DEFAULT_BYTES_PER_SIGOP ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : NODE_RELAY ) ;
argsman . AddArg ( " -datacarrier " , strprintf ( " Relay and mine data carrier transactions (default: %u) " , DEFAULT_ACCEPT_DATACARRIER ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : NODE_RELAY ) ;
argsman . AddArg ( " -datacarriersize " , strprintf ( " Maximum size of data in data carrier transactions we relay and mine (default: %u) " , MAX_OP_RETURN_RELAY ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : NODE_RELAY ) ;
argsman . AddArg ( " -minrelaytxfee=<amt> " , strprintf ( " Fees (in %s/kB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s) " ,
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
CURRENCY_UNIT , FormatMoney ( DEFAULT_MIN_RELAY_TX_FEE ) ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : NODE_RELAY ) ;
2020-02-26 18:44:25 +01:00
argsman . AddArg ( " -whitelistforcerelay " , strprintf ( " Add 'forcerelay' permission to whitelisted inbound peers with default permissions. This will relay transactions even if the transactions were already in the mempool. (default: %d) " , DEFAULT_WHITELISTFORCERELAY ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : NODE_RELAY ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -whitelistrelay " , strprintf ( " Add 'relay' permission to whitelisted inbound peers with default permissions. This will accept relayed transactions even when not relaying transactions (default: %d) " , DEFAULT_WHITELISTRELAY ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : NODE_RELAY ) ;
argsman . AddArg ( " -blockmaxsize=<n> " , strprintf ( " Set maximum block size in bytes (default: %d) " , DEFAULT_BLOCK_MAX_SIZE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : BLOCK_CREATION ) ;
argsman . AddArg ( " -blockmintxfee=<amt> " , strprintf ( " Set lowest fee rate (in %s/kB) for transactions to be included in block creation. (default: %s) " , CURRENCY_UNIT , FormatMoney ( DEFAULT_BLOCK_MIN_TX_FEE ) ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : BLOCK_CREATION ) ;
argsman . AddArg ( " -blockversion=<n> " , " Override block version to test forking scenarios " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : BLOCK_CREATION ) ;
argsman . AddArg ( " -rest " , strprintf ( " Accept public REST requests (default: %u) " , DEFAULT_REST_ENABLE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -rpcallowip=<ip> " , " Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times " , ArgsManager : : ALLOW_ANY , OptionsCategory : : RPC ) ;
2020-01-30 23:10:50 +01:00
argsman . AddArg ( " -rpcauth=<userpw> " , " Username and HMAC-SHA-256 hashed password for JSON-RPC connections. The field <userpw> comes in the format: <USERNAME>:<SALT>$<HASH>. A canonical python script is included in share/rpcuser. The client then connects normally using the rpcuser=<USERNAME>/rpcpassword=<PASSWORD> pair of arguments. This option can be specified multiple times " , ArgsManager : : ALLOW_ANY | ArgsManager : : SENSITIVE , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -rpcbind=<addr>[:port] " , " Bind to given address to listen for JSON-RPC connections. Do not expose the RPC server to untrusted networks such as the public internet! This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost, or if -rpcallowip has been specified, 0.0.0.0 and :: i.e., all addresses) " , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY | ArgsManager : : SENSITIVE , OptionsCategory : : RPC ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -rpccookiefile=<loc> " , " Location of the auth cookie. Relative paths will be prefixed by a net-specific datadir location. (default: data dir) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : RPC ) ;
2020-01-30 23:10:50 +01:00
argsman . AddArg ( " -rpcpassword=<pw> " , " Password for JSON-RPC connections " , ArgsManager : : ALLOW_ANY | ArgsManager : : SENSITIVE , OptionsCategory : : RPC ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -rpcport=<port> " , strprintf ( " Listen for JSON-RPC connections on <port> (default: %u, testnet: %u, regtest: %u) " , defaultBaseParams - > RPCPort ( ) , testnetBaseParams - > RPCPort ( ) , regtestBaseParams - > RPCPort ( ) ) , ArgsManager : : ALLOW_ANY | ArgsManager : : NETWORK_ONLY , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -rpcservertimeout=<n> " , strprintf ( " Timeout during HTTP requests (default: %d) " , DEFAULT_HTTP_SERVER_TIMEOUT ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -rpcthreads=<n> " , strprintf ( " Set the number of threads to service RPC calls (default: %d) " , DEFAULT_HTTP_THREADS ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : RPC ) ;
2020-01-30 23:10:50 +01:00
argsman . AddArg ( " -rpcuser=<user> " , " Username for JSON-RPC connections " , ArgsManager : : ALLOW_ANY | ArgsManager : : SENSITIVE , OptionsCategory : : RPC ) ;
Merge #12763: Add RPC Whitelist Feature from #12248
2081442c421cc4376e5d7839f68fbe7630e89103 test: Add test for rpc_whitelist (Emil Engler)
7414d3820c833566b4f48c6c120a18bf53978c55 Add RPC Whitelist Feature from #12248 (Jeremy Rubin)
Pull request description:
Summary
====
This patch adds the RPC whitelisting feature requested in #12248. RPC Whitelists help enforce application policies for services being built on top of Bitcoin Core (e.g., your Lightning Node maybe shouldn't be adding new peers). The aim of this PR is not to make it advisable to connect your Bitcoin node to arbitrary services, but to reduce risk and prevent unintended access.
Using RPC Whitelists
====
The way it works is you specify (in your bitcoin.conf) configurations such as
```
rpcauth=user1:4cc74397d6e9972e5ee7671fd241$11849357f26a5be7809c68a032bc2b16ab5dcf6348ef3ed1cf30dae47b8bcc71
rpcauth=user2:181b4a25317bff60f3749adee7d6bca0$d9c331474f1322975fa170a2ffbcb176ba11644211746b27c1d317f265dd4ada
rpcauth=user3:a6c8a511b53b1edcf69c36984985e$13cfba0e626db19061c9d61fa58e712d0319c11db97ad845fa84517f454f6675
rpcwhitelist=user1:getnetworkinfo
rpcwhitelist=user2:getnetworkinfo,getwalletinfo, getbestblockhash
rpcwhitelistdefault=0
```
Now user1 can only call getnetworkinfo, user2 can only call getnetworkinfo or getwalletinfo, while user3 can still call all RPCs.
If any rpcwhitelist is set, act as if all users are subject to whitelists unless rpcwhitelistdefault is set to 0. If rpcwhitelistdefault is set to 1 and no rpcwhitelist is set, act as if all users are subject to whitelists.
Review Request
=====
In addition to normal review, would love specific review from someone working on LN (e.g., @ roasbeef) and someone working on an infrastructure team at an exchange (e.g., @ jimpo) to check that this works well with their system.
Notes
=====
The rpc list is spelling sensitive -- whitespace is stripped though. Spelling errors fail towards the RPC call being blocked, which is safer.
It was unclear to me if HTTPReq_JSONRPC is the best function to patch this functionality into, or if it would be better to place it in exec or somewhere else.
It was also unclear to me if it would be preferred to cache the whitelists on startup or parse them on every RPC as is done with multiUserAuthorized. I opted for the cached approach as I thought it was a bit cleaner.
Future Work
=====
In a future PR, I would like to add an inheritance scheme. This seemed more controversial so I didn't want to include that here. Inheritance semantics are tricky, but it would also make these whitelists easier to read.
It also might be good to add a `getrpcwhitelist` command to facilitate permission discovery.
Tests
=====
Thanks to @ emilengler for adding tests for this feature. The tests cover all cases except for where `rpcwhitelistdefault=1` is used, given difficulties around testing with the current test framework.
ACKs for top commit:
laanwj:
ACK 2081442c421cc4376e5d7839f68fbe7630e89103
Tree-SHA512: 0dc1ac6a6f2f4b0be9c9054d495dd17752fe7b3589aeab2c6ac4e1f91cf4e7e355deedcb5d76d707cbb5a949c2f989c871b74d6bf129351f429569a701adbcbf
2019-12-13 11:25:39 +01:00
argsman . AddArg ( " -rpcwhitelist=<whitelist> " , " Set a whitelist to filter incoming RPC calls for a specific user. The field <whitelist> comes in the format: <USERNAME>:<rpc 1>,<rpc 2>,...,<rpc n>. If multiple whitelists are set for a given user, they are set-intersected. See -rpcwhitelistdefault documentation for information on default whitelist behavior. " , ArgsManager : : ALLOW_ANY , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -rpcwhitelistdefault " , " Sets default behavior for rpc whitelisting. Unless rpcwhitelistdefault is set to 0, if any -rpcwhitelist is set, the rpc server acts as if all rpc users are subject to empty-unless-otherwise-specified whitelists. If rpcwhitelistdefault is set to 1 and no -rpcwhitelist is set, rpc server acts as if all rpc users are subject to empty whitelists. " , ArgsManager : : ALLOW_BOOL , OptionsCategory : : RPC ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -rpcworkqueue=<n> " , strprintf ( " Set the depth of the work queue to service RPC calls (default: %d) " , DEFAULT_HTTP_WORKQUEUE ) , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -server " , " Accept command line and JSON-RPC commands " , ArgsManager : : ALLOW_ANY , OptionsCategory : : RPC ) ;
argsman . AddArg ( " -statsenabled " , strprintf ( " Publish internal stats to statsd (default: %u) " , DEFAULT_STATSD_ENABLE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : STATSD ) ;
argsman . AddArg ( " -statshost=<ip> " , strprintf ( " Specify statsd host (default: %s) " , DEFAULT_STATSD_HOST ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : STATSD ) ;
argsman . AddArg ( " -statshostname=<ip> " , strprintf ( " Specify statsd host name (default: %s) " , DEFAULT_STATSD_HOSTNAME ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : STATSD ) ;
argsman . AddArg ( " -statsport=<port> " , strprintf ( " Specify statsd port (default: %u) " , DEFAULT_STATSD_PORT ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : STATSD ) ;
argsman . AddArg ( " -statsns=<ns> " , strprintf ( " Specify additional namespace prefix (default: %s) " , DEFAULT_STATSD_NAMESPACE ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : STATSD ) ;
argsman . AddArg ( " -statsperiod=<seconds> " , strprintf ( " Specify the number of seconds between periodic measurements (default: %d) " , DEFAULT_STATSD_PERIOD ) , ArgsManager : : ALLOW_ANY , OptionsCategory : : STATSD ) ;
2021-06-19 16:34:39 +02:00
# if HAVE_DECL_DAEMON
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -daemon " , " Run in the background as a daemon and accept commands " , ArgsManager : : ALLOW_ANY , OptionsCategory : : OPTIONS ) ;
2021-06-19 16:34:39 +02:00
# 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
2022-05-21 10:27:30 +02:00
argsman . 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
2022-03-24 05:13:51 +01:00
return CopyrightHolders ( _ ( " Copyright (C) " ) . translated , 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. "
2022-03-24 05:13:51 +01:00
" Visit %s for further information about the software. " ) . translated ,
2016-06-16 10:53:23 +02:00
PACKAGE_NAME , URL_WEBSITE ) +
" \n " +
2022-03-24 05:13:51 +01:00
strprintf ( _ ( " The source code is available from %s. " ) . translated ,
2016-06-16 10:53:23 +02:00
URL_SOURCE_CODE ) +
2014-06-10 16:02:46 +02:00
" \n " +
2016-06-16 10:53:23 +02:00
" \n " +
2022-03-24 05:13:51 +01:00
_ ( " This is experimental software. " ) . translated + " \n " +
2019-10-26 14:15:43 +02:00
strprintf ( _ ( " Distributed under the MIT software license, see the accompanying file %s or %s " ) . translated , " COPYING " , " <https://opensource.org/licenses/MIT> " ) +
2014-06-10 16:02:46 +02:00
" \n " ;
}
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 ) {
2022-12-20 17:18:10 +01:00
if ( LocaleIndependentAtoi < int > ( item . first ) = = nContigCounter ) {
2015-06-02 21:24:53 +02:00
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
}
}
2022-05-21 11:30:27 +02:00
static void ThreadImport ( ChainstateManager & chainman , std : : vector < fs : : path > vImportFiles , const ArgsManager & args )
2013-03-07 04:31:26 +01:00
{
2015-04-17 14:40:24 +02:00
const CChainParams & chainparams = Params ( ) ;
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 ) {
2021-08-12 09:02:29 +02:00
FlatFilePos pos ( nFile , 0 ) ;
if ( ! fs : : exists ( GetBlockPosFilename ( pos ) ) )
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 ) ;
2020-04-27 21:36:05 +02:00
if ( ShutdownRequested ( ) ) {
LogPrintf ( " Shutdown requested. Exit %s \n " , __func__ ) ;
return ;
}
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
}
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 ) ;
2020-04-27 21:36:05 +02:00
if ( ShutdownRequested ( ) ) {
LogPrintf ( " Shutdown requested. Exit %s \n " , __func__ ) ;
return ;
}
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
2022-04-03 16:41:38 +02:00
// We can't hold cs_main during ActivateBestChain even though we're accessing
2022-05-05 20:07:00 +02:00
// the chainman unique_ptrs since ABC requires us not to be holding cs_main, so retrieve
2022-04-03 16:41:38 +02:00
// the relevant pointers before the ABC call.
2022-05-05 20:07:00 +02:00
for ( CChainState * chainstate : WITH_LOCK ( : : cs_main , return chainman . GetAll ( ) ) ) {
2022-04-03 16:41:38 +02:00
CValidationState state ;
if ( ! chainstate - > ActivateBestChain ( state , chainparams , nullptr ) ) {
LogPrintf ( " Failed to connect best block (%s) \n " , FormatStateMessage ( state ) ) ;
StartShutdown ( ) ;
return ;
}
2017-07-10 16:41:14 +02:00
}
2022-05-21 11:30:27 +02:00
if ( args . 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.
2021-10-16 12:54:22 +02:00
// GetMainSignals().UpdatedBlockTip(::ChainActive().Tip());
2018-09-12 13:13:17 +02:00
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 ( ) ;
refactor: numerous changes to avoid passing around a const ref to shared_ptr of CDeterministicMNC when not needed. (#4653)
* refactor: numerous changes to avoid passing around a const ref to shared_ptr of CDeterministicMNC when not needed.
Introduces ForEachMNShared, a version of ForEachMN that uses a shared_ptr, and may extend the lifetime of the underlying shared_ptr. This is not preferred, should prefer ForEachMN. See docs.
Adjusts ForEachMN to pass a reference. This is preferred for use over ForEachMNShared. See docs. A reference should be used since in usage we assume it's non-null anyway. Additionally, it allows us to know that the lifespan of the dmn is not being being extended (if lifespan needs to be extended, should use ForEachMNShared.
IsMNValid, IsMNPoSeBanned, UpdateMN, UpdateMN, AddUniqueProperty, DeleteUniqueProperty, UpdateUniqueProperty now take a const reference to CDeterministicMN instead of a const reference to shared_ptr<CDeterministicMN>. All of these functions previously assumed (or would've crashed) a non-null ptr, and non extended lifetime, as such converting to ref is appropriate.
CompareByLastPaid ptr overload now takes raw ptr instead of a const ref to shared. Since we simply dereference them, a raw ptr makes the most sense. This also avoids a potential expensive and implicit raw ptr -> shared ptr conversion if the function was called with raw ptrs.
rpcevo BuildDMNListEntry now takes a const ref for reasons as stated above
Signed-off-by: Pasta <pasta@dashboost.org>
* make stuff const
Signed-off-by: Pasta <pasta@dashboost.org>
* refactor/llmq: use ranges count_if
Signed-off-by: Pasta <pasta@dashboost.org>
2022-01-04 17:13:38 +01:00
mnList . ForEachMN ( false , [ & ] ( auto & dmn ) {
2019-11-22 19:12:57 +01:00
Coin coin ;
refactor: numerous changes to avoid passing around a const ref to shared_ptr of CDeterministicMNC when not needed. (#4653)
* refactor: numerous changes to avoid passing around a const ref to shared_ptr of CDeterministicMNC when not needed.
Introduces ForEachMNShared, a version of ForEachMN that uses a shared_ptr, and may extend the lifetime of the underlying shared_ptr. This is not preferred, should prefer ForEachMN. See docs.
Adjusts ForEachMN to pass a reference. This is preferred for use over ForEachMNShared. See docs. A reference should be used since in usage we assume it's non-null anyway. Additionally, it allows us to know that the lifespan of the dmn is not being being extended (if lifespan needs to be extended, should use ForEachMNShared.
IsMNValid, IsMNPoSeBanned, UpdateMN, UpdateMN, AddUniqueProperty, DeleteUniqueProperty, UpdateUniqueProperty now take a const reference to CDeterministicMN instead of a const reference to shared_ptr<CDeterministicMN>. All of these functions previously assumed (or would've crashed) a non-null ptr, and non extended lifetime, as such converting to ref is appropriate.
CompareByLastPaid ptr overload now takes raw ptr instead of a const ref to shared. Since we simply dereference them, a raw ptr makes the most sense. This also avoids a potential expensive and implicit raw ptr -> shared ptr conversion if the function was called with raw ptrs.
rpcevo BuildDMNListEntry now takes a const ref for reasons as stated above
Signed-off-by: Pasta <pasta@dashboost.org>
* make stuff const
Signed-off-by: Pasta <pasta@dashboost.org>
* refactor/llmq: use ranges count_if
Signed-off-by: Pasta <pasta@dashboost.org>
2022-01-04 17:13:38 +01:00
GetUTXOCoin ( dmn . collateralOutpoint , coin ) ;
2019-11-22 19:12:57 +01:00
} ) ;
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 ) ;
2022-05-07 17:46:33 +02:00
activeMasternodeManager - > Init ( : : ChainActive ( ) . Tip ( ) ) ;
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
2020-09-07 09:47:14 +02:00
chainman . ActiveChainstate ( ) . LoadMempool ( args ) ;
2012-10-22 22:45:26 +02:00
}
2020-09-07 09:47:14 +02:00
static void PeriodicStats ( ArgsManager & args , const CTxMemPool & mempool )
2020-12-15 17:22:23 +01:00
{
2022-05-21 11:30:27 +02:00
assert ( args . GetBoolArg ( " -statsenabled " , DEFAULT_STATSD_ENABLE ) ) ;
2020-12-15 17:22:23 +01:00
CCoinsStats stats ;
2021-10-09 16:14:44 +02:00
: : ChainstateActive ( ) . ForceFlushStateToDisk ( ) ;
2022-12-25 09:25:19 +01:00
if ( WITH_LOCK ( cs_main , return GetUTXOStats ( & : : ChainstateActive ( ) . CoinsDB ( ) , stats , CoinStatsHashType : : NONE , RpcInterruptionPoint ) ) ) {
2020-12-15 17:22:23 +01:00
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);
2022-05-07 17:46:33 +02:00
CBlockIndex * tip = : : ChainActive ( ) . Tip ( ) ;
2020-12-15 17:22:23 +01:00
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 ) ) ;
2021-10-21 19:27:31 +02:00
statsClient . gauge ( " transactions.txCacheSize " , WITH_LOCK ( cs_main , return : : ChainstateActive ( ) . CoinsTip ( ) . GetCacheSize ( ) ) , 1.0f ) ;
2021-01-08 20:45:57 +01:00
statsClient . gauge ( " transactions.totalTransactions " , tip - > nChainTx , 1.0f ) ;
2020-12-15 17:22:23 +01:00
2020-09-07 09:47:14 +02:00
{
LOCK ( mempool . cs ) ;
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 ( args . GetArg ( " -maxmempool " , DEFAULT_MAX_MEMPOOL_SIZE ) * 1000000 ) . GetFeePerK ( ) , 1.0f ) ;
}
2020-12-15 17:22:23 +01:00
}
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-09-20 23:57:13 +02:00
static bool InitSanityCheck ( )
2014-06-03 01:21:03 +02:00
{
2020-05-08 18:17:47 +02:00
if ( ! ECC_InitSanityCheck ( ) ) {
return InitError ( Untranslated ( " Elliptic curve cryptography sanity check failure. Aborting. " ) ) ;
2014-06-03 01:21:03 +02:00
}
2017-03-01 12:40:06 +01:00
2021-03-10 07:31:10 +01:00
if ( ! glibcxx_sanity_test ( ) )
2014-06-14 01:23:01 +02:00
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 ( ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( Untranslated ( " OS cryptographic RNG sanity check failure. Aborting. " ) ) ;
2017-03-01 12:40:06 +01:00
}
2014-06-03 01:21:03 +02:00
return true ;
}
2022-10-22 19:18:03 +02:00
static bool AppInitServers ( const CoreContext & context , NodeContext & node )
2011-05-14 20:10:21 +02:00
{
2022-05-21 11:30:27 +02:00
const ArgsManager & args = * Assert ( node . args ) ;
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 ( ) ;
2020-06-18 21:19:26 +02:00
node . rpc_interruption_point = RpcInterruptionPoint ;
2022-04-23 09:46:44 +02:00
if ( ! StartHTTPRPC ( context ) )
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
return false ;
2022-05-21 11:30:27 +02:00
if ( args . GetBoolArg ( " -rest " , DEFAULT_REST_ENABLE ) ) StartREST ( context ) ;
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
2022-05-21 11:30:27 +02:00
void InitParameterInteraction ( ArgsManager & args )
2015-10-08 09:58:31 +02:00
{
// when specifying an explicit binding address, you want to listen on it
// even when -connect or -proxy is specified
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -bind " ) ) {
if ( args . SoftSetBoolArg ( " -listen " , true ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -bind set -> setting -listen=1 \n " , __func__ ) ;
2014-06-04 13:16:07 +02:00
}
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -whitebind " ) ) {
if ( args . SoftSetBoolArg ( " -listen " , true ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -whitebind set -> setting -listen=1 \n " , __func__ ) ;
2012-05-24 19:02:21 +02:00
}
2012-05-21 16:47:29 +02:00
2022-05-21 11:30:27 +02:00
if ( args . 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
2022-05-21 11:30:27 +02:00
if ( args . SoftSetBoolArg ( " -dnsseed " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -connect set -> setting -dnsseed=0 \n " , __func__ ) ;
2022-05-21 11:30:27 +02:00
if ( args . 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
}
2022-05-21 11:30:27 +02:00
if ( args . 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
2022-05-21 11:30:27 +02:00
if ( args . SoftSetBoolArg ( " -listen " , false ) )
2015-05-18 11:21:32 +02:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -listen=0 \n " , __func__ ) ;
2022-02-26 13:19:13 +01:00
// to protect privacy, do not map ports when a proxy is set. The user may still specify -listen=1
2015-05-18 11:21:32 +02:00
// to listen locally, so don't rely on this happening through -listen below.
2022-05-21 11:30:27 +02:00
if ( args . SoftSetBoolArg ( " -upnp " , false ) )
2015-05-18 11:21:32 +02:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -upnp=0 \n " , __func__ ) ;
2022-05-21 11:30:27 +02:00
if ( args . SoftSetBoolArg ( " -natpmp " , false ) )
2022-02-26 13:19:13 +01:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -natpmp=0 \n " , __func__ ) ;
2014-07-21 08:32:25 +02:00
// to protect privacy, do not discover addresses by default
2022-05-21 11:30:27 +02:00
if ( args . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -proxy set -> setting -discover=0 \n " , __func__ ) ;
2012-05-24 19:02:21 +02:00
}
2022-05-21 11:30:27 +02:00
if ( ! args . 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)
2022-05-21 11:30:27 +02:00
if ( args . SoftSetBoolArg ( " -upnp " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -upnp=0 \n " , __func__ ) ;
2022-05-21 11:30:27 +02:00
if ( args . SoftSetBoolArg ( " -natpmp " , false ) )
2022-02-26 13:19:13 +01:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -natpmp=0 \n " , __func__ ) ;
2022-05-21 11:30:27 +02:00
if ( args . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -discover=0 \n " , __func__ ) ;
2022-05-21 11:30:27 +02:00
if ( args . SoftSetBoolArg ( " -listenonion " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -listen=0 -> setting -listenonion=0 \n " , __func__ ) ;
2012-05-21 16:47:29 +02:00
}
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -externalip " ) ) {
2012-05-24 19:02:21 +02:00
// if an explicit public IP is specified, do not try to find others
2022-05-21 11:30:27 +02:00
if ( args . SoftSetBoolArg ( " -discover " , false ) )
2015-10-08 09:58:31 +02:00
LogPrintf ( " %s: parameter interaction: -externalip set -> setting -discover=0 \n " , __func__ ) ;
2012-05-24 19:02:21 +02:00
}
2016-11-23 07:17:47 +01:00
// disable whitelistrelay in blocksonly mode
2022-05-21 11:30:27 +02:00
if ( args . GetBoolArg ( " -blocksonly " , DEFAULT_BLOCKSONLY ) ) {
if ( args . 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.
2022-05-21 11:30:27 +02:00
if ( args . GetBoolArg ( " -whitelistforcerelay " , DEFAULT_WHITELISTFORCERELAY ) ) {
if ( args . 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
}
2022-05-21 11:30:27 +02:00
int64_t nPruneArg = args . GetArg ( " -prune " , 0 ) ;
2020-07-29 15:27:45 +02:00
if ( nPruneArg > 0 ) {
2022-05-21 11:30:27 +02:00
if ( args . 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
}
2022-05-21 11:30:27 +02:00
if ( args . 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 =
2022-05-21 11:30:27 +02:00
args . GetBoolArg ( " -addressindex " , DEFAULT_ADDRESSINDEX ) | |
args . GetBoolArg ( " -spentindex " , DEFAULT_SPENTINDEX ) | |
args . GetBoolArg ( " -timestampindex " , DEFAULT_TIMESTAMPINDEX ) ;
2017-12-12 02:24:24 +01:00
2022-05-21 11:30:27 +02:00
if ( fAdditionalIndexes & & args . GetArg ( " -checklevel " , DEFAULT_CHECKLEVEL ) < 4 ) {
args . 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
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -masternodeblsprivkey " ) & & args . SoftSetBoolArg ( " -disablewallet " , true ) ) {
2020-12-09 21:29:31 +01:00
LogPrintf ( " %s: parameter interaction: -masternodeblsprivkey set -> setting -disablewallet=1 \n " , __func__ ) ;
}
2015-10-08 09:58:31 +02:00
}
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 .
*/
2022-05-21 11:30:27 +02:00
void InitLogging ( const ArgsManager & args )
2015-11-26 14:03:27 +01:00
{
2022-05-21 11:30:27 +02:00
LogInstance ( ) . m_print_to_file = ! args . IsArgNegated ( " -debuglogfile " ) ;
LogInstance ( ) . m_file_path = AbsPathForConfigVal ( args . GetArg ( " -debuglogfile " , DEFAULT_DEBUGLOGFILE ) ) ;
LogInstance ( ) . m_print_to_console = args . GetBoolArg ( " -printtoconsole " , ! args . GetBoolArg ( " -daemon " , false ) ) ;
LogInstance ( ) . m_log_timestamps = args . GetBoolArg ( " -logtimestamps " , DEFAULT_LOGTIMESTAMPS ) ;
LogInstance ( ) . m_log_time_micros = args . GetBoolArg ( " -logtimemicros " , DEFAULT_LOGTIMEMICROS ) ;
LogInstance ( ) . m_log_threadnames = args . GetBoolArg ( " -logthreadnames " , DEFAULT_LOGTHREADNAMES ) ;
2018-05-01 04:13:30 +02:00
2022-05-21 11:30:27 +02:00
fLogIPs = args . 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 ( ) ;
2022-03-14 22:40:40 +01:00
# ifdef DEBUG_CORE
2018-01-29 11:12:08 +01:00
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 ;
2022-03-11 20:39:12 +01:00
ServiceFlags nLocalServices = ServiceFlags ( NODE_NETWORK | NODE_NETWORK_LIMITED | NODE_HEADERS_COMPRESSED ) ;
2018-12-04 12:06:35 +01:00
int64_t peer_connect_timeout ;
2019-12-06 21:47:55 +01:00
std : : set < BlockFilterType > g_enabled_filter_types ;
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 ( ) ;
} ;
2020-12-06 01:14:17 +01:00
bool AppInitBasicSetup ( const ArgsManager & args )
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
2020-01-20 20:54:23 +01:00
// Enable heap terminate-on-corruption
HeapSetInformation ( nullptr , HeapEnableTerminationOnCorruption , nullptr , 0 ) ;
2011-05-14 20:10:21 +02:00
# endif
2014-06-04 13:16:07 +02:00
2020-05-08 18:17:47 +02:00
if ( ! SetupNetworking ( ) ) {
return InitError ( Untranslated ( " Initializing networking failed. " ) ) ;
}
2015-09-02 16:18:16 +02:00
# ifndef WIN32
2022-05-21 11:30:27 +02:00
if ( ! args . 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
2022-05-21 11:30:27 +02:00
bool AppInitParameterInteraction ( const ArgsManager & args )
2016-12-01 01:07:21 +01:00
{
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
2020-06-01 10:05:15 +02:00
// Error if network-specific options (-addnode, -connect, etc) are
2021-10-17 04:03:18 +02:00
// specified in default section of config file, but not overridden
// on the command line or in this network's section of the config file.
2022-05-21 11:30:27 +02:00
std : : string network = args . GetChainName ( ) ;
2020-06-01 10:05:15 +02:00
bilingual_str errors ;
2022-05-21 11:30:27 +02:00
for ( const auto & arg : args . GetUnsuitableSectionOnlyArgs ( ) ) {
2020-06-01 10:05:15 +02:00
errors + = strprintf ( _ ( " Config setting for %s only applied on %s network when in [%s] section. " ) + Untranslated ( " \n " ) , arg , network , network ) ;
}
if ( ! errors . empty ( ) ) {
return InitError ( errors ) ;
2021-10-17 04:03:18 +02:00
}
// Warn if unrecognized section name are present in the config file.
2020-06-01 10:05:15 +02:00
bilingual_str warnings ;
2022-05-21 11:30:27 +02:00
for ( const auto & section : args . GetUnrecognizedSections ( ) ) {
2020-06-01 10:05:15 +02:00
warnings + = strprintf ( Untranslated ( " %s:%i " ) + _ ( " Section [%s] is not recognized. " ) + Untranslated ( " \n " ) , section . m_file , section . m_line , section . m_name ) ;
}
if ( ! warnings . empty ( ) ) {
InitWarning ( warnings ) ;
2021-10-17 04:03:18 +02:00
}
2019-01-16 13:28:54 +01:00
if ( ! fs : : is_directory ( GetBlocksDir ( ) ) ) {
2022-05-21 11:30:27 +02:00
return InitError ( strprintf ( _ ( " Specified blocks directory \" %s \" does not exist. " ) , args . GetArg ( " -blocksdir " , " " ) ) ) ;
2018-03-27 21:04:22 +02:00
}
2021-08-12 09:04:28 +02:00
// parse and validate enabled filter types
2022-05-21 11:30:27 +02:00
std : : string blockfilterindex_value = args . GetArg ( " -blockfilterindex " , DEFAULT_BLOCKFILTERINDEX ) ;
2021-08-12 09:04:28 +02:00
if ( blockfilterindex_value = = " " | | blockfilterindex_value = = " 1 " ) {
g_enabled_filter_types = AllBlockFilterTypes ( ) ;
} else if ( blockfilterindex_value ! = " 0 " ) {
2022-05-21 11:30:27 +02:00
const std : : vector < std : : string > names = args . GetArgs ( " -blockfilterindex " ) ;
2021-08-12 09:04:28 +02:00
for ( const auto & name : names ) {
BlockFilterType filter_type ;
if ( ! BlockFilterTypeByName ( name , filter_type ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Unknown -blockfilterindex value %s. " ) , name ) ) ;
2021-08-12 09:04:28 +02:00
}
2019-12-06 21:47:55 +01:00
g_enabled_filter_types . insert ( filter_type ) ;
2021-08-12 09:04:28 +02:00
}
}
2020-06-01 04:58:42 +02:00
// Signal NODE_COMPACT_FILTERS if peerblockfilters and basic filters index are both enabled.
2022-05-21 11:30:27 +02:00
if ( args . GetBoolArg ( " -peerblockfilters " , DEFAULT_PEERBLOCKFILTERS ) ) {
2020-06-01 04:58:42 +02:00
if ( g_enabled_filter_types . count ( BlockFilterType : : BASIC_FILTER ) ! = 1 ) {
2020-05-08 18:17:47 +02:00
return InitError ( _ ( " Cannot set -peerblockfilters without -blockfilterindex. " ) ) ;
2020-06-01 04:58:42 +02:00
}
nLocalServices = ServiceFlags ( nLocalServices | NODE_COMPACT_FILTERS ) ;
2021-09-19 06:31:43 +02:00
}
2020-07-09 01:28:30 +02:00
// if using block pruning, then disallow txindex and require disabling governance validation
2022-05-21 11:30:27 +02:00
if ( args . GetArg ( " -prune " , 0 ) ) {
if ( args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) )
2020-05-08 18:17:47 +02:00
return InitError ( _ ( " Prune mode is incompatible with -txindex. " ) ) ;
2022-05-21 11:30:27 +02:00
if ( ! args . GetBoolArg ( " -disablegovernance " , false ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( _ ( " Prune mode is incompatible with -disablegovernance=false. " ) ) ;
2020-07-09 01:28:30 +02:00
}
2021-08-12 09:04:28 +02:00
if ( ! g_enabled_filter_types . empty ( ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( _ ( " Prune mode is incompatible with -blockfilterindex. " ) ) ;
2021-08-12 09:04:28 +02:00
}
Add block pruning functionality
This adds a -prune=N option to bitcoind, which if set to N>0 will enable block
file pruning. When pruning is enabled, block and undo files will be deleted to
try to keep total space used by those files to below the prune target (N, in
MB) specified by the user, subject to some constraints:
- The last 288 blocks on the main chain are always kept (MIN_BLOCKS_TO_KEEP),
- N must be at least 550MB (chosen as a value for the target that could
reasonably be met, with some assumptions about block sizes, orphan rates,
etc; see comment in main.h),
- No blocks are pruned until chainActive is at least 100,000 blocks long (on
mainnet; defined separately for mainnet, testnet, and regtest in chainparams
as nPruneAfterHeight).
This unsets NODE_NETWORK if pruning is enabled.
Also included is an RPC test for pruning (pruning.py).
Thanks to @rdponticelli for earlier work on this feature; this is based in
part off that work.
2015-02-23 20:27:44 +01:00
}
2015-11-20 15:03:57 +01:00
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -devnet " ) ) {
2017-12-20 12:45:01 +01:00
// Require setting of ports when running devnet
2022-05-21 11:30:27 +02:00
if ( args . GetArg ( " -listen " , DEFAULT_LISTEN ) & & ! args . IsArgSet ( " -port " ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( _ ( " -port must be specified when -devnet and -listen are specified " ) ) ;
2017-05-15 07:30:09 +02:00
}
2022-05-21 11:30:27 +02:00
if ( args . GetArg ( " -server " , false ) & & ! args . IsArgSet ( " -rpcport " ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( _ ( " -rpcport must be specified when -devnet and -server are specified " ) ) ;
2017-05-15 07:30:09 +02:00
}
2022-05-21 11:30:27 +02:00
if ( args . GetArgs ( " -devnet " ) . size ( ) > 1 ) {
2020-05-08 18:17:47 +02: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
}
2022-05-21 11:30:27 +02:00
fAllowPrivateNet = args . 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
2022-05-21 11:30:27 +02:00
size_t nUserBind = args . GetArgs ( " -bind " ) . size ( ) + args . GetArgs ( " -whitebind " ) . size ( ) ;
if ( nUserBind ! = 0 & & ! args . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( Untranslated ( " Cannot set -bind or -whitebind together with -listen=0 " ) ) ;
2017-06-26 14:42:46 +02:00
}
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 ) ) ;
2022-05-21 11:30:27 +02:00
nUserMaxConnections = args . 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
Merge #20024: init: Fix incorrect warning "Reducing -maxconnections from N to N-1, because of system limitations"
ea93bbeb26948c0ddba39b589bd166eaecf446c8 init: Fix incorrect warning "Reducing -maxconnections from N to N-1, because of system limitations" (practicalswift)
Pull request description:
Fix incorrect warning `Reducing -maxconnections from N to N-1, because of system limitations`.
Before this patch (only the first warning is correct):
```
$ src/bitcoind -maxconnections=10000000 | grep Warning
2020-09-26T01:23:45Z Warning: Reducing -maxconnections from 10000000 to 1048417, because of system limitations.
$ src/bitcoind -maxconnections=1000000 | grep Warning
2020-09-26T01:23:45Z Warning: Reducing -maxconnections from 1000000 to 999999, because of system limitations.
$ src/bitcoind -maxconnections=100000 | grep Warning
2020-09-26T01:23:45Z Warning: Reducing -maxconnections from 100000 to 99999, because of system limitations.
$ src/bitcoind -maxconnections=10000 | grep Warning
2020-09-26T01:23:45Z Warning: Reducing -maxconnections from 10000 to 9999, because of system limitations.
$ src/bitcoind -maxconnections=1000 | grep Warning
2020-09-26T01:23:45Z Warning: Reducing -maxconnections from 1000 to 999, because of system limitations.
$ src/bitcoind -maxconnections=100 | grep Warning
[no warning]
```
After this patch (no incorrect warnings):
```
$ src/bitcoind -maxconnections=10000000 | grep Warning
2020-09-26T01:23:45Z Warning: Reducing -maxconnections from 10000000 to 1048417, because of system limitations.
$ src/bitcoind -maxconnections=1000000 | grep Warning
[no warning]
$ src/bitcoind -maxconnections=100000 | grep Warning
[no warning]
$ src/bitcoind -maxconnections=10000 | grep Warning
[no warning]
$ src/bitcoind -maxconnections=1000 | grep Warning
[no warning]
$ src/bitcoind -maxconnections=100 | grep Warning
[no warning]
```
ACKs for top commit:
n-thumann:
tACK https://github.com/bitcoin/bitcoin/pull/20024/commits/ea93bbeb26948c0ddba39b589bd166eaecf446c8, Ran on other systems running Debian 10.5 (4.19.0-8-amd64) and Debian bullseye/sid (5.3.0-1-amd64) and was able to reproduce the issue exactly as you described above on both of them. After applying your patch the issue is fixed :v:
laanwj:
Code review ACK ea93bbeb26948c0ddba39b589bd166eaecf446c8
theStack:
tACK ea93bbeb26948c0ddba39b589bd166eaecf446c8
Tree-SHA512: 9b0939a1a51fdf991d11024a5d20b4f39cab1a80320b799a1d24d0250aa059666bcb1ae6dd79c941c2f2686f07f59fc0f6618b5746aa8ca6011fdd202828a930
2020-11-19 15:28:37 +01:00
nFD = RaiseFileDescriptorLimit ( nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS + nBind ) ;
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 )
2020-05-08 18:17:47 +02:00
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 )
2020-05-13 20:30:31 +02:00
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
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -debug " ) ) {
2019-05-22 23:51:39 +02:00
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
2022-05-21 11:30:27 +02:00
const std : : vector < std : : string > categories = args . 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 ) {
2019-02-04 20:26:02 +01:00
if ( ! LogInstance ( ) . EnableCategory ( cat ) ) {
2020-05-13 20:30:31 +02:00
InitWarning ( strprintf ( _ ( " Unsupported logging category %s=%s. " ) , " -debug " , cat ) ) ;
2019-05-22 23:51:39 +02:00
}
}
}
}
// Now remove the logging categories which were explicitly excluded
2022-05-21 11:30:27 +02:00
for ( const std : : string & cat : args . GetArgs ( " -debugexclude " ) ) {
2019-02-04 20:26:02 +01:00
if ( ! LogInstance ( ) . DisableCategory ( cat ) ) {
2020-05-13 20:30:31 +02:00
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
2022-05-21 11:30:27 +02:00
fCheckBlockIndex = args . GetBoolArg ( " -checkblockindex " , chainparams . DefaultConsistencyChecks ( ) ) ;
fCheckpointsEnabled = args . GetBoolArg ( " -checkpoints " , DEFAULT_CHECKPOINTS_ENABLED ) ;
2012-06-22 19:11:57 +02:00
2022-05-21 11:30:27 +02:00
hashAssumeValid = uint256S ( args . 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 " ) ;
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -minimumchainwork " ) ) {
const std : : string minChainWorkStr = args . GetArg ( " -minimumchainwork " , " " ) ;
2017-09-06 18:49:43 +02:00
if ( ! IsHexNumber ( minChainWorkStr ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( Untranslated ( " Invalid non-hex (%s) minimum chain work value specified " ), minChainWorkStr)) ;
2017-09-06 18:49:43 +02:00
}
nMinimumChainWork = UintToArith256 ( uint256S ( minChainWorkStr ) ) ;
} else {
nMinimumChainWork = UintToArith256 ( chainparams . GetConsensus ( ) . nMinimumChainWork ) ;
}
LogPrintf ( " Setting nMinimumChainWork=%s \n " , nMinimumChainWork . GetHex ( ) ) ;
if ( nMinimumChainWork < UintToArith256 ( chainparams . GetConsensus ( ) . nMinimumChainWork ) ) {
LogPrintf ( " Warning: nMinimumChainWork set below default value of %s \n " , chainparams . GetConsensus ( ) . nMinimumChainWork . GetHex ( ) ) ;
}
2015-11-19 21:48:02 +01:00
// mempool limits
2022-05-21 11:30:27 +02:00
int64_t nMempoolSizeMax = args . GetArg ( " -maxmempool " , DEFAULT_MAX_MEMPOOL_SIZE ) * 1000000 ;
int64_t nMempoolSizeMin = args . GetArg ( " -limitdescendantsize " , DEFAULT_DESCENDANT_SIZE_LIMIT ) * 1000 * 40 ;
2015-11-19 21:48:02 +01:00
if ( nMempoolSizeMax < 0 | | nMempoolSizeMax < nMempoolSizeMin )
2020-05-08 18:17:47 +02: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.
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -incrementalrelayfee " ) ) {
2022-12-20 17:14:58 +01:00
if ( std : : optional < CAmount > inc_relay_fee = ParseMoney ( args . GetArg ( " -incrementalrelayfee " , " " ) ) ) {
: : incrementalRelayFee = CFeeRate { inc_relay_fee . value ( ) } ;
} else {
2022-05-21 11:30:27 +02:00
return InitError ( AmountErrMsg ( " incrementalrelayfee " , args . GetArg ( " -incrementalrelayfee " , " " ) ) ) ;
2022-12-20 17:14:58 +01:00
}
2017-01-16 19:32:51 +01:00
}
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
2022-05-21 11:30:27 +02:00
int64_t nPruneArg = args . GetArg ( " -prune " , 0 ) ;
2017-01-11 14:16:11 +01:00
if ( nPruneArg < 0 ) {
2020-05-08 18:17:47 +02:00
return InitError ( _ ( " Prune cannot be configured with a negative value. " ) ) ;
Add block pruning functionality
This adds a -prune=N option to bitcoind, which if set to N>0 will enable block
file pruning. When pruning is enabled, block and undo files will be deleted to
try to keep total space used by those files to below the prune target (N, in
MB) specified by the user, subject to some constraints:
- The last 288 blocks on the main chain are always kept (MIN_BLOCKS_TO_KEEP),
- N must be at least 550MB (chosen as a value for the target that could
reasonably be met, with some assumptions about block sizes, orphan rates,
etc; see comment in main.h),
- No blocks are pruned until chainActive is at least 100,000 blocks long (on
mainnet; defined separately for mainnet, testnet, and regtest in chainparams
as nPruneAfterHeight).
This unsets NODE_NETWORK if pruning is enabled.
Also included is an RPC test for pruning (pruning.py).
Thanks to @rdponticelli for earlier work on this feature; this is based in
part off that work.
2015-02-23 20:27:44 +01:00
}
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 ) {
2022-05-21 11:30:27 +02:00
if ( args . 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 ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Prune configured below the minimum of %d MiB. Please use a higher number. " ) , 550 ) ) ;
2019-05-21 15:52:59 +02:00
}
} else {
if ( nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Prune configured below the minimum of %d MiB. Please use a higher number. " ) , MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024 ) ) ;
2019-05-21 15:52:59 +02:00
}
Add block pruning functionality
This adds a -prune=N option to bitcoind, which if set to N>0 will enable block
file pruning. When pruning is enabled, block and undo files will be deleted to
try to keep total space used by those files to below the prune target (N, in
MB) specified by the user, subject to some constraints:
- The last 288 blocks on the main chain are always kept (MIN_BLOCKS_TO_KEEP),
- N must be at least 550MB (chosen as a value for the target that could
reasonably be met, with some assumptions about block sizes, orphan rates,
etc; see comment in main.h),
- No blocks are pruned until chainActive is at least 100,000 blocks long (on
mainnet; defined separately for mainnet, testnet, and regtest in chainparams
as nPruneAfterHeight).
This unsets NODE_NETWORK if pruning is enabled.
Also included is an RPC test for pruning (pruning.py).
Thanks to @rdponticelli for earlier work on this feature; this is based in
part off that work.
2015-02-23 20:27:44 +01:00
}
2019-01-30 20:16:41 +01:00
LogPrintf ( " Prune configured to target %u MiB on disk for block and undo files. \n " , nPruneTarget / 1024 / 1024 ) ;
Add block pruning functionality
This adds a -prune=N option to bitcoind, which if set to N>0 will enable block
file pruning. When pruning is enabled, block and undo files will be deleted to
try to keep total space used by those files to below the prune target (N, in
MB) specified by the user, subject to some constraints:
- The last 288 blocks on the main chain are always kept (MIN_BLOCKS_TO_KEEP),
- N must be at least 550MB (chosen as a value for the target that could
reasonably be met, with some assumptions about block sizes, orphan rates,
etc; see comment in main.h),
- No blocks are pruned until chainActive is at least 100,000 blocks long (on
mainnet; defined separately for mainnet, testnet, and regtest in chainparams
as nPruneAfterHeight).
This unsets NODE_NETWORK if pruning is enabled.
Also included is an RPC test for pruning (pruning.py).
Thanks to @rdponticelli for earlier work on this feature; this is based in
part off that work.
2015-02-23 20:27:44 +01:00
fPruneMode = true ;
}
2022-05-21 11:30:27 +02:00
nConnectTimeout = args . 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
}
2022-05-21 11:30:27 +02:00
peer_connect_timeout = args . GetArg ( " -peertimeout " , DEFAULT_PEER_CONNECT_TIMEOUT ) ;
2018-12-04 12:06:35 +01:00
if ( peer_connect_timeout < = 0 ) {
2020-05-08 18:17:47 +02:00
return InitError ( Untranslated ( " peertimeout cannot be configured with a negative value. " ) ) ;
2018-12-04 12:06:35 +01:00
}
2012-05-21 16:47:29 +02:00
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -minrelaytxfee " ) ) {
2022-12-20 17:14:58 +01:00
if ( std : : optional < CAmount > min_relay_fee = ParseMoney ( args . GetArg ( " -minrelaytxfee " , " " ) ) ) {
// High fee check is done afterward in CWallet::Create()
: : minRelayTxFee = CFeeRate { min_relay_fee . value ( ) } ;
} else {
2022-05-21 11:30:27 +02:00
return InitError ( AmountErrMsg ( " minrelaytxfee " , args . GetArg ( " -minrelaytxfee " , " " ) ) ) ;
2019-03-14 15:44:42 +01:00
}
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
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -blockmintxfee " ) ) {
2022-12-20 17:14:58 +01:00
if ( ! ParseMoney ( args . GetArg ( " -blockmintxfee " , " " ) ) ) {
2022-05-21 11:30:27 +02:00
return InitError ( AmountErrMsg ( " blockmintxfee " , args . GetArg ( " -blockmintxfee " , " " ) ) ) ;
2022-12-20 17:14:58 +01:00
}
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
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -dustrelayfee " ) ) {
2022-12-20 17:14:58 +01:00
if ( std : : optional < CAmount > parsed = ParseMoney ( args . GetArg ( " -dustrelayfee " , " " ) ) ) {
dustRelayFee = CFeeRate { parsed . value ( ) } ;
} else {
2022-05-21 11:30:27 +02:00
return InitError ( AmountErrMsg ( " dustrelayfee " , args . GetArg ( " -dustrelayfee " , " " ) ) ) ;
2022-12-20 17:14:58 +01:00
}
2013-04-26 02:11:27 +02:00
}
2012-05-21 16:47:29 +02:00
2022-05-21 11:30:27 +02:00
fRequireStandard = ! args . GetBoolArg ( " -acceptnonstdtxn " , ! chainparams . RequireStandard ( ) ) ;
2019-07-16 22:07:14 +02:00
if ( ! chainparams . IsTestChain ( ) & & ! fRequireStandard ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( Untranslated ( " acceptnonstdtxn is not currently supported for %s chain " ) , chainparams . NetworkIDString ( ) ) ) ;
2019-07-16 22:07:14 +02:00
}
2022-05-21 11:30:27 +02:00
nBytesPerSigOp = args . 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
2022-05-21 11:30:27 +02:00
fIsBareMultisigStd = args . GetBoolArg ( " -permitbaremultisig " , DEFAULT_PERMIT_BAREMULTISIG ) ;
fAcceptDatacarrier = args . GetBoolArg ( " -datacarrier " , DEFAULT_ACCEPT_DATACARRIER ) ;
nMaxDatacarrierBytes = args . 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):
2022-05-21 11:30:27 +02:00
SetMockTime ( args . GetArg ( " -mocktime " , 0 ) ) ; // SetMockTime(0) is a no-op
2015-06-19 16:42:39 +02:00
2022-05-21 11:30:27 +02:00
if ( args . 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
2022-05-21 11:30:27 +02:00
nMaxTipAge = args . GetArg ( " -maxtipage " , DEFAULT_MAX_TIP_AGE ) ;
2016-01-18 11:55:52 +01:00
2021-02-01 17:10:19 +01:00
try {
2022-08-02 19:14:25 +02:00
const bool fRecoveryEnabled { llmq : : utils : : QuorumDataRecoveryEnabled ( ) } ;
const bool fQuorumVvecRequestsEnabled { llmq : : utils : : GetEnabledQuorumVvecSyncEntries ( ) . size ( ) > 0 } ;
2021-02-01 17:10:19 +01:00
if ( ! fRecoveryEnabled & & fQuorumVvecRequestsEnabled ) {
2020-05-13 20:30:31 +02:00
InitWarning ( Untranslated ( " -llmq-qvvec-sync set but recovery is disabled due to -llmq-data-recovery=0 " ) ) ;
2021-02-01 17:10:19 +01:00
}
} catch ( const std : : invalid_argument & e ) {
2020-05-08 18:17:47 +02:00
return InitError ( Untranslated ( e . what ( ) ) ) ;
2021-02-01 17:10:19 +01:00
}
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -masternodeblsprivkey " ) ) {
if ( ! args . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) & & Params ( ) . RequireRoutableExternalIP ( ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( Untranslated ( " Masternode must accept connections from outside, set -listen=1 " ) ) ;
2020-03-12 11:32:39 +01:00
}
2022-05-21 11:30:27 +02:00
if ( ! args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( Untranslated ( " Masternode must have transaction index enabled, set -txindex=1 " ) ) ;
2020-03-12 11:32:39 +01:00
}
2022-05-21 11:30:27 +02:00
if ( ! args . GetBoolArg ( " -peerbloomfilters " , DEFAULT_PEERBLOOMFILTERS ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( Untranslated ( " Masternode must have bloom filters enabled, set -peerbloomfilters=1 " ) ) ;
2020-03-12 11:32:39 +01:00
}
2022-05-21 11:30:27 +02:00
if ( args . GetArg ( " -prune " , 0 ) > 0 ) {
2020-05-08 18:17:47 +02:00
return InitError ( Untranslated ( " Masternode must have no pruning enabled, set -prune=0 " ) ) ;
2020-03-12 11:32:39 +01:00
}
2022-05-21 11:30:27 +02:00
if ( args . GetArg ( " -maxconnections " , DEFAULT_MAX_PEER_CONNECTIONS ) < DEFAULT_MAX_PEER_CONNECTIONS ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( Untranslated ( " Masternode must be able to handle at least %d connections, set -maxconnections=%d " ) , DEFAULT_MAX_PEER_CONNECTIONS , DEFAULT_MAX_PEER_CONNECTIONS ) ) ;
2020-03-12 11:32:39 +01:00
}
2022-05-21 11:30:27 +02:00
if ( args . GetBoolArg ( " -disablegovernance " , false ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( _ ( " You can not disable governance validation on a masternode. " ) ) ;
2020-03-12 11:32:39 +01:00
}
}
2022-05-21 11:30:27 +02:00
fDisableGovernance = args . GetBoolArg ( " -disablegovernance " , false ) ;
2020-07-09 01:28:30 +02:00
LogPrintf ( " fDisableGovernance %d \n " , fDisableGovernance ) ;
if ( fDisableGovernance ) {
2022-04-07 21:19:02 +02:00
InitWarning ( _ ( " You are starting with governance validation disabled. " ) +
( fPruneMode ?
Untranslated ( " " ) + _ ( " This is expected because you are running a pruned node. " ) :
Untranslated ( " " ) ) ) ;
2020-07-09 01:28:30 +02:00
}
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 ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Cannot write to data directory '%s'; check permissions. " ) , datadir . string ( ) ) ) ;
2018-03-22 14:57:46 +01:00
}
2018-01-16 10:54:13 +01:00
if ( ! LockDirectory ( datadir , " .lock " , probeOnly ) ) {
2020-05-08 18:17:47 +02:00
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 ( ) )
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Initialization sanity check failed. %s is shutting down. " ) , PACKAGE_NAME ) ) ;
2016-12-01 01:07:21 +01:00
// 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
2020-08-31 10:10:52 +02:00
bool AppInitInterfaces ( NodeContext & node )
{
node . chain = interfaces : : MakeChain ( node ) ;
// Create client interfaces for wallets that are supposed to be loaded
// according to -wallet and -disablewallet options. This only constructs
// the interfaces, it doesn't load wallet data. Wallets actually get loaded
// when load() and start() interface methods are called below.
g_wallet_init_interface . Construct ( node ) ;
return true ;
}
2022-10-22 19:18:03 +02:00
bool AppInitMain ( const CoreContext & context , NodeContext & node , interfaces : : BlockAndHeaderTipInfo * tip_info )
2017-07-17 17:12:00 +02:00
{
2022-05-21 11:30:27 +02:00
const ArgsManager & args = * Assert ( node . args ) ;
2017-07-17 17:12:00 +02:00
const CChainParams & chainparams = Params ( ) ;
// ********************************************************* Step 4a: application initialization
2022-05-21 11:30:27 +02:00
if ( ! CreatePidFile ( args ) ) {
2021-09-06 14:23:00 +02:00
// Detailed error printed inside CreatePidFile().
return false ;
}
2019-02-04 20:26:02 +01:00
if ( LogInstance ( ) . m_print_to_file ) {
2022-05-21 11:30:27 +02:00
if ( args . GetBoolArg ( " -shrinkdebugfile " , LogInstance ( ) . 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
2019-02-04 20:26:02 +01:00
LogInstance ( ) . ShrinkDebugFile ( ) ;
2018-04-17 17:07:19 +02:00
}
2021-06-08 04:19:35 +02:00
}
2019-02-04 20:26:02 +01:00
if ( ! LogInstance ( ) . StartLogging ( ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( Untranslated ( " Could not open debug log file %s " ) ,
2019-02-04 20:26:02 +01:00
LogInstance ( ) . m_file_path . string ( ) ) ) ;
2017-12-04 18:30:25 +01:00
}
2015-05-15 21:31:14 +02:00
2019-02-04 20:26:02 +01:00
if ( ! LogInstance ( ) . 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.
2022-05-21 11:30:27 +02:00
fs : : path config_file_path = GetConfigFile ( args . GetArg ( " -conf " , BITCOIN_CONF_FILENAME ) ) ;
2018-09-10 15:37:20 +02:00
if ( fs : : exists ( config_file_path ) ) {
LogPrintf ( " Config file: %s \n " , config_file_path . string ( ) ) ;
2022-05-21 11:30:27 +02:00
} else if ( args . IsArgSet ( " -conf " ) ) {
2018-09-10 15:37:20 +02:00
// Warn if no conf file exists at path provided by user
2020-05-13 20:30:31 +02:00
InitWarning ( strprintf ( _ ( " The specified config file %s does not exist \n " ) , config_file_path . string ( ) ) ) ;
2018-09-10 15:37:20 +02:00
} else {
// Not categorizing as "Warning" because it's the default behavior
LogPrintf ( " Config file: %s (not found, skipping) \n " , config_file_path . string ( ) ) ;
}
2020-01-30 23:10:50 +01:00
// Log the config arguments to debug.log
args . LogArgs ( ) ;
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.
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -datadir " ) & & ! fs : : path ( args . 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 " ,
2022-05-21 11:30:27 +02:00
args . GetArg ( " -datadir " , " " ) , fs : : current_path ( ) . string ( ) ) ;
2018-01-19 17:44:27 +01:00
}
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
2022-05-21 11:30:27 +02:00
int script_threads = args . GetArg ( " -par " , DEFAULT_SCRIPTCHECK_THREADS ) ;
2019-11-02 22:13:06 +01:00
if ( script_threads < = 0 ) {
// -par=0 means autodetect (number of cores - 1 script threads)
// -par=-n means "leave n cores free" (number of cores - n - 1 script threads)
script_threads + = GetNumCores ( ) ;
}
// Subtract 1 because the main thread counts towards the par threads
script_threads = std : : max ( script_threads - 1 , 0 ) ;
// Number of script-checking threads <= MAX_SCRIPTCHECK_THREADS
script_threads = std : : min ( script_threads , MAX_SCRIPTCHECK_THREADS ) ;
LogPrintf ( " Script verification uses %d additional threads \n " , script_threads ) ;
if ( script_threads > = 1 ) {
g_parallel_script_checks = true ;
2021-06-16 15:03:04 +02:00
StartScriptCheckWorkerThreads ( script_threads ) ;
2012-12-01 23:04:14 +01:00
}
2022-08-06 10:50:11 +02:00
assert ( activeMasternodeInfo . blsKeyOperator = = nullptr ) ;
assert ( activeMasternodeInfo . blsPubKeyOperator = = nullptr ) ;
fMasternodeMode = false ;
std : : string strMasterNodeBLSPrivKey = args . GetArg ( " -masternodeblsprivkey " , " " ) ;
if ( ! strMasterNodeBLSPrivKey . empty ( ) ) {
CBLSSecretKey keyOperator ( ParseHex ( strMasterNodeBLSPrivKey ) ) ;
if ( ! keyOperator . IsValid ( ) ) {
return InitError ( _ ( " Invalid masternodeblsprivkey. Please see documentation. " ) ) ;
}
fMasternodeMode = true ;
{
LOCK ( activeMasternodeInfoCs ) ;
activeMasternodeInfo . blsKeyOperator = std : : make_unique < CBLSSecretKey > ( keyOperator ) ;
activeMasternodeInfo . blsPubKeyOperator = std : : make_unique < CBLSPublicKey > ( keyOperator . GetPublicKey ( ) ) ;
}
LogPrintf ( " MASTERNODE: \n blsPubKeyOperator: %s \n " , activeMasternodeInfo . blsPubKeyOperator - > ToString ( ) ) ;
} else {
LOCK ( activeMasternodeInfoCs ) ;
activeMasternodeInfo . blsKeyOperator = std : : make_unique < CBLSSecretKey > ( ) ;
activeMasternodeInfo . blsPubKeyOperator = std : : make_unique < CBLSPublicKey > ( ) ;
}
2022-01-09 18:03:26 +01:00
assert ( ! node . scheduler ) ;
2022-10-15 20:35:50 +02:00
node . scheduler = std : : make_unique < CScheduler > ( ) ;
2022-01-09 18:03:26 +01:00
2015-04-03 17:50:06 +02:00
// Start the lightweight task scheduler thread
2022-12-25 09:25:19 +01:00
node . scheduler - > m_service_thread = std : : thread ( [ & ] { TraceThread ( " scheduler " , [ & ] { node . scheduler - > serviceQueue ( ) ; } ) ; } ) ;
2015-04-03 17:50:06 +02:00
2022-04-25 11:59:51 +02:00
// Gather some entropy once per minute.
node . scheduler - > scheduleEvery ( [ ] {
RandAddPeriodic ( ) ;
2023-01-15 12:04:56 +01:00
} , std : : chrono : : minutes { 1 } ) ;
2022-04-25 11:59:51 +02:00
2022-01-09 18:03:26 +01:00
GetMainSignals ( ) . RegisterBackgroundSignalScheduler ( * node . scheduler ) ;
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 ) ;
2022-04-05 11:09:41 +02:00
for ( const auto & client : node . chain_clients ) {
2018-11-09 15:36:34 +01:00
client - > registerRpcs ( ) ;
}
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 .
*/
2022-05-21 11:30:27 +02:00
if ( args . GetBoolArg ( " -server " , false ) ) {
2018-08-13 21:01:07 +02:00
uiInterface . InitMessage_connect ( SetRPCWarmupStatus ) ;
2020-06-18 21:19:26 +02:00
if ( ! AppInitServers ( context , node ) )
2020-05-08 18:17:47 +02: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 ;
2022-04-05 11:09:41 +02:00
for ( const auto & client : node . chain_clients ) {
2018-11-09 15:36:34 +01:00
if ( ! client - > verify ( ) ) {
return false ;
}
}
2014-12-26 12:53:29 +01:00
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
2023-02-22 08:53:20 +01:00
// see Step 2: parameter interactions for more information about these
fListen = args . GetBoolArg ( " -listen " , DEFAULT_LISTEN ) ;
fDiscover = args . GetBoolArg ( " -discover " , true ) ;
g_relay_txes = ! args . GetBoolArg ( " -blocksonly " , DEFAULT_BLOCKSONLY ) ;
2022-04-05 11:09:41 +02:00
assert ( ! node . banman ) ;
2022-10-15 20:35:50 +02:00
node . banman = std : : make_unique < BanMan > ( GetDataDir ( ) / " banlist.dat " , & uiInterface , args . GetArg ( " -bantime " , DEFAULT_MISBEHAVING_BANTIME ) ) ;
2022-04-05 11:09:41 +02:00
assert ( ! node . connman ) ;
node . connman = std : : make_unique < 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
2023-02-22 08:53:20 +01:00
assert ( ! node . fee_estimator ) ;
// Don't initialize fee estimation with old data if we don't relay transactions,
// as they would never get updated.
if ( g_relay_txes ) node . fee_estimator = std : : make_unique < CBlockPolicyEstimator > ( ) ;
2022-04-17 12:52:51 +02:00
assert ( ! node . mempool ) ;
2023-02-20 20:31:40 +01:00
int check_ratio = std : : min < int > ( std : : max < int > ( args . GetArg ( " -checkmempool " , chainparams . DefaultConsistencyChecks ( ) ? 1 : 0 ) , 0 ) , 1000000 ) ;
node . mempool = std : : make_unique < CTxMemPool > ( node . fee_estimator . get ( ) , check_ratio ) ;
2020-09-07 09:47:14 +02:00
2022-05-05 20:07:00 +02:00
assert ( ! node . chainman ) ;
node . chainman = & g_chainman ;
2022-06-10 12:55:53 +02:00
ChainstateManager & chainman = * Assert ( node . chainman ) ;
2022-04-17 12:52:51 +02:00
2022-09-22 13:14:48 +02:00
node . peer_logic . reset ( new PeerLogicValidation (
2020-08-12 12:38:56 +02:00
* node . connman , node . banman . get ( ) , * node . scheduler , chainman , * node . mempool , node . llmq_ctx
2022-12-02 11:13:01 +01:00
) ) ;
2022-04-05 11:09:41 +02:00
RegisterValidationInterface ( node . peer_logic . get ( ) ) ;
2013-05-07 15:16:25 +02:00
2022-08-26 23:52:53 +02:00
: : governance = std : : make_unique < CGovernanceManager > ( ) ;
assert ( ! : : sporkManager ) ;
: : sporkManager = std : : make_unique < CSporkManager > ( ) ;
2022-10-25 06:42:48 +02:00
: : masternodeSync = std : : make_unique < CMasternodeSync > ( * node . connman ) ;
2022-08-26 23:52:53 +02:00
std : : vector < std : : string > vSporkAddresses ;
if ( args . IsArgSet ( " -sporkaddr " ) ) {
vSporkAddresses = args . GetArgs ( " -sporkaddr " ) ;
} else {
vSporkAddresses = Params ( ) . SporkAddresses ( ) ;
}
for ( const auto & address : vSporkAddresses ) {
if ( ! : : sporkManager - > SetSporkAddress ( address ) ) {
return InitError ( _ ( " Invalid spork address specified with -sporkaddr " ) ) ;
}
}
int minsporkkeys = args . GetArg ( " -minsporkkeys " , Params ( ) . MinSporkKeys ( ) ) ;
if ( ! : : sporkManager - > SetMinSporkKeys ( minsporkkeys ) ) {
return InitError ( _ ( " Invalid minimum number of spork signers specified with -minsporkkeys " ) ) ;
}
if ( args . IsArgSet ( " -sporkkey " ) ) { // spork priv key
if ( ! : : sporkManager - > SetPrivKey ( args . GetArg ( " -sporkkey " , " " ) ) ) {
return InitError ( _ ( " Unable to sign spork message, wrong key? " ) ) ;
}
}
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
2022-05-21 11:30:27 +02:00
uacomments . push_back ( strprintf ( " devnet.%s " , args . GetDevNetName ( ) ) ) ;
2017-12-20 12:45:01 +01:00
}
2022-05-21 11:30:27 +02:00
for ( const std : : string & cmt : args . GetArgs ( " -uacomment " ) ) {
2017-06-27 14:22:54 +02:00
if ( cmt ! = SanitizeString ( cmt , SAFE_CHARS_UA_COMMENT ) )
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " User Agent comment (%s) contains unsafe characters . " ), cmt)) ;
2017-06-27 14:22:54 +02:00
uacomments . push_back ( cmt ) ;
2015-09-09 14:24:56 +02:00
}
strSubVersion = FormatSubVersion ( CLIENT_NAME , CLIENT_VERSION , uacomments ) ;
2015-07-31 18:05:42 +02:00
if ( strSubVersion . size ( ) > MAX_SUBVERSION_LENGTH ) {
2020-05-08 18:17:47 +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 ) ) ;
}
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -onlynet " ) ) {
2012-05-21 16:47:29 +02:00
std : : set < enum Network > nets ;
2022-05-21 11:30:27 +02:00
for ( const std : : string & snet : args . GetArgs ( " -onlynet " ) ) {
2012-05-21 16:47:29 +02:00
enum Network net = ParseNetwork ( snet ) ;
if ( net = = NET_UNROUTABLE )
2020-05-08 18:17:47 +02: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 ) )
2019-01-14 14:22:47 +01:00
SetReachable ( net , false ) ;
2012-05-21 16:47:29 +02:00
}
}
2017-03-03 16:10:16 +01:00
// Check for host lookup allowed before parsing any network related parameters
2022-05-21 11:30:27 +02:00
fNameLookup = args . GetBoolArg ( " -dns " , DEFAULT_NAME_LOOKUP ) ;
2017-03-03 16:10:16 +01:00
2022-05-21 11:30:27 +02:00
bool proxyRandomize = args . GetBoolArg ( " -proxyrandomize " , DEFAULT_PROXYRANDOMIZE ) ;
2015-06-10 09:19:13 +02:00
// -proxy sets a proxy for all outgoing network traffic
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
2022-05-21 11:30:27 +02:00
std : : string proxyArg = args . GetArg ( " -proxy " , " " ) ;
2019-01-14 14:22:47 +01:00
SetReachable ( NET_ONION , false ) ;
2015-06-10 09:19:13 +02:00
if ( proxyArg ! = " " & & proxyArg ! = " 0 " ) {
2017-03-03 16:10:16 +01:00
CService proxyAddr ;
Merge #17754: net: Don't allow resolving of std::string with embedded NUL characters. Add tests.
7a046cdc1423963bdcbcf9bb98560af61fa90b37 tests: Avoid using C-style NUL-terminated strings as arguments (practicalswift)
fefb9165f23fe9d10ad092ec31715f906e0d2ee7 tests: Add tests to make sure lookup methods fail on std::string parameters with embedded NUL characters (practicalswift)
9574de86ad703ad942cdd0eca79f48c0d42b102b net: Avoid using C-style NUL-terminated strings as arguments in the netbase interface (practicalswift)
Pull request description:
Don't allow resolving of `std::string`:s with embedded `NUL` characters.
Avoid using C-style `NUL`-terminated strings as arguments in the `netbase` interface
Add tests.
The only place in where C-style `NUL`-terminated strings are actually needed is here:
```diff
+ if (!ValidAsCString(name)) {
+ return false;
+ }
...
- int nErr = getaddrinfo(pszName, nullptr, &aiHint, &aiRes);
+ int nErr = getaddrinfo(name.c_str(), nullptr, &aiHint, &aiRes);
if (nErr)
return false;
```
Interface changes:
```diff
-bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
+bool LookupHost(const std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
-bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup);
+bool LookupHost(const std::string& name, CNetAddr& addr, bool fAllowLookup);
-bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLookup);
+bool Lookup(const std::string& name, CService& addr, int portDefault, bool fAllowLookup);
-bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
+bool Lookup(const std::string& name, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
-bool LookupSubNet(const char *pszName, CSubNet& subnet);
+bool LookupSubNet(const std::string& strSubnet, CSubNet& subnet);
-CService LookupNumeric(const char *pszName, int portDefault = 0);
+CService LookupNumeric(const std::string& name, int portDefault = 0);
-bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed);
+bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool& outProxyConnectionFailed);
```
It should be noted that the `ConnectThroughProxy` change (from `bool *outProxyConnectionFailed` to `bool& outProxyConnectionFailed`) has nothing to do with `NUL` handling but I thought it was worth doing when touching this file :)
ACKs for top commit:
EthanHeilman:
ACK 7a046cdc1423963bdcbcf9bb98560af61fa90b37
laanwj:
ACK 7a046cdc1423963bdcbcf9bb98560af61fa90b37
Tree-SHA512: 66556e290db996917b54091acd591df221f72230f6b9f6b167b9195ee870ebef6e26f4cda2f6f54d00e1c362e1743bf56785d0de7cae854e6bf7d26f6caccaba
2020-01-22 20:14:12 +01:00
if ( ! Lookup ( proxyArg , proxyAddr , 9050 , fNameLookup ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Invalid -proxy address or hostname: '%s' " ) , proxyArg ) ) ;
2017-03-03 16:10:16 +01:00
}
proxyType addrProxy = proxyType ( proxyAddr , proxyRandomize ) ;
2012-05-24 19:02:21 +02:00
if ( ! addrProxy . IsValid ( ) )
2020-05-08 18:17:47 +02: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 ) ;
2019-01-14 14:22:47 +01:00
SetReachable ( NET_ONION , true ) ; // 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)
2022-05-21 11:30:27 +02:00
std : : string onionArg = args . GetArg ( " -onion " , " " ) ;
2015-06-10 09:19:13 +02:00
if ( onionArg ! = " " ) {
if ( onionArg = = " 0 " ) { // Handle -noonion/-onion=0
2019-01-14 14:22:47 +01:00
SetReachable ( NET_ONION , false ) ;
2015-06-10 09:19:13 +02:00
} else {
2017-03-03 16:10:16 +01:00
CService onionProxy ;
Merge #17754: net: Don't allow resolving of std::string with embedded NUL characters. Add tests.
7a046cdc1423963bdcbcf9bb98560af61fa90b37 tests: Avoid using C-style NUL-terminated strings as arguments (practicalswift)
fefb9165f23fe9d10ad092ec31715f906e0d2ee7 tests: Add tests to make sure lookup methods fail on std::string parameters with embedded NUL characters (practicalswift)
9574de86ad703ad942cdd0eca79f48c0d42b102b net: Avoid using C-style NUL-terminated strings as arguments in the netbase interface (practicalswift)
Pull request description:
Don't allow resolving of `std::string`:s with embedded `NUL` characters.
Avoid using C-style `NUL`-terminated strings as arguments in the `netbase` interface
Add tests.
The only place in where C-style `NUL`-terminated strings are actually needed is here:
```diff
+ if (!ValidAsCString(name)) {
+ return false;
+ }
...
- int nErr = getaddrinfo(pszName, nullptr, &aiHint, &aiRes);
+ int nErr = getaddrinfo(name.c_str(), nullptr, &aiHint, &aiRes);
if (nErr)
return false;
```
Interface changes:
```diff
-bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
+bool LookupHost(const std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
-bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup);
+bool LookupHost(const std::string& name, CNetAddr& addr, bool fAllowLookup);
-bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLookup);
+bool Lookup(const std::string& name, CService& addr, int portDefault, bool fAllowLookup);
-bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
+bool Lookup(const std::string& name, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
-bool LookupSubNet(const char *pszName, CSubNet& subnet);
+bool LookupSubNet(const std::string& strSubnet, CSubNet& subnet);
-CService LookupNumeric(const char *pszName, int portDefault = 0);
+CService LookupNumeric(const std::string& name, int portDefault = 0);
-bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed);
+bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool& outProxyConnectionFailed);
```
It should be noted that the `ConnectThroughProxy` change (from `bool *outProxyConnectionFailed` to `bool& outProxyConnectionFailed`) has nothing to do with `NUL` handling but I thought it was worth doing when touching this file :)
ACKs for top commit:
EthanHeilman:
ACK 7a046cdc1423963bdcbcf9bb98560af61fa90b37
laanwj:
ACK 7a046cdc1423963bdcbcf9bb98560af61fa90b37
Tree-SHA512: 66556e290db996917b54091acd591df221f72230f6b9f6b167b9195ee870ebef6e26f4cda2f6f54d00e1c362e1743bf56785d0de7cae854e6bf7d26f6caccaba
2020-01-22 20:14:12 +01:00
if ( ! Lookup ( onionArg , onionProxy , 9050 , fNameLookup ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Invalid -onion address or hostname: '%s' " ) , onionArg ) ) ;
2017-03-03 16:10:16 +01:00
}
proxyType addrOnion = proxyType ( onionProxy , proxyRandomize ) ;
2015-06-10 09:19:13 +02:00
if ( ! addrOnion . IsValid ( ) )
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Invalid -onion address or hostname: '%s' " ) , onionArg ) ) ;
2020-04-16 07:21:49 +02:00
SetProxy ( NET_ONION , addrOnion ) ;
2019-01-14 14:22:47 +01:00
SetReachable ( NET_ONION , true ) ;
2015-06-10 09:19:13 +02:00
}
2012-05-24 19:02:21 +02:00
}
2022-05-21 11:30:27 +02:00
for ( const std : : string & strAddr : args . GetArgs ( " -externalip " ) ) {
2017-06-27 14:22:54 +02:00
CService addrLocal ;
Merge #17754: net: Don't allow resolving of std::string with embedded NUL characters. Add tests.
7a046cdc1423963bdcbcf9bb98560af61fa90b37 tests: Avoid using C-style NUL-terminated strings as arguments (practicalswift)
fefb9165f23fe9d10ad092ec31715f906e0d2ee7 tests: Add tests to make sure lookup methods fail on std::string parameters with embedded NUL characters (practicalswift)
9574de86ad703ad942cdd0eca79f48c0d42b102b net: Avoid using C-style NUL-terminated strings as arguments in the netbase interface (practicalswift)
Pull request description:
Don't allow resolving of `std::string`:s with embedded `NUL` characters.
Avoid using C-style `NUL`-terminated strings as arguments in the `netbase` interface
Add tests.
The only place in where C-style `NUL`-terminated strings are actually needed is here:
```diff
+ if (!ValidAsCString(name)) {
+ return false;
+ }
...
- int nErr = getaddrinfo(pszName, nullptr, &aiHint, &aiRes);
+ int nErr = getaddrinfo(name.c_str(), nullptr, &aiHint, &aiRes);
if (nErr)
return false;
```
Interface changes:
```diff
-bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
+bool LookupHost(const std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
-bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup);
+bool LookupHost(const std::string& name, CNetAddr& addr, bool fAllowLookup);
-bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLookup);
+bool Lookup(const std::string& name, CService& addr, int portDefault, bool fAllowLookup);
-bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
+bool Lookup(const std::string& name, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
-bool LookupSubNet(const char *pszName, CSubNet& subnet);
+bool LookupSubNet(const std::string& strSubnet, CSubNet& subnet);
-CService LookupNumeric(const char *pszName, int portDefault = 0);
+CService LookupNumeric(const std::string& name, int portDefault = 0);
-bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed);
+bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool& outProxyConnectionFailed);
```
It should be noted that the `ConnectThroughProxy` change (from `bool *outProxyConnectionFailed` to `bool& outProxyConnectionFailed`) has nothing to do with `NUL` handling but I thought it was worth doing when touching this file :)
ACKs for top commit:
EthanHeilman:
ACK 7a046cdc1423963bdcbcf9bb98560af61fa90b37
laanwj:
ACK 7a046cdc1423963bdcbcf9bb98560af61fa90b37
Tree-SHA512: 66556e290db996917b54091acd591df221f72230f6b9f6b167b9195ee870ebef6e26f4cda2f6f54d00e1c362e1743bf56785d0de7cae854e6bf7d26f6caccaba
2020-01-22 20:14:12 +01:00
if ( Lookup ( strAddr , addrLocal , GetListenPort ( ) , fNameLookup ) & & addrLocal . IsValid ( ) )
2017-06-27 14:22:54 +02:00
AddLocal ( addrLocal , LOCAL_MANUAL ) ;
else
2022-04-07 10:17:19 +02:00
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
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -asmap " ) ) {
fs : : path asmap_path = fs : : path ( args . GetArg ( " -asmap " , " " ) ) ;
2021-05-18 18:30:48 +02:00
if ( asmap_path . empty ( ) ) {
asmap_path = DEFAULT_ASMAP_FILENAME ;
}
if ( ! asmap_path . is_absolute ( ) ) {
asmap_path = GetDataDir ( ) / asmap_path ;
}
if ( ! fs : : exists ( asmap_path ) ) {
2020-05-08 18:17:47 +02:00
InitError ( strprintf ( _ ( " Could not find asmap file %s " ) , asmap_path ) ) ;
2021-05-18 18:30:48 +02:00
return false ;
}
std : : vector < bool > asmap = CAddrMan : : DecodeAsmap ( asmap_path ) ;
if ( asmap . size ( ) = = 0 ) {
2020-05-08 18:17:47 +02:00
InitError ( strprintf ( _ ( " Could not parse asmap file %s " ) , asmap_path ) ) ;
2021-05-18 18:30:48 +02:00
return false ;
}
const uint256 asmap_version = SerializeHash ( asmap ) ;
2022-04-05 11:09:41 +02:00
node . 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
2022-09-22 13:14:48 +02:00
pdsNotificationInterface = new CDSNotificationInterface (
2022-11-07 19:09:44 +01:00
* node . connman , : : masternodeSync , : : deterministicMNManager , : : governance , node . llmq_ctx
2022-09-22 13:14:48 +02:00
) ;
2016-03-02 22:20:04 +01:00
RegisterValidationInterface ( pdsNotificationInterface ) ;
2022-08-06 10:50:11 +02:00
if ( fMasternodeMode ) {
// Create and register activeMasternodeManager, will init later in ThreadImport
2022-08-26 23:52:53 +02:00
activeMasternodeManager = std : : make_unique < CActiveMasternodeManager > ( * node . connman ) ;
RegisterValidationInterface ( activeMasternodeManager . get ( ) ) ;
2022-08-06 10:50:11 +02:00
}
2020-07-09 01:28:30 +02:00
// ********************************************************* Step 7a: Load sporks
2018-12-20 14:31:23 +01:00
2022-03-24 05:13:51 +01:00
uiInterface . InitMessage ( _ ( " Loading sporks cache... " ) . translated ) ;
2020-06-13 20:18:31 +02:00
CFlatDB < CSporkManager > flatdb6 ( " sporks.dat " , " magicSporkCache " ) ;
2022-08-26 23:52:53 +02:00
if ( ! flatdb6 . Load ( * : : sporkManager ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Failed to load sporks cache from %s " ) , ( 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
2022-05-21 11:30:27 +02:00
fReindex = args . GetBoolArg ( " -reindex " , false ) ;
bool fReindexChainState = args . GetBoolArg ( " -reindex-chainstate " , false ) ;
2012-10-21 21:23:13 +02:00
2012-11-04 17:11:48 +01:00
// cache size calculations
2022-05-21 11:30:27 +02:00
int64_t nTotalCache = ( args . 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 ;
2022-05-21 11:30:27 +02:00
int64_t nTxIndexCache = std : : min ( nTotalCache / 8 , args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ? nMaxTxIndexCache < < 20 : 0 ) ;
2021-05-25 12:48:04 +02:00
nTotalCache - = nTxIndexCache ;
2021-08-12 09:04:28 +02:00
int64_t filter_index_cache = 0 ;
if ( ! g_enabled_filter_types . empty ( ) ) {
size_t n_indexes = g_enabled_filter_types . size ( ) ;
int64_t max_cache = std : : min ( nTotalCache / 8 , max_filter_index_cache < < 20 ) ;
filter_index_cache = max_cache / n_indexes ;
nTotalCache - = filter_index_cache * n_indexes ;
}
2015-05-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 ;
2022-04-03 16:43:18 +02:00
int64_t nCoinCacheUsage = nTotalCache ; // the rest goes to in-memory cache
2022-05-21 11:30:27 +02:00
int64_t nMempoolSizeMax = args . GetArg ( " -maxmempool " , DEFAULT_MAX_MEMPOOL_SIZE ) * 1000000 ;
2022-09-23 16:46:18 +02:00
int64_t nEvoDbCache = 1024 * 1024 * 64 ; // TODO
2015-05-04 01:56:42 +02:00
LogPrintf ( " Cache configuration: \n " ) ;
2019-01-30 20:16:41 +01:00
LogPrintf ( " * Using %.1f MiB for block index database \n " , nBlockTreeDBCache * ( 1.0 / 1024 / 1024 ) ) ;
2022-05-21 11:30:27 +02:00
if ( args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ) {
2019-01-30 20:16:41 +01:00
LogPrintf ( " * Using %.1f MiB for transaction index database \n " , nTxIndexCache * ( 1.0 / 1024 / 1024 ) ) ;
2021-05-25 12:48:04 +02:00
}
2021-08-12 09:04:28 +02:00
for ( BlockFilterType filter_type : g_enabled_filter_types ) {
LogPrintf ( " * Using %.1f MiB for %s block filter index database \n " ,
filter_index_cache * ( 1.0 / 1024 / 1024 ) , BlockFilterTypeName ( filter_type ) ) ;
}
2019-01-30 20:16:41 +01:00
LogPrintf ( " * Using %.1f MiB for chain state database \n " , nCoinDBCache * ( 1.0 / 1024 / 1024 ) ) ;
LogPrintf ( " * Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space) \n " , nCoinCacheUsage * ( 1.0 / 1024 / 1024 ) , nMempoolSizeMax * ( 1.0 / 1024 / 1024 ) ) ;
2012-11-04 17:11:48 +01:00
2013-02-16 17:58:45 +01:00
bool fLoaded = false ;
2018-05-13 22:57:12 +02:00
2021-06-21 00:49:59 +02:00
while ( ! fLoaded & & ! ShutdownRequested ( ) ) {
2021-04-27 08:26:54 +02:00
const bool fReset = fReindex ;
2022-04-03 16:41:38 +02:00
auto is_coinsview_empty = [ & ] ( CChainState * chainstate ) EXCLUSIVE_LOCKS_REQUIRED ( : : cs_main ) {
return fReset | | fReindexChainState | | chainstate - > CoinsTip ( ) . GetBestBlock ( ) . IsNull ( ) ;
} ;
2020-05-08 18:17:47 +02:00
bilingual_str strLoadError ;
2013-01-11 22:57:22 +01:00
2022-03-24 05:13:51 +01:00
uiInterface . InitMessage ( _ ( " Loading block index... " ) . translated ) ;
2012-07-06 16:33:34 +02:00
2013-02-16 17:58:45 +01:00
do {
2022-04-03 16:41:38 +02:00
bool failed_verification = false ;
2018-07-05 18:07:21 +02:00
const int64_t load_block_index_start_time = GetTimeMillis ( ) ;
2022-04-03 16:41:38 +02:00
2013-02-16 17:58:45 +01:00
try {
Merge #15402: Granular invalidateblock and RewindBlockIndex
519b0bc5dc5155b6f7e2362c2105552bb7618ad0 Make last disconnected block BLOCK_FAILED_VALID, even when aborted (Pieter Wuille)
8d220417cd7bc34464e28a4861a885193ec091c2 Optimization: don't add txn back to mempool after 10 invalidates (Pieter Wuille)
9ce9c37004440d6a329874dbf66b51666d497dcb Prevent callback overruns in InvalidateBlock and RewindBlockIndex (Pieter Wuille)
9bb32eb571a846b66ed3bac493f55cee11a3a1b9 Release cs_main during InvalidateBlock iterations (Pieter Wuille)
9b1ff5c742dec0a6e0d6aab29b0bb771ad6d8135 Call InvalidateBlock without cs_main held (Pieter Wuille)
241b2c74ac8c4c3000e778554da1271e3f293e5d Make RewindBlockIndex interruptible (Pieter Wuille)
880ce7d46b51835c00d77a366ec28f54a05239df Call RewindBlockIndex without cs_main held (Pieter Wuille)
436f7d735f1c37e77d42ff59d4cbb1bd76d5fcfb Release cs_main during RewindBlockIndex operation (Pieter Wuille)
1d342875c21b5d0a17cf4d176063bb14b35b657e Merge the disconnection and erasing loops in RewindBlockIndex (Pieter Wuille)
32b2696ab4b079db736074b57bbc24deaee0b3d9 Move erasure of non-active blocks to a separate loop in RewindBlockIndex (Pieter Wuille)
9d6dcc52c6cb0cdcda220fddccaabb0ffd40068d Abstract EraseBlockData out of RewindBlockIndex (Pieter Wuille)
Pull request description:
This PR makes a number of improvements to the InvalidateBlock (`invalidateblock` RPC) and RewindBlockIndex functions, primarily around breaking up their long-term cs_main holding. In addition:
* They're made safely interruptible (`bitcoind` can be shutdown, and no progress in either will be lost, though if incomplete, `invalidateblock` won't continue after restart and will need to be called again)
* The validation queue is prevented from overflowing (meaning `invalidateblock` on a very old block will not drive bitcoind OOM) (see #14289).
* `invalidateblock` won't bother to move transactions back into the mempool after 10 blocks (optimization).
This is not an optimal solution, as we're relying on the scheduler call sites to make sure the scheduler doesn't overflow. Ideally, the scheduler would guarantee this directly, but that needs a few further changes (moving the signal emissions out of cs_main) to prevent deadlocks.
I have manually tested the `invalidateblock` changes (including interrupting, and running with -checkblockindex and -checkmempool), but haven't tried the rewinding (which is probably becoming increasingly unnecessary, as very few pre-0.13.1 nodes remain that would care to upgrade).
Tree-SHA512: 692e42758bd3d3efc2eb701984a8cb5db25fbeee32e7575df0183a00d0c2c30fdf72ce64c7625c32ad8c8bdc56313da72a7471658faeb0d39eefe39c4b8b8474
2019-03-07 17:39:54 +01:00
LOCK ( cs_main ) ;
refactor: remove the g_evoDb global; use NodeContext and locals (#5058)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
globals should be avoided to avoid annoying lifetime / nullptr /
initialization issues
## What was done?
<!--- Describe your changes in detail -->
removed a global, g_evoDB
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
make check
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [ ] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
2022-12-10 18:58:17 +01:00
node . evodb . reset ( ) ;
node . evodb = std : : make_unique < CEvoDB > ( nEvoDbCache , false , fReset | | fReindexChainState ) ;
2020-08-31 07:21:12 +02:00
chainman . InitializeChainstate ( llmq : : chainLocksHandler , llmq : : quorumInstantSendManager , llmq : : quorumBlockProcessor , node . evodb , * Assert ( node . mempool ) ) ;
2022-04-03 16:43:18 +02:00
chainman . m_total_coinstip_cache = nCoinCacheUsage ;
chainman . m_total_coinsdb_cache = nCoinDBCache ;
2020-09-07 09:47:14 +02:00
UnloadBlockIndex ( node . mempool . get ( ) ) ;
2019-07-24 17:45:04 +02:00
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 ) ) ;
2022-11-07 19:09:44 +01:00
2020-03-16 20:06:21 +01:00
// Same logic as above with pblocktree
deterministicMNManager . reset ( ) ;
refactor: remove the g_evoDb global; use NodeContext and locals (#5058)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
globals should be avoided to avoid annoying lifetime / nullptr /
initialization issues
## What was done?
<!--- Describe your changes in detail -->
removed a global, g_evoDB
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
make check
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [ ] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
2022-12-10 18:58:17 +01:00
deterministicMNManager . reset ( new CDeterministicMNManager ( * node . evodb , * node . connman ) ) ;
2022-04-16 16:46:04 +02:00
llmq : : quorumSnapshotManager . reset ( ) ;
refactor: remove the g_evoDb global; use NodeContext and locals (#5058)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
globals should be avoided to avoid annoying lifetime / nullptr /
initialization issues
## What was done?
<!--- Describe your changes in detail -->
removed a global, g_evoDB
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
make check
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [ ] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
2022-12-10 18:58:17 +01:00
llmq : : quorumSnapshotManager . reset ( new llmq : : CQuorumSnapshotManager ( * node . evodb ) ) ;
2022-11-07 19:09:44 +01:00
node . llmq_ctx . reset ( ) ;
refactor: remove the g_evoDb global; use NodeContext and locals (#5058)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
globals should be avoided to avoid annoying lifetime / nullptr /
initialization issues
## What was done?
<!--- Describe your changes in detail -->
removed a global, g_evoDB
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
make check
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [ ] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
2022-12-10 18:58:17 +01:00
node . llmq_ctx . reset ( new LLMQContext ( * node . evodb , * node . mempool , * node . connman , * : : sporkManager , 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!
2022-05-05 20:07:00 +02:00
if ( ! chainman . LoadBlockIndex ( chainparams ) ) {
2019-05-19 10:43:13 +02:00
if ( ShutdownRequested ( ) ) break ;
2020-05-08 18:17:47 +02:00
strLoadError = _ ( " Error loading block database " ) ;
2013-02-16 17:58:45 +01:00
break ;
}
2022-05-21 11:30:27 +02:00
if ( ! fDisableGovernance & & ! args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) & & 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-05-08 18:17:47 +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).
2022-06-01 17:06:00 +02:00
if ( ! chainman . BlockIndex ( ) . empty ( ) & &
2021-10-16 19:42:59 +02:00
! LookupBlockIndex ( chainparams . GetConsensus ( ) . hashGenesisBlock ) ) {
2020-05-08 18:17:47 +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
2022-06-01 17:06:00 +02:00
if ( ! chainparams . GetConsensus ( ) . hashDevnetGenesisBlock . IsNull ( ) & & ! chainman . BlockIndex ( ) . empty ( ) & &
! LookupBlockIndex ( chainparams . GetConsensus ( ) . hashDevnetGenesisBlock ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( _ ( " Incorrect or no devnet genesis block found. Wrong datadir for devnet specified? " ) ) ;
2022-06-01 17:06:00 +02:00
}
2017-12-20 12:45:01 +01:00
2019-10-31 18:30:42 +01:00
// Check for changed -addressindex state
2022-05-21 11:30:27 +02:00
if ( fAddressIndex ! = args . GetBoolArg ( " -addressindex " , DEFAULT_ADDRESSINDEX ) ) {
2020-05-08 18:17:47 +02:00
strLoadError = _ ( " You need to rebuild the database using -reindex to change -addressindex " ) ;
2019-10-31 18:30:42 +01:00
break ;
}
// Check for changed -timestampindex state
2022-05-21 11:30:27 +02:00
if ( fTimestampIndex ! = args . GetBoolArg ( " -timestampindex " , DEFAULT_TIMESTAMPINDEX ) ) {
2020-05-08 18:17:47 +02:00
strLoadError = _ ( " You need to rebuild the database using -reindex to change -timestampindex " ) ;
2019-10-31 18:30:42 +01:00
break ;
}
// Check for changed -spentindex state
2022-05-21 11:30:27 +02:00
if ( fSpentIndex ! = args . GetBoolArg ( " -spentindex " , DEFAULT_SPENTINDEX ) ) {
2020-05-08 18:17:47 +02:00
strLoadError = _ ( " You need to rebuild the database using -reindex to change -spentindex " ) ;
2019-10-31 18:30:42 +01:00
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 ) {
2020-05-08 18:17:47 +02:00
strLoadError = _ ( " You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain " ) ;
Add block pruning functionality
This adds a -prune=N option to bitcoind, which if set to N>0 will enable block
file pruning. When pruning is enabled, block and undo files will be deleted to
try to keep total space used by those files to below the prune target (N, in
MB) specified by the user, subject to some constraints:
- The last 288 blocks on the main chain are always kept (MIN_BLOCKS_TO_KEEP),
- N must be at least 550MB (chosen as a value for the target that could
reasonably be met, with some assumptions about block sizes, orphan rates,
etc; see comment in main.h),
- No blocks are pruned until chainActive is at least 100,000 blocks long (on
mainnet; defined separately for mainnet, testnet, and regtest in chainparams
as nPruneAfterHeight).
This unsets NODE_NETWORK if pruning is enabled.
Also included is an RPC test for pruning (pruning.py).
Thanks to @rdponticelli for earlier work on this feature; this is based in
part off that work.
2015-02-23 20:27:44 +01:00
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 ) ) {
2020-05-08 18:17:47 +02:00
strLoadError = _ ( " Error initializing block database " ) ;
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
break ;
}
// At this point we're either in reindex or we've loaded a useful
2021-10-16 19:42:59 +02:00
// block tree into BlockIndex()!
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
2022-04-03 16:41:38 +02:00
bool failed_chainstate_init = false ;
2022-05-05 20:07:00 +02:00
for ( CChainState * chainstate : chainman . GetAll ( ) ) {
2022-04-03 16:41:38 +02:00
chainstate - > InitCoinsDB (
/* cache_size_bytes */ nCoinDBCache ,
/* in_memory */ false ,
/* should_wipe */ fReset | | fReindexChainState ) ;
chainstate - > CoinsErrorCatcher ( ) . AddReadErrCallback ( [ ] ( ) {
uiInterface . ThreadSafeMessageBox (
_ ( " Error reading from database, shutting down. " ) ,
" " , CClientUIInterface : : MSG_ERROR ) ;
} ) ;
// If necessary, upgrade from older database format.
// This is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
if ( ! chainstate - > CoinsDB ( ) . Upgrade ( ) ) {
strLoadError = _ ( " Error upgrading chainstate database " ) ;
failed_chainstate_init = true ;
break ;
}
2017-06-28 18:24:32 +02:00
2022-04-03 16:41:38 +02:00
// ReplayBlocks is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
if ( ! chainstate - > ReplayBlocks ( chainparams ) ) {
strLoadError = _ ( " Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate. " ) ;
failed_chainstate_init = true ;
break ;
}
2020-05-11 14:33:21 +02:00
2022-04-03 16:41:38 +02:00
// The on-disk coinsdb is now in a good state, create the cache
2022-04-03 16:43:18 +02:00
chainstate - > InitCoinsCache ( nCoinCacheUsage ) ;
2022-04-03 16:41:38 +02:00
assert ( chainstate - > CanFlushToDisk ( ) ) ;
// flush evodb
// TODO: CEvoDB instance should probably be a part of CChainState
// (for multiple chainstates to actually work in parallel)
// and not a global
refactor: remove the g_evoDb global; use NodeContext and locals (#5058)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
globals should be avoided to avoid annoying lifetime / nullptr /
initialization issues
## What was done?
<!--- Describe your changes in detail -->
removed a global, g_evoDB
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
make check
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [ ] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
2022-12-10 18:58:17 +01:00
if ( & : : ChainstateActive ( ) = = chainstate & & ! node . evodb - > CommitRootTransaction ( ) ) {
2022-04-03 16:41:38 +02:00
strLoadError = _ ( " Failed to commit EvoDB " ) ;
failed_chainstate_init = true ;
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
break ;
}
2022-04-03 16:41:38 +02:00
if ( ! is_coinsview_empty ( chainstate ) ) {
// LoadChainTip initializes the chain based on CoinsTip()'s best block
if ( ! chainstate - > LoadChainTip ( chainparams ) ) {
strLoadError = _ ( " Error initializing block database " ) ;
failed_chainstate_init = true ;
break ; // out of the per-chainstate loop
}
assert ( chainstate - > m_chain . Tip ( ) ! = nullptr ) ;
}
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
2022-04-03 16:41:38 +02:00
if ( failed_chainstate_init ) {
break ; // out of the chainstate activation do-while
2020-09-25 18:19:58 +02:00
}
2023-02-14 19:48:33 +01:00
if ( ! deterministicMNManager - > MigrateDBIfNeeded ( ) ) {
strLoadError = _ ( " Error upgrading evo database " ) ;
break ;
}
2022-12-27 01:58:51 +01:00
if ( ! llmq : : quorumBlockProcessor - > UpgradeDB ( ) ) {
2020-05-08 18:17:47 +02:00
strLoadError = _ ( " Error upgrading evo database " ) ;
2020-06-11 19:52:58 +02:00
break ;
}
2019-09-22 16:28:59 +02:00
2022-05-05 20:07:00 +02:00
for ( CChainState * chainstate : chainman . GetAll ( ) ) {
2022-04-03 16:41:38 +02:00
if ( ! is_coinsview_empty ( chainstate ) ) {
uiInterface . InitMessage ( _ ( " Verifying blocks... " ) . translated ) ;
2022-05-21 11:30:27 +02:00
if ( fHavePruned & & args . GetArg ( " -checkblocks " , DEFAULT_CHECKBLOCKS ) > MIN_BLOCKS_TO_KEEP ) {
2022-04-03 16:41:38 +02:00
LogPrintf ( " Prune: pruned datadir may not have more than %d blocks; only checking available blocks \n " ,
MIN_BLOCKS_TO_KEEP ) ;
}
CBlockIndex * tip = chainstate - > m_chain . 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 " ) ;
failed_verification = true ;
break ;
}
2022-12-30 06:45:31 +01:00
if ( llmq : : utils : : IsV19Active ( tip ) )
bls : : bls_legacy_scheme . store ( false ) ;
2022-04-03 16:41:38 +02:00
// Only verify the DB of the active chainstate. This is fixed in later
// work when we allow VerifyDB to be parameterized by chainstate.
if ( & : : ChainstateActive ( ) = = chainstate & &
2022-05-21 11:30:27 +02:00
! CVerifyDB ( ) . VerifyDB (
2022-04-03 16:41:38 +02:00
chainparams , & chainstate - > CoinsDB ( ) ,
refactor: remove the g_evoDb global; use NodeContext and locals (#5058)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
globals should be avoided to avoid annoying lifetime / nullptr /
initialization issues
## What was done?
<!--- Describe your changes in detail -->
removed a global, g_evoDB
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
make check
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [ ] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
2022-12-10 18:58:17 +01:00
* node . evodb ,
2022-05-21 11:30:27 +02:00
args . GetArg ( " -checklevel " , DEFAULT_CHECKLEVEL ) ,
args . GetArg ( " -checkblocks " , DEFAULT_CHECKBLOCKS ) ) ) {
2022-04-03 16:41:38 +02:00
strLoadError = _ ( " Corrupted block database detected " ) ;
failed_verification = true ;
break ;
}
} else {
// TODO: CEvoDB instance should probably be a part of CChainState
// (for multiple chainstates to actually work in parallel)
// and not a global
refactor: remove the g_evoDb global; use NodeContext and locals (#5058)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
globals should be avoided to avoid annoying lifetime / nullptr /
initialization issues
## What was done?
<!--- Describe your changes in detail -->
removed a global, g_evoDB
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
make check
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [ ] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
2022-12-10 18:58:17 +01:00
if ( & : : ChainstateActive ( ) = = chainstate & & ! node . evodb - > IsEmpty ( ) ) {
2022-04-03 16:41:38 +02:00
// EvoDB processed some blocks earlier but we have no blocks anymore, something is wrong
strLoadError = _ ( " Error initializing block database " ) ;
failed_verification = true ;
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
}
2021-01-21 17:18:25 +01:00
2022-05-21 11:30:27 +02:00
if ( args . GetArg ( " -checklevel " , DEFAULT_CHECKLEVEL ) > = 3 ) {
2022-01-27 19:55:43 +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 ( ) ) ;
2020-05-08 18:17:47 +02:00
strLoadError = _ ( " Error opening block database " ) ;
2022-04-03 16:41:38 +02:00
failed_verification = true ;
2013-02-16 17:58:45 +01:00
break ;
}
2013-01-03 15:29:07 +01:00
2022-04-03 16:41:38 +02:00
if ( ! failed_verification ) {
fLoaded = true ;
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 (
2020-05-08 18:17:47 +02:00
strLoadError + Untranslated ( " . \n \n " ) + _ ( " Do you want to rebuild the block database now? " ) ,
strLoadError . original + " . \n Please restart with -reindex or -reindex-chainstate to recover. " ,
2013-02-16 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
2021-05-25 12:48:04 +02:00
// ********************************************************* Step 8: start indexers
2022-05-21 11:30:27 +02:00
if ( args . GetBoolArg ( " -txindex " , DEFAULT_TXINDEX ) ) {
2022-10-15 20:35:50 +02:00
g_txindex = std : : make_unique < TxIndex > ( nTxIndexCache , false , fReindex ) ;
2021-05-25 12:48:04 +02:00
g_txindex - > Start ( ) ;
}
2021-08-12 09:04:28 +02:00
for ( const auto & filter_type : g_enabled_filter_types ) {
InitBlockFilterIndex ( filter_type , filter_index_cache , false , fReindex ) ;
GetBlockFilterIndex ( filter_type ) - > Start ( ) ;
}
2021-05-25 12:48:04 +02:00
// ********************************************************* Step 9: load wallet
2022-04-05 11:09:41 +02:00
for ( const auto & client : node . chain_clients ) {
2018-11-09 15:36:34 +01:00
if ( ! client - > load ( ) ) {
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 ) {
2022-04-03 16:41:38 +02:00
LOCK ( cs_main ) ;
2022-05-05 20:07:00 +02:00
for ( CChainState * chainstate : chainman . GetAll ( ) ) {
2022-04-03 16:41:38 +02:00
uiInterface . InitMessage ( _ ( " Pruning blockstore... " ) . translated ) ;
chainstate - > PruneAndFlush ( ) ;
}
2015-06-30 19:22:48 +02:00
}
}
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 ;
}
2022-08-06 10:50:11 +02:00
// ********************************************************* Step 10a: Setup CoinJoin
2018-11-01 22:58:01 +01:00
2020-09-07 09:47:14 +02:00
: : coinJoinServer = std : : make_unique < CCoinJoinServer > ( * node . mempool , * node . connman , : : masternodeSync ) ;
2022-08-26 23:52:53 +02:00
# ifdef ENABLE_WALLET
2023-02-22 08:53:20 +01:00
if ( g_relay_txes ) {
: : coinJoinClientQueueManager = std : : make_unique < CCoinJoinClientQueueManager > ( * node . connman , : : masternodeSync ) ;
}
2022-08-26 23:52:53 +02:00
# endif // ENABLE_WALLET
2021-03-17 23:36:11 +01:00
g_wallet_init_interface . InitCoinJoinSettings ( ) ;
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
2022-05-07 17:46:33 +02:00
bool fLoadCacheFiles = ! ( fReindex | | fReindexChainState ) & & ( : : ChainActive ( ) . Tip ( ) ! = nullptr ) ;
2020-01-10 11:24:21 +01:00
fs : : path pathDB = GetDataDir ( ) ;
std : : string strDBName ;
strDBName = " mncache.dat " ;
2022-03-24 05:13:51 +01:00
uiInterface . InitMessage ( _ ( " Loading masternode cache... " ) . translated ) ;
2020-01-10 11:24:21 +01:00
CFlatDB < CMasternodeMetaMan > flatdb1 ( strDBName , " magicMasternodeCache " ) ;
if ( fLoadCacheFiles ) {
2019-01-03 21:08:34 +01:00
if ( ! flatdb1 . Load ( mmetaman ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Failed to load masternode cache from %s " ) , ( pathDB / strDBName ) . string ( ) ) ) ;
2018-03-29 17:08:00 +02:00
}
2020-01-10 11:24:21 +01:00
} else {
CMasternodeMetaMan mmetamanTmp ;
if ( ! flatdb1 . Dump ( mmetamanTmp ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Failed to clear masternode cache at %s " ) , ( pathDB / strDBName ) . string ( ) ) ) ;
2020-01-10 11:24:21 +01:00
}
}
2018-03-29 17:08:00 +02:00
2020-01-10 11:24:21 +01:00
strDBName = " governance.dat " ;
2022-03-24 05:13:51 +01:00
uiInterface . InitMessage ( _ ( " Loading governance cache... " ) . translated ) ;
2020-01-10 11:24:21 +01:00
CFlatDB < CGovernanceManager > flatdb3 ( strDBName , " magicGovernanceCache " ) ;
2020-06-28 23:00:00 +02:00
if ( fLoadCacheFiles & & ! fDisableGovernance ) {
2022-08-26 23:52:53 +02:00
if ( ! flatdb3 . Load ( * : : governance ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Failed to load governance cache from %s " ) , ( pathDB / strDBName ) . string ( ) ) ) ;
2016-12-26 16:33:28 +01:00
}
2022-08-26 23:52:53 +02:00
: : governance - > InitOnLoad ( ) ;
2020-01-10 11:24:21 +01:00
} else {
CGovernanceManager governanceTmp ;
if ( ! flatdb3 . Dump ( governanceTmp ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Failed to clear governance cache at %s " ) , ( pathDB / strDBName ) . string ( ) ) ) ;
2020-01-10 11:24:21 +01:00
}
}
2016-05-30 08:22:08 +02:00
2020-01-10 11:24:21 +01:00
strDBName = " netfulfilled.dat " ;
2022-03-24 05:13:51 +01:00
uiInterface . InitMessage ( _ ( " Loading fulfilled requests cache... " ) . translated ) ;
2020-01-10 11:24:21 +01:00
CFlatDB < CNetFulfilledRequestManager > flatdb4 ( strDBName , " magicFulfilledCache " ) ;
if ( fLoadCacheFiles ) {
2018-03-29 17:08:00 +02:00
if ( ! flatdb4 . Load ( netfulfilledman ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Failed to load fulfilled requests cache from %s " ) , ( 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 ) ) {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Failed to clear fulfilled requests cache at %s " ) , ( pathDB / strDBName ) . string ( ) ) ) ;
2020-01-10 11:24:21 +01:00
}
2016-11-16 16:37:40 +01:00
}
2016-05-30 08:22:08 +02:00
2022-08-06 10:50:11 +02:00
// ********************************************************* Step 10b: schedule Dash-specific tasks
2018-07-16 14:47:37 +02:00
2023-01-15 12:04:56 +01:00
node . scheduler - > scheduleEvery ( std : : bind ( & CNetFulfilledRequestManager : : DoMaintenance , std : : ref ( netfulfilledman ) ) , std : : chrono : : minutes { 1 } ) ;
node . scheduler - > scheduleEvery ( std : : bind ( & CMasternodeSync : : DoMaintenance , std : : ref ( * : : masternodeSync ) ) , std : : chrono : : seconds { 1 } ) ;
node . scheduler - > scheduleEvery ( std : : bind ( & CMasternodeUtils : : DoMaintenance , std : : ref ( * node . connman ) , std : : ref ( * : : masternodeSync ) ) , std : : chrono : : minutes { 1 } ) ;
node . scheduler - > scheduleEvery ( std : : bind ( & CDeterministicMNManager : : DoMaintenance , std : : ref ( * deterministicMNManager ) ) , std : : chrono : : seconds { 10 } ) ;
2018-07-16 14:47:37 +02:00
2020-06-28 23:00:00 +02:00
if ( ! fDisableGovernance ) {
2023-01-15 12:04:56 +01:00
node . scheduler - > scheduleEvery ( std : : bind ( & CGovernanceManager : : DoMaintenance , std : : ref ( * : : governance ) , std : : ref ( * node . connman ) ) , std : : chrono : : minutes { 5 } ) ;
2019-06-27 22:24:43 +02:00
}
if ( fMasternodeMode ) {
2023-01-15 12:04:56 +01:00
node . scheduler - > scheduleEvery ( std : : bind ( & CCoinJoinServer : : DoMaintenance , std : : ref ( * : : coinJoinServer ) ) , std : : chrono : : seconds { 1 } ) ;
node . scheduler - > scheduleEvery ( std : : bind ( & llmq : : CDKGSessionManager : : CleanupOldContributions , std : : ref ( * node . llmq_ctx - > qdkgsman ) ) , std : : chrono : : hours { 1 } ) ;
2022-04-07 17:32:40 +02:00
# ifdef ENABLE_WALLET
2023-02-22 08:53:20 +01:00
} else if ( g_relay_txes & & CCoinJoinClientOptions : : IsEnabled ( ) ) {
node . scheduler - > scheduleEvery ( std : : bind ( & DoCoinJoinMaintenance , std : : ref ( * node . connman ) , std : : ref ( * node . fee_estimator ) , std : : ref ( * node . mempool ) ) , std : : chrono : : seconds { 1 } ) ;
2022-04-07 17:32:40 +02:00
# endif // ENABLE_WALLET
2018-07-16 14:47:37 +02:00
}
2014-12-09 02:17:57 +01:00
2022-05-21 11:30:27 +02:00
if ( args . GetBoolArg ( " -statsenabled " , DEFAULT_STATSD_ENABLE ) ) {
int nStatsPeriod = std : : min ( std : : max ( ( int ) args . GetArg ( " -statsperiod " , DEFAULT_STATSD_PERIOD ) , MIN_STATSD_PERIOD ) , MAX_STATSD_PERIOD ) ;
2020-09-07 09:47:14 +02:00
node . scheduler - > scheduleEvery ( std : : bind ( & PeriodicStats , std : : ref ( * node . args ) , std : : cref ( * node . mempool ) ) , std : : chrono : : seconds { nStatsPeriod } ) ;
2020-12-15 17:22:23 +01:00
}
2022-11-07 19:09:44 +01:00
node . llmq_ctx - > Start ( ) ;
2019-02-17 12:39:43 +01:00
2019-03-25 07:14:57 +01:00
// ********************************************************* Step 11: import blocks
2021-08-12 09:02:29 +02:00
if ( ! CheckDiskSpace ( GetDataDir ( ) ) ) {
2020-05-08 18:17:47 +02:00
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
}
2021-08-12 09:02:29 +02:00
if ( ! CheckDiskSpace ( GetBlocksDir ( ) ) ) {
2020-05-08 18:17:47 +02:00
InitError ( strprintf ( _ ( " Error: Disk space is low for %s " ) , GetBlocksDir ( ) ) ) ;
2019-01-09 15:31:32 +01:00
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-04-23 19:02:18 +02:00
boost : : signals2 : : connection block_notify_genesis_wait_connection ;
2021-10-16 12:54:22 +02:00
if ( : : ChainActive ( ) . Tip ( ) = = nullptr ) {
2019-04-23 19:02:18 +02:00
block_notify_genesis_wait_connection = uiInterface . NotifyBlockTip_connect ( BlockNotifyGenesisWait ) ;
2019-03-25 07:14:57 +01:00
} else {
fHaveGenesis = true ;
}
2022-05-21 09:57:28 +02:00
# if HAVE_SYSTEM
2022-05-21 11:30:27 +02:00
if ( args . IsArgSet ( " -blocknotify " ) ) {
const std : : string block_notify = args . GetArg ( " -blocknotify " , " " ) ;
const auto BlockNotifyCallback = [ block_notify ] ( bool initialSync , const CBlockIndex * pBlockIndex ) {
if ( initialSync | | ! pBlockIndex )
return ;
std : : string strCmd = block_notify ;
if ( ! strCmd . empty ( ) ) {
2022-05-05 08:28:29 +02:00
ReplaceAll ( strCmd , " %s " , pBlockIndex - > GetBlockHash ( ) . GetHex ( ) ) ;
2022-05-21 11:30:27 +02:00
std : : thread t ( runCommand , strCmd ) ;
t . detach ( ) ; // thread runs free
}
} ;
2018-08-13 21:01:07 +02:00
uiInterface . NotifyBlockTip_connect ( BlockNotifyCallback ) ;
2022-05-21 11:30:27 +02:00
}
2022-05-21 09:33:04 +02:00
# endif
2019-03-25 07:14:57 +01:00
2017-04-06 20:19:21 +02:00
std : : vector < fs : : path > vImportFiles ;
2022-05-21 11:30:27 +02:00
for ( const std : : string & strFile : args . GetArgs ( " -loadblock " ) ) {
2017-06-27 14:22:54 +02:00
vImportFiles . push_back ( strFile ) ;
2019-03-25 07:14:57 +01:00
}
2020-06-06 14:23:05 +02:00
g_load_block = std : : thread ( & TraceThread < std : : function < void ( ) > > , " loadblk " , [ = , & chainman , & args ] { ThreadImport ( chainman , vImportFiles , args ) ; } ) ;
2019-03-25 07:14:57 +01:00
// 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
}
2019-04-23 19:02:18 +02:00
block_notify_genesis_wait_connection . disconnect ( ) ;
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 ) ;
2022-06-01 17:06:00 +02:00
LogPrintf ( " block tree size = %u \n " , chainman . BlockIndex ( ) . size ( ) ) ;
chain_active_height = chainman . ActiveChain ( ) . Height ( ) ;
2022-04-16 08:24:42 +02:00
if ( tip_info ) {
tip_info - > block_height = chain_active_height ;
2022-06-01 17:06:00 +02:00
tip_info - > block_time = chainman . ActiveChain ( ) . Tip ( ) ? chainman . ActiveChain ( ) . Tip ( ) - > GetBlockTime ( ) : Params ( ) . GenesisBlock ( ) . GetBlockTime ( ) ;
tip_info - > block_hash = chainman . ActiveChain ( ) . Tip ( ) ? chainman . ActiveChain ( ) . Tip ( ) - > GetBlockHash ( ) : Params ( ) . GenesisBlock ( ) . GetHash ( ) ;
tip_info - > verification_progress = GuessVerificationProgress ( Params ( ) . TxData ( ) , chainman . ActiveChain ( ) . Tip ( ) ) ;
2022-04-16 08:24:42 +02:00
}
if ( tip_info & & : : pindexBestHeader ) {
tip_info - > header_height = : : pindexBestHeader - > nHeight ;
tip_info - > header_time = : : pindexBestHeader - > GetBlockTime ( ) ;
}
2017-10-05 15:03:09 +02:00
}
2021-10-16 12:54:22 +02:00
LogPrintf ( " ::ChainActive().Height() = %d \n " , chain_active_height ) ;
2022-05-21 11:30:27 +02:00
if ( args . 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
2022-02-26 13:19:13 +01:00
// Map ports with UPnP or NAT-PMP.
2022-05-21 11:30:27 +02:00
StartMapPort ( args . GetBoolArg ( " -upnp " , DEFAULT_UPNP ) , args . GetBoolArg ( " -natpmp " , DEFAULT_NATPMP ) ) ;
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 ;
2022-06-19 08:02:28 +02:00
connOptions . m_max_outbound_full_relay = std : : min ( MAX_OUTBOUND_FULL_RELAY_CONNECTIONS , connOptions . nMaxConnections ) ;
2020-07-21 16:04:31 +02:00
connOptions . m_max_outbound_block_relay = std : : min ( MAX_BLOCK_RELAY_ONLY_CONNECTIONS , connOptions . nMaxConnections - connOptions . m_max_outbound_full_relay ) ;
2017-01-06 16:47:05 +01:00
connOptions . nMaxAddnode = MAX_ADDNODE_CONNECTIONS ;
2020-05-12 15:08:32 +02:00
connOptions . nMaxFeeler = MAX_FEELER_CONNECTIONS ;
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 ;
2022-04-05 11:09:41 +02:00
connOptions . m_banman = node . banman . get ( ) ;
connOptions . m_msgproc = node . peer_logic . get ( ) ;
2022-05-21 11:30:27 +02:00
connOptions . nSendBufferMaxSize = 1000 * args . GetArg ( " -maxsendbuffer " , DEFAULT_MAXSENDBUFFER ) ;
connOptions . nReceiveFloodSize = 1000 * args . GetArg ( " -maxreceivebuffer " , DEFAULT_MAXRECEIVEBUFFER ) ;
connOptions . m_added_nodes = args . 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
2022-10-15 23:50:01 +02:00
connOptions . nMaxOutboundLimit = 1024 * 1024 * args . GetArg ( " -maxuploadtarget " , DEFAULT_MAX_UPLOAD_TARGET ) ;
2018-12-04 12:06:35 +01:00
connOptions . m_peer_connect_timeout = peer_connect_timeout ;
2016-09-19 16:46:18 +02:00
2022-05-21 11:30:27 +02:00
for ( const std : : string & strBind : args . GetArgs ( " -bind " ) ) {
2017-06-27 14:22:54 +02:00
CService addrBind ;
Merge #17754: net: Don't allow resolving of std::string with embedded NUL characters. Add tests.
7a046cdc1423963bdcbcf9bb98560af61fa90b37 tests: Avoid using C-style NUL-terminated strings as arguments (practicalswift)
fefb9165f23fe9d10ad092ec31715f906e0d2ee7 tests: Add tests to make sure lookup methods fail on std::string parameters with embedded NUL characters (practicalswift)
9574de86ad703ad942cdd0eca79f48c0d42b102b net: Avoid using C-style NUL-terminated strings as arguments in the netbase interface (practicalswift)
Pull request description:
Don't allow resolving of `std::string`:s with embedded `NUL` characters.
Avoid using C-style `NUL`-terminated strings as arguments in the `netbase` interface
Add tests.
The only place in where C-style `NUL`-terminated strings are actually needed is here:
```diff
+ if (!ValidAsCString(name)) {
+ return false;
+ }
...
- int nErr = getaddrinfo(pszName, nullptr, &aiHint, &aiRes);
+ int nErr = getaddrinfo(name.c_str(), nullptr, &aiHint, &aiRes);
if (nErr)
return false;
```
Interface changes:
```diff
-bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
+bool LookupHost(const std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
-bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup);
+bool LookupHost(const std::string& name, CNetAddr& addr, bool fAllowLookup);
-bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLookup);
+bool Lookup(const std::string& name, CService& addr, int portDefault, bool fAllowLookup);
-bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
+bool Lookup(const std::string& name, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
-bool LookupSubNet(const char *pszName, CSubNet& subnet);
+bool LookupSubNet(const std::string& strSubnet, CSubNet& subnet);
-CService LookupNumeric(const char *pszName, int portDefault = 0);
+CService LookupNumeric(const std::string& name, int portDefault = 0);
-bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed);
+bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool& outProxyConnectionFailed);
```
It should be noted that the `ConnectThroughProxy` change (from `bool *outProxyConnectionFailed` to `bool& outProxyConnectionFailed`) has nothing to do with `NUL` handling but I thought it was worth doing when touching this file :)
ACKs for top commit:
EthanHeilman:
ACK 7a046cdc1423963bdcbcf9bb98560af61fa90b37
laanwj:
ACK 7a046cdc1423963bdcbcf9bb98560af61fa90b37
Tree-SHA512: 66556e290db996917b54091acd591df221f72230f6b9f6b167b9195ee870ebef6e26f4cda2f6f54d00e1c362e1743bf56785d0de7cae854e6bf7d26f6caccaba
2020-01-22 20:14:12 +01:00
if ( ! Lookup ( strBind , addrBind , GetListenPort ( ) , false ) ) {
2022-04-07 10:17:19 +02:00
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
}
2022-05-21 11:30:27 +02:00
for ( const std : : string & strBind : args . GetArgs ( " -whitebind " ) ) {
Merge #16248: Make whitebind/whitelist permissions more flexible
c5b404e8f1973afe071a07c63ba1038eefe13f0f Add functional tests for flexible whitebind/list (nicolas.dorier)
d541fa391844f658bd7035659b5b16695733dd56 Replace the use of fWhitelisted by permission checks (nicolas.dorier)
ecd5cf7ea4c3644a30092100ffc399e30e193275 Do not disconnect peer for asking mempool if it has NO_BAN permission (nicolas.dorier)
e5b26deaaa6842f7dd7c4537ede000f965ea0189 Make whitebind/whitelist permissions more flexible (nicolas.dorier)
Pull request description:
# Motivation
In 0.19, bloom filter will be disabled by default. I tried to make [a PR](https://github.com/bitcoin/bitcoin/pull/16176) to enable bloom filter for whitelisted peers regardless of `-peerbloomfilters`.
Bloom filter have non existent privacy and server can omit filter's matches. However, both problems are completely irrelevant when you connect to your own node. If you connect to your own node, bloom filters are the most bandwidth efficient way to synchronize your light client without the need of some middleware like Electrum.
It is also a superior alternative to BIP157 as it does not require to maintain an additional index and it would work well on pruned nodes.
When I attempted to allow bloom filters for whitelisted peer, my proposal has been NACKed in favor of [a more flexible approach](https://github.com/bitcoin/bitcoin/pull/16176#issuecomment-500762907) which should allow node operator to set fine grained permissions instead of a global `whitelisted` attribute.
Doing so will also make follow up idea very easy to implement in a backward compatible way.
# Implementation details
The PR propose a new format for `--white{list,bind}`. I added a way to specify permissions granted to inbound connection matching `white{list,bind}`.
The following permissions exists:
* ForceRelay
* Relay
* NoBan
* BloomFilter
* Mempool
Example:
* `-whitelist=bloomfilter@127.0.0.1/32`.
* `-whitebind=bloomfilter,relay,noban@127.0.0.1:10020`.
If no permissions are specified, `NoBan | Mempool` is assumed. (making this PR backward compatible)
When we receive an inbound connection, we calculate the effective permissions for this peer by fetching the permissions granted from `whitelist` and add to it the permissions granted from `whitebind`.
To keep backward compatibility, if no permissions are specified in `white{list,bind}` (e.g. `--whitelist=127.0.0.1`) then parameters `-whitelistforcerelay` and `-whiterelay` will add the permissions `ForceRelay` and `Relay` to the inbound node.
`-whitelistforcerelay` and `-whiterelay` are ignored if the permissions flags are explicitly set in `white{bind,list}`.
# Follow up idea
Based on this PR, other changes become quite easy to code in a trivially review-able, backward compatible way:
* Changing `connect` at rpc and config file level to understand the permissions flags.
* Changing the permissions of a peer at RPC level.
ACKs for top commit:
laanwj:
re-ACK c5b404e8f1973afe071a07c63ba1038eefe13f0f
Tree-SHA512: adfefb373d09e68cae401247c8fc64034e305694cdef104bdcdacb9f1704277bd53b18f52a2427a5cffdbc77bda410d221aed252bc2ece698ffbb9cf1b830577
2019-08-14 16:35:54 +02:00
NetWhitebindPermissions whitebind ;
2022-04-07 10:17:19 +02:00
bilingual_str error ;
if ( ! NetWhitebindPermissions : : TryParse ( strBind , whitebind , error ) ) return InitError ( error ) ;
Merge #16248: Make whitebind/whitelist permissions more flexible
c5b404e8f1973afe071a07c63ba1038eefe13f0f Add functional tests for flexible whitebind/list (nicolas.dorier)
d541fa391844f658bd7035659b5b16695733dd56 Replace the use of fWhitelisted by permission checks (nicolas.dorier)
ecd5cf7ea4c3644a30092100ffc399e30e193275 Do not disconnect peer for asking mempool if it has NO_BAN permission (nicolas.dorier)
e5b26deaaa6842f7dd7c4537ede000f965ea0189 Make whitebind/whitelist permissions more flexible (nicolas.dorier)
Pull request description:
# Motivation
In 0.19, bloom filter will be disabled by default. I tried to make [a PR](https://github.com/bitcoin/bitcoin/pull/16176) to enable bloom filter for whitelisted peers regardless of `-peerbloomfilters`.
Bloom filter have non existent privacy and server can omit filter's matches. However, both problems are completely irrelevant when you connect to your own node. If you connect to your own node, bloom filters are the most bandwidth efficient way to synchronize your light client without the need of some middleware like Electrum.
It is also a superior alternative to BIP157 as it does not require to maintain an additional index and it would work well on pruned nodes.
When I attempted to allow bloom filters for whitelisted peer, my proposal has been NACKed in favor of [a more flexible approach](https://github.com/bitcoin/bitcoin/pull/16176#issuecomment-500762907) which should allow node operator to set fine grained permissions instead of a global `whitelisted` attribute.
Doing so will also make follow up idea very easy to implement in a backward compatible way.
# Implementation details
The PR propose a new format for `--white{list,bind}`. I added a way to specify permissions granted to inbound connection matching `white{list,bind}`.
The following permissions exists:
* ForceRelay
* Relay
* NoBan
* BloomFilter
* Mempool
Example:
* `-whitelist=bloomfilter@127.0.0.1/32`.
* `-whitebind=bloomfilter,relay,noban@127.0.0.1:10020`.
If no permissions are specified, `NoBan | Mempool` is assumed. (making this PR backward compatible)
When we receive an inbound connection, we calculate the effective permissions for this peer by fetching the permissions granted from `whitelist` and add to it the permissions granted from `whitebind`.
To keep backward compatibility, if no permissions are specified in `white{list,bind}` (e.g. `--whitelist=127.0.0.1`) then parameters `-whitelistforcerelay` and `-whiterelay` will add the permissions `ForceRelay` and `Relay` to the inbound node.
`-whitelistforcerelay` and `-whiterelay` are ignored if the permissions flags are explicitly set in `white{bind,list}`.
# Follow up idea
Based on this PR, other changes become quite easy to code in a trivially review-able, backward compatible way:
* Changing `connect` at rpc and config file level to understand the permissions flags.
* Changing the permissions of a peer at RPC level.
ACKs for top commit:
laanwj:
re-ACK c5b404e8f1973afe071a07c63ba1038eefe13f0f
Tree-SHA512: adfefb373d09e68cae401247c8fc64034e305694cdef104bdcdacb9f1704277bd53b18f52a2427a5cffdbc77bda410d221aed252bc2ece698ffbb9cf1b830577
2019-08-14 16:35:54 +02:00
connOptions . vWhiteBinds . push_back ( whitebind ) ;
2017-06-26 14:42:46 +02:00
}
2022-05-21 11:30:27 +02:00
for ( const auto & net : args . GetArgs ( " -whitelist " ) ) {
Merge #16248: Make whitebind/whitelist permissions more flexible
c5b404e8f1973afe071a07c63ba1038eefe13f0f Add functional tests for flexible whitebind/list (nicolas.dorier)
d541fa391844f658bd7035659b5b16695733dd56 Replace the use of fWhitelisted by permission checks (nicolas.dorier)
ecd5cf7ea4c3644a30092100ffc399e30e193275 Do not disconnect peer for asking mempool if it has NO_BAN permission (nicolas.dorier)
e5b26deaaa6842f7dd7c4537ede000f965ea0189 Make whitebind/whitelist permissions more flexible (nicolas.dorier)
Pull request description:
# Motivation
In 0.19, bloom filter will be disabled by default. I tried to make [a PR](https://github.com/bitcoin/bitcoin/pull/16176) to enable bloom filter for whitelisted peers regardless of `-peerbloomfilters`.
Bloom filter have non existent privacy and server can omit filter's matches. However, both problems are completely irrelevant when you connect to your own node. If you connect to your own node, bloom filters are the most bandwidth efficient way to synchronize your light client without the need of some middleware like Electrum.
It is also a superior alternative to BIP157 as it does not require to maintain an additional index and it would work well on pruned nodes.
When I attempted to allow bloom filters for whitelisted peer, my proposal has been NACKed in favor of [a more flexible approach](https://github.com/bitcoin/bitcoin/pull/16176#issuecomment-500762907) which should allow node operator to set fine grained permissions instead of a global `whitelisted` attribute.
Doing so will also make follow up idea very easy to implement in a backward compatible way.
# Implementation details
The PR propose a new format for `--white{list,bind}`. I added a way to specify permissions granted to inbound connection matching `white{list,bind}`.
The following permissions exists:
* ForceRelay
* Relay
* NoBan
* BloomFilter
* Mempool
Example:
* `-whitelist=bloomfilter@127.0.0.1/32`.
* `-whitebind=bloomfilter,relay,noban@127.0.0.1:10020`.
If no permissions are specified, `NoBan | Mempool` is assumed. (making this PR backward compatible)
When we receive an inbound connection, we calculate the effective permissions for this peer by fetching the permissions granted from `whitelist` and add to it the permissions granted from `whitebind`.
To keep backward compatibility, if no permissions are specified in `white{list,bind}` (e.g. `--whitelist=127.0.0.1`) then parameters `-whitelistforcerelay` and `-whiterelay` will add the permissions `ForceRelay` and `Relay` to the inbound node.
`-whitelistforcerelay` and `-whiterelay` are ignored if the permissions flags are explicitly set in `white{bind,list}`.
# Follow up idea
Based on this PR, other changes become quite easy to code in a trivially review-able, backward compatible way:
* Changing `connect` at rpc and config file level to understand the permissions flags.
* Changing the permissions of a peer at RPC level.
ACKs for top commit:
laanwj:
re-ACK c5b404e8f1973afe071a07c63ba1038eefe13f0f
Tree-SHA512: adfefb373d09e68cae401247c8fc64034e305694cdef104bdcdacb9f1704277bd53b18f52a2427a5cffdbc77bda410d221aed252bc2ece698ffbb9cf1b830577
2019-08-14 16:35:54 +02:00
NetWhitelistPermissions subnet ;
2022-04-07 10:17:19 +02:00
bilingual_str error ;
if ( ! NetWhitelistPermissions : : TryParse ( net , subnet , error ) ) return InitError ( error ) ;
2017-06-27 14:22:54 +02:00
connOptions . vWhitelistedRange . push_back ( subnet ) ;
2017-06-26 14:42:46 +02:00
}
2022-05-21 11:30:27 +02:00
connOptions . vSeedNodes = args . GetArgs ( " -seednode " ) ;
2017-09-22 23:58:52 +02:00
2017-09-06 01:54:31 +02:00
// Initiate outbound connections unless connect=0
2022-05-21 11:30:27 +02:00
connOptions . m_use_addrman_outgoing = ! args . IsArgSet ( " -connect " ) ;
2017-09-06 01:54:31 +02:00
if ( ! connOptions . m_use_addrman_outgoing ) {
2022-05-21 11:30:27 +02:00
const auto connect = args . GetArgs ( " -connect " ) ;
2017-09-06 01:54:31 +02:00
if ( connect . size ( ) ! = 1 | | connect [ 0 ] ! = " 0 " ) {
connOptions . m_specified_outgoing = connect ;
}
}
2020-04-16 10:11:26 +02:00
2022-05-21 11:30:27 +02:00
std : : string strSocketEventsMode = args . GetArg ( " -socketevents " , DEFAULT_SOCKETEVENTS ) ;
2020-04-16 10:11:26 +02:00
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 {
2020-05-08 18:17:47 +02:00
return InitError ( strprintf ( _ ( " Invalid -socketevents ('%s') specified . Only these modes are supported : % s " ), strSocketEventsMode, GetSupportedSocketEventsStr())) ;
2020-04-16 10:11:26 +02:00
}
2022-01-09 18:03:26 +01:00
if ( ! node . connman - > Start ( * node . scheduler , connOptions ) ) {
2017-06-26 14:42:46 +02:00
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 ( ) ;
2022-03-24 05:13:51 +01:00
uiInterface . InitMessage ( _ ( " Done loading " ) . translated ) ;
2012-05-21 16:47:29 +02:00
2022-04-05 11:09:41 +02:00
for ( const auto & client : node . chain_clients ) {
2022-01-09 18:03:26 +01:00
client - > start ( * node . scheduler ) ;
2018-11-09 15:36:34 +01:00
}
2011-05-14 20:10:21 +02:00
2022-04-05 11:09:41 +02:00
BanMan * banman = node . banman . get ( ) ;
2022-01-09 18:03:26 +01:00
node . scheduler - > scheduleEvery ( [ banman ] {
2022-04-05 11:09:41 +02:00
banman - > DumpBanlist ( ) ;
2023-01-15 12:04:56 +01:00
} , DUMP_BANS_INTERVAL ) ;
2019-01-21 18:45:59 +01:00
2017-12-12 10:27:45 +01:00
return true ;
2011-05-14 20:10:21 +02:00
}