Skip to content

Commit

Permalink
refactor: replace RelayAddrsWithConn check with !IsBlockOnlyConn
Browse files Browse the repository at this point in the history
Dash uses a lot more CNode::RelayAddrsWithConn checks than Bitcoin (esp.
since a483122 (dashpay#4888)), so bitcoin#21186 will not adequately cover the
removal of RelayAddrsWithConn usages. As IsBlockOnlyConn and
RelayAddrsWithConn are mutually exclusive and bitcoin#21186 does away
with RelayAddrsWithConn, we can replace all Dash-added usages of
RelayAddrsWithConn with NOT IsBlockOnlyConn checks instead.
  • Loading branch information
kwvg committed Mar 28, 2024
1 parent e1ba12d commit 6de440f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/llmq/instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -651,7 +651,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3899,7 +3899,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;
}
{
Expand All @@ -3919,7 +3919,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;
}
{
Expand Down
2 changes: 1 addition & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ class CNode
};

// 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>()};

/** UNIX epoch time of the last block received from this peer that we had
Expand Down
26 changes: 13 additions & 13 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -2142,7 +2142,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
} else if (inv.IsMsgFilteredBlk()) {
bool sendMerkleBlock = false;
CMerkleBlock merkleBlock;
if (pfrom.RelayAddrsWithConn()) {
if (!pfrom.IsBlockOnlyConn()) {
LOCK(pfrom.m_tx_relay->cs_filter);
if (pfrom.m_tx_relay->pfilter) {
sendMerkleBlock = true;
Expand Down Expand Up @@ -2245,8 +2245,8 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic

const std::chrono::seconds now = GetTime<std::chrono::seconds>();
// Get last mempool request time
const std::chrono::seconds mempool_req = pfrom.RelayAddrsWithConn() ? pfrom.m_tx_relay->m_last_mempool_req.load()
: std::chrono::seconds::min();
const std::chrono::seconds mempool_req = !pfrom.IsBlockOnlyConn() ? pfrom.m_tx_relay->m_last_mempool_req.load()
: std::chrono::seconds::min();

// Process as many TX items from the front of the getdata queue as
// possible, since they're common and it's efficient to batch process
Expand All @@ -2266,7 +2266,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
}
++it;

if (!pfrom.RelayAddrsWithConn() && NetMessageViolatesBlocksOnly(inv.GetCommand())) {
if (pfrom.IsBlockOnlyConn() && NetMessageViolatesBlocksOnly(inv.GetCommand())) {
// Note that if we receive a getdata for non-block messages
// from a block-relay-only outbound peer that violate the policy,
// we skip such getdata messages from this peer
Expand Down Expand Up @@ -3109,7 +3109,7 @@ void PeerManagerImpl::ProcessMessage(
// set nodes not capable of serving the complete blockchain history as "limited nodes"
pfrom.m_limited_node = (!(nServices & NODE_NETWORK) && (nServices & NODE_NETWORK_LIMITED));

if (pfrom.RelayAddrsWithConn()) {
if (!pfrom.IsBlockOnlyConn()) {
LOCK(pfrom.m_tx_relay->cs_filter);
pfrom.m_tx_relay->fRelayTxes = fRelay; // set to true after we get the first filter* message
}
Expand Down Expand Up @@ -4292,7 +4292,7 @@ void PeerManagerImpl::ProcessMessage(
return;
}

if (pfrom.RelayAddrsWithConn()) {
if (!pfrom.IsBlockOnlyConn()) {
LOCK(pfrom.m_tx_relay->cs_tx_inventory);
pfrom.m_tx_relay->fSendMempool = true;
}
Expand Down Expand Up @@ -4386,7 +4386,7 @@ void PeerManagerImpl::ProcessMessage(
// There is no excuse for sending a too-large filter
Misbehaving(pfrom.GetId(), 100, "too-large bloom filter");
}
else if (pfrom.RelayAddrsWithConn())
else if (!pfrom.IsBlockOnlyConn())
{
LOCK(pfrom.m_tx_relay->cs_filter);
pfrom.m_tx_relay->pfilter.reset(new CBloomFilter(filter));
Expand All @@ -4409,7 +4409,7 @@ void PeerManagerImpl::ProcessMessage(
bool bad = false;
if (vData.size() > MAX_SCRIPT_ELEMENT_SIZE) {
bad = true;
} else if (pfrom.RelayAddrsWithConn()) {
} else if (!pfrom.IsBlockOnlyConn()) {
LOCK(pfrom.m_tx_relay->cs_filter);
if (pfrom.m_tx_relay->pfilter) {
pfrom.m_tx_relay->pfilter->insert(vData);
Expand All @@ -4429,7 +4429,7 @@ void PeerManagerImpl::ProcessMessage(
pfrom.fDisconnect = true;
return;
}
if (!pfrom.RelayAddrsWithConn()) {
if (pfrom.IsBlockOnlyConn()) {
return;
}
LOCK(pfrom.m_tx_relay->cs_filter);
Expand Down Expand Up @@ -5216,7 +5216,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
LOCK2(m_mempool.cs, peer->m_block_inv_mutex);

size_t reserve = INVENTORY_BROADCAST_MAX_PER_1MB_BLOCK * MaxBlockSize() / 1000000;
if (pto->RelayAddrsWithConn()) {
if (!pto->IsBlockOnlyConn()) {
LOCK(pto->m_tx_relay->cs_tx_inventory);
reserve = std::min<size_t>(pto->m_tx_relay->setInventoryTxToSend.size(), reserve);
}
Expand Down Expand Up @@ -5247,7 +5247,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
}
};

if (pto->RelayAddrsWithConn()) {
if (!pto->IsBlockOnlyConn()) {
LOCK(pto->m_tx_relay->cs_tx_inventory);
// Check whether periodic sends should happen
// Note: If this node is running in a Masternode mode, it makes no sense to delay outgoing txes
Expand Down

0 comments on commit 6de440f

Please sign in to comment.