Bitcoin Core  0.20.99
P2P Digital Currency
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PeerLogicValidation Class Referencefinal

#include <net_processing.h>

Inheritance diagram for PeerLogicValidation:
[legend]
Collaboration diagram for PeerLogicValidation:
[legend]

Public Member Functions

 PeerLogicValidation (CConnman &connman, BanMan *banman, CScheduler &scheduler, ChainstateManager &chainman, CTxMemPool &pool)
 
void BlockConnected (const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexConnected) override
 Overridden from CValidationInterface. More...
 
void BlockDisconnected (const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex) override
 Notifies listeners of a block being disconnected. More...
 
void UpdatedBlockTip (const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
 Overridden from CValidationInterface. More...
 
void BlockChecked (const CBlock &block, const BlockValidationState &state) override
 Overridden from CValidationInterface. More...
 
void NewPoWValidBlock (const CBlockIndex *pindex, const std::shared_ptr< const CBlock > &pblock) override
 Overridden from CValidationInterface. More...
 
void InitializeNode (CNode *pnode) override
 Initialize a peer by adding it to mapNodeState and pushing a message requesting its version. More...
 
void FinalizeNode (NodeId nodeid, bool &fUpdateConnectionTime) override
 Handle removal of a peer by updating various state and removing it from mapNodeState. More...
 
bool ProcessMessages (CNode *pfrom, std::atomic< bool > &interrupt) override
 Process protocol messages received from a given node. More...
 
bool SendMessages (CNode *pto) override EXCLUSIVE_LOCKS_REQUIRED(pto -> cs_sendProcessing)
 Send queued protocol messages to be sent to a give node. More...
 
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've been behind our tip. More...
 
void CheckForStaleTipAndEvictPeers (const Consensus::Params &consensusParams)
 Evict extra outbound peers. More...
 
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. More...
 
void ReattemptInitialBroadcast (CScheduler &scheduler) const
 Retrieve unbroadcast transactions from the mempool and reattempt sending to peers. More...
 
void ProcessMessage (CNode &pfrom, const std::string &msg_type, CDataStream &vRecv, const std::chrono::microseconds time_received, const CChainParams &chainparams, const std::atomic< bool > &interruptMsgProc)
 Process a single message from a peer. More...
 

Private Member Functions

bool MaybeDiscourageAndDisconnect (CNode &pnode)
 Maybe disconnect a peer and discourage future connections from its address. More...
 

Private Attributes

CConnmanm_connman
 
BanMan *const m_banman
 Pointer to this node's banman. More...
 
ChainstateManagerm_chainman
 
CTxMemPoolm_mempool
 
int64_t m_stale_tip_check_time
 Next time to check for stale tip. More...
 

Additional Inherited Members

- Protected Member Functions inherited from CValidationInterface
 ~CValidationInterface ()=default
 Protected destructor so that instances can only be deleted by derived classes. More...
 
virtual void TransactionAddedToMempool (const CTransactionRef &tx)
 Notifies listeners of a transaction having been added to mempool. More...
 
virtual void TransactionRemovedFromMempool (const CTransactionRef &tx, MemPoolRemovalReason reason)
 Notifies listeners of a transaction leaving mempool. More...
 
virtual void ChainStateFlushed (const CBlockLocator &locator)
 Notifies listeners of the new active block chain on-disk. More...
 
- Protected Member Functions inherited from NetEventsInterface
 ~NetEventsInterface ()=default
 Protected destructor so that instances can only be deleted by derived classes. More...
 

Detailed Description

Definition at line 30 of file net_processing.h.

Constructor & Destructor Documentation

◆ PeerLogicValidation()

PeerLogicValidation::PeerLogicValidation ( CConnman connman,
BanMan banman,
CScheduler scheduler,
ChainstateManager chainman,
CTxMemPool pool 
)

Definition at line 1244 of file net_processing.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ BlockChecked()

void PeerLogicValidation::BlockChecked ( const CBlock block,
const BlockValidationState state 
)
overridevirtual

Overridden from CValidationInterface.

Handle invalid block rejection and consequent peer discouragement, maintain which peers announce compact blocks.

Reimplemented from CValidationInterface.

Definition at line 1433 of file net_processing.cpp.

Here is the call graph for this function:

◆ BlockConnected()

void PeerLogicValidation::BlockConnected ( const std::shared_ptr< const CBlock > &  pblock,
const CBlockIndex pindex 
)
overridevirtual

Overridden from CValidationInterface.

Evict orphan txn pool entries (EraseOrphanTx) based on a newly connected block.

Also save the time of the last tip update.

Reimplemented from CValidationInterface.

Definition at line 1282 of file net_processing.cpp.

Here is the call graph for this function:

◆ BlockDisconnected()

void PeerLogicValidation::BlockDisconnected ( const std::shared_ptr< const CBlock > &  block,
const CBlockIndex pindex 
)
overridevirtual

Notifies listeners of a block being disconnected.

Called on a background thread.

Reimplemented from CValidationInterface.

Definition at line 1326 of file net_processing.cpp.

◆ CheckForStaleTipAndEvictPeers()

void PeerLogicValidation::CheckForStaleTipAndEvictPeers ( const Consensus::Params consensusParams)

Evict extra outbound peers.

If we think our tip may be stale, connect to an extra outbound

Definition at line 4050 of file net_processing.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ConsiderEviction()

void PeerLogicValidation::ConsiderEviction ( CNode pto,
int64_t  time_in_seconds 
)

Consider evicting an outbound peer based on the amount of time they've been behind our tip.

Definition at line 3938 of file net_processing.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EvictExtraOutboundPeers()

void PeerLogicValidation::EvictExtraOutboundPeers ( int64_t  time_in_seconds)

If we have extra outbound peers, try to disconnect the one with the oldest block announcement.

Definition at line 3991 of file net_processing.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FinalizeNode()

void PeerLogicValidation::FinalizeNode ( NodeId  nodeid,
bool &  fUpdateConnectionTime 
)
overridevirtual

Handle removal of a peer by updating various state and removing it from mapNodeState.

Implements NetEventsInterface.

Definition at line 910 of file net_processing.cpp.

Here is the call graph for this function:

◆ InitializeNode()

void PeerLogicValidation::InitializeNode ( CNode pnode)
overridevirtual

Initialize a peer by adding it to mapNodeState and pushing a message requesting its version.

Implements NetEventsInterface.

Definition at line 872 of file net_processing.cpp.

Here is the call graph for this function:

◆ MaybeDiscourageAndDisconnect()

bool PeerLogicValidation::MaybeDiscourageAndDisconnect ( CNode pnode)
private

Maybe disconnect a peer and discourage future connections from its address.

Parameters
[in]pnodeThe node to check.
Returns
True if the peer was marked for disconnection in this function

Definition at line 3803 of file net_processing.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NewPoWValidBlock()

void PeerLogicValidation::NewPoWValidBlock ( const CBlockIndex pindex,
const std::shared_ptr< const CBlock > &  pblock 
)
overridevirtual

Overridden from CValidationInterface.

Maintain state about the best-seen block and fast-announce a compact block to compatible peers.

Reimplemented from CValidationInterface.

Definition at line 1351 of file net_processing.cpp.

Here is the call graph for this function:

◆ ProcessMessage()

void PeerLogicValidation::ProcessMessage ( CNode pfrom,
const std::string &  msg_type,
CDataStream vRecv,
const std::chrono::microseconds  time_received,
const CChainParams chainparams,
const std::atomic< bool > &  interruptMsgProc 
)

Process a single message from a peer.

Public for fuzz testing

Definition at line 2341 of file net_processing.cpp.

Here is the caller graph for this function:

◆ ProcessMessages()

bool PeerLogicValidation::ProcessMessages ( CNode pfrom,
std::atomic< bool > &  interrupt 
)
overridevirtual

Process protocol messages received from a given node.

Parameters
[in]pfromThe node which we have received messages from.
[in]interruptInterrupt condition for processing threads

Implements NetEventsInterface.

Definition at line 3845 of file net_processing.cpp.

Here is the call graph for this function:

◆ ReattemptInitialBroadcast()

void PeerLogicValidation::ReattemptInitialBroadcast ( CScheduler scheduler) const

Retrieve unbroadcast transactions from the mempool and reattempt sending to peers.

Definition at line 890 of file net_processing.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SendMessages()

bool PeerLogicValidation::SendMessages ( CNode pto) -> cs_sendProcessing)
overridevirtual

