@@ -977,6 +977,20 @@ static void AddKnownTx(Peer& peer, const uint256& hash)
977
977
tx_relay->m_tx_inventory_known_filter .insert (hash);
978
978
}
979
979
980
+ /* * Whether this peer can serve us blocks. */
981
+ static bool CanServeBlocks (const Peer& peer)
982
+ {
983
+ return peer.m_their_services & (NODE_NETWORK|NODE_NETWORK_LIMITED);
984
+ }
985
+
986
+ /* * Whether this peer can only serve limited recent blocks (e.g. because
987
+ * it prunes old blocks) */
988
+ static bool IsLimitedPeer (const Peer& peer)
989
+ {
990
+ return (!(peer.m_their_services & NODE_NETWORK) &&
991
+ (peer.m_their_services & NODE_NETWORK_LIMITED));
992
+ }
993
+
980
994
std::chrono::microseconds PeerManagerImpl::NextInvToInbounds (std::chrono::microseconds now,
981
995
std::chrono::seconds average_interval)
982
996
{
@@ -2873,12 +2887,6 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
2873
2887
}
2874
2888
peer->m_starting_height = starting_height;
2875
2889
2876
- // set nodes not relaying blocks and tx and not serving (parts) of the historical blockchain as "clients"
2877
- pfrom.fClient = (!(nServices & NODE_NETWORK) && !(nServices & NODE_NETWORK_LIMITED));
2878
-
2879
- // set nodes not capable of serving the complete blockchain history as "limited nodes"
2880
- pfrom.m_limited_node = (!(nServices & NODE_NETWORK) && (nServices & NODE_NETWORK_LIMITED));
2881
-
2882
2890
// We only initialize the m_tx_relay data structure if:
2883
2891
// - this isn't an outbound block-relay-only connection; and
2884
2892
// - fRelay=true or we're offering NODE_BLOOM to this peer
@@ -2903,7 +2911,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
2903
2911
{
2904
2912
LOCK (cs_main);
2905
2913
CNodeState* state = State (pfrom.GetId ());
2906
- state->fPreferredDownload = (!pfrom.IsInboundConn () || pfrom.HasPermission (NetPermissionFlags::NoBan)) && !pfrom.IsAddrFetchConn () && !pfrom. fClient ;
2914
+ state->fPreferredDownload = (!pfrom.IsInboundConn () || pfrom.HasPermission (NetPermissionFlags::NoBan)) && !pfrom.IsAddrFetchConn () && CanServeBlocks (*peer) ;
2907
2915
m_num_preferred_download_peers += state->fPreferredDownload ;
2908
2916
}
2909
2917
@@ -4863,7 +4871,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4863
4871
bool sync_blocks_and_headers_from_peer = false ;
4864
4872
if (state.fPreferredDownload ) {
4865
4873
sync_blocks_and_headers_from_peer = true ;
4866
- } else if (!pto-> fClient && !pto->IsAddrFetchConn ()) {
4874
+ } else if (CanServeBlocks (*peer) && !pto->IsAddrFetchConn ()) {
4867
4875
// Typically this is an inbound peer. If we don't have any outbound
4868
4876
// peers, or if we aren't downloading any blocks from such peers,
4869
4877
// then allow block downloads from this peer, too.
@@ -4878,7 +4886,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4878
4886
}
4879
4887
}
4880
4888
4881
- if (!state.fSyncStarted && !pto-> fClient && !fImporting && !fReindex ) {
4889
+ if (!state.fSyncStarted && CanServeBlocks (*peer) && !fImporting && !fReindex ) {
4882
4890
// Only actively request headers from a single peer, unless we're close to today.
4883
4891
if ((nSyncStarted == 0 && sync_blocks_and_headers_from_peer) || m_chainman.m_best_header ->GetBlockTime () > GetAdjustedTime () - 24 * 60 * 60 ) {
4884
4892
const CBlockIndex* pindexStart = m_chainman.m_best_header ;
@@ -5255,7 +5263,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5255
5263
// Message: getdata (blocks)
5256
5264
//
5257
5265
std::vector<CInv> vGetData;
5258
- if (!pto-> fClient && ((sync_blocks_and_headers_from_peer && !pto-> m_limited_node ) || !m_chainman.ActiveChainstate ().IsInitialBlockDownload ()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
5266
+ if (CanServeBlocks (*peer) && ((sync_blocks_and_headers_from_peer && !IsLimitedPeer (*peer) ) || !m_chainman.ActiveChainstate ().IsInitialBlockDownload ()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
5259
5267
std::vector<const CBlockIndex*> vToDownload;
5260
5268
NodeId staller = -1 ;
5261
5269
FindNextBlocksToDownload (pto->GetId (), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight , vToDownload, staller);
0 commit comments