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 extern RecursiveMutex cs_main;
14 
15 namespace avalanche {
16 struct ProofId;
17 }
18 
19 class AddrMan;
20 class CTxMemPool;
21 class ChainstateManager;
22 class Config;
23 
28 static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
33 static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
34 static const bool DEFAULT_PEERBLOCKFILTERS = false;
37 static const int DISCOURAGEMENT_THRESHOLD{100};
38 
41  int nSyncHeight = -1;
42  int nCommonHeight = -1;
44  std::chrono::microseconds m_ping_wait;
45  std::vector<int> vHeightInFlight;
46  uint64_t m_addr_processed = 0;
47  uint64_t m_addr_rate_limited = 0;
48  bool m_addr_relay_enabled{false};
49 };
50 
52 public:
53  static std::unique_ptr<PeerManager>
54  make(const CChainParams &chainparams, CConnman &connman, AddrMan &addrman,
55  BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool,
56  bool ignore_incoming_txs);
57  virtual ~PeerManager() {}
58 
69  virtual std::optional<std::string>
70  FetchBlock(const Config &config, NodeId peer_id,
71  const CBlockIndex &block_index) = 0;
72 
74  virtual void StartScheduledTasks(CScheduler &scheduler) = 0;
75 
77  virtual bool GetNodeStateStats(NodeId nodeid,
78  CNodeStateStats &stats) const = 0;
79 
81  virtual bool IgnoresIncomingTxs() = 0;
82 
84  virtual void RelayTransaction(const TxId &txid) = 0;
85 
87  virtual void RelayProof(const avalanche::ProofId &proofid) = 0;
88 
90  virtual void SendPings() = 0;
91 
93  virtual void SetBestHeight(int height) = 0;
94 
101  virtual void Misbehaving(const NodeId pnode, const int howmuch,
102  const std::string &message) = 0;
103 
108  virtual void CheckForStaleTipAndEvictPeers() = 0;
109 
111  virtual void ProcessMessage(const Config &config, CNode &pfrom,
112  const std::string &msg_type, CDataStream &vRecv,
113  const std::chrono::microseconds time_received,
114  const std::atomic<bool> &interruptMsgProc) = 0;
115 };
116 
117 #endif // BITCOIN_NET_PROCESSING_H
Stochastic address manager.
Definition: addrman.h:68
Definition: banman.h:58
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:26
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:74
Definition: net.h:912
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
Information about a peer.
Definition: net.h:443
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:36
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:435
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:1046
Definition: config.h:17
Interface for message handling.
Definition: net.h:868
static std::unique_ptr< PeerManager > make(const CChainParams &chainparams, 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)=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 Misbehaving(const NodeId pnode, const int howmuch, const std::string &message)=0
Increment peer's misbehavior score.
virtual void RelayTransaction(const TxId &txid)=0
Relay transaction to all peers.
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 CheckForStaleTipAndEvictPeers()=0
Evict extra outbound peers.
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.
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:111
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
std::chrono::microseconds m_ping_wait
std::vector< int > vHeightInFlight
uint64_t m_addr_rate_limited
uint64_t m_addr_processed
A TxId is the identifier of a transaction.
Definition: txid.h:14