@@ -582,7 +582,7 @@ class PeerManagerImpl final : public PeerManager
582
582
std::map<NodeId, PeerRef> m_peer_map GUARDED_BY (m_peer_mutex);
583
583
584
584
/* * 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);
586
586
587
587
/* * Get a pointer to a const CNodeState, used when not mutating the CNodeState object. */
588
588
const CNodeState* State (NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -611,7 +611,7 @@ class PeerManagerImpl final : public PeerManager
611
611
int m_outbound_peers_with_protect_from_disconnect GUARDED_BY (cs_main) = 0;
612
612
613
613
/* * 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 };
615
615
616
616
bool AlreadyHaveTx (const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
617
617
@@ -680,15 +680,15 @@ class PeerManagerImpl final : public PeerManager
680
680
std::chrono::seconds average_interval);
681
681
682
682
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 };
689
689
690
690
/* * Height of the highest block announced using BIP 152 high-bandwidth mode. */
691
- int nHighestFastAnnounce {0 };
691
+ int m_highest_fast_announce {0 };
692
692
693
693
/* * Have we requested this block from a peer */
694
694
bool IsBlockRequested (const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -834,8 +834,8 @@ class PeerManagerImpl final : public PeerManager
834
834
835
835
const CNodeState* PeerManagerImpl::State (NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
836
836
{
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 ())
839
839
return nullptr ;
840
840
return &it->second ;
841
841
}
@@ -1236,7 +1236,7 @@ void PeerManagerImpl::InitializeNode(CNode *pnode)
1236
1236
NodeId nodeid = pnode->GetId ();
1237
1237
{
1238
1238
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 ()));
1240
1240
assert (m_txrequest.Count (nodeid) == 0 );
1241
1241
}
1242
1242
PeerRef peer = std::make_shared<Peer>(nodeid, /* tx_relay=*/ !pnode->IsBlockOnlyConn ());
@@ -1298,18 +1298,18 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
1298
1298
}
1299
1299
WITH_LOCK (g_cs_orphans, m_orphanage.EraseForPeer (nodeid));
1300
1300
m_txrequest.DisconnectedPeer (nodeid);
1301
- nPreferredDownload -= state->fPreferredDownload ;
1301
+ m_num_preferred_download_peers -= state->fPreferredDownload ;
1302
1302
m_peers_downloading_from -= (state->nBlocksInFlight != 0 );
1303
1303
assert (m_peers_downloading_from >= 0 );
1304
1304
m_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync .m_protect ;
1305
1305
assert (m_outbound_peers_with_protect_from_disconnect >= 0 );
1306
1306
1307
- mapNodeState .erase (nodeid);
1307
+ m_node_states .erase (nodeid);
1308
1308
1309
- if (mapNodeState .empty ()) {
1309
+ if (m_node_states .empty ()) {
1310
1310
// Do a consistency check after the last peer is removed.
1311
1311
assert (mapBlocksInFlight.empty ());
1312
- assert (nPreferredDownload == 0 );
1312
+ assert (m_num_preferred_download_peers == 0 );
1313
1313
assert (m_peers_downloading_from == 0 );
1314
1314
assert (m_outbound_peers_with_protect_from_disconnect == 0 );
1315
1315
assert (m_wtxid_relay_peers == 0 );
@@ -1635,21 +1635,21 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
1635
1635
1636
1636
LOCK (cs_main);
1637
1637
1638
- if (pindex->nHeight <= nHighestFastAnnounce )
1638
+ if (pindex->nHeight <= m_highest_fast_announce )
1639
1639
return ;
1640
- nHighestFastAnnounce = pindex->nHeight ;
1640
+ m_highest_fast_announce = pindex->nHeight ;
1641
1641
1642
1642
bool fWitnessEnabled = DeploymentActiveAt (*pindex, m_chainparams.GetConsensus (), Consensus::DEPLOYMENT_SEGWIT);
1643
1643
uint256 hashBlock (pblock->GetHash ());
1644
1644
const std::shared_future<CSerializedNetMsg> lazy_ser{
1645
1645
std::async (std::launch::deferred, [&] { return msgMaker.Make (NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
1646
1646
1647
1647
{
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 ;
1653
1653
}
1654
1654
1655
1655
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&
1856
1856
std::shared_ptr<const CBlockHeaderAndShortTxIDs> a_recent_compact_block;
1857
1857
bool fWitnessesPresentInARecentCompactBlock ;
1858
1858
{
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 ;
1863
1863
}
1864
1864
1865
1865
bool need_activate_chain = false ;
@@ -2735,7 +2735,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
2735
2735
LOCK (cs_main);
2736
2736
CNodeState* state = State (pfrom.GetId ());
2737
2737
state->fPreferredDownload = (!pfrom.IsInboundConn () || pfrom.HasPermission (NetPermissionFlags::NoBan)) && !pfrom.IsAddrFetchConn () && !pfrom.fClient ;
2738
- nPreferredDownload += state->fPreferredDownload ;
2738
+ m_num_preferred_download_peers += state->fPreferredDownload ;
2739
2739
}
2740
2740
2741
2741
// Self advertisement & GETADDR logic
@@ -3158,8 +3158,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3158
3158
{
3159
3159
std::shared_ptr<const CBlock> a_recent_block;
3160
3160
{
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 ;
3163
3163
}
3164
3164
BlockValidationState state;
3165
3165
if (!m_chainman.ActiveChainstate ().ActivateBestChain (state, a_recent_block)) {
@@ -3210,10 +3210,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3210
3210
3211
3211
std::shared_ptr<const CBlock> recent_block;
3212
3212
{
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
3217
3217
}
3218
3218
if (recent_block) {
3219
3219
SendBlockTransactions (pfrom, *recent_block, req);
@@ -4677,7 +4677,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4677
4677
if (m_chainman.m_best_header == nullptr ) {
4678
4678
m_chainman.m_best_header = m_chainman.ActiveChain ().Tip ();
4679
4679
}
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.
4681
4681
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex ) {
4682
4682
// Only actively request headers from a single peer, unless we're close to today.
4683
4683
if ((nSyncStarted == 0 && fFetch ) || m_chainman.m_best_header ->GetBlockTime () > GetAdjustedTime () - 24 * 60 * 60 ) {
@@ -4782,12 +4782,12 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4782
4782
4783
4783
bool fGotBlockFromCache = false ;
4784
4784
{
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 ));
4789
4789
else {
4790
- CBlockHeaderAndShortTxIDs cmpctblock (*most_recent_block , state.fWantsCmpctWitness );
4790
+ CBlockHeaderAndShortTxIDs cmpctblock (*m_most_recent_block , state.fWantsCmpctWitness );
4791
4791
m_connman.PushMessage (pto, msgMaker.Make (nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
4792
4792
}
4793
4793
fGotBlockFromCache = true ;
@@ -5022,7 +5022,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5022
5022
if (state.fSyncStarted && state.m_headers_sync_timeout < std::chrono::microseconds::max ()) {
5023
5023
// Detect whether this is a stalling initial-headers-sync peer
5024
5024
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 )) {
5026
5026
// Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer,
5027
5027
// and we have others we could be using instead.
5028
5028
// Note: If all our peers are inbound, then we won't
0 commit comments