aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authordergoegge <n.goeggi@gmail.com>2022-03-18 23:39:26 +0100
committerdergoegge <n.goeggi@gmail.com>2022-04-20 13:33:07 +0200
commita4c55a93ef9277e1043c286120e2417652ee8bbb (patch)
tree42cfef71f734d90710a70f9167787b769cdf66d4 /src/net_processing.cpp
parent490c08f96a34ed436c3d2cf7b9a3ed72694b6147 (diff)
downloadbitcoin-a4c55a93ef9277e1043c286120e2417652ee8bbb.tar.xz
[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.
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp18
1 files changed, 4 insertions, 14 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index b81d40e5c5..014b722ea3 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -613,8 +613,6 @@ private:
/** Number of preferable block download peers. */
int nPreferredDownload GUARDED_BY(cs_main){0};
- void UpdatePreferredDownload(const CNode& node, CNodeState* state) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
-
bool AlreadyHaveTx(const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
/**
@@ -875,16 +873,6 @@ static void AddKnownTx(Peer& peer, const uint256& hash)
}
}
-void PeerManagerImpl::UpdatePreferredDownload(const CNode& node, CNodeState* state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
-{
- nPreferredDownload -= state->fPreferredDownload;
-
- // Whether this node should be marked as a preferred download node.
- state->fPreferredDownload = (!node.IsInboundConn() || node.HasPermission(NetPermissionFlags::NoBan)) && !node.IsAddrFetchConn() && !node.fClient;
-
- nPreferredDownload += state->fPreferredDownload;
-}
-
std::chrono::microseconds PeerManagerImpl::NextInvToInbounds(std::chrono::microseconds now,
std::chrono::seconds average_interval)
{
@@ -2741,8 +2729,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
// Potentially mark this peer as a preferred download peer.
{
- LOCK(cs_main);
- UpdatePreferredDownload(pfrom, State(pfrom.GetId()));
+ LOCK(cs_main);
+ CNodeState* state = State(pfrom.GetId());
+ state->fPreferredDownload = (!pfrom.IsInboundConn() || pfrom.HasPermission(NetPermissionFlags::NoBan)) && !pfrom.IsAddrFetchConn() && !pfrom.fClient;
+ nPreferredDownload += state->fPreferredDownload;
}
// Self advertisement & GETADDR logic