Bitcoin Core Fuzz Coverage Report

Coverage Report

Created: 2026-03-24 13:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/interfaces/node.h
Line
Count
Source
1
// Copyright (c) 2018-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_INTERFACES_NODE_H
6
#define BITCOIN_INTERFACES_NODE_H
7
8
#include <common/settings.h>
9
#include <consensus/amount.h>
10
#include <logging.h>
11
#include <net.h>
12
#include <net_types.h>
13
#include <netaddress.h>
14
#include <netbase.h>
15
#include <support/allocators/secure.h>
16
#include <util/translation.h>
17
18
#include <cstddef>
19
#include <cstdint>
20
#include <functional>
21
#include <memory>
22
#include <string>
23
#include <tuple>
24
#include <vector>
25
26
class BanMan;
27
class CFeeRate;
28
class CNodeStats;
29
class Coin;
30
class UniValue;
31
class Proxy;
32
enum class SynchronizationState;
33
struct CNodeStateStats;
34
struct bilingual_str;
35
namespace node {
36
enum class TransactionError;
37
struct NodeContext;
38
} // namespace node
39
namespace wallet {
40
class CCoinControl;
41
} // namespace wallet
42
43
namespace interfaces {
44
class Handler;
45
class WalletLoader;
46
struct BlockTip;
47
48
//! Block and header tip information
49
struct BlockAndHeaderTipInfo
50
{
51
    int block_height;
52
    int64_t block_time;
53
    int header_height;
54
    int64_t header_time;
55
    double verification_progress;
56
};
57
58
//! External signer interface used by the GUI.
59
class ExternalSigner
60
{
61
public:
62
    virtual ~ExternalSigner() = default;
63
64
    //! Get signer display name
65
    virtual std::string getName() = 0;
66
};
67
68
//! Top-level interface for a bitcoin node (bitcoind process).
69
class Node
70
{
71
public:
72
0
    virtual ~Node() = default;
73
74
    //! Init logging.
75
    virtual void initLogging() = 0;
76
77
    //! Init parameter interaction.
78
    virtual void initParameterInteraction() = 0;
79
80
    //! Get warnings.
81
    virtual bilingual_str getWarnings() = 0;
82
83
    //! Get exit status.
84
    virtual int getExitStatus() = 0;
85
86
    // Get log flags.
87
    virtual BCLog::CategoryMask getLogCategories() = 0;
88
89
    //! Initialize app dependencies.
90
    virtual bool baseInitialize() = 0;
91
92
    //! Start node.
93
    virtual bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info = nullptr) = 0;
94
95
    //! Stop node.
96
    virtual void appShutdown() = 0;
97
98
    //! Start shutdown.
99
    virtual void startShutdown() = 0;
100
101
    //! Return whether shutdown was requested.
102
    virtual bool shutdownRequested() = 0;
103
104
    //! Return whether a particular setting in <datadir>/settings.json is or
105
    //! would be ignored because it is also specified in the command line.
106
    virtual bool isSettingIgnored(const std::string& name) = 0;
107
108
    //! Return setting value from <datadir>/settings.json or bitcoin.conf.
109
    virtual common::SettingsValue getPersistentSetting(const std::string& name) = 0;
110
111
    //! Update a setting in <datadir>/settings.json.
112
    virtual void updateRwSetting(const std::string& name, const common::SettingsValue& value) = 0;
113
114
    //! Force a setting value to be applied, overriding any other configuration
115
    //! source, but not being persisted.
116
    virtual void forceSetting(const std::string& name, const common::SettingsValue& value) = 0;
117
118
    //! Clear all settings in <datadir>/settings.json and store a backup of
119
    //! previous settings in <datadir>/settings.json.bak.
120
    virtual void resetSettings() = 0;
121
122
    //! Map port.
123
    virtual void mapPort(bool enable) = 0;
124
125
    //! Get proxy.
126
    virtual bool getProxy(Network net, Proxy& proxy_info) = 0;
127
128
    //! Get number of connections.
129
    virtual size_t getNodeCount(ConnectionDirection flags) = 0;
130
131
    //! Get stats for connected nodes.
132
    using NodesStats = std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>;
133
    virtual bool getNodesStats(NodesStats& stats) = 0;
134
135
    //! Get ban map entries.
136
    virtual bool getBanned(banmap_t& banmap) = 0;
137
138
    //! Ban node.
139
    virtual bool ban(const CNetAddr& net_addr, int64_t ban_time_offset) = 0;
140
141
    //! Unban node.
142
    virtual bool unban(const CSubNet& ip) = 0;
143
144
    //! Disconnect node by address.
145
    virtual bool disconnectByAddress(const CNetAddr& net_addr) = 0;
146
147
    //! Disconnect node by id.
148
    virtual bool disconnectById(NodeId id) = 0;
149
150
    //! Return list of external signers (attached devices which can sign transactions).
151
    virtual std::vector<std::unique_ptr<ExternalSigner>> listExternalSigners() = 0;
152
153
    //! Get total bytes recv.
154
    virtual int64_t getTotalBytesRecv() = 0;
155
156
    //! Get total bytes sent.
157
    virtual int64_t getTotalBytesSent() = 0;
158
159
    //! Get mempool size.
160
    virtual size_t getMempoolSize() = 0;
161
162
    //! Get mempool dynamic usage.
163
    virtual size_t getMempoolDynamicUsage() = 0;
164
165
    //! Get mempool maximum memory usage.
166
    virtual size_t getMempoolMaxUsage() = 0;
167
168
    //! Get header tip height and time.
169
    virtual bool getHeaderTip(int& height, int64_t& block_time) = 0;
170
171
    //! Get num blocks.
172
    virtual int getNumBlocks() = 0;
173
174
    //! Get network local addresses.
175
    virtual std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() = 0;
176
177
    //! Get best block hash.
178
    virtual uint256 getBestBlockHash() = 0;
179
180
    //! Get last block time.
181
    virtual int64_t getLastBlockTime() = 0;
182
183
    //! Get verification progress.
184
    virtual double getVerificationProgress() = 0;
185
186
    //! Is initial block download.
187
    virtual bool isInitialBlockDownload() = 0;
188
189
    //! Is loading blocks.
190
    virtual bool isLoadingBlocks() = 0;
191
192
    //! Set network active.
193
    virtual void setNetworkActive(bool active) = 0;
194
195
    //! Get network active.
196
    virtual bool getNetworkActive() = 0;
197
198
    //! Get dust relay fee.
199
    virtual CFeeRate getDustRelayFee() = 0;
200
201
    //! Execute rpc command.
202
    virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0;
203
204
    //! List rpc commands.
205
    virtual std::vector<std::string> listRpcCommands() = 0;
206
207
    //! Get unspent output associated with a transaction.
208
    virtual std::optional<Coin> getUnspentOutput(const COutPoint& output) = 0;
209
210
    //! Broadcast transaction.
211
    virtual node::TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) = 0;
