diff --git a/src/llmq/instantsend.cpp b/src/llmq/instantsend.cpp index 927a8088ca..c0ba51d3bd 100644 --- a/src/llmq/instantsend.cpp +++ b/src/llmq/instantsend.cpp @@ -1068,7 +1068,7 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, const uint256& has // bump mempool counter to make sure newly locked txes are picked up by getblocktemplate mempool.AddTransactionsUpdated(1); } else { - AskNodesForLockedTx(islock->txid, connman); + AskNodesForLockedTx(islock->txid, connman, *m_peerman.load()); } } @@ -1344,7 +1344,7 @@ void CInstantSendManager::RemoveMempoolConflictsForLock(const uint256& hash, con for (const auto& p : toDelete) { RemoveConflictedTx(*p.second); } - AskNodesForLockedTx(islock.txid, connman); + AskNodesForLockedTx(islock.txid, connman, *m_peerman.load()); } } @@ -1449,16 +1449,16 @@ void CInstantSendManager::RemoveConflictingLock(const uint256& islockHash, const } } -void CInstantSendManager::AskNodesForLockedTx(const uint256& txid, const CConnman& connman) +void CInstantSendManager::AskNodesForLockedTx(const uint256& txid, const CConnman& connman, const PeerManager& peerman) { std::vector nodesToAskFor; nodesToAskFor.reserve(4); - auto maybe_add_to_nodesToAskFor = [&nodesToAskFor, &txid](CNode* pnode) { + auto maybe_add_to_nodesToAskFor = [&peerman, &nodesToAskFor, &txid](CNode* pnode) { if (nodesToAskFor.size() >= 4) { return; } - if (!pnode->IsBlockOnlyConn()) { + if (peerman.CanRelayAddrs(pnode->GetId())) { LOCK(pnode->m_tx_relay->cs_tx_inventory); if (pnode->m_tx_relay->filterInventoryKnown.contains(txid)) { pnode->AddRef(); diff --git a/src/llmq/instantsend.h b/src/llmq/instantsend.h index bddf057f6a..cd141b65b5 100644 --- a/src/llmq/instantsend.h +++ b/src/llmq/instantsend.h @@ -299,7 +299,7 @@ private: void RemoveMempoolConflictsForLock(const uint256& hash, const CInstantSendLock& islock); void ResolveBlockConflicts(const uint256& islockHash, const CInstantSendLock& islock) LOCKS_EXCLUDED(cs_pendingLocks, cs_nonLocked); - static void AskNodesForLockedTx(const uint256& txid, const CConnman& connman); + static void AskNodesForLockedTx(const uint256& txid, const CConnman& connman, const PeerManager& peerman); void ProcessPendingRetryLockTxs() LOCKS_EXCLUDED(cs_creating, cs_nonLocked, cs_pendingRetry); void WorkThreadMain(); diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 34330318ee..47ba9c613d 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -325,6 +325,7 @@ public: void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv, const std::chrono::microseconds time_received, const std::atomic& interruptMsgProc) override; bool IsBanned(NodeId pnode) override EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool CanRelayAddrs(NodeId pnode) const override; private: /** Helper to process result of external handlers of message */ @@ -1630,6 +1631,14 @@ bool PeerManagerImpl::IsBanned(NodeId pnode) return false; } +bool PeerManagerImpl::CanRelayAddrs(NodeId pnode) const +{ + PeerRef peer = GetPeerRef(pnode); + if (peer == nullptr) + return false; + return RelayAddrsWithPeer(*peer); +} + bool PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state, bool via_compact_block, const std::string& message) { diff --git a/src/net_processing.h b/src/net_processing.h index d868d10256..680dd2cae5 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -87,6 +87,9 @@ public: virtual bool IsBanned(NodeId pnode) = 0; + /* Can we send addr messages to a peer. Used by InstantSend. */ + virtual bool CanRelayAddrs(NodeId pnode) const = 0; + /** Whether we've completed initial sync yet, for determining when to turn * on extra block-relay-only peers. */ bool m_initial_sync_finished{false};