Skip to content

Commit f65e83d

Browse files
jnewberydergoegge
authored andcommitted
[net processing] Remove fClient and m_limited_node
fClient is replaced by CanServeBlocks(), and m_limited_node is replaced by IsLimitedPeer().
1 parent fc5eb52 commit f65e83d

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/net.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,6 @@ class CNode
399399
bool HasPermission(NetPermissionFlags permission) const {
400400
return NetPermissions::HasFlag(m_permissionFlags, permission);
401401
}
402-
bool fClient{false}; // set by version message
403-
bool m_limited_node{false}; //after BIP159, set by version message
404402
/** fSuccessfullyConnected is set to true on receiving VERACK from the peer. */
405403
std::atomic_bool fSuccessfullyConnected{false};
406404
// Setting fDisconnect to true will cause the node to be disconnected the

src/net_processing.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,20 @@ static void AddKnownTx(Peer& peer, const uint256& hash)
977977
tx_relay->m_tx_inventory_known_filter.insert(hash);
978978
}
979979

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+
980994
std::chrono::microseconds PeerManagerImpl::NextInvToInbounds(std::chrono::microseconds now,
981995
std::chrono::seconds average_interval)
982996
{
@@ -2873,12 +2887,6 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
28732887
}
28742888
peer->m_starting_height = starting_height;
28752889

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-
28822890
// We only initialize the m_tx_relay data structure if:
28832891
// - this isn't an outbound block-relay-only connection; and
28842892
// - 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,
29032911
{
29042912
LOCK(cs_main);
29052913
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);
29072915
m_num_preferred_download_peers += state->fPreferredDownload;
29082916
}
29092917

@@ -4863,7 +4871,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
48634871
bool sync_blocks_and_headers_from_peer = false;
48644872
if (state.fPreferredDownload) {
48654873
sync_blocks_and_headers_from_peer = true;
4866-
} else if (!pto->fClient && !pto->IsAddrFetchConn()) {
4874+
} else if (CanServeBlocks(*peer) && !pto->IsAddrFetchConn()) {
48674875
// Typically this is an inbound peer. If we don't have any outbound
48684876
// peers, or if we aren't downloading any blocks from such peers,
48694877
// then allow block downloads from this peer, too.
@@ -4878,7 +4886,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
48784886
}
48794887
}
48804888

4881-
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) {
4889+
if (!state.fSyncStarted && CanServeBlocks(*peer) && !fImporting && !fReindex) {
48824890
// Only actively request headers from a single peer, unless we're close to today.
48834891
if ((nSyncStarted == 0 && sync_blocks_and_headers_from_peer) || m_chainman.m_best_header->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) {
48844892
const CBlockIndex* pindexStart = m_chainman.m_best_header;
@@ -5255,7 +5263,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
52555263
// Message: getdata (blocks)
52565264
//
52575265
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) {
52595267
std::vector<const CBlockIndex*> vToDownload;
52605268
NodeId staller = -1;
52615269
FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller);

0 commit comments

Comments
 (0)