Bitcoin Core 28.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
net_processing.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2022 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 <net.h>
10#include <validationinterface.h>
11
12#include <chrono>
13
14class AddrMan;
15class CChainParams;
16class CTxMemPool;
18
19namespace node {
20class Warnings;
21} // namespace node
22
24static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false};
26static const uint32_t DEFAULT_MAX_ORPHAN_TRANSACTIONS{100};
29static const uint32_t DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN{100};
30static const bool DEFAULT_PEERBLOOMFILTERS = false;
31static const bool DEFAULT_PEERBLOCKFILTERS = false;
33static const unsigned int MAX_CMPCTBLOCKS_INFLIGHT_PER_BLOCK = 3;
34
36 int nSyncHeight = -1;
37 int nCommonHeight = -1;
39 std::chrono::microseconds m_ping_wait;
40 std::vector<int> vHeightInFlight;
43 uint64_t m_addr_processed = 0;
44 uint64_t m_addr_rate_limited = 0;
47 int64_t presync_height{-1};
48 std::chrono::seconds time_offset{0};
49};
50
52 std::chrono::seconds median_outbound_time_offset{0s};
54};
55
57{
58public:
75
76 static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman,
77 BanMan* banman, ChainstateManager& chainman,
78 CTxMemPool& pool, node::Warnings& warnings, Options opts);
79 virtual ~PeerManager() = default;
80
88 virtual std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) = 0;
89
91 virtual void StartScheduledTasks(CScheduler& scheduler) = 0;
92
94 virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;
95
97 virtual PeerManagerInfo GetInfo() const = 0;
98
100 virtual void RelayTransaction(const uint256& txid, const uint256& wtxid) = 0;
101
103 virtual void SendPings() = 0;
104
106 virtual void SetBestBlock(int height, std::chrono::seconds time) = 0;
107
108 /* Public for unit testing. */
109 virtual void UnitTestMisbehaving(NodeId peer_id) = 0;
110
116
118 virtual void ProcessMessage(CNode& pfrom, const std::string& msg_type, DataStream& vRecv,
119 const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) = 0;
120
122 virtual void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) = 0;
123
146};
147
148#endif // BITCOIN_NET_PROCESSING_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition amount.h:12
Stochastic address manager.
Definition addrman.h:88
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition chain.h:141
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition chainparams.h:81
Information about a peer.
Definition net.h:670
Simple class for background tasks that should be run periodically or once "after a while".
Definition scheduler.h:40
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition txmempool.h:304
Implement this to subscribe to events generated in validation and mempool.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition validation.h:871
Double ended buffer combining vector and stream-like interfaces.
Definition streams.h:147
Interface for message handling.
Definition net.h:989
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
Definition net.h:992
virtual std::optional< std::string > FetchBlock(NodeId peer_id, const CBlockIndex &block_index)=0
Attempt to manually fetch block from a given peer.
virtual void ProcessMessage(CNode &pfrom, const std::string &msg_type, DataStream &vRecv, const std::chrono::microseconds time_received, const std::atomic< bool > &interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex)=0
Process a single message from a peer.
virtual ~PeerManager()=default
virtual void RelayTransaction(const uint256 &txid, const uint256 &wtxid)=0
Relay transaction to all peers.
virtual void SendPings()=0
Send ping message to all peers.
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.
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, node::Warnings &warnings, Options opts)
virtual void UnitTestMisbehaving(NodeId peer_id)=0
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:178
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition net.h:81
int64_t NodeId
Definition net.h:97
static const uint32_t DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN
Default number of non-mempool transactions to keep around for block reconstruction.
static const uint32_t DEFAULT_MAX_ORPHAN_TRANSACTIONS
Default for -maxorphantx, maximum number of orphan transactions kept in memory.
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 bool DEFAULT_PEERBLOOMFILTERS
ServiceFlags
nServices flags
Definition protocol.h:309
std::chrono::microseconds 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_addr_processed
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.
uint32_t max_orphan_txs
Maximum number of orphan transactions kept in memory.
bool ignore_incoming_txs
Whether this node is running in -blocksonly mode.
bool capture_messages
Whether all P2P messages are captured to disk.
std::chrono::seconds median_outbound_time_offset
#define EXCLUSIVE_LOCKS_REQUIRED(...)