diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -275,10 +275,10 @@ }; /** Map maintaining per-node state. Requires cs_main. */ -std::map mapNodeState; +static std::map mapNodeState; // Requires cs_main. -CNodeState *State(NodeId pnode) { +static CNodeState *State(NodeId pnode) { std::map::iterator it = mapNodeState.find(pnode); if (it == mapNodeState.end()) { return nullptr; @@ -287,7 +287,7 @@ return &it->second; } -void UpdatePreferredDownload(CNode *node, CNodeState *state) { +static void UpdatePreferredDownload(CNode *node, CNodeState *state) { nPreferredDownload -= state->fPreferredDownload; // Whether this node should be marked as a preferred download node. @@ -297,8 +297,8 @@ nPreferredDownload += state->fPreferredDownload; } -void PushNodeVersion(const Config &config, CNode *pnode, CConnman *connman, - int64_t nTime) { +static void PushNodeVersion(const Config &config, CNode *pnode, + CConnman *connman, int64_t nTime) { ServiceFlags nLocalNodeServices = pnode->GetLocalServices(); uint64_t nonce = pnode->GetLocalNonce(); int nNodeStartingHeight = pnode->GetMyStartingHeight(); @@ -334,7 +334,7 @@ // Returns a bool indicating whether we requested this block. // Also used if a block was /not/ received and timed out or started with another // peer. -bool MarkBlockAsReceived(const uint256 &hash) { +static bool MarkBlockAsReceived(const uint256 &hash) { std::map::iterator>>::iterator itInFlight = mapBlocksInFlight.find(hash); @@ -381,7 +381,9 @@ itInFlight = mapBlocksInFlight.find(hash); if (itInFlight != mapBlocksInFlight.end() && itInFlight->second.first == nodeid) { - *pit = &itInFlight->second.second; + if (pit) { + *pit = &itInFlight->second.second; + } return false; } @@ -416,7 +418,7 @@ } /** Check whether the last unknown block a peer advertised is not yet known. */ -void ProcessBlockAvailability(NodeId nodeid) { +static void ProcessBlockAvailability(NodeId nodeid) { CNodeState *state = State(nodeid); assert(state != nullptr); @@ -435,7 +437,7 @@ } /** Update tracking information about which blocks a peer is assumed to have. */ -void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { +static void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { CNodeState *state = State(nodeid); assert(state != nullptr); @@ -455,7 +457,8 @@ } } -void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman *connman) { +static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, + CConnman *connman) { AssertLockHeld(cs_main); CNodeState *nodestate = State(nodeid); if (!nodestate) { @@ -503,7 +506,7 @@ }); } -bool TipMayBeStale(const Consensus::Params &consensusParams) { +static bool TipMayBeStale(const Consensus::Params &consensusParams) { AssertLockHeld(cs_main); if (g_last_tip_update == 0) { g_last_tip_update = GetTime(); @@ -514,13 +517,13 @@ } // Requires cs_main -bool CanDirectFetch(const Consensus::Params &consensusParams) { +static bool CanDirectFetch(const Consensus::Params &consensusParams) { return chainActive.Tip()->GetBlockTime() > GetAdjustedTime() - consensusParams.nPowTargetSpacing * 20; } // Requires cs_main -bool PeerHasHeader(CNodeState *state, const CBlockIndex *pindex) { +static bool PeerHasHeader(CNodeState *state, const CBlockIndex *pindex) { if (state->pindexBestKnownBlock && pindex == state->pindexBestKnownBlock->GetAncestor(pindex->nHeight)) { return true; @@ -536,10 +539,10 @@ * Update pindexLastCommonBlock and add not-in-flight missing successors to * vBlocks, until it has at most count entries. */ -void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, - std::vector &vBlocks, - NodeId &nodeStaller, - const Consensus::Params &consensusParams) { +static void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, + std::vector &vBlocks, + NodeId &nodeStaller, + const Consensus::Params &consensusParams) { if (count == 0) { return; } @@ -651,7 +654,7 @@ // Returns true for outbound peers, excluding manual connections, feelers, and // one-shots. -bool IsOutboundDisconnectionCandidate(const CNode *node) { +static bool IsOutboundDisconnectionCandidate(const CNode *node) { return !(node->fInbound || node->m_manual_connection || node->fFeeler || node->fOneShot); } @@ -735,7 +738,7 @@ // mapOrphanTransactions // -void AddToCompactExtraTransactions(const CTransactionRef &tx) { +static void AddToCompactExtraTransactions(const CTransactionRef &tx) { size_t max_extra_txn = gArgs.GetArg("-blockreconstructionextratxn", DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN); if (max_extra_txn <= 0) { @@ -2101,9 +2104,7 @@ std::vector vToFetch; - for (size_t nInv = 0; nInv < vInv.size(); nInv++) { - CInv &inv = vInv[nInv]; - + for (CInv &inv : vInv) { if (interruptMsgProc) { return true; } @@ -2468,7 +2469,7 @@ } } - for (uint256 hash : vEraseQueue) { + for (const uint256 &hash : vEraseQueue) { EraseOrphanTx(hash); } } else if (fMissingInputs) { @@ -3545,11 +3546,12 @@ m_stale_tip_check_time = time_in_seconds + STALE_CHECK_INTERVAL; } +namespace { class CompareInvMempoolOrder { CTxMemPool *mp; public: - CompareInvMempoolOrder(CTxMemPool *_mempool) { mp = _mempool; } + explicit CompareInvMempoolOrder(CTxMemPool *_mempool) { mp = _mempool; } bool operator()(std::set::iterator a, std::set::iterator b) { @@ -3558,6 +3560,7 @@ return mp->CompareDepthAndScore(*b, *a); } }; +} bool PeerLogicValidation::SendMessages(const Config &config, CNode *pto, std::atomic &interruptMsgProc) {