[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.
This commit is contained in:
1 parent
490c08f96a
commit
a4c55a93ef
1 file changed
+4
-14
+4
-14
@@ -613,8 +613,6 @@ private:
|
|||||||
/** Number of preferable block download peers. */
|
/** Number of preferable block download peers. */
|
||||||
int nPreferredDownload GUARDED_BY(cs_main){0};
|
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);
|
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::microseconds PeerManagerImpl::NextInvToInbounds(std::chrono::microseconds now,
|
||||||
std::chrono::seconds average_interval)
|
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.
|
// Potentially mark this peer as a preferred download peer.
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
UpdatePreferredDownload(pfrom, State(pfrom.GetId()));
|
CNodeState* state = State(pfrom.GetId());
|
||||||
|
state->fPreferredDownload = (!pfrom.IsInboundConn() || pfrom.HasPermission(NetPermissionFlags::NoBan)) && !pfrom.IsAddrFetchConn() && !pfrom.fClient;
|
||||||
|
nPreferredDownload += state->fPreferredDownload;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Self advertisement & GETADDR logic
|
// Self advertisement & GETADDR logic
|
||||||
|
|||||||
Reference in new issue
Block a user