net: introduce CanRelayAddrs as RelayAddrsWithConn substitute

Since bitcoin#21186, mutual exclusivity is not a given (i.e.
RelayAddrsWithConn != !IsBlockOnlyConn), we should use RelayPeersWithConn
for a definitive answer and since relying on a no-longer-true property
breaks InstantSend, let's fetch the right answer instead.
This commit is contained in:
Kittywhiskers Van Gogh 2024-03-28 18:50:04 +00:00
parent 5478001a81
commit 2e55327f55
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
4 changed files with 18 additions and 6 deletions

View File

@ -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<CNode*> 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();

View File

@ -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();

View File

@ -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<bool>& 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)
{

View File

@ -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};