Bitcoin Core 28.99.0
P2P Digital Currency
Macros | Functions | Variables
init.cpp File Reference
#include <bitcoin-build-config.h>
#include <init.h>
#include <kernel/checks.h>
#include <addrman.h>
#include <banman.h>
#include <blockfilter.h>
#include <chain.h>
#include <chainparams.h>
#include <chainparamsbase.h>
#include <clientversion.h>
#include <common/args.h>
#include <common/system.h>
#include <consensus/amount.h>
#include <consensus/consensus.h>
#include <deploymentstatus.h>
#include <hash.h>
#include <httprpc.h>
#include <httpserver.h>
#include <index/blockfilterindex.h>
#include <index/coinstatsindex.h>
#include <index/txindex.h>
#include <init/common.h>
#include <interfaces/chain.h>
#include <interfaces/init.h>
#include <interfaces/ipc.h>
#include <interfaces/mining.h>
#include <interfaces/node.h>
#include <kernel/caches.h>
#include <kernel/context.h>
#include <key.h>
#include <logging.h>
#include <mapport.h>
#include <net.h>
#include <net_permissions.h>
#include <net_processing.h>
#include <netbase.h>
#include <netgroup.h>
#include <node/blockmanager_args.h>
#include <node/blockstorage.h>
#include <node/caches.h>
#include <node/chainstate.h>
#include <node/chainstatemanager_args.h>
#include <node/context.h>
#include <node/interface_ui.h>
#include <node/kernel_notifications.h>
#include <node/mempool_args.h>
#include <node/mempool_persist.h>
#include <node/mempool_persist_args.h>
#include <node/miner.h>
#include <node/peerman_args.h>
#include <policy/feerate.h>
#include <policy/fees.h>
#include <policy/fees_args.h>
#include <policy/policy.h>
#include <policy/settings.h>
#include <protocol.h>
#include <rpc/blockchain.h>
#include <rpc/register.h>
#include <rpc/server.h>
#include <rpc/util.h>
#include <scheduler.h>
#include <script/sigcache.h>
#include <sync.h>
#include <torcontrol.h>
#include <txdb.h>
#include <txmempool.h>
#include <util/asmap.h>
#include <util/batchpriority.h>
#include <util/chaintype.h>
#include <util/check.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/moneystr.h>
#include <util/result.h>
#include <util/signalinterrupt.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/syserror.h>
#include <util/thread.h>
#include <util/threadnames.h>
#include <util/time.h>
#include <util/translation.h>
#include <validation.h>
#include <validationinterface.h>
#include <walletinitinterface.h>
#include <algorithm>
#include <condition_variable>
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <functional>
#include <set>
#include <string>
#include <thread>
#include <vector>
#include <cerrno>
#include <signal.h>
#include <sys/stat.h>
#include <boost/signals2/signal.hpp>

Go to the source code of this file.

Macros

#define MIN_LEVELDB_FDS   150
 

Functions

static fs::path GetPidFile (const ArgsManager &args)
 
static bool CreatePidFile (const ArgsManager &args)
 
static void RemovePidFile (const ArgsManager &args)
 
void InitContext (NodeContext &node)
 Initialize node context shutdown and args variables. More...
 
bool ShutdownRequested (node::NodeContext &node)
 Return whether node shutdown was requested. More...
 
void Interrupt (NodeContext &node)
 Interrupt threads. More...
 
void Shutdown (NodeContext &node)
 
static void HandleSIGTERM (int)
 Signal handlers are very limited in what they are allowed to do. More...
 
static void HandleSIGHUP (int)
 
static void registerSignalHandler (int signal, void(*handler)(int))
 
void SetupServerArgs (ArgsManager &argsman, bool can_listen_ipc)
 Register all arguments with the ArgsManager. More...
 
static bool AppInitServers (NodeContext &node)
 
void InitParameterInteraction (ArgsManager &args)
 Parameter interaction: change current parameters depending on various rules. More...
 
void InitLogging (const ArgsManager &args)
 Initialize global loggers. More...
 
static void new_handler_terminate ()
 
bool AppInitBasicSetup (const ArgsManager &args, std::atomic< int > &exit_status)
 Initialize bitcoin core: Basic context setup. More...
 
bool AppInitParameterInteraction (const ArgsManager &args)
 Initialization: parameter interaction. More...
 
