Skip to content

Commit 778343a

Browse files
committed
scripted-diff: Rename PeerManagerImpl members
-BEGIN VERIFY SCRIPT- ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); } ren mapNodeState m_node_states ren cs_most_recent_block m_most_recent_block_mutex ren most_recent_block m_most_recent_block ren most_recent_compact_block m_most_recent_compact_block ren most_recent_block_hash m_most_recent_block_hash ren fWitnessesPresentInMostRecentCompactBlock m_most_recent_compact_block_has_witnesses ren nPreferredDownload m_num_preferred_download_peers ren nHighestFastAnnounce m_highest_fast_announce -END VERIFY SCRIPT-
1 parent 91c3392 commit 778343a

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

src/net_processing.cpp

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ class PeerManagerImpl final : public PeerManager
582582
std::map<NodeId, PeerRef> m_peer_map GUARDED_BY(m_peer_mutex);
583583

584584
/** Map maintaining per-node state. */
585-
std::map<NodeId, CNodeState> mapNodeState GUARDED_BY(cs_main);
585+
std::map<NodeId, CNodeState> m_node_states GUARDED_BY(cs_main);
586586

587587
/** Get a pointer to a const CNodeState, used when not mutating the CNodeState object. */
588588
const CNodeState* State(NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -611,7 +611,7 @@ class PeerManagerImpl final : public PeerManager
611611
int m_outbound_peers_with_protect_from_disconnect GUARDED_BY(cs_main) = 0;
612612

613613
/** Number of preferable block download peers. */
614-
int nPreferredDownload GUARDED_BY(cs_main){0};
614+
int m_num_preferred_download_peers GUARDED_BY(cs_main){0};
615615

616616
bool AlreadyHaveTx(const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
617617

@@ -680,15 +680,15 @@ class PeerManagerImpl final : public PeerManager
680680
std::chrono::seconds average_interval);
681681

682682

683-
// All of the following cache a recent block, and are protected by cs_most_recent_block
684-
RecursiveMutex cs_most_recent_block;
685-
std::shared_ptr<const CBlock> most_recent_block GUARDED_BY(cs_most_recent_block);
686-
std::shared_ptr<const CBlockHeaderAndShortTxIDs> most_recent_compact_block GUARDED_BY(cs_most_recent_block);
687-
uint256 most_recent_block_hash GUARDED_BY(cs_most_recent_block);
688-
bool fWitnessesPresentInMostRecentCompactBlock GUARDED_BY(cs_most_recent_block){false};
683+
// All of the following cache a recent block, and are protected by m_most_recent_block_mutex
684+
RecursiveMutex m_most_recent_block_mutex;
685+
std::shared_ptr<const CBlock> m_most_recent_block GUARDED_BY(m_most_recent_block_mutex);
686+
std::shared_ptr<const CBlockHeaderAndShortTxIDs> m_most_recent_compact_block GUARDED_BY(m_most_recent_block_mutex);
687+
uint256 m_most_recent_block_hash GUARDED_BY(m_most_recent_block_mutex);
688+
bool m_most_recent_compact_block_has_witnesses GUARDED_BY(m_most_recent_block_mutex){false};
689689

690690
/** Height of the highest block announced using BIP 152 high-bandwidth mode. */
691-
int nHighestFastAnnounce{0};
691+
int m_highest_fast_announce{0};
692692

693693
/** Have we requested this block from a peer */
694694
bool IsBlockRequested(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -834,8 +834,8 @@ class PeerManagerImpl final : public PeerManager
834834

835835
const CNodeState* PeerManagerImpl::State(NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
836836
{
837-
std::map<NodeId, CNodeState>::const_iterator it = mapNodeState.find(pnode);
838-
if (it == mapNodeState.end())
837+
std::map<NodeId, CNodeState>::const_iterator it = m_node_states.find(pnode);
838+
if (it == m_node_states.end())
839839
return nullptr;
840840
return &it->second;
841841
}
@@ -1236,7 +1236,7 @@ void PeerManagerImpl::InitializeNode(CNode *pnode)
12361236
NodeId nodeid = pnode->GetId();
12371237
{
12381238
LOCK(cs_main);
1239-
mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(pnode->IsInboundConn()));
1239+
m_node_states.emplace_hint(m_node_states.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(pnode->IsInboundConn()));
12401240
assert(m_txrequest.Count(nodeid) == 0);
12411241
}
12421242
PeerRef peer = std::make_shared<Peer>(nodeid, /*tx_relay=*/ !pnode->IsBlockOnlyConn());
@@ -1298,18 +1298,18 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
12981298
}
12991299
WITH_LOCK(g_cs_orphans, m_orphanage.EraseForPeer(nodeid));
13001300
m_txrequest.DisconnectedPeer(nodeid);
1301-
nPreferredDownload -= state->fPreferredDownload;
1301+
m_num_preferred_download_peers -= state->fPreferredDownload;
13021302
m_peers_downloading_from -= (state->nBlocksInFlight != 0);
13031303
assert(m_peers_downloading_from >= 0);
13041304
m_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync.m_protect;
13051305
assert(m_outbound_peers_with_protect_from_disconnect >= 0);
13061306

1307-
mapNodeState.erase(nodeid);
1307+
m_node_states.erase(nodeid);
13081308

1309-
if (mapNodeState.empty()) {
1309+
if (m_node_states.empty()) {
13101310
// Do a consistency check after the last peer is removed.
13111311
assert(mapBlocksInFlight.empty());
1312-
assert(nPreferredDownload == 0);
1312+
assert(m_num_preferred_download_peers == 0);
13131313
assert(m_peers_downloading_from == 0);
13141314
assert(m_outbound_peers_with_protect_from_disconnect == 0);
13151315
assert(m_wtxid_relay_peers == 0);
@@ -1635,21 +1635,21 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
16351635

16361636
LOCK(cs_main);
16371637

1638-
if (pindex->nHeight <= nHighestFastAnnounce)
1638+
if (pindex->nHeight <= m_highest_fast_announce)
16391639
return;
1640-
nHighestFastAnnounce = pindex->nHeight;
1640+
m_highest_fast_announce = pindex->nHeight;
16411641

16421642
bool fWitnessEnabled = DeploymentActiveAt(*pindex, m_chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT);
16431643
uint256 hashBlock(pblock->GetHash());
16441644
const std::shared_future<CSerializedNetMsg> lazy_ser{
16451645
std::async(std::launch::deferred, [&] { return msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
16461646

16471647
{
1648-
LOCK(cs_most_recent_block);
1649-
most_recent_block_hash = hashBlock;
1650-
most_recent_block = pblock;
1651-
most_recent_compact_block = pcmpctblock;
1652-
fWitnessesPresentInMostRecentCompactBlock = fWitnessEnabled;
1648+
LOCK(m_most_recent_block_mutex);
1649+
m_most_recent_block_hash = hashBlock;
1650+
m_most_recent_block = pblock;
1651+
m_most_recent_compact_block = pcmpctblock;
1652+
m_most_recent_compact_block_has_witnesses = fWitnessEnabled;
16531653
}
16541654

16551655
m_connman.ForEachNode([this, pindex, fWitnessEnabled, &lazy_ser, &hashBlock](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
@@ -1856,10 +1856,10 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
18561856
std::shared_ptr<const CBlockHeaderAndShortTxIDs> a_recent_compact_block;
18571857
bool fWitnessesPresentInARecentCompactBlock;
18581858
{
1859-
LOCK(cs_most_recent_block);
1860-
a_recent_block = most_recent_block;
1861-
a_recent_compact_block = most_recent_compact_block;
1862-
fWitnessesPresentInARecentCompactBlock = fWitnessesPresentInMostRecentCompactBlock;
1859+
LOCK(m_most_recent_block_mutex);
1860+
a_recent_block = m_most_recent_block;
1861+
a_recent_compact_block = m_most_recent_compact_block;
1862+
fWitnessesPresentInARecentCompactBlock = m_most_recent_compact_block_has_witnesses;
18631863
}
18641864

18651865
bool need_activate_chain = false;
@@ -2735,7 +2735,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
27352735
LOCK(cs_main);
27362736
CNodeState* state = State(pfrom.GetId());
27372737
state->fPreferredDownload = (!pfrom.IsInboundConn() || pfrom.HasPermission(NetPermissionFlags::NoBan)) && !pfrom.IsAddrFetchConn() && !pfrom.fClient;
2738-
nPreferredDownload += state->fPreferredDownload;
2738+
m_num_preferred_download_peers += state->fPreferredDownload;
27392739
}
27402740

27412741
// Self advertisement & GETADDR logic
@@ -3158,8 +3158,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
31583158
{
31593159
std::shared_ptr<const CBlock> a_recent_block;
31603160
{
3161-
LOCK(cs_most_recent_block);
3162-
a_recent_block = most_recent_block;
3161+
LOCK(m_most_recent_block_mutex);
3162+
a_recent_block = m_most_recent_block;
31633163
}
31643164
BlockValidationState state;
31653165
if (!m_chainman.ActiveChainstate().ActivateBestChain(state, a_recent_block)) {
@@ -3210,10 +3210,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
32103210

32113211
std::shared_ptr<const CBlock> recent_block;
32123212
{
3213-
LOCK(cs_most_recent_block);
3214-
if (most_recent_block_hash == req.blockhash)
3215-
recent_block = most_recent_block;
3216-
// Unlock cs_most_recent_block to avoid cs_main lock inversion
3213+
LOCK(m_most_recent_block_mutex);
3214+
if (m_most_recent_block_hash == req.blockhash)
3215+
recent_block = m_most_recent_block;
3216+
// Unlock m_most_recent_block_mutex to avoid cs_main lock inversion
32173217
}
32183218
if (recent_block) {
32193219
SendBlockTransactions(pfrom, *recent_block, req);
@@ -4677,7 +4677,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
46774677
if (m_chainman.m_best_header == nullptr) {
46784678
m_chainman.m_best_header = m_chainman.ActiveChain().Tip();
46794679
}
4680-
bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->IsAddrFetchConn()); // Download if this is a nice peer, or we have no nice peers and this one might do.
4680+
bool fFetch = state.fPreferredDownload || (m_num_preferred_download_peers == 0 && !pto->fClient && !pto->IsAddrFetchConn()); // Download if this is a nice peer, or we have no nice peers and this one might do.
46814681
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) {
46824682
// Only actively request headers from a single peer, unless we're close to today.
46834683
if ((nSyncStarted == 0 && fFetch) || m_chainman.m_best_header->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) {
@@ -4782,12 +4782,12 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
47824782

47834783
bool fGotBlockFromCache = false;
47844784
{
4785-
LOCK(cs_most_recent_block);
4786-
if (most_recent_block_hash == pBestIndex->GetBlockHash()) {
4787-
if (state.fWantsCmpctWitness || !fWitnessesPresentInMostRecentCompactBlock)
4788-
m_connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, *most_recent_compact_block));
4785+
LOCK(m_most_recent_block_mutex);
4786+
if (m_most_recent_block_hash == pBestIndex->GetBlockHash()) {
4787+
if (state.fWantsCmpctWitness || !m_most_recent_compact_block_has_witnesses)
4788+
m_connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, *m_most_recent_compact_block));
47894789
else {
4790-
CBlockHeaderAndShortTxIDs cmpctblock(*most_recent_block, state.fWantsCmpctWitness);
4790+
CBlockHeaderAndShortTxIDs cmpctblock(*m_most_recent_block, state.fWantsCmpctWitness);
47914791
m_connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
47924792
}
47934793
fGotBlockFromCache = true;
@@ -5022,7 +5022,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
50225022
if (state.fSyncStarted && state.m_headers_sync_timeout < std::chrono::microseconds::max()) {
50235023
// Detect whether this is a stalling initial-headers-sync peer
50245024
if (m_chainman.m_best_header->GetBlockTime() <= GetAdjustedTime() - 24 * 60 * 60) {
5025-
if (current_time > state.m_headers_sync_timeout && nSyncStarted == 1 && (nPreferredDownload - state.fPreferredDownload >= 1)) {
5025+
if (current_time > state.m_headers_sync_timeout && nSyncStarted == 1 && (m_num_preferred_download_peers - state.fPreferredDownload >= 1)) {
50265026
// Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer,
50275027
// and we have others we could be using instead.
50285028
// Note: If all our peers are inbound, then we won't

0 commit comments

Comments
 (0)