Bitcoin Core  24.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-2021 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 class AddrMan;
13 class CChainParams;
14 class CTxMemPool;
15 class ChainstateManager;
16 
18 static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
20 static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
21 static const bool DEFAULT_PEERBLOOMFILTERS = false;
22 static const bool DEFAULT_PEERBLOCKFILTERS = false;
24 static const int DISCOURAGEMENT_THRESHOLD{100};
25 
27  int nSyncHeight = -1;
28  int nCommonHeight = -1;
30  std::chrono::microseconds m_ping_wait;
31  std::vector<int> vHeightInFlight;
34  uint64_t m_addr_processed = 0;
35  uint64_t m_addr_rate_limited = 0;
36  bool m_addr_relay_enabled{false};
38  int64_t presync_height{-1};
39 };
40 
42 {
43 public:
44  static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman,
45  BanMan* banman, ChainstateManager& chainman,
46  CTxMemPool& pool, bool ignore_incoming_txs);
47  virtual ~PeerManager() { }
48 
56  virtual std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) = 0;
57 
59  virtual void StartScheduledTasks(CScheduler& scheduler) = 0;
60 
62  virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;
63 
65  virtual bool IgnoresIncomingTxs() = 0;
66 
68  virtual void RelayTransaction(const uint256& txid, const uint256& wtxid) = 0;
69 
71  virtual void SendPings() = 0;
72 
74  virtual void SetBestHeight(int height) = 0;
75 
76  /* Public for unit testing. */
77  virtual void UnitTestMisbehaving(NodeId peer_id, int howmuch) = 0;
78 
83  virtual void CheckForStaleTipAndEvictPeers() = 0;
84 
86  virtual void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
87  const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) = 0;
88 
90  virtual void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) = 0;
91 };
92 
93 #endif // BITCOIN_NET_PROCESSING_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
Stochastic address manager.
Definition: addrman.h:87
Definition: banman.h:59
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:152
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:70
Definition: net.h:667
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:186
Information about a peer.
Definition: net.h:347
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:432
Implement this to subscribe to events generated in validation.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:800
Interface for message handling.
Definition: net.h:629
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
Definition: net.h:632
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, bool ignore_incoming_txs)
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 void ProcessMessage(CNode &pfrom, const std::string &msg_type, CDataStream &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 std::optional< std::string > FetchBlock(NodeId peer_id, const CBlockIndex &block_index)=0
Attempt to manually fetch block from a given peer.
virtual void StartScheduledTasks(CScheduler &scheduler)=0
Begin running background tasks, should only be called once.
virtual void SetBestHeight(int height)=0
Set the best height.
virtual bool IgnoresIncomingTxs()=0
Whether this node ignores txs received over p2p.
virtual void UnitTestMisbehaving(NodeId peer_id, int howmuch)=0
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) const =0
Get statistics from node state.
virtual ~PeerManager()
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.
256-bit opaque blob.
Definition: uint256.h:119
Definition: init.h:25
int64_t NodeId
Definition: net.h:92
static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN
Default number of orphan+recently-replaced txn to keep around for block reconstruction.
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS
Default for -maxorphantx, maximum number of orphan transactions kept in memory.
static const int DISCOURAGEMENT_THRESHOLD
Threshold for marking a node to be discouraged, e.g.
static const bool DEFAULT_PEERBLOCKFILTERS
static const bool DEFAULT_PEERBLOOMFILTERS
ServiceFlags
nServices flags
Definition: protocol.h:267
std::chrono::microseconds m_ping_wait
std::vector< int > vHeightInFlight
CAmount m_fee_filter_received
uint64_t m_addr_rate_limited
uint64_t m_addr_processed
int64_t presync_height
ServiceFlags their_services
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49