From d54ba447a7243862e5384e5b045b2e02eeb68496 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Fri, 5 Apr 2024 22:22:34 +0000 Subject: [PATCH] net: use ForEachNode instead of manually iterating through vNodes ForEachNode is publicly available, which will help us extract the functions from CConnman in a subsequent commit --- src/net.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index d39a891f8b07b..0326d4fd78a51 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -3934,52 +3934,49 @@ void CConnman::RelayTransaction(const CTransaction& tx, const bool is_dstx) } void CConnman::RelayInv(CInv &inv, const int minProtoVersion) { - LOCK(cs_vNodes); - for (const auto& pnode : vNodes) { + ForEachNode([&](CNode* pnode) { if (pnode->nVersion < minProtoVersion || !pnode->CanRelay()) - continue; + return; pnode->PushInventory(inv); - } + }); } void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const int minProtoVersion) { - LOCK(cs_vNodes); - for (const auto& pnode : vNodes) { + ForEachNode([&](CNode* pnode) { if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || pnode->IsBlockOnlyConn()) { - continue; + return; } { LOCK(pnode->m_tx_relay->cs_filter); if (!pnode->m_tx_relay->fRelayTxes) { - continue; + return; } if (pnode->m_tx_relay->pfilter && !pnode->m_tx_relay->pfilter->IsRelevantAndUpdate(relatedTx)) { - continue; + return; } } pnode->PushInventory(inv); - } + }); } void CConnman::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash, const int minProtoVersion) { - LOCK(cs_vNodes); - for (const auto& pnode : vNodes) { + ForEachNode([&](CNode* pnode) { if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || pnode->IsBlockOnlyConn()) { - continue; + return; } { LOCK(pnode->m_tx_relay->cs_filter); if (!pnode->m_tx_relay->fRelayTxes) { - continue; + return; } if (pnode->m_tx_relay->pfilter && !pnode->m_tx_relay->pfilter->contains(relatedTxHash)) { - continue; + return; } } pnode->PushInventory(inv); - } + }); } void CConnman::RecordBytesRecv(uint64_t bytes)