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.
This commit is contained in:
Kittywhiskers Van Gogh 2024-03-28 19:07:00 +00:00
parent 4844e729e2
commit 26c39f5b92
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
4 changed files with 9 additions and 9 deletions

View File

@ -1458,7 +1458,7 @@ void CInstantSendManager::AskNodesForLockedTx(const uint256& txid, const CConnma
if (nodesToAskFor.size() >= 4) { if (nodesToAskFor.size() >= 4) {
return; return;
} }
if (pnode->RelayAddrsWithConn()) { if (!pnode->IsBlockOnlyConn()) {
LOCK(pnode->m_tx_relay->cs_tx_inventory); LOCK(pnode->m_tx_relay->cs_tx_inventory);
if (pnode->m_tx_relay->filterInventoryKnown.contains(txid)) { if (pnode->m_tx_relay->filterInventoryKnown.contains(txid)) {
pnode->AddRef(); pnode->AddRef();

View File

@ -582,7 +582,7 @@ bool CNode::IsBlockRelayOnly() const {
// Stop processing non-block data early if // Stop processing non-block data early if
// 1) We are in blocks only mode and peer has no relay permission // 1) We are in blocks only mode and peer has no relay permission
// 2) This peer is a block-relay-only peer // 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 std::string CNode::ConnectionTypeAsString() const
@ -651,7 +651,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
X(addrBind); X(addrBind);
stats.m_network = ConnectedThroughNetwork(); stats.m_network = ConnectedThroughNetwork();
stats.m_mapped_as = addr.GetMappedAS(m_asmap); stats.m_mapped_as = addr.GetMappedAS(m_asmap);
if (RelayAddrsWithConn()) { if (!IsBlockOnlyConn()) {
LOCK(m_tx_relay->cs_filter); LOCK(m_tx_relay->cs_filter);
stats.fRelayTxes = m_tx_relay->fRelayTxes; stats.fRelayTxes = m_tx_relay->fRelayTxes;
} else { } else {
@ -1088,7 +1088,7 @@ bool CConnman::AttemptToEvictConnection()
bool peer_relay_txes = false; bool peer_relay_txes = false;
bool peer_filter_not_null = false; bool peer_filter_not_null = false;
if (node->RelayAddrsWithConn()) { if (!node->IsBlockOnlyConn()) {
LOCK(node->m_tx_relay->cs_filter); LOCK(node->m_tx_relay->cs_filter);
peer_relay_txes = node->m_tx_relay->fRelayTxes; peer_relay_txes = node->m_tx_relay->fRelayTxes;
peer_filter_not_null = node->m_tx_relay->pfilter != nullptr; 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); LOCK(cs_vNodes);
for (const auto& pnode : vNodes) { for (const auto& pnode : vNodes) {
if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || !pnode->RelayAddrsWithConn()) { if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || pnode->IsBlockOnlyConn()) {
continue; continue;
} }
{ {
@ -3917,7 +3917,7 @@ void CConnman::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash, const i
{ {
LOCK(cs_vNodes); LOCK(cs_vNodes);
for (const auto& pnode : vNodes) { for (const auto& pnode : vNodes) {
if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || !pnode->RelayAddrsWithConn()) { if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || pnode->IsBlockOnlyConn()) {
continue; continue;
} }
{ {

View File

@ -631,7 +631,7 @@ public:
}; };
// in bitcoin: m_tx_relay == nullptr if we're not relaying transactions with this peer // 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<TxRelay> m_tx_relay{std::make_unique<TxRelay>()}; std::unique_ptr<TxRelay> m_tx_relay{std::make_unique<TxRelay>()};
/** UNIX epoch time of the last block received from this peer that we had /** UNIX epoch time of the last block received from this peer that we had

View File

@ -1075,7 +1075,7 @@ void PeerManagerImpl::PushNodeVersion(CNode& pnode, int64_t nTime)
nProtocolVersion = gArgs.GetArg("-pushversion", PROTOCOL_VERSION); 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, 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())); nonce, strSubVersion, nNodeStartingHeight, tx_relay, mnauthChallenge, pnode.m_masternode_connection.load()));
@ -1315,7 +1315,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node) {
} }
} // cs_main } // 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 // Only change visible addrman state for full outbound peers. We don't
// call Connected() for feeler connections since they don't have // call Connected() for feeler connections since they don't have
// fSuccessfullyConnected set. // fSuccessfullyConnected set.