Bitcoin Core 31.99.0
P2P Digital Currency
net_processing.h
Go to the documentation of this file.
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_NET_PROCESSING_H
7#define BITCOIN_NET_PROCESSING_H
8
9#include <consensus/amount.h>
10#include <net.h>
11#include <node/txorphanage.h>
12#include <node/types.h>
13#include <private_broadcast.h>
14#include <protocol.h>
15#include <uint256.h>
16#include <util/expected.h>
17#include <validationinterface.h>
18
19#include <atomic>
20#include <chrono>
21#include <cstdint>
22#include <memory>
23#include <optional>
24#include <string>
25#include <vector>
26
27class AddrMan;
28class CTxMemPool;
30class BanMan;
31class CBlockIndex;
32class CScheduler;
33class DataStream;
34class uint256;
35
36namespace node {
37class Warnings;
38} // namespace node
39
41static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false};
44static const uint32_t DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN{100};
46static constexpr unsigned int DEFAULT_TX_SEND_RATE{14};
47static const bool DEFAULT_PEERBLOOMFILTERS = false;
48static const bool DEFAULT_PEERBLOCKFILTERS = false;
50static const unsigned int MAX_CMPCTBLOCKS_INFLIGHT_PER_BLOCK = 3;
53static const unsigned int MAX_HEADERS_RESULTS = 2000;
55static constexpr uint64_t CMPCTBLOCKS_VERSION{2};
56
58 int nSyncHeight = -1;
59 int nCommonHeight = -1;
60 NodeClock::duration m_ping_wait;
61 std::vector<int> vHeightInFlight;
64 uint64_t m_last_inv_seq{0};
66 uint64_t m_addr_processed = 0;
67 uint64_t m_addr_rate_limited = 0;
70 int64_t presync_height{-1};
71 std::chrono::seconds time_offset{0};
72};
73
76 size_t backlog_count{0};
77 double count_bucket{0};
78 double size_bucket{0};
79 };
80
81 std::chrono::seconds median_outbound_time_offset{0s};
84 unsigned int tx_send_rate{0};
87};
88
90{
91public:
92 struct Options {
101 bool capture_messages{false};
104 bool deterministic_rng{false};
112 };
113
114 static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman,
115 BanMan* banman, ChainstateManager& chainman,
116 CTxMemPool& pool, node::Warnings& warnings, Options opts);
117 virtual ~PeerManager() = default;
118
125 virtual util::Expected<void, std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) = 0;
126
128 virtual void StartScheduledTasks(CScheduler& scheduler) = 0;
129
131 virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;
132
133 virtual std::vector<node::TxOrphanage::OrphanInfo> GetOrphanTransactions() = 0;
134
136 virtual PeerManagerInfo GetInfo() const = 0;
137
139 virtual std::vector<PrivateBroadcast::TxBroadcastInfo> GetPrivateBroadcastInfo() const = 0;
140
151 virtual std::vector<CTransactionRef> AbortPrivateBroadcast(const uint256& id) = 0;
152
159 virtual void InitiateTxBroadcastToAll(const Wtxid& wtxid) = 0;
160
168
170 virtual void SendPings() = 0;
171
173 virtual void SetBestBlock(int height, std::chrono::seconds time) = 0;
174
175 /* Public for unit testing. */
176 virtual void UnitTestMisbehaving(NodeId peer_id) = 0;
177
183
185 virtual void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) = 0;
186
209};
210
211#endif // BITCOIN_NET_PROCESSING_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
Stochastic address manager.
Definition: addrman.h:110
Definition: banman.h:64
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:94
Definition: net.h:1085
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:39
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:187
Implement this to subscribe to events generated in validation and mempool.
Interface for managing multiple Chainstate objects, where each chainstate is associated with chainsta...
Definition: validation.h:945
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:165
Interface for message handling.
Definition: net.h:1041
virtual node::TransactionError InitiateTxBroadcastPrivate(const CTransactionRef &tx)=0
Initiate a private transaction broadcast.
virtual ~PeerManager()=default
virtual void SendPings()=0
Send ping message to all peers.
virtual util::Expected< void, std::string > FetchBlock(NodeId peer_id, const CBlockIndex &block_index)=0
Attempt to manually fetch block from a given peer.
virtual std::vector< PrivateBroadcast::TxBroadcastInfo > GetPrivateBroadcastInfo() const =0
Get info about transactions currently being privately broadcast.
virtual ServiceFlags GetDesirableServiceFlags(ServiceFlags services) const =0
Gets the set of service flags which are "desirable" for a given peer.
virtual void SetBestBlock(int height, std::chrono::seconds time)=0
Set the height of the best block and its time (seconds since epoch).
virtual void StartScheduledTasks(CScheduler &scheduler)=0
Begin running background tasks, should only be called once.
virtual PeerManagerInfo GetInfo() const =0
Get peer manager info.
virtual std::vector< node::TxOrphanage::OrphanInfo > GetOrphanTransactions()=0
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, node::Warnings &warnings, Options opts)
virtual void InitiateTxBroadcastToAll(const Wtxid &wtxid)=0
Initiate a transaction broadcast to eligible peers.
virtual void UnitTestMisbehaving(NodeId peer_id)=0
virtual std::vector< CTransactionRef > AbortPrivateBroadcast(const uint256 &id)=0
Abort private broadcast attempts for transactions currently being privately broadcast.
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) const =0
Get statistics from node state.
virtual void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)=0
This function is used for testing the stale tip eviction logic, see denialofservice_tests....
virtual void CheckForStaleTipAndEvictPeers()=0
Evict extra outbound peers.
Manages warning messages within a node.
Definition: warnings.h:40
256-bit opaque blob.
Definition: uint256.h:196
The util::Expected class provides a standard way for low-level functions to return either error value...
Definition: expected.h:44
Definition: messages.h:22
TransactionError
Definition: types.h:19
static constexpr bool DEFAULT_PRIVATE_BROADCAST
Default for -privatebroadcast.
Definition: net.h:91
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:87
int64_t NodeId
Definition: net.h:105
static constexpr unsigned int DEFAULT_TX_SEND_RATE
Default maximum per-second rate for sending transaction inventory to peers.
static const uint32_t DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN
Default number of non-mempool transactions to keep around for block reconstruction.
static constexpr uint64_t CMPCTBLOCKS_VERSION
The compactblocks version we support.
static const unsigned int MAX_CMPCTBLOCKS_INFLIGHT_PER_BLOCK
Maximum number of outstanding CMPCTBLOCK requests for the same block.
static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE
Whether transaction reconciliation protocol should be enabled by default.
static const bool DEFAULT_PEERBLOCKFILTERS
static const unsigned int MAX_HEADERS_RESULTS
Number of headers sent in one getheaders result.
static const bool DEFAULT_PEERBLOOMFILTERS
is a home for public enum and struct type definitions that are used internally by node code,...
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:403
ServiceFlags
nServices flags
Definition: protocol.h:321
NodeClock::duration m_ping_wait
std::vector< int > vHeightInFlight
CAmount m_fee_filter_received
std::chrono::seconds time_offset
uint64_t m_addr_rate_limited
uint64_t m_last_inv_seq
uint64_t m_addr_processed
int64_t presync_height
ServiceFlags their_services
bool deterministic_rng
Whether or not the internal RNG behaves deterministically (this is a test-only option).
bool reconcile_txs
Whether transaction reconciliation protocol is enabled.
uint32_t max_extra_txs
Number of non-mempool transactions to keep around for block reconstruction.
unsigned int tx_send_rate
Maximum per-second rate for sending transaction inventory to peers.
uint32_t max_headers_result
Number of headers sent in one getheaders message result (this is a test-only option).
bool private_broadcast
Whether private broadcast is used for sending transactions.
bool ignore_incoming_txs
Whether this node is running in -blocksonly mode.
bool capture_messages
Whether all P2P messages are captured to disk.
InvBucketInfo inbound_bucket
InvBucketInfo outbound_bucket
unsigned int tx_send_rate
std::chrono::seconds median_outbound_time_offset