Skip to content

Commit a4c55a9

Browse files
committed
[net processing] Inline and simplify UpdatePreferredDownload
We inline `UpdatePreferredDownload` because it is only used in one location during the version handshake. We simplify it by removing the initial subtraction of `state->fPreferredDownload` from `nPreferredDownload`. This is ok since the version handshake is only called once per peer and `state->fPreferredDownload` will always be false before the newly inlined code is called, making the subtraction a noop.
1 parent 490c08f commit a4c55a9

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/net_processing.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,6 @@ class PeerManagerImpl final : public PeerManager
613613
/** Number of preferable block download peers. */
614614
int nPreferredDownload GUARDED_BY(cs_main){0};
615615

616-
void UpdatePreferredDownload(const CNode& node, CNodeState* state) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
617-
618616
bool AlreadyHaveTx(const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
619617

620618
/**
@@ -875,16 +873,6 @@ static void AddKnownTx(Peer& peer, const uint256& hash)
875873
}
876874
}
877875

878-
void PeerManagerImpl::UpdatePreferredDownload(const CNode& node, CNodeState* state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
879-
{
880-
nPreferredDownload -= state->fPreferredDownload;
881-
882-
// Whether this node should be marked as a preferred download node.
883-
state->fPreferredDownload = (!node.IsInboundConn() || node.HasPermission(NetPermissionFlags::NoBan)) && !node.IsAddrFetchConn() && !node.fClient;
884-
885-
nPreferredDownload += state->fPreferredDownload;
886-
}
887-
888876
std::chrono::microseconds PeerManagerImpl::NextInvToInbounds(std::chrono::microseconds now,
889877
std::chrono::seconds average_interval)
890878
{
@@ -2741,8 +2729,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
27412729

27422730
// Potentially mark this peer as a preferred download peer.
27432731
{
2744-
LOCK(cs_main);
2745-
UpdatePreferredDownload(pfrom, State(pfrom.GetId()));
2732+
LOCK(cs_main);
2733+
CNodeState* state = State(pfrom.GetId());
2734+
state->fPreferredDownload = (!pfrom.IsInboundConn() || pfrom.HasPermission(NetPermissionFlags::NoBan)) && !pfrom.IsAddrFetchConn() && !pfrom.fClient;
2735+
nPreferredDownload += state->fPreferredDownload;
27462736
}
27472737

27482738
// Self advertisement & GETADDR logic

0 commit comments

Comments
 (0)