Bitcoin ABC  0.26.3
P2P Digital Currency
net_processing.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 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 <sync.h>
11 #include <validationinterface.h>
12 
13 namespace avalanche {
14 struct ProofId;
15 }
16 
17 class AddrMan;
18 class CTxMemPool;
19 class ChainstateManager;
20 class Config;
21 
26 static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
31 static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
32 static const bool DEFAULT_PEERBLOCKFILTERS = false;
35 static const int DISCOURAGEMENT_THRESHOLD{100};
36 
38  int nSyncHeight = -1;
39  int nCommonHeight = -1;
41  std::chrono::microseconds m_ping_wait;
42  std::vector<int> vHeightInFlight;
45  uint64_t m_addr_processed = 0;
46  uint64_t m_addr_rate_limited = 0;
47  bool m_addr_relay_enabled{false};
49  int64_t presync_height{-1};
50 };
51 
53 public:
54  static std::unique_ptr<PeerManager> make(CConnman &connman,
55  AddrMan &addrman, BanMan *banman,
56  ChainstateManager &chainman,
57  CTxMemPool &pool,
58  bool ignore_incoming_txs);
59  virtual ~PeerManager() {}
60 
71  virtual std::optional<std::string>
72  FetchBlock(const Config &config, NodeId peer_id,
73  const CBlockIndex &block_index) = 0;
74 
76  virtual void StartScheduledTasks(CScheduler &scheduler) = 0;
77 
79  virtual bool GetNodeStateStats(NodeId nodeid,
80  CNodeStateStats &stats) const = 0;
81 
83  virtual bool IgnoresIncomingTxs() = 0;
84 
86  virtual void RelayTransaction(const TxId &txid) = 0;
87 
89  virtual void RelayProof(const avalanche::ProofId &proofid) = 0;
90 
92  virtual void SendPings() = 0;
93 
95  virtual void SetBestHeight(int height) = 0;
96 
98  virtual void UnitTestMisbehaving(const NodeId peer_id,
99  const int howmuch) = 0;
100 
105  virtual void CheckForStaleTipAndEvictPeers() = 0;
106 
108  virtual void ProcessMessage(const Config &config, CNode &pfrom,
109  const std::string &msg_type, CDataStream &vRecv,
110  const std::chrono::microseconds time_received,
111  const std::atomic<bool> &interruptMsgProc)
113 
119  int64_t time_in_seconds) = 0;
120 };
121 
122 #endif // BITCOIN_NET_PROCESSING_H
Stochastic address manager.
Definition: addrman.h:69
Definition: banman.h:58
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:27
Definition: net.h:845
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:199
Information about a peer.
Definition: net.h:456
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:41
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:354
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:1166
Definition: config.h:17
Interface for message handling.
Definition: net.h:794
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
Definition: net.h:799
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, bool ignore_incoming_txs)
virtual void SendPings()=0
Send ping message to all peers.
virtual void ProcessMessage(const Config &config, 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 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 RelayTransaction(const TxId &txid)=0
Relay transaction to all peers.
virtual void UnitTestMisbehaving(const NodeId peer_id, const int howmuch)=0
Public for unit testing.
virtual std::optional< std::string > FetchBlock(const Config &config, NodeId peer_id, const CBlockIndex &block_index)=0
Attempt to manually fetch block from a given peer.
virtual void RelayProof(const avalanche::ProofId &proofid)=0
Relay proof to all peers.
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.
Definition: init.h:28
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
int64_t NodeId
Definition: nodeid.h:10
ServiceFlags
nServices flags.
Definition: protocol.h:335
Definition: amount.h:19
std::chrono::microseconds m_ping_wait
Amount m_fee_filter_received
std::vector< int > vHeightInFlight
uint64_t m_addr_rate_limited
uint64_t m_addr_processed
int64_t presync_height
ServiceFlags their_services
A TxId is the identifier of a transaction.
Definition: txid.h:14
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56