@@ -472,6 +472,24 @@ class PeerManagerImpl final : public PeerManager
472
472
std::vector<std::pair<uint256, CTransactionRef>> vExtraTxnForCompact GUARDED_BY (g_cs_orphans);
473
473
/* * Offset into vExtraTxnForCompact to insert the next tx */
474
474
size_t vExtraTxnForCompactIt GUARDED_BY (g_cs_orphans) = 0;
475
+
476
+ void ProcessBlockAvailability (NodeId nodeid) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
477
+ void UpdateBlockAvailability (NodeId nodeid, const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
478
+ bool CanDirectFetch (const Consensus::Params &consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
479
+ bool BlockRequestAllowed (const CBlockIndex* pindex, const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
480
+ bool AlreadyHaveBlock (const uint256& block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
481
+ void ProcessGetBlockData (CNode& pfrom, Peer& peer, const CChainParams& chainparams, const CInv& inv, CConnman& connman);
482
+ bool PrepareBlockFilterRequest (CNode& peer, const CChainParams& chain_params,
483
+ BlockFilterType filter_type, uint32_t start_height,
484
+ const uint256& stop_hash, uint32_t max_height_diff,
485
+ const CBlockIndex*& stop_index,
486
+ BlockFilterIndex*& filter_index);
487
+ void ProcessGetCFilters (CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
488
+ CConnman& connman);
489
+ void ProcessGetCFHeaders (CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
490
+ CConnman& connman);
491
+ void ProcessGetCFCheckPt (CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
492
+ CConnman& connman);
475
493
};
476
494
} // namespace
477
495
@@ -684,41 +702,6 @@ bool PeerManagerImpl::MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, co
684
702
return true ;
685
703
}
686
704
687
- /* * Check whether the last unknown block a peer advertised is not yet known. */
688
- static void ProcessBlockAvailability (NodeId nodeid) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
689
- CNodeState *state = State (nodeid);
690
- assert (state != nullptr );
691
-
692
- if (!state->hashLastUnknownBlock .IsNull ()) {
693
- const CBlockIndex* pindex = g_chainman.m_blockman .LookupBlockIndex (state->hashLastUnknownBlock );
694
- if (pindex && pindex->nChainWork > 0 ) {
695
- if (state->pindexBestKnownBlock == nullptr || pindex->nChainWork >= state->pindexBestKnownBlock ->nChainWork ) {
696
- state->pindexBestKnownBlock = pindex;
697
- }
698
- state->hashLastUnknownBlock .SetNull ();
699
- }
700
- }
701
- }
702
-
703
- /* * Update tracking information about which blocks a peer is assumed to have. */
704
- static void UpdateBlockAvailability (NodeId nodeid, const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
705
- CNodeState *state = State (nodeid);
706
- assert (state != nullptr );
707
-
708
- ProcessBlockAvailability (nodeid);
709
-
710
- const CBlockIndex* pindex = g_chainman.m_blockman .LookupBlockIndex (hash);
711
- if (pindex && pindex->nChainWork > 0 ) {
712
- // An actually better block was announced.
713
- if (state->pindexBestKnownBlock == nullptr || pindex->nChainWork >= state->pindexBestKnownBlock ->nChainWork ) {
714
- state->pindexBestKnownBlock = pindex;
715
- }
716
- } else {
717
- // An unknown block was announced; just assume that the latest one is the best one.
718
- state->hashLastUnknownBlock = hash;
719
- }
720
- }
721
-
722
705
void PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs (NodeId nodeid)
723
706
{
724
707
AssertLockHeld (cs_main);
@@ -768,7 +751,7 @@ bool PeerManagerImpl::TipMayBeStale()
768
751
return m_last_tip_update < GetTime () - consensusParams.nPowTargetSpacing * 3 && mapBlocksInFlight.empty ();
769
752
}
770
753
771
- static bool CanDirectFetch (const Consensus::Params &consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main )
754
+ bool PeerManagerImpl:: CanDirectFetch (const Consensus::Params &consensusParams)
772
755
{
773
756
return ::ChainActive ().Tip ()->GetBlockTime () > GetAdjustedTime () - consensusParams.nPowTargetSpacing * 20 ;
774
757
}
@@ -782,6 +765,41 @@ static bool PeerHasHeader(CNodeState *state, const CBlockIndex *pindex) EXCLUSIV
782
765
return false ;
783
766
}
784
767
768
+ /* * Check whether the last unknown block a peer advertised is not yet known. */
769
+ void PeerManagerImpl::ProcessBlockAvailability (NodeId nodeid) {
770
+ CNodeState *state = State (nodeid);
771
+ assert (state != nullptr );
772
+
773
+ if (!state->hashLastUnknownBlock .IsNull ()) {
774
+ const CBlockIndex* pindex = g_chainman.m_blockman .LookupBlockIndex (state->hashLastUnknownBlock );
775
+ if (pindex && pindex->nChainWork > 0 ) {
776
+ if (state->pindexBestKnownBlock == nullptr || pindex->nChainWork >= state->pindexBestKnownBlock ->nChainWork ) {
777
+ state->pindexBestKnownBlock = pindex;
778
+ }
779
+ state->hashLastUnknownBlock .SetNull ();
780
+ }
781
+ }
782
+ }
783
+
784
+ /* * Update tracking information about which blocks a peer is assumed to have. */
785
+ void PeerManagerImpl::UpdateBlockAvailability (NodeId nodeid, const uint256 &hash) {
786
+ CNodeState *state = State (nodeid);
787
+ assert (state != nullptr );
788
+
789
+ ProcessBlockAvailability (nodeid);
790
+
791
+ const CBlockIndex* pindex = g_chainman.m_blockman .LookupBlockIndex (hash);
792
+ if (pindex && pindex->nChainWork > 0 ) {
793
+ // An actually better block was announced.
794
+ if (state->pindexBestKnownBlock == nullptr || pindex->nChainWork >= state->pindexBestKnownBlock ->nChainWork ) {
795
+ state->pindexBestKnownBlock = pindex;
796
+ }
797
+ } else {
798
+ // An unknown block was announced; just assume that the latest one is the best one.
799
+ state->hashLastUnknownBlock = hash;
800
+ }
801
+ }
802
+
785
803
void PeerManagerImpl::FindNextBlocksToDownload (NodeId nodeid, unsigned int count, std::vector<const CBlockIndex*>& vBlocks, NodeId& nodeStaller)
786
804
{
787
805
if (count == 0 )
@@ -1200,7 +1218,7 @@ bool PeerManagerImpl::MaybePunishNodeForTx(NodeId nodeid, const TxValidationStat
1200
1218
// active chain if they are no more than a month older (both in time, and in
1201
1219
// best equivalent proof of work) than the best header chain we know about and
1202
1220
// we fully-validated them at some point.
1203
- static bool BlockRequestAllowed (const CBlockIndex* pindex, const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main )
1221
+ bool PeerManagerImpl:: BlockRequestAllowed (const CBlockIndex* pindex, const Consensus::Params& consensusParams)
1204
1222
{
1205
1223
AssertLockHeld (cs_main);
1206
1224
if (::ChainActive ().Contains (pindex)) return true ;
@@ -1454,7 +1472,7 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid)
1454
1472
return recentRejects->contains (hash) || m_mempool.exists (gtxid);
1455
1473
}
1456
1474
1457
- bool static AlreadyHaveBlock (const uint256& block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main )
1475
+ bool PeerManagerImpl:: AlreadyHaveBlock (const uint256& block_hash)
1458
1476
{
1459
1477
return g_chainman.m_blockman .LookupBlockIndex (block_hash) != nullptr ;
1460
1478
}
@@ -1535,7 +1553,7 @@ static void RelayAddress(const CNode& originator,
1535
1553
connman.ForEachNodeThen (std::move (sortfunc), std::move (pushfunc));
1536
1554
}
1537
1555
1538
- void static ProcessGetBlockData (CNode& pfrom, Peer& peer, const CChainParams& chainparams, const CInv& inv, CConnman& connman)
1556
+ void PeerManagerImpl:: ProcessGetBlockData (CNode& pfrom, Peer& peer, const CChainParams& chainparams, const CInv& inv, CConnman& connman)
1539
1557
{
1540
1558
bool send = false ;
1541
1559
std::shared_ptr<const CBlock> a_recent_block;
@@ -2118,7 +2136,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
2118
2136
* @param[out] filter_index The filter index, if the request can be serviced.
2119
2137
* @return True if the request can be serviced.
2120
2138
*/
2121
- static bool PrepareBlockFilterRequest (CNode& peer, const CChainParams& chain_params,
2139
+ bool PeerManagerImpl:: PrepareBlockFilterRequest (CNode& peer, const CChainParams& chain_params,
2122
2140
BlockFilterType filter_type, uint32_t start_height,
2123
2141
const uint256& stop_hash, uint32_t max_height_diff,
2124
2142
const CBlockIndex*& stop_index,
@@ -2181,7 +2199,7 @@ static bool PrepareBlockFilterRequest(CNode& peer, const CChainParams& chain_par
2181
2199
* @param[in] chain_params Chain parameters
2182
2200
* @param[in] connman Pointer to the connection manager
2183
2201
*/
2184
- static void ProcessGetCFilters (CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
2202
+ void PeerManagerImpl:: ProcessGetCFilters (CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
2185
2203
CConnman& connman)
2186
2204
{
2187
2205
uint8_t filter_type_ser;
@@ -2223,7 +2241,7 @@ static void ProcessGetCFilters(CNode& peer, CDataStream& vRecv, const CChainPara
2223
2241
* @param[in] chain_params Chain parameters
2224
2242
* @param[in] connman Pointer to the connection manager
2225
2243
*/
2226
- static void ProcessGetCFHeaders (CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
2244
+ void PeerManagerImpl:: ProcessGetCFHeaders (CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
2227
2245
CConnman& connman)
2228
2246
{
2229
2247
uint8_t filter_type_ser;
@@ -2278,7 +2296,7 @@ static void ProcessGetCFHeaders(CNode& peer, CDataStream& vRecv, const CChainPar
2278
2296
* @param[in] chain_params Chain parameters
2279
2297
* @param[in] connman Pointer to the connection manager
2280
2298
*/
2281
- static void ProcessGetCFCheckPt (CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
2299
+ void PeerManagerImpl:: ProcessGetCFCheckPt (CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
2282
2300
CConnman& connman)
2283
2301
{
2284
2302
uint8_t filter_type_ser;
@@ -4747,4 +4765,3 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4747
4765
} // release cs_main
4748
4766
return true ;
4749
4767
}
4750
-
0 commit comments