BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
net_processing.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 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 
15 
17 static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
19 static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
21 static constexpr bool DEFAULT_ENABLE_BIP61{false};
22 
24 private:
25  CConnman* const connman;
26 
27 public:
28  explicit PeerLogicValidation(CConnman* connman, CScheduler &scheduler, bool enable_bip61);
29 
33  void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected, const std::vector<CTransactionRef>& vtxConflicted) override;
37  void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
41  void BlockChecked(const CBlock& block, const CValidationState& state) override;
45  void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override;
46 
48  void InitializeNode(CNode* pnode) override;
50  void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) override;
57  bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override;
64  bool SendMessages(CNode* pto) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing);
65 
67  void ConsiderEviction(CNode *pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
69  void CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams);
71  void EvictExtraOutboundPeers(int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
72 
73 private:
75 
77  const bool m_enable_bip61;
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 
90 #endif // BITCOIN_NET_PROCESSING_H
CConnman *const connman
Definition: block.h:74
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.
PeerLogicValidation(CConnman *connman, CScheduler &scheduler, bool enable_bip61)
Interface for message handling.
Definition: net.h:484
const bool m_enable_bip61
Enable BIP61 (sending reject messages)
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.
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...
CCriticalSection cs_main
Definition: validation.cpp:216
int64_t NodeId
Definition: net.h:88
Definition: net.h:115
Parameters that influence chain consensus.
Definition: params.h:40
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.
Capture information about block/transaction validation.
Definition: validation.h:26
void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr< const CBlock > &pblock) override
Overridden from CValidationInterface.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
void BlockChecked(const CBlock &block, const CValidationState &state) override
Overridden from CValidationInterface.
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:626
std::vector< int > vHeightInFlight
void InitializeNode(CNode *pnode) override
Initialize a peer by adding it to mapNodeState and pushing a message requesting its version...