212
213
    //! Get wallet loader.
214
    virtual WalletLoader& walletLoader() = 0;
215
216
    //! Register handler for init messages.
217
    using InitMessageFn = std::function<void(const std::string& message)>;
218
    virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
219
220
    //! Register handler for message box messages.
221
    using MessageBoxFn =
222
        std::function<bool(const bilingual_str& message, unsigned int style)>;
223
    virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
224
225
    //! Register handler for question messages.
226
    using QuestionFn = std::function<bool(const bilingual_str& message,
227
        const std::string& non_interactive_message,
228
        unsigned int style)>;
229
    virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0;
230
231
    //! Register handler for progress messages.
232
    using ShowProgressFn = std::function<void(const std::string& title, int progress, bool resume_possible)>;
233
    virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
234
235
    //! Register handler for wallet loader constructed messages.
236
    using InitWalletFn = std::function<void()>;
237
    virtual std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) = 0;
238
239
    //! Register handler for number of connections changed messages.
240
    using NotifyNumConnectionsChangedFn = std::function<void(int new_num_connections)>;
241
    virtual std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) = 0;
242
243
    //! Register handler for network active messages.
244
    using NotifyNetworkActiveChangedFn = std::function<void(bool network_active)>;
245
    virtual std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) = 0;
246
247
    //! Register handler for notify alert messages.
248
    using NotifyAlertChangedFn = std::function<void()>;
249
    virtual std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) = 0;
250
251
    //! Register handler for ban list messages.
252
    using BannedListChangedFn = std::function<void()>;
253
    virtual std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) = 0;
254
255
    //! Register handler for block tip messages.
256
    using NotifyBlockTipFn =
257
        std::function<void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)>;
258
    virtual std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) = 0;
259
260
    //! Register handler for header tip messages.
261
    using NotifyHeaderTipFn =
262
        std::function<void(SynchronizationState, interfaces::BlockTip tip, bool presync)>;
263
    virtual std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0;
264
265
    //! Get and set internal node context. Useful for testing, but not
266
    //! accessible across processes.
267
0
    virtual node::NodeContext* context() { return nullptr; }
268
0
    virtual void setContext(node::NodeContext* context) { }
269
};
270
271
//! Return implementation of Node interface.
272
std::unique_ptr<Node> MakeNode(node::NodeContext& context);
273
274
//! Block tip (could be a header or not, depends on the subscribed signal).
275
struct BlockTip {
276
    int block_height;
277
    int64_t block_time;
278
    uint256 block_hash;
279
};
280
281
} // namespace interfaces
282
283
#endif // BITCOIN_INTERFACES_NODE_H