@@ -401,6 +401,12 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) {
401
401
}
402
402
}
403
403
404
+ /* *
405
+ * When a peer sends us a valid block, instruct it to announce blocks to us
406
+ * using CMPCTBLOCK if possible by adding its nodeid to the end of
407
+ * lNodesAnnouncingHeaderAndIDs, and keeping that list under a certain size by
408
+ * removing the first element if necessary.
409
+ */
404
410
void MaybeSetPeerAsAnnouncingHeaderAndIDs (NodeId nodeid, CConnman* connman) {
405
411
AssertLockHeld (cs_main);
406
412
CNodeState* nodestate = State (nodeid);
@@ -749,7 +755,11 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
749
755
return nEvicted;
750
756
}
751
757
752
- // Requires cs_main.
758
+ /* *
759
+ * Mark a misbehaving peer to be banned depending upon the value of `-banscore`.
760
+ *
761
+ * Requires cs_main.
762
+ */
753
763
void Misbehaving (NodeId pnode, int howmuch, const std::string& message)
754
764
{
755
765
if (howmuch == 0 )
@@ -808,6 +818,10 @@ PeerLogicValidation::PeerLogicValidation(CConnman* connmanIn, CScheduler &schedu
808
818
scheduler.scheduleEvery (std::bind (&PeerLogicValidation::CheckForStaleTipAndEvictPeers, this , consensusParams), EXTRA_PEER_CHECK_INTERVAL * 1000 );
809
819
}
810
820
821
+ /* *
822
+ * Evict orphan txn pool entries (EraseOrphanTx) based on a newly connected
823
+ * block. Also save the time of the last tip update.
824
+ */
811
825
void PeerLogicValidation::BlockConnected (const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex, const std::vector<CTransactionRef>& vtxConflicted) {
812
826
LOCK (g_cs_orphans);
813
827
@@ -828,7 +842,7 @@ void PeerLogicValidation::BlockConnected(const std::shared_ptr<const CBlock>& pb
828
842
}
829
843
}
830
844
831
- // Erase orphan transactions include or precluded by this block
845
+ // Erase orphan transactions included or precluded by this block
832
846
if (vOrphanErase.size ()) {
833
847
int nErased = 0 ;
834
848
for (uint256 &orphanHash : vOrphanErase) {
@@ -847,6 +861,10 @@ static std::shared_ptr<const CBlockHeaderAndShortTxIDs> most_recent_compact_bloc
847
861
static uint256 most_recent_block_hash;
848
862
static bool fWitnessesPresentInMostRecentCompactBlock ;
849
863
864
+ /* *
865
+ * Maintain state about the best-seen block and fast-announce a compact block
866
+ * to compatible peers.
867
+ */
850
868
void PeerLogicValidation::NewPoWValidBlock (const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) {
851
869
std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true );
852
870
const CNetMsgMaker msgMaker (PROTOCOL_VERSION);
@@ -888,6 +906,10 @@ void PeerLogicValidation::NewPoWValidBlock(const CBlockIndex *pindex, const std:
888
906
});
889
907
}
890
908
909
+ /* *
910
+ * Update our best height and announce any block hashes which weren't previously
911
+ * in chainActive to our peers.
912
+ */
891
913
void PeerLogicValidation::UpdatedBlockTip (const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload ) {
892
914
const int nNewHeight = pindexNew->nHeight ;
893
915
connman->SetBestHeight (nNewHeight);
@@ -920,6 +942,10 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CB
920
942
nTimeBestReceived = GetTime ();
921
943
}
922
944
945
+ /* *
946
+ * Handle invalid block rejection and consequent peer banning, maintain which
947
+ * peers announce compact blocks.
948
+ */
923
949
void PeerLogicValidation::BlockChecked (const CBlock& block, const CValidationState& state) {
924
950
LOCK (cs_main);
925
951
0 commit comments