Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2019-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_NODE_CONTEXT_H6#define BITCOIN_NODE_CONTEXT_H8#include <node/mining_types.h>10#include <atomic>11#include <cstdlib>12#include <functional>13#include <memory>14#include <thread>15#include <vector>17class ArgsManager;18class AddrMan;19class BanMan;20class BaseIndex;21class CConnman;22class FeeRateEstimatorManager;23class ValidationSignals;24class CScheduler;25class CTxMemPool;26class ChainstateManager;27class ECC_Context;28class NetGroupManager;29class PeerManager;30class TorController;31namespace interfaces {32class Chain;33class ChainClient;34class Mining;35class Init;36class WalletLoader;37} // namespace interfaces38namespace kernel {39struct Context;40}41namespace util {42class SignalInterrupt;43}45namespace node {46class KernelNotifications;47class Warnings;49//! NodeContext struct containing references to chain state and connection50//! state.51//!52//! This is used by init, rpc, and test code to pass object references around53//! without needing to declare the same variables and parameters repeatedly, or54//! to use globals. More variables could be added to this struct (particularly55//! references to validation objects) to eliminate use of globals56//! and make code more modular and testable. The struct isn't intended to have57//! any member functions. It should just be a collection of references that can58//! be used without pulling in unwanted dependencies or functionality.59struct NodeContext {60//! libbitcoin_kernel context61std::unique_ptr<kernel::Context> kernel;62std::unique_ptr<ECC_Context> ecc_context;63//! Init interface for initializing current process and connecting to other processes.64interfaces::Init* init{nullptr};65//! Function to request a shutdown.66std::function<bool()> shutdown_request;67//! Interrupt object used to track whether node shutdown was requested.68util::SignalInterrupt* shutdown_signal{nullptr};69std::unique_ptr<AddrMan> addrman;70std::unique_ptr<CConnman> connman;71std::unique_ptr<CTxMemPool> mempool;72std::unique_ptr<const NetGroupManager> netgroupman;73std::unique_ptr<FeeRateEstimatorManager> fee_estimator_man;74std::unique_ptr<PeerManager> peerman;75std::unique_ptr<TorController> tor_controller;76std::unique_ptr<ChainstateManager> chainman;77std::unique_ptr<BanMan> banman;78ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct79std::vector<BaseIndex*> indexes; // raw pointers because memory is not managed by this struct80std::unique_ptr<interfaces::Chain> chain;81//! List of all chain clients (wallet processes or other client) connected to node.82std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;83//! Reference to chain client that should used to load or create wallets84//! opened by the gui.85std::unique_ptr<interfaces::Mining> mining;86//! Mining options used to create block templates. This value member is an87//! exception to the dependency guidance above because BlockCreateOptions is88//! a minimal dependency. It could be moved to the BlockTemplateCache89//! proposed in bitcoin/bitcoin#33421.90BlockCreateOptions mining_args;91interfaces::WalletLoader* wallet_loader{nullptr};92std::unique_ptr<CScheduler> scheduler;93std::function<void()> rpc_interruption_point = [] {};94//! Issues blocking calls about sync status, errors and warnings95std::unique_ptr<KernelNotifications> notifications;96//! Issues calls about blocks and transactions97std::unique_ptr<ValidationSignals> validation_signals;98std::atomic<int> exit_status{EXIT_SUCCESS};99//! Manages all the node warnings100std::unique_ptr<node::Warnings> warnings;101std::thread background_init_thread;103//! Declare default constructor and destructor that are not inline, so code104//! instantiating the NodeContext struct doesn't need to #include class105//! definitions for all the unique_ptr members.106NodeContext();107~NodeContext();108};109} // namespace node111#endif // BITCOIN_NODE_CONTEXT_H