init.h raw

   1  // Copyright (c) 2009-2010 Satoshi Nakamoto
   2  // Copyright (c) 2009-present The Bitcoin Core developers
   3  // Distributed under the MIT software license, see the accompanying
   4  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   5  
   6  #ifndef BITCOIN_INIT_H
   7  #define BITCOIN_INIT_H
   8  
   9  #include <atomic>
  10  
  11  //! Default value for -daemon option
  12  static constexpr bool DEFAULT_DAEMON = false;
  13  //! Default value for -daemonwait option
  14  static constexpr bool DEFAULT_DAEMONWAIT = false;
  15  
  16  class ArgsManager;
  17  namespace interfaces {
  18  struct BlockAndHeaderTipInfo;
  19  }
  20  namespace kernel {
  21  struct Context;
  22  }
  23  namespace node {
  24  struct NodeContext;
  25  } // namespace node
  26  
  27  /** Initialize node context shutdown and args variables. */
  28  void InitContext(node::NodeContext& node);
  29  /** Return whether node shutdown was requested. */
  30  bool ShutdownRequested(node::NodeContext& node);
  31  
  32  /** Interrupt threads */
  33  void Interrupt(node::NodeContext& node);
  34  void Shutdown(node::NodeContext& node);
  35  //!Initialize the logging infrastructure
  36  void InitLogging(const ArgsManager& args);
  37  //!Parameter interaction: change current parameters depending on various rules
  38  void InitParameterInteraction(ArgsManager& args);
  39  
  40  /** Initialize bitcoin core: Basic context setup.
  41   *  @note This can be done before daemonization. Do not call Shutdown() if this function fails.
  42   *  @pre Parameters should be parsed and config file should be read.
  43   */
  44  bool AppInitBasicSetup(const ArgsManager& args, std::atomic<int>& exit_status);
  45  /**
  46   * Initialization: parameter interaction.
  47   * @note This can be done before daemonization. Do not call Shutdown() if this function fails.
  48   * @pre Parameters should be parsed and config file should be read, AppInitBasicSetup should have been called.
  49   */
  50  bool AppInitParameterInteraction(const ArgsManager& args);
  51  /**
  52   * Initialization sanity checks.
  53   * @note This can be done before daemonization. Do not call Shutdown() if this function fails.
  54   * @pre Parameters should be parsed and config file should be read, AppInitParameterInteraction should have been called.
  55   */
  56  bool AppInitSanityChecks(const kernel::Context& kernel);
  57  /**
  58   * Lock bitcoin core critical directories.
  59   * @note This should only be done after daemonization. Do not call Shutdown() if this function fails.
  60   * @pre Parameters should be parsed and config file should be read, AppInitSanityChecks should have been called.
  61   */
  62  bool AppInitLockDirectories();
  63  /**
  64   * Initialize node and wallet interface pointers. Has no prerequisites or side effects besides allocating memory.
  65   */
  66  bool AppInitInterfaces(node::NodeContext& node);
  67  /**
  68   * Bitcoin core main initialization.
  69   * @note This should only be done after daemonization. Call Shutdown() if this function fails.
  70   * @pre Parameters should be parsed and config file should be read, AppInitLockDirectories should have been called.
  71   */
  72  bool AppInitMain(node::NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
  73  
  74  /**
  75   * Register all arguments with the ArgsManager
  76   */
  77  void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc=false);
  78  
  79  /** Validates requirements to run the indexes and spawns each index initial sync thread */
  80  bool StartIndexBackgroundSync(node::NodeContext& node);
  81  
  82  #endif // BITCOIN_INIT_H
  83