Bitcoin Core  21.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-2020 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 class CChainParams;
14 class CTxMemPool;
15 class ChainstateManager;
16 
17 extern RecursiveMutex cs_main;
19 
21 static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
23 static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
24 static const bool DEFAULT_PEERBLOOMFILTERS = false;
25 static const bool DEFAULT_PEERBLOCKFILTERS = false;
27 static const int DISCOURAGEMENT_THRESHOLD{100};
28 
30  int nSyncHeight = -1;
31  int nCommonHeight = -1;
33  std::vector<int> vHeightInFlight;
34 };
35 
37 {
38 public:
39  static std::unique_ptr<PeerManager> make(const CChainParams& chainparams, CConnman& connman, BanMan* banman,
40  CScheduler& scheduler, ChainstateManager& chainman, CTxMemPool& pool,
41  bool ignore_incoming_txs);
42  virtual ~PeerManager() { }
43 
45  virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) = 0;
46 
48  virtual bool IgnoresIncomingTxs() = 0;
49 
51  virtual void SetBestHeight(int height) = 0;
52 
58  virtual void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) = 0;
59 
64  virtual void CheckForStaleTipAndEvictPeers() = 0;
65 
67  virtual void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
68  const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) = 0;
69 };
70 
72 void RelayTransaction(const uint256& txid, const uint256& wtxid, const CConnman& connman) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
73 
74 #endif // BITCOIN_NET_PROCESSING_H
Definition: banman.h:57
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:772
virtual ~PeerManager()
Interface for message handling.
Definition: net.h:760
RecursiveMutex g_cs_orphans
Guards orphan transactions and extra txs for compact blocks.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Definition: chainparams.h:52
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:202
Implement this to subscribe to events generated in validation.
static const bool DEFAULT_PEERBLOCKFILTERS
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: validation.cpp:128
int64_t NodeId
Definition: net.h:83
Definition: net.h:795
static const int DISCOURAGEMENT_THRESHOLD
Threshold for marking a node to be discouraged, e.g.
void RelayTransaction(const uint256 &txid, const uint256 &wtxid, const CConnman &connman) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Relay transaction to every node.
256-bit opaque blob.
Definition: uint256.h:124
static const bool DEFAULT_PEERBLOOMFILTERS
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:474
static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN
Default number of orphan+recently-replaced txn to keep around for block reconstruction.
Information about a peer.
Definition: net.h:388
std::vector< int > vHeightInFlight
Simple class for background tasks that should be run periodically or once "after a while"...
Definition: scheduler.h:32
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS
Default for -maxorphantx, maximum number of orphan transactions kept in memory.