Bitcoin Core  0.19.99
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 <validationinterface.h>
11 #include <consensus/params.h>
12 #include <sync.h>
13 
14 extern RecursiveMutex cs_main;
15 
17 static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
19 static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
20 static const bool DEFAULT_PEERBLOOMFILTERS = false;
21 
23 private:
24  CConnman* const connman;
25  BanMan* const m_banman;
26 
27  bool CheckIfBanned(CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
28 
29 public:
30  PeerLogicValidation(CConnman* connman, BanMan* banman, CScheduler& scheduler);
31 
35  void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected, const std::vector<CTransactionRef>& vtxConflicted) override;
36  void BlockDisconnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex) override;
40  void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
44  void BlockChecked(const CBlock& block, const BlockValidationState& state) override;
48  void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override;
49 
51  void InitializeNode(CNode* pnode) override;
53  void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) override;
60  bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override;
67  bool SendMessages(CNode* pto) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing);
68 
70  void ConsiderEviction(CNode *pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
72  void CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams);
74  void EvictExtraOutboundPeers(int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
75 
76 private:
78 };
79 
81  int nMisbehavior = 0;
82  int nSyncHeight = -1;
83  int nCommonHeight = -1;
84  std::vector<int> vHeightInFlight;
85 };
86 
88 bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
89 
91 void RelayTransaction(const uint256&, const CConnman& connman);
92 
93 #endif // BITCOIN_NET_PROCESSING_H
Definition: banman.h:38
CConnman *const connman
Definition: block.h:72
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
Overridden from CValidationInterface.
void CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams)
Evict extra outbound peers.
bool SendMessages(CNode *pto) override EXCLUSIVE_LOCKS_REQUIRED(pto -> cs_sendProcessing)
Send queued protocol messages to be sent to a give node.
void RelayTransaction(const uint256 &, const CConnman &connman)
Relay transaction to every node.
Interface for message handling.
Definition: net.h:510
Implement this to subscribe to events generated in validation.
bool ProcessMessages(CNode *pfrom, std::atomic< bool > &interrupt) override
Process protocol messages received from a given node.
PeerLogicValidation(CConnman *connman, BanMan *banman, CScheduler &scheduler)
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
Get statistics from node state.
void ConsiderEviction(CNode *pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Consider evicting an outbound peer based on the amount of time they&#39;ve been behind our tip...
BanMan *const m_banman
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: validation.cpp:106
int64_t NodeId
Definition: net.h:93
Definition: net.h:121
Parameters that influence chain consensus.
Definition: params.h:45
void EvictExtraOutboundPeers(int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
If we have extra outbound peers, try to disconnect the one with the oldest block announcement.
int64_t m_stale_tip_check_time
Next time to check for stale tip.
void BlockConnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexConnected, const std::vector< CTransactionRef > &vtxConflicted) override
Overridden from CValidationInterface.
256-bit opaque blob.
Definition: uint256.h:120
static const bool DEFAULT_PEERBLOOMFILTERS
void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr< const CBlock > &pblock) override
Overridden from CValidationInterface.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
void BlockDisconnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex) override
Notifies listeners of a block being disconnected.
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:137
static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN
Default number of orphan+recently-replaced txn to keep around for block reconstruction.
void FinalizeNode(NodeId nodeid, bool &fUpdateConnectionTime) override
Handle removal of a peer by updating various state and removing it from mapNodeState.
Information about a peer.
Definition: net.h:707
std::vector< int > vHeightInFlight
bool CheckIfBanned(CNode *pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
void InitializeNode(CNode *pnode) override
Initialize a peer by adding it to mapNodeState and pushing a message requesting its version...
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS
Default for -maxorphantx, maximum number of orphan transactions kept in memory.
void BlockChecked(const CBlock &block, const BlockValidationState &state) override
Overridden from CValidationInterface.