From 26c39f5b929edda6a0dea8d6e6bd58b3d4a69e7c Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Thu, 28 Mar 2024 19:07:00 +0000 Subject: [PATCH] net: replace RelayAddrsWithConn check with !IsBlockOnlyConn Dash uses a lot more CNode::RelayAddrsWithConn checks than Bitcoin (esp. since a483122f (#4888)), so bitcoin#21186 will not adequately cover the removal of RelayAddrsWithConn usages. When possible to query with RelayAddrsWithPeer, that should be used, as that value is the most reliable, else we rely on the former mutual exclusivity of IsBlockOnlyConn and RelayAddrsWithConn to fill in the blanks where a more reliable query isn't available. Note: To prevent builds from breaking, a change has been made in InstantSend code despite it breaking functionality. A commit later will repair it by creating a way to access RelayAddrsWithPeer. --- src/llmq/instantsend.cpp | 2 +- src/net.cpp | 10 +++++----- src/net.h | 2 +- src/net_processing.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/llmq/instantsend.cpp b/src/llmq/instantsend.cpp index a48e254181..927a8088ca 100644 --- a/src/llmq/instantsend.cpp +++ b/src/llmq/instantsend.cpp @@ -1458,7 +1458,7 @@ void CInstantSendManager::AskNodesForLockedTx(const uint256& txid, const CConnma if (nodesToAskFor.size() >= 4) { return; } - if (pnode->RelayAddrsWithConn()) { + if (!pnode->IsBlockOnlyConn()) { LOCK(pnode->m_tx_relay->cs_tx_inventory); if (pnode->m_tx_relay->filterInventoryKnown.contains(txid)) { pnode->AddRef(); diff --git a/src/net.cpp b/src/net.cpp index 3c922bc62b..1e1c2bf3bf 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -582,7 +582,7 @@ bool CNode::IsBlockRelayOnly() const { // Stop processing non-block data early if // 1) We are in blocks only mode and peer has no relay permission // 2) This peer is a block-relay-only peer - return (ignores_incoming_txs && !HasPermission(NetPermissionFlags::Relay)) || !RelayAddrsWithConn(); + return (ignores_incoming_txs && !HasPermission(NetPermissionFlags::Relay)) || IsBlockOnlyConn(); } std::string CNode::ConnectionTypeAsString() const @@ -651,7 +651,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector &m_asmap) X(addrBind); stats.m_network = ConnectedThroughNetwork(); stats.m_mapped_as = addr.GetMappedAS(m_asmap); - if (RelayAddrsWithConn()) { + if (!IsBlockOnlyConn()) { LOCK(m_tx_relay->cs_filter); stats.fRelayTxes = m_tx_relay->fRelayTxes; } else { @@ -1088,7 +1088,7 @@ bool CConnman::AttemptToEvictConnection() bool peer_relay_txes = false; bool peer_filter_not_null = false; - if (node->RelayAddrsWithConn()) { + if (!node->IsBlockOnlyConn()) { LOCK(node->m_tx_relay->cs_filter); peer_relay_txes = node->m_tx_relay->fRelayTxes; peer_filter_not_null = node->m_tx_relay->pfilter != nullptr; @@ -3897,7 +3897,7 @@ void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const { LOCK(cs_vNodes); for (const auto& pnode : vNodes) { - if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || !pnode->RelayAddrsWithConn()) { + if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || pnode->IsBlockOnlyConn()) { continue; } { @@ -3917,7 +3917,7 @@ void CConnman::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash, const i { LOCK(cs_vNodes); for (const auto& pnode : vNodes) { - if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || !pnode->RelayAddrsWithConn()) { + if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || pnode->IsBlockOnlyConn()) { continue; } { diff --git a/src/net.h b/src/net.h index 0725560b0e..0be08ba7aa 100644 --- a/src/net.h +++ b/src/net.h @@ -631,7 +631,7 @@ public: }; // in bitcoin: m_tx_relay == nullptr if we're not relaying transactions with this peer - // in dash: m_tx_relay should never be nullptr, use `RelayAddrsWithConn() == false` instead + // in dash: m_tx_relay should never be nullptr, use `!IsBlockOnlyConn() == false` instead std::unique_ptr m_tx_relay{std::make_unique()}; /** UNIX epoch time of the last block received from this peer that we had diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 2e9b18ff83..9bb5b0ef6b 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1075,7 +1075,7 @@ void PeerManagerImpl::PushNodeVersion(CNode& pnode, int64_t nTime) nProtocolVersion = gArgs.GetArg("-pushversion", PROTOCOL_VERSION); } - const bool tx_relay = !m_ignore_incoming_txs && pnode.RelayAddrsWithConn(); + const bool tx_relay = !m_ignore_incoming_txs && !pnode.IsBlockOnlyConn(); m_connman.PushMessage(&pnode, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERSION, nProtocolVersion, (uint64_t)nLocalNodeServices, nTime, addrYou, addrMe, nonce, strSubVersion, nNodeStartingHeight, tx_relay, mnauthChallenge, pnode.m_masternode_connection.load())); @@ -1315,7 +1315,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node) { } } // cs_main - if (node.fSuccessfullyConnected && misbehavior == 0 && node.RelayAddrsWithConn() && !node.IsInboundConn()) { + if (node.fSuccessfullyConnected && misbehavior == 0 && !node.IsBlockOnlyConn() && !node.IsInboundConn()) { // Only change visible addrman state for full outbound peers. We don't // call Connected() for feeler connections since they don't have // fSuccessfullyConnected set.