mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
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:
parent
5478001a81
commit
2e55327f55
@ -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
|
// bump mempool counter to make sure newly locked txes are picked up by getblocktemplate
|
||||||
mempool.AddTransactionsUpdated(1);
|
mempool.AddTransactionsUpdated(1);
|
||||||
} else {
|
} 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) {
|
for (const auto& p : toDelete) {
|
||||||
RemoveConflictedTx(*p.second);
|
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;
|
std::vector<CNode*> nodesToAskFor;
|
||||||
nodesToAskFor.reserve(4);
|
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) {
|
if (nodesToAskFor.size() >= 4) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!pnode->IsBlockOnlyConn()) {
|
if (peerman.CanRelayAddrs(pnode->GetId())) {
|
||||||
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();
|
||||||
|
@ -299,7 +299,7 @@ private:
|
|||||||
|
|
||||||
void RemoveMempoolConflictsForLock(const uint256& hash, const CInstantSendLock& islock);
|
void RemoveMempoolConflictsForLock(const uint256& hash, const CInstantSendLock& islock);
|
||||||
void ResolveBlockConflicts(const uint256& islockHash, const CInstantSendLock& islock) LOCKS_EXCLUDED(cs_pendingLocks, cs_nonLocked);
|
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 ProcessPendingRetryLockTxs() LOCKS_EXCLUDED(cs_creating, cs_nonLocked, cs_pendingRetry);
|
||||||
|
|
||||||
void WorkThreadMain();
|
void WorkThreadMain();
|
||||||
|
@ -325,6 +325,7 @@ public:
|
|||||||
void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
|
void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
|
||||||
const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) override;
|
const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) override;
|
||||||
bool IsBanned(NodeId pnode) override EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
bool IsBanned(NodeId pnode) override EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
bool CanRelayAddrs(NodeId pnode) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Helper to process result of external handlers of message */
|
/** Helper to process result of external handlers of message */
|
||||||
@ -1630,6 +1631,14 @@ bool PeerManagerImpl::IsBanned(NodeId pnode)
|
|||||||
return false;
|
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 PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,
|
||||||
bool via_compact_block, const std::string& message)
|
bool via_compact_block, const std::string& message)
|
||||||
{
|
{
|
||||||
|
@ -87,6 +87,9 @@ public:
|
|||||||
|
|
||||||
virtual bool IsBanned(NodeId pnode) = 0;
|
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
|
/** Whether we've completed initial sync yet, for determining when to turn
|
||||||
* on extra block-relay-only peers. */
|
* on extra block-relay-only peers. */
|
||||||
bool m_initial_sync_finished{false};
|
bool m_initial_sync_finished{false};
|
||||||
|
Loading…
Reference in New Issue
Block a user