Bitcoin Core  0.20.99
P2P Digital Currency
Classes | Macros | Functions | Variables
init.cpp File Reference
#include <init.h>
#include <addrman.h>
#include <amount.h>
#include <banman.h>
#include <blockfilter.h>
#include <chain.h>
#include <chainparams.h>
#include <compat/sanity.h>
#include <consensus/validation.h>
#include <fs.h>
#include <hash.h>
#include <httprpc.h>
#include <httpserver.h>
#include <index/blockfilterindex.h>
#include <index/txindex.h>
#include <interfaces/chain.h>
#include <key.h>
#include <miner.h>
#include <net.h>
#include <net_permissions.h>
#include <net_processing.h>
#include <netbase.h>
#include <node/context.h>
#include <node/ui_interface.h>
#include <policy/feerate.h>
#include <policy/fees.h>
#include <policy/policy.h>
#include <policy/settings.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 <script/standard.h>
#include <shutdown.h>
#include <sync.h>
#include <timedata.h>
#include <torcontrol.h>
#include <txdb.h>
#include <txmempool.h>
#include <util/asmap.h>
#include <util/check.h>
#include <util/moneystr.h>
#include <util/string.h>
#include <util/system.h>
#include <util/threadnames.h>
#include <util/translation.h>
#include <validation.h>
#include <validationinterface.h>
#include <walletinitinterface.h>
#include <functional>
#include <set>
#include <stdint.h>
#include <stdio.h>
#include <attributes.h>
#include <cerrno>
#include <signal.h>
#include <sys/stat.h>
#include <boost/algorithm/string/replace.hpp>
#include <boost/signals2/signal.hpp>
#include <boost/thread/thread.hpp>

Go to the source code of this file.

Classes

struct  CImportingNow
 

Macros

#define MIN_CORE_FILEDESCRIPTORS   150
 

Functions

static fs::path GetPidFile ()
 
static NODISCARD bool CreatePidFile ()
 
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))
 
static void OnRPCStarted ()
 
static void OnRPCStopped ()
 
void SetupServerArgs (NodeContext &node)
 Register all arguments with the ArgsManager. More...
 
std::string LicenseInfo ()
 Returns licensing information (for -version) More...
 
static void BlockNotifyGenesisWait (const CBlockIndex *pBlockIndex)
 
static void CleanupBlockRevFiles ()
 
static void ThreadImport (ChainstateManager &chainman, std::vector< fs::path > vImportFiles)
 
static bool InitSanityCheck ()
 Sanity checks Ensure that Bitcoin is running in a usable environment with all necessary library support. More...
 
static bool AppInitServers (const util::Ref &context)
 
void InitParameterInteraction ()
 Parameter interaction: change current parameters depending on various rules. More...
 
void InitLogging ()
 Initialize global loggers. More...
 
static void new_handler_terminate ()
 
bool AppInitBasicSetup ()
 Initialize bitcoin core: Basic context setup. More...
 
bool AppInitParameterInteraction ()
 Initialization: parameter interaction. More...
 
static bool LockDataDirectory (bool probeOnly)
 
bool AppInitSanityChecks ()
 Initialization sanity checks: ecc init, sanity checks, dir lock. More...
 
bool AppInitLockDataDirectory ()
 Lock bitcoin core data directory. More...
 
bool AppInitMain (const util::Ref &context, NodeContext &node)
 Bitcoin core main initialization. More...
 

Variables

static bool fFeeEstimatesInitialized = false
 
static const bool DEFAULT_PROXYRANDOMIZE = true
 
static const bool DEFAULT_REST_ENABLE = false
 
static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false
 
static const char * FEE_ESTIMATES_FILENAME ="fee_estimates.dat"
 
static const char * DEFAULT_ASMAP_FILENAME ="ip_asn.map"
 
static const char * BITCOIN_PID_FILENAME = "bitcoind.pid"
 The PID file facilities. More...
 
static std::unique_ptr< ECCVerifyHandleglobalVerifyHandle
 
static std::thread g_load_block
 
static boost::thread_group threadGroup
 
static boost::signals2::connection rpc_notify_block_change_connection
 
static bool fHaveGenesis = false
 
static Mutex g_genesis_wait_mutex
 
static std::condition_variable g_genesis_wait_cv
 

Macro Definition Documentation

◆ MIN_CORE_FILEDESCRIPTORS

#define MIN_CORE_FILEDESCRIPTORS   150

Definition at line 97 of file init.cpp.

Function Documentation

◆ AppInitBasicSetup()

bool AppInitBasicSetup ( )

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 908 of file init.cpp.

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

◆ AppInitLockDataDirectory()

bool AppInitLockDataDirectory ( )

