Skip to content

Commit 9781c08

Browse files
committed
net_processing: move some globals into PeerManagerImpl
nSyncStarted, mapBlockSource, g_wtxid_relay_peers, g_outbound_peers_with_protect_from_disconnect were all only used by PeerManagerImpl methods already.
1 parent c8b8351 commit 9781c08

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/net_processing.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,7 @@ class PeerManagerImpl final : public PeerManager
345345
* their own locks.
346346
*/
347347
std::map<NodeId, PeerRef> m_peer_map GUARDED_BY(m_peer_mutex);
348-
};
349-
} // namespace
350348

351-
namespace {
352349
/** Number of nodes with fSyncStarted. */
353350
int nSyncStarted GUARDED_BY(cs_main) = 0;
354351

@@ -360,6 +357,15 @@ namespace {
360357
*/
361358
std::map<uint256, std::pair<NodeId, bool>> mapBlockSource GUARDED_BY(cs_main);
362359

360+
/** Number of peers with wtxid relay. */
361+
int m_wtxid_relay_peers GUARDED_BY(cs_main) = 0;
362+
363+
/** Number of outbound peers with m_chain_sync.m_protect. */
364+
int m_outbound_peers_with_protect_from_disconnect GUARDED_BY(cs_main) = 0;
365+
};
366+
} // namespace
367+
368+
namespace {
363369
/**
364370
* Filter for transactions that were recently rejected by
365371
* AcceptToMemoryPool. These are not rerequested until the chain tip
@@ -423,12 +429,6 @@ namespace {
423429
/** Number of peers from which we're downloading blocks. */
424430
int nPeersWithValidatedDownloads GUARDED_BY(cs_main) = 0;
425431

426-
/** Number of peers with wtxid relay. */
427-
int g_wtxid_relay_peers GUARDED_BY(cs_main) = 0;
428-
429-
/** Number of outbound peers with m_chain_sync.m_protect. */
430-
int g_outbound_peers_with_protect_from_disconnect GUARDED_BY(cs_main) = 0;
431-
432432
/** When our tip was last updated. */
433433
std::atomic<int64_t> g_last_tip_update(0);
434434

@@ -911,7 +911,7 @@ void PeerManagerImpl::AddTxAnnouncement(const CNode& node, const GenTxid& gtxid,
911911
auto delay = std::chrono::microseconds{0};
912912
const bool preferred = state->fPreferredDownload;
913913
if (!preferred) delay += NONPREF_PEER_TX_DELAY;
914-
if (!gtxid.IsWtxid() && g_wtxid_relay_peers > 0) delay += TXID_RELAY_DELAY;
914+
if (!gtxid.IsWtxid() && m_wtxid_relay_peers > 0) delay += TXID_RELAY_DELAY;
915915
const bool overloaded = !node.HasPermission(PF_RELAY) &&
916916
m_txrequest.CountInFlight(nodeid) >= MAX_PEER_TX_REQUEST_IN_FLIGHT;
917917
if (overloaded) delay += OVERLOADED_PEER_TX_DELAY;
@@ -1004,10 +1004,10 @@ void PeerManagerImpl::FinalizeNode(const CNode& node, bool& fUpdateConnectionTim
10041004
nPreferredDownload -= state->fPreferredDownload;
10051005
nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0);
10061006
assert(nPeersWithValidatedDownloads >= 0);
1007-
g_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync.m_protect;
1008-
assert(g_outbound_peers_with_protect_from_disconnect >= 0);
1009-
g_wtxid_relay_peers -= state->m_wtxid_relay;
1010-
assert(g_wtxid_relay_peers >= 0);
1007+
m_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync.m_protect;
1008+
assert(m_outbound_peers_with_protect_from_disconnect >= 0);
1009+
m_wtxid_relay_peers -= state->m_wtxid_relay;
1010+
assert(m_wtxid_relay_peers >= 0);
10111011

10121012
mapNodeState.erase(nodeid);
10131013

@@ -1016,8 +1016,8 @@ void PeerManagerImpl::FinalizeNode(const CNode& node, bool& fUpdateConnectionTim
10161016
assert(mapBlocksInFlight.empty());
10171017
assert(nPreferredDownload == 0);
10181018
assert(nPeersWithValidatedDownloads == 0);
1019-
assert(g_outbound_peers_with_protect_from_disconnect == 0);
1020-
assert(g_wtxid_relay_peers == 0);
1019+
assert(m_outbound_peers_with_protect_from_disconnect == 0);
1020+
assert(m_wtxid_relay_peers == 0);
10211021
assert(m_txrequest.Size() == 0);
10221022
}
10231023
LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid);
@@ -2146,10 +2146,10 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
21462146
// thus always subject to eviction under the bad/lagging chain logic.
21472147
// See ChainSyncTimeoutState.
21482148
if (!pfrom.fDisconnect && pfrom.IsFullOutboundConn() && nodestate->pindexBestKnownBlock != nullptr) {
2149-
if (g_outbound_peers_with_protect_from_disconnect < MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT && nodestate->pindexBestKnownBlock->nChainWork >= ::ChainActive().Tip()->nChainWork && !nodestate->m_chain_sync.m_protect) {
2149+
if (m_outbound_peers_with_protect_from_disconnect < MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT && nodestate->pindexBestKnownBlock->nChainWork >= ::ChainActive().Tip()->nChainWork && !nodestate->m_chain_sync.m_protect) {
21502150
LogPrint(BCLog::NET, "Protecting outbound peer=%d from eviction\n", pfrom.GetId());
21512151
nodestate->m_chain_sync.m_protect = true;
2152-
++g_outbound_peers_with_protect_from_disconnect;
2152+
++m_outbound_peers_with_protect_from_disconnect;
21532153
}
21542154
}
21552155
}
@@ -2759,7 +2759,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
27592759
LOCK(cs_main);
27602760
if (!State(pfrom.GetId())->m_wtxid_relay) {
27612761
State(pfrom.GetId())->m_wtxid_relay = true;
2762-
g_wtxid_relay_peers++;
2762+
m_wtxid_relay_peers++;
27632763
} else {
27642764
LogPrint(BCLog::NET, "ignoring duplicate wtxidrelay from peer=%d\n", pfrom.GetId());
27652765
}

0 commit comments

Comments
 (0)