diff --git a/src/net_processing.h b/src/net_processing.h --- a/src/net_processing.h +++ b/src/net_processing.h @@ -71,19 +71,39 @@ public: explicit PeerLogicValidation(CConnman *connman, CScheduler &scheduler); + /** + * Overridden from CValidationInterface. + */ void BlockConnected(const std::shared_ptr &pblock, const CBlockIndex *pindexConnected, const std::vector &vtxConflicted) override; + /** + * Overridden from CValidationInterface. + */ void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override; + /** + * Overridden from CValidationInterface. + */ void BlockChecked(const CBlock &block, const CValidationState &state) override; + /** + * Overridden from CValidationInterface. + */ void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr &pblock) override; + /** + * Initialize a peer by adding it to mapNodeState and pushing a message + * requesting its version. + */ void InitializeNode(const Config &config, CNode *pnode) override; + /** + * Handle removal of a peer by updating various state and removing it from + * mapNodeState. + */ void FinalizeNode(const Config &config, NodeId nodeid, bool &fUpdateConnectionTime) override; /** @@ -102,9 +122,21 @@ std::atomic &interrupt) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing); + /** + * Consider evicting an outbound peer based on the amount of time they've + * been behind our tip. + */ void ConsiderEviction(CNode *pto, int64_t time_in_seconds); + /** + * Evict extra outbound peers. If we think our tip may be stale, connect to + * an extra outbound. + */ void CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams); + /** + * If we have extra outbound peers, try to disconnect the one with the + * oldest block announcement. + */ void EvictExtraOutboundPeers(int64_t time_in_seconds); private: diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -980,6 +980,10 @@ EXTRA_PEER_CHECK_INTERVAL * 1000); } +/** + * Evict orphan txn pool entries (EraseOrphanTx) based on a newly connected + * block. Also save the time of the last tip update. + */ void PeerLogicValidation::BlockConnected( const std::shared_ptr &pblock, const CBlockIndex *pindex, const std::vector &vtxConflicted) { @@ -1006,7 +1010,7 @@ } } - // Erase orphan transactions include or precluded by this block + // Erase orphan transactions included or precluded by this block if (vOrphanErase.size()) { int nErased = 0; for (uint256 &orphanId : vOrphanErase) { @@ -1029,6 +1033,10 @@ most_recent_compact_block GUARDED_BY(cs_most_recent_block); static uint256 most_recent_block_hash GUARDED_BY(cs_most_recent_block); +/** + * Maintain state about the best-seen block and fast-announce a compact block + * to compatible peers. + */ void PeerLogicValidation::NewPoWValidBlock( const CBlockIndex *pindex, const std::shared_ptr &pblock) { std::shared_ptr pcmpctblock = @@ -1077,6 +1085,10 @@ }); } +/** + * Update our best height and announce any block hashes which weren't previously + * in chainActive to our peers. + */ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) { @@ -1115,6 +1127,10 @@ nTimeBestReceived = GetTime(); } +/** + * Handle invalid block rejection and consequent peer banning, maintain which + * peers announce compact blocks. + */ void PeerLogicValidation::BlockChecked(const CBlock &block, const CValidationState &state) { LOCK(cs_main);