Lock bitcoin core data directory.

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 1230 of file init.cpp.

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

◆ AppInitMain()

bool AppInitMain ( const util::Ref context,
NodeContext node 
)

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, AppInitLockDataDirectory should have been called.

Definition at line 1242 of file init.cpp.

Here is the caller graph for this function:

◆ AppInitParameterInteraction()

bool AppInitParameterInteraction ( )

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 950 of file init.cpp.

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

◆ AppInitSanityChecks()

bool AppInitSanityChecks ( )

Initialization sanity checks: ecc init, sanity checks, dir lock.

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 1209 of file init.cpp.

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

◆ AppInitServers()

static bool AppInitServers ( const util::Ref context)
static

Definition at line 778 of file init.cpp.

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

◆ BlockNotifyGenesisWait()

static void BlockNotifyGenesisWait ( const CBlockIndex pBlockIndex)
static

Definition at line 618 of file init.cpp.

Here is the caller graph for this function:

◆ CleanupBlockRevFiles()

static void CleanupBlockRevFiles ( )
static

Definition at line 649 of file init.cpp.

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

◆ CreatePidFile()

static NODISCARD bool CreatePidFile ( )
static

Definition at line 114 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 ( )
static

Definition at line 109 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 330 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 325 of file init.cpp.

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

◆ InitLogging()

void InitLogging ( )

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 862 of file init.cpp.

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

◆ InitParameterInteraction()

void InitParameterInteraction ( )

Parameter interaction: change current parameters depending on various rules.

Definition at line 793 of file init.cpp.

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

◆ InitSanityCheck()

static bool InitSanityCheck ( )
static

Sanity checks Ensure that Bitcoin is running in a usable environment with all necessary library support.

Definition at line 762 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 160 of file init.cpp.

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

◆ LicenseInfo()

std::string LicenseInfo ( )

Returns licensing information (for -version)

Definition at line 580 of file init.cpp.

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

◆ LockDataDirectory()

static bool LockDataDirectory ( bool  probeOnly)
static

Definition at line 1196 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 895 of file init.cpp.

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

◆ OnRPCStarted()

static void OnRPCStarted ( )
static

Definition at line 355 of file init.cpp.

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

◆ OnRPCStopped()

static void OnRPCStopped ( )
static

Definition at line 360 of file init.cpp.

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

◆ registerSignalHandler()

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

Definition at line 344 of file init.cpp.

Here is the caller graph for this function:

◆ SetupServerArgs()

void SetupServerArgs ( NodeContext node)

Register all arguments with the ArgsManager.

Definition at line 368 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 176 of file init.cpp.

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

◆ ThreadImport()

static void ThreadImport ( ChainstateManager chainman,
std::vector< fs::path >  vImportFiles 
)
static

Definition at line 684 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 107 of file init.cpp.

◆ DEFAULT_ASMAP_FILENAME

const char* DEFAULT_ASMAP_FILENAME ="ip_asn.map"
static

Definition at line 102 of file init.cpp.

◆ DEFAULT_PROXYRANDOMIZE

const bool DEFAULT_PROXYRANDOMIZE = true
static

Definition at line 87 of file init.cpp.

◆ DEFAULT_REST_ENABLE

const bool DEFAULT_REST_ENABLE = false
static

Definition at line 88 of file init.cpp.

◆ DEFAULT_STOPAFTERBLOCKIMPORT

const bool DEFAULT_STOPAFTERBLOCKIMPORT = false
static

Definition at line 89 of file init.cpp.

◆ FEE_ESTIMATES_FILENAME

const char* FEE_ESTIMATES_FILENAME ="fee_estimates.dat"
static

Definition at line 100 of file init.cpp.

◆ fFeeEstimatesInitialized

bool fFeeEstimatesInitialized = false
static

Definition at line 86 of file init.cpp.

◆ fHaveGenesis

bool fHaveGenesis = false
static

Definition at line 614 of file init.cpp.

◆ g_genesis_wait_cv

std::condition_variable g_genesis_wait_cv
static

Definition at line 616 of file init.cpp.

◆ g_genesis_wait_mutex

Mutex g_genesis_wait_mutex
static

Definition at line 615 of file init.cpp.

◆ g_load_block

std::thread g_load_block
static

Definition at line 156 of file init.cpp.

◆ globalVerifyHandle

std::unique_ptr<ECCVerifyHandle> globalVerifyHandle
static

Definition at line 154 of file init.cpp.

◆ rpc_notify_block_change_connection

boost::signals2::connection rpc_notify_block_change_connection
static

Definition at line 354 of file init.cpp.

◆ threadGroup

boost::thread_group threadGroup
static

Definition at line 158 of file init.cpp.