static bool LockDirectory (const fs::path &dir, bool probeOnly)
 
static bool LockDirectories (bool probeOnly)
 
bool AppInitSanityChecks (const kernel::Context &kernel)
 Initialization sanity checks. More...
 
bool AppInitLockDirectories ()
 Lock bitcoin core critical directories. More...
 
bool AppInitInterfaces (NodeContext &node)
 Initialize node and wallet interface pointers. More...
 
bool CheckHostPortOptions (const ArgsManager &args)
 
static ChainstateLoadResult InitAndLoadChainstate (NodeContext &node, bool do_reindex, const bool do_reindex_chainstate, const kernel::CacheSizes &cache_sizes, const ArgsManager &args)
 
bool AppInitMain (NodeContext &node, interfaces::BlockAndHeaderTipInfo *tip_info)
 Bitcoin core main initialization. More...
 
bool StartIndexBackgroundSync (NodeContext &node)
 Validates requirements to run the indexes and spawns each index initial sync thread. More...
 

Variables

static constexpr bool DEFAULT_PROXYRANDOMIZE {true}
 
static constexpr bool DEFAULT_REST_ENABLE {false}
 
static constexpr bool DEFAULT_I2P_ACCEPT_INCOMING {true}
 
static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT {false}
 
static constexpr int MIN_CORE_FDS = MIN_LEVELDB_FDS + NUM_FDS_MESSAGE_CAPTURE
 
static const char * DEFAULT_ASMAP_FILENAME ="ip_asn.map"
 
static const char * BITCOIN_PID_FILENAME = "bitcoind.pid"
 The PID file facilities. More...
 
static bool g_generated_pid {false}
 True if this process has created a PID file. More...
 
static std::optional< util::SignalInterruptg_shutdown
 

Macro Definition Documentation

◆ MIN_LEVELDB_FDS

#define MIN_LEVELDB_FDS   150

Definition at line 156 of file init.cpp.

Function Documentation

◆ AppInitBasicSetup()

bool AppInitBasicSetup ( const ArgsManager args,
std::atomic< int > &  exit_status 
)

Initialize bitcoin core: Basic context setup.

Note
This can be done before daemonization. Do not call Shutdown() if this function fails.
Precondition
Parameters should be parsed and config file should be read.

Definition at line 833 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AppInitInterfaces()

bool AppInitInterfaces ( node::NodeContext node)

Initialize node and wallet interface pointers.

Has no prerequisites or side effects besides allocating memory.

Definition at line 1148 of file init.cpp.

Here is the caller graph for this function:

◆ AppInitLockDirectories()

bool AppInitLockDirectories ( )

Lock bitcoin core critical directories.

Note
This should only be done after daemonization. Do not call Shutdown() if this function fails.
Precondition
Parameters should be parsed and config file should be read, AppInitSanityChecks should have been called.

Definition at line 1136 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AppInitMain()

bool AppInitMain ( node::NodeContext node,
interfaces::BlockAndHeaderTipInfo tip_info = nullptr 
)

Bitcoin core main initialization.

Note
This should only be done after daemonization. Call Shutdown() if this function fails.
Precondition
Parameters should be parsed and config file should be read, AppInitLockDirectories should have been called.

Definition at line 1313 of file init.cpp.

Here is the caller graph for this function:

◆ AppInitParameterInteraction()

bool AppInitParameterInteraction ( const ArgsManager args)

Initialization: parameter interaction.

Note
This can be done before daemonization. Do not call Shutdown() if this function fails.
Precondition
Parameters should be parsed and config file should be read, AppInitBasicSetup should have been called.

Definition at line 870 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AppInitSanityChecks()

bool AppInitSanityChecks ( const kernel::Context kernel)

Initialization sanity checks.

Note
This can be done before daemonization. Do not call Shutdown() if this function fails.
Precondition
Parameters should be parsed and config file should be read, AppInitParameterInteraction should have been called.

Definition at line 1117 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AppInitServers()

static bool AppInitServers ( NodeContext node)
static

Definition at line 699 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckHostPortOptions()

bool CheckHostPortOptions ( const ArgsManager args)

Definition at line 1155 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreatePidFile()

static bool CreatePidFile ( const ArgsManager args)
static

Definition at line 177 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPidFile()

static fs::path GetPidFile ( const ArgsManager args)
static

Definition at line 172 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleSIGHUP()