Send queued protocol messages to be sent to a give node.

Parameters
[in]ptoThe node which we are sending messages to.
Returns
True if there is more work to be done

Implements NetEventsInterface.

Definition at line 4092 of file net_processing.cpp.

Here is the call graph for this function:

◆ UpdatedBlockTip()

void PeerLogicValidation::UpdatedBlockTip ( const CBlockIndex pindexNew,
const CBlockIndex pindexFork,
bool  fInitialDownload 
)
overridevirtual

Overridden from CValidationInterface.

Update our best height and announce any block hashes which weren't previously in ChainActive() to our peers.

Reimplemented from CValidationInterface.

Definition at line 1398 of file net_processing.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ m_banman

BanMan* const PeerLogicValidation::m_banman
private

Pointer to this node's banman.

May be nullptr - check existence before dereferencing.

Definition at line 34 of file net_processing.h.

◆ m_chainman

ChainstateManager& PeerLogicValidation::m_chainman
private

Definition at line 35 of file net_processing.h.

◆ m_connman

CConnman& PeerLogicValidation::m_connman
private

Definition at line 32 of file net_processing.h.

◆ m_mempool

CTxMemPool& PeerLogicValidation::m_mempool
private

Definition at line 36 of file net_processing.h.

◆ m_stale_tip_check_time

int64_t PeerLogicValidation::m_stale_tip_check_time
private

Next time to check for stale tip.

Definition at line 95 of file net_processing.h.


The documentation for this class was generated from the following files: