Bitcoin Core  0.20.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 <consensus/params.h>
10 #include <net.h>
11 #include <sync.h>
12 #include <validationinterface.h>
13 
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;
26 
28 private:
29  CConnman* const connman;
30  BanMan* const m_banman;
33 
34  bool CheckIfBanned(CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
35 
36 public:
37  PeerLogicValidation(CConnman* connman, BanMan* banman, CScheduler& scheduler, ChainstateManager& chainman, CTxMemPool& pool);
38 
42  void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override;
43  void BlockDisconnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex) override;
47  void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
51  void BlockChecked(const CBlock& block, const BlockValidationState& state) override;
55  void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override;
56 
58  void InitializeNode(CNode* pnode) override;
60  void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) override;
67  bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override;
74  bool SendMessages(CNode* pto) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing);
75 
77  void ConsiderEviction(CNode *pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
79  void CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams);
81  void EvictExtraOutboundPeers(int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
83  void ReattemptInitialBroadcast(CScheduler& scheduler) const;
84 
85 private:
87 };
88 
90  int nMisbehavior = 0;
91  int nSyncHeight = -1;
92  int nCommonHeight = -1;
93  std::vector<int> vHeightInFlight;
94 };
95 
97 bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
98 
100 void RelayTransaction(const uint256&, const CConnman& connman);
101 
102 #endif // BITCOIN_NET_PROCESSING_H
Definition: banman.h:41
ChainstateManager & m_chainman
CConnman *const connman
Definition: block.h:62
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
Overridden from CValidationInterface.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:726
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.
CTxMemPool & m_mempool
void RelayTransaction(const uint256 &, const CConnman &connman)
Relay transaction to every node.
Interface for message handling.
Definition: net.h:505
RecursiveMutex g_cs_orphans
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.
static const bool DEFAULT_PEERBLOCKFILTERS
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
void ReattemptInitialBroadcast(CScheduler &scheduler) const
Retrieve unbroadcast transactions from the mempool and reattempt sending to peers.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: validation.cpp:124
int64_t NodeId
Definition: net.h:90
Definition: net.h:118
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.
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.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:443
void BlockConnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexConnected) override
Overridden from CValidationInterface.
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.
PeerLogicValidation(CConnman *connman, BanMan *banman, CScheduler &scheduler, ChainstateManager &chainman, CTxMemPool &pool)
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:716
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.