Bitcoin ABC 0.30.5
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
10#include <net.h>
11#include <sync.h>
12#include <validationinterface.h>
13
14namespace avalanche {
15struct ProofId;
16class Processor;
17} // namespace avalanche
18
19class AddrMan;
20class CTxMemPool;
22class Config;
23
28static const uint32_t DEFAULT_MAX_ORPHAN_TRANSACTIONS{100};
32static const uint32_t DEFAULT_MAX_CONFLICTING_TRANSACTIONS{100};
37static const uint32_t DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN{100};
38static const bool DEFAULT_PEERBLOCKFILTERS = false;
41static const int DISCOURAGEMENT_THRESHOLD{100};
43static const unsigned int MAX_CMPCTBLOCKS_INFLIGHT_PER_BLOCK = 3;
45static constexpr size_t MAX_ADDR_TO_SEND{1000};
46
52static const unsigned int MAX_HEADERS_RESULTS = 2000;
53
55 int nSyncHeight = -1;
56 int nCommonHeight = -1;
58 std::chrono::microseconds m_ping_wait;
59 std::vector<int> vHeightInFlight;
62 uint64_t m_addr_processed = 0;
63 uint64_t m_addr_rate_limited = 0;
66 int64_t presync_height{-1};
67};
68
70public:
71 struct Options {
82 bool capture_messages{false};
87
100
103 bool deterministic_rng{false};
104 };
105
106 static std::unique_ptr<PeerManager>
107 make(CConnman &connman, AddrMan &addrman, BanMan *banman,
108 ChainstateManager &chainman, CTxMemPool &pool,
109 avalanche::Processor *const avalanche, Options opts);
110 virtual ~PeerManager() {}
111
122 virtual std::optional<std::string>
123 FetchBlock(const Config &config, NodeId peer_id,
124 const CBlockIndex &block_index) = 0;
125
127 virtual void StartScheduledTasks(CScheduler &scheduler) = 0;
128
130 virtual bool GetNodeStateStats(NodeId nodeid,
131 CNodeStateStats &stats) const = 0;
132
134 virtual bool IgnoresIncomingTxs() = 0;
135
137 virtual void RelayTransaction(const TxId &txid) = 0;
138
140 virtual void RelayProof(const avalanche::ProofId &proofid) = 0;
141
143 virtual void SendPings() = 0;
144
146 virtual void SetBestHeight(int height) = 0;
147
149 virtual void UnitTestMisbehaving(const NodeId peer_id,
150 const int howmuch) = 0;
151
157
159 virtual void ProcessMessage(const Config &config, CNode &pfrom,
160 const std::string &msg_type, CDataStream &vRecv,
161 const std::chrono::microseconds time_received,
162 const std::atomic<bool> &interruptMsgProc)
164
170 int64_t time_in_seconds) = 0;
171};
172
173#endif // BITCOIN_NET_PROCESSING_H
static constexpr bool DEFAULT_AVALANCHE_STAKING_PRECONSENSUS
Default for -avalanchestakingpreconsensus.
Definition: avalanche.h:69
static constexpr size_t AVALANCHE_DEFAULT_PEER_REPLACEMENT_COOLDOWN
Peer replacement cooldown time default value in seconds.
Definition: avalanche.h:34
static constexpr bool DEFAULT_AVALANCHE_PRECONSENSUS
Default for -avalanchepreconsensus.
Definition: avalanche.h:66
static constexpr size_t AVALANCHE_DEFAULT_COOLDOWN
Avalanche default cooldown in milliseconds.
Definition: avalanche.h:40
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:25
Definition: net.h:856
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:177
Information about a peer.
Definition: net.h:460
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:212
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:1219
Definition: config.h:19
Interface for message handling.
Definition: net.h:805
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
Definition: net.h:810
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 SendPings()=0
Send ping message to all peers.
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, avalanche::Processor *const avalanche, Options opts)
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 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 bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:94
static constexpr size_t MAX_ADDR_TO_SEND
The maximum number of address records permitted in an ADDR message.
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_CONFLICTING_TRANSACTIONS
Maximum number of conflicting transactions kept in memory.
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 const int DISCOURAGEMENT_THRESHOLD
Threshold for marking a node to be discouraged, e.g.
static const bool DEFAULT_PEERBLOCKFILTERS
static const unsigned int MAX_HEADERS_RESULTS
Number of headers sent in one getheaders result.
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
bool avalanche_staking_preconsensus
Whether this node has enabled avalanche staking rewards preconsensus.
int64_t avalanche_cooldown
Minimum time between two AVAPOLL messages.
size_t max_addr_to_send
Number of addresses a node may send in an ADDR message.
bool deterministic_rng
Whether or not the internal RNG behaves deterministically (this is a test-only option).
uint32_t max_extra_txs
Number of non-mempool transactions to keep around for block reconstruction.
uint32_t max_conflicting_txs
Maximum number of conflicting transactions kept in memory.
uint32_t max_orphan_txs
Maximum number of orphan transactions kept in memory.
bool avalanche_preconsensus
Whether this node has enabled avalanche preconsensus.
int64_t avalanche_peer_replacement_cooldown
Minimum time before we will consider replacing a finalized proof with a conflicting one.
bool ignore_incoming_txs
Whether this node is running in -blocksonly mode.
bool capture_messages
Whether all P2P messages are captured to disk.
A TxId is the identifier of a transaction.
Definition: txid.h:14
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56