static void HandleSIGHUP ( int  )
static

Definition at line 417 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleSIGTERM()

static void HandleSIGTERM ( int  )
static

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:

Definition at line 410 of file init.cpp.

Here is the caller graph for this function:

◆ InitAndLoadChainstate()

static ChainstateLoadResult InitAndLoadChainstate ( NodeContext node,
bool  do_reindex,
const bool  do_reindex_chainstate,
const kernel::CacheSizes cache_sizes,
const ArgsManager args 
)
static

Definition at line 1204 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitContext()

void InitContext ( NodeContext node)

Initialize node context shutdown and args variables.

Definition at line 207 of file init.cpp.

Here is the call graph for this function:

◆ InitLogging()

void InitLogging ( const ArgsManager args)

Initialize global loggers.

Initialize the logging infrastructure.

Note that this is called very early in the process lifetime, so you should be careful about what global state you rely on here.

Definition at line 804 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitParameterInteraction()

void InitParameterInteraction ( ArgsManager args)

Parameter interaction: change current parameters depending on various rules.

Definition at line 715 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Interrupt()

void Interrupt ( NodeContext node)

Interrupt threads.

Definition at line 264 of file init.cpp.

Here is the call graph for this function:

◆ LockDirectories()

static bool LockDirectories ( bool  probeOnly)
static

Definition at line 1111 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LockDirectory()

static bool LockDirectory ( const fs::path dir,
bool  probeOnly 
)
static

Definition at line 1099 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ new_handler_terminate()

static void new_handler_terminate ( )
static

Definition at line 820 of file init.cpp.

Here is the caller graph for this function:

◆ registerSignalHandler()

static void registerSignalHandler ( int  signal,
void(*)(int)  handler 
)
static

Definition at line 434 of file init.cpp.

Here is the caller graph for this function:

◆ RemovePidFile()

static void RemovePidFile ( const ArgsManager args)
static

Definition at line 195 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetupServerArgs()

void SetupServerArgs ( ArgsManager argsman,
bool  can_listen_ipc 
)

Register all arguments with the ArgsManager.

Definition at line 444 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Shutdown()

void Shutdown ( NodeContext node)

Note: Shutdown() must be able to handle cases in which initialization failed part of the way, 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.

Definition at line 282 of file init.cpp.

Here is the call graph for this function:

◆ ShutdownRequested()

bool ShutdownRequested ( node::NodeContext node)

Return whether node shutdown was requested.

Definition at line 246 of file init.cpp.

Here is the caller graph for this function:

◆ StartIndexBackgroundSync()

bool StartIndexBackgroundSync ( NodeContext node)

Validates requirements to run the indexes and spawns each index initial sync thread.

Definition at line 2067 of file init.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ BITCOIN_PID_FILENAME

const char* BITCOIN_PID_FILENAME = "bitcoind.pid"
static

The PID file facilities.

Definition at line 165 of file init.cpp.

◆ DEFAULT_ASMAP_FILENAME

const char* DEFAULT_ASMAP_FILENAME ="ip_asn.map"
static

Definition at line 160 of file init.cpp.

◆ DEFAULT_I2P_ACCEPT_INCOMING

constexpr bool DEFAULT_I2P_ACCEPT_INCOMING {true}
staticconstexpr

Definition at line 147 of file init.cpp.

◆ DEFAULT_PROXYRANDOMIZE

constexpr bool DEFAULT_PROXYRANDOMIZE {true}
staticconstexpr

Definition at line 145 of file init.cpp.

◆ DEFAULT_REST_ENABLE

constexpr bool DEFAULT_REST_ENABLE {false}
staticconstexpr

Definition at line 146 of file init.cpp.

◆ DEFAULT_STOPAFTERBLOCKIMPORT

constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT {false}
staticconstexpr

Definition at line 148 of file init.cpp.

◆ g_generated_pid

bool g_generated_pid {false}
static

True if this process has created a PID file.

Used to determine whether we should remove the PID file on shutdown.

Definition at line 170 of file init.cpp.

◆ g_shutdown

std::optional<util::SignalInterrupt> g_shutdown
static

Definition at line 205 of file init.cpp.

◆ MIN_CORE_FDS

constexpr int MIN_CORE_FDS = MIN_LEVELDB_FDS + NUM_FDS_MESSAGE_CAPTURE
staticconstexpr

Definition at line 159 of file init.cpp.