Coverage Report

Created: 2026-09-15 16:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/node/context.h
Line
Count
Source
1
// Copyright (c) 2019-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_NODE_CONTEXT_H
6
#define BITCOIN_NODE_CONTEXT_H
7
8
#include <atomic>
9
#include <cstdlib>
10
#include <functional>
11
#include <memory>
12
#include <thread>
13
#include <vector>
14
15
class ArgsManager;
16
class AddrMan;
17
class BanMan;
18
class BaseIndex;
19
class CConnman;
20
class FeeRateEstimatorManager;
21
class ValidationSignals;
22
class CScheduler;
23
class CTxMemPool;
24
class ChainstateManager;
25
class ECC_Context;
26
class NetGroupManager;
27
class PeerManager;
28
class TorController;
29
namespace interfaces {
30
class Chain;
31
class ChainClient;
32
class Init;
33
class WalletLoader;
34
} // namespace interfaces
35
namespace kernel {
36
struct Context;
37
}
38
namespace util {
39
class SignalInterrupt;
40
}
41
42
namespace node {
43
class BlockTemplateManager;
44
class KernelNotifications;
45
class Warnings;
46
47
//! NodeContext struct containing references to chain state and connection
48
//! state.
49
//!
50
//! This is used by init, rpc, and test code to pass object references around
51
//! without needing to declare the same variables and parameters repeatedly, or
52
//! to use globals. More variables could be added to this struct (particularly
53
//! references to validation objects) to eliminate use of globals
54
//! and make code more modular and testable. The struct isn't intended to have
55
//! any member functions. It should just be a collection of references that can
56
//! be used without pulling in unwanted dependencies or functionality.
57
struct NodeContext {
58
    //! libbitcoin_kernel context
59
    std::unique_ptr<kernel::Context> kernel;
60
    std::unique_ptr<ECC_Context> ecc_context;
61
    //! Init interface for initializing current process and connecting to other processes.
62
    interfaces::Init* init{nullptr};
63
    //! Function to request a shutdown.
64
    std::function<bool()> shutdown_request;
65
    //! Interrupt object used to track whether node shutdown was requested.
66
    util::SignalInterrupt* shutdown_signal{nullptr};
67
    std::unique_ptr<AddrMan> addrman;
68
    std::unique_ptr<CConnman> connman;
69
    std::unique_ptr<CTxMemPool> mempool;
70
    std::unique_ptr<const NetGroupManager> netgroupman;
71
    std::unique_ptr<FeeRateEstimatorManager> fee_estimator_man;
72
    std::unique_ptr<PeerManager> peerman;
73
    std::unique_ptr<TorController> tor_controller;
74
    std::unique_ptr<ChainstateManager> chainman;
75
    std::unique_ptr<BanMan> banman;
76
    ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
77
    std::vector<BaseIndex*> indexes; // raw pointers because memory is not managed by this struct
78
    std::unique_ptr<interfaces::Chain> chain;
79
    //! List of all chain clients (wallet processes or other client) connected to node.
80
    std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
81
    interfaces::WalletLoader* wallet_loader{nullptr};
82
    std::unique_ptr<CScheduler> scheduler;
83
0
    std::function<void()> rpc_interruption_point = [] {};
84
    //! Issues blocking calls about sync status, errors and warnings
85
    std::unique_ptr<KernelNotifications> notifications;
86
    //! Must be destroyed before its dependencies (holds references to them).
87
    std::unique_ptr<BlockTemplateManager> block_template_manager;
88
    //! Issues calls about blocks and transactions
89
    std::unique_ptr<ValidationSignals> validation_signals;
90
    std::atomic<int> exit_status{EXIT_SUCCESS};
91
    //! Manages all the node warnings
92
    std::unique_ptr<node::Warnings> warnings;
93
    std::thread background_init_thread;
94
95
    //! Declare default constructor and destructor that are not inline, so code
96
    //! instantiating the NodeContext struct doesn't need to #include class
97
    //! definitions for all the unique_ptr members.
98
    NodeContext();
99
    ~NodeContext();
100
};
101
} // namespace node
102
103
#endif // BITCOIN_NODE_CONTEXT_H