Skip to content

Commit 18f636f

Browse files
PastaPastaPastaknst
authored andcommitted
Merge dashpay#6426: fix: respect SENDDSQUEUE message, move DSQ relay into net processing / peerman
dafa736 fix: respect SENDDSQUEUE message, move DSQ relay into net processing / peerman (pasta) Pull request description: ## Issue being fixed or feature implemented in dashpay#6148, I broke the functionality where a peer must opt in / opt out of DSQUEUE messages. This was mostly ok, and not immediately detected, as with this bug, simply everyone would receive DSQ messages over inventory (or classically, old proto versions were not affected by this bug). But this still would result in quite a bit of wasted bandwidth for peers which may not care about DSQ at all. ## What was done? This commit should restore the prior functionality, where a node should send the SENDDSQUEUE message if they wish to receive DSQs. Once they've sent that, depending on their protocol version, they will either have the messages pushed to them as available, or on modern protocols, they will thereafter receive DSQs over the inventory system. NOTE: I also refactor the code in this commit, moving some network proccessing into.... wait for it... net_processing.cpp! This allowed us to remove some dependencies in coinjoin.h. DSQ messages are now relayed to peers by calling peer_manager.RelayDSQ ## How Has This Been Tested? I have not yet mixed on testnet with this; we should include it in rc.2 and test ## Breaking Changes Slightly breaking for v22.0.x (so rc.1), as they in theory could be relying on this new logic of always receiving the DSQ inv. But I don't think anyone besides core is using this new protocol. ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone ACKs for top commit: UdjinM6: light ACK dafa736 kwvg: utACK dafa736 Tree-SHA512: 18f9b0dfe05cde19db451653db9bb9a00352efd1bc37adffd83f74958010475f2782b1111b1c0d2dd967e7a851c3c4795fa55033b4bd0cc810aa293e754ce314
1 parent 9fed456 commit 18f636f

File tree

8 files changed

+55
-23
lines changed

8 files changed

+55
-23
lines changed

src/coinjoin/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS
132132
WITH_LOCK(cs_vecqueue, vecCoinJoinQueue.push_back(dsq));
133133
}
134134
} // cs_ProcessDSQueue
135-
dsq.Relay(connman, *peerman);
135+
peerman->RelayDSQ(dsq);
136136
return {};
137137
}
138138

src/coinjoin/client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CMasternodeSync;
2828
class CNode;
2929
class CoinJoinWalletManager;
3030
class CTxMemPool;
31+
class PeerManager;
3132

3233
class UniValue;
3334

src/coinjoin/coinjoin.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <masternode/node.h>
1515
#include <masternode/sync.h>
1616
#include <messagesigner.h>
17-
#include <net_processing.h>
1817
#include <netmessagemaker.h>
1918
#include <txmempool.h>
2019
#include <util/moneystr.h>
@@ -71,19 +70,6 @@ bool CCoinJoinQueue::CheckSignature(const CBLSPublicKey& blsPubKey) const
7170
return true;
7271
}
7372

74-
bool CCoinJoinQueue::Relay(CConnman& connman, PeerManager& peerman)
75-
{
76-
CInv inv(MSG_DSQ, GetHash());
77-
peerman.RelayInv(inv, DSQ_INV_VERSION);
78-
connman.ForEachNode([&connman, this](CNode* pnode) {
79-
CNetMsgMaker msgMaker(pnode->GetCommonVersion());
80-
if (pnode->fSendDSQueue && pnode->nVersion < DSQ_INV_VERSION) {
81-
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSQUEUE, (*this)));
82-
}
83-
});
84-
return true;
85-
}
86-
8773
bool CCoinJoinQueue::IsTimeOutOfBounds(int64_t current_time) const
8874
{
8975
return current_time - nTime > COINJOIN_QUEUE_TIMEOUT ||

src/coinjoin/coinjoin.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424

2525
class CActiveMasternodeManager;
2626
class CChainState;
27-
class CConnman;
2827
class CBLSPublicKey;
2928
class CBlockIndex;
3029
class ChainstateManager;
3130
class CMasternodeSync;
3231
class CTxMemPool;
3332
class TxValidationState;
34-
class PeerManager;
3533

3634
namespace llmq {
3735
class CChainLocksHandler;
@@ -221,8 +219,6 @@ class CCoinJoinQueue
221219
/// Check if we have a valid Masternode address
222220
[[nodiscard]] bool CheckSignature(const CBLSPublicKey& blsPubKey) const;
223221

224-
bool Relay(CConnman& connman, PeerManager& peerman);
225-
226222
/// Check if a queue is too old or too far into the future
227223
[[nodiscard]] bool IsTimeOutOfBounds(int64_t current_time = GetAdjustedTime()) const;
228224

src/coinjoin/server.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ PeerMsgRet CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv
186186
TRY_LOCK(cs_vecqueue, lockRecv);
187187
if (!lockRecv) return {};
188188
vecCoinJoinQueue.push_back(dsq);
189-
dsq.Relay(connman, *m_peerman);
189+
m_peerman->RelayDSQ(dsq);
190190
}
191191
return {};
192192
}
@@ -519,7 +519,7 @@ void CCoinJoinServer::CheckForCompleteQueue()
519519
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CheckForCompleteQueue -- queue is ready, signing and relaying (%s) " /* Continued */
520520
"with %d participants\n", dsq.ToString(), vecSessionCollaterals.size());
521521
dsq.Sign(*m_mn_activeman);
522-
dsq.Relay(connman, *m_peerman);
522+
m_peerman->RelayDSQ(dsq);
523523
}
524524
}
525525

@@ -732,7 +732,7 @@ bool CCoinJoinServer::CreateNewSession(const CCoinJoinAccept& dsa, PoolMessage&
732732
GetAdjustedTime(), false);
733733
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString());
734734
dsq.Sign(*m_mn_activeman);
735-
dsq.Relay(connman, *m_peerman);
735+
m_peerman->RelayDSQ(dsq);
736736
LOCK(cs_vecqueue);
737737
vecCoinJoinQueue.push_back(dsq);
738738
}

src/coinjoin/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class CActiveMasternodeManager;
1313
class CCoinJoinServer;
14+
class CConnman;
1415
class CDataStream;
1516
class CDeterministicMNManager;
1617
class CDSTXManager;

src/net_processing.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,15 @@ struct Peer {
366366
/** Whether the peer has signaled support for receiving ADDRv2 (BIP155)
367367
* messages, indicating a preference to receive ADDRv2 instead of ADDR ones. */
368368
std::atomic_bool m_wants_addrv2{false};
369+
370+
enum class WantsDSQ {
371+
NONE, // Peer doesn't want DSQs
372+
INV, // Peer will be notified of DSQs over Inventory System (see: DSQ_INV_VERSION)
373+
ALL, // Peer will be notified of all DSQs, by simply sending them the DSQ
374+
};
375+
376+
std::atomic<WantsDSQ> m_wants_dsq{WantsDSQ::NONE};
377+
369378
/** Whether this peer has already sent us a getaddr message. */
370379
bool m_getaddr_recvd GUARDED_BY(NetEventsInterface::g_msgproc_mutex){false};
371380
/** Number of addresses that can be processed from this peer. Start at 1 to
@@ -607,6 +616,7 @@ class PeerManagerImpl final : public PeerManager
607616
void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
608617
void RelayInvFiltered(CInv &inv, const uint256 &relatedTxHash, const int minProtoVersion) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
609618
void RelayTransaction(const uint256& txid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
619+
void RelayDSQ(const CCoinJoinQueue& queue) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
610620
void SetBestHeight(int height) override { m_best_height = height; };
611621
void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message = "") override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
612622
void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
@@ -2276,6 +2286,34 @@ void PeerManagerImpl::RelayInv(CInv &inv, const int minProtoVersion)
22762286
});
22772287
}
22782288

2289+
void PeerManagerImpl::RelayDSQ(const CCoinJoinQueue& queue)
2290+
{
2291+
CInv inv{MSG_DSQ, queue.GetHash()};
2292+
std::vector<NodeId> nodes_send_all;
2293+
{
2294+
LOCK(m_peer_mutex);
2295+
for (const auto& [nodeid, peer] : m_peer_map) {
2296+
switch (peer->m_wants_dsq) {
2297+
case Peer::WantsDSQ::NONE:
2298+
break;
2299+
case Peer::WantsDSQ::INV:
2300+
PushInv(*peer, inv);
2301+
break;
2302+
case Peer::WantsDSQ::ALL:
2303+
nodes_send_all.push_back(nodeid);
2304+
break;
2305+
}
2306+
}
2307+
}
2308+
for (auto nodeId : nodes_send_all) {
2309+
m_connman.ForNode(nodeId, [&](CNode* pnode) -> bool {
2310+
CNetMsgMaker msgMaker(pnode->GetCommonVersion());
2311+
m_connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSQUEUE, queue));
2312+
return true;
2313+
});
2314+
}
2315+
}
2316+
22792317
void PeerManagerImpl::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const int minProtoVersion)
22802318
{
22812319
// TODO: Migrate to iteration through m_peer_map
@@ -3940,7 +3978,13 @@ void PeerManagerImpl::ProcessMessage(
39403978
{
39413979
bool b;
39423980
vRecv >> b;
3943-
pfrom.fSendDSQueue = b;
3981+
if (!b) {
3982+
peer->m_wants_dsq = Peer::WantsDSQ::NONE;
3983+
} else if (pfrom.GetCommonVersion() < DSQ_INV_VERSION) {
3984+
peer->m_wants_dsq = Peer::WantsDSQ::ALL;
3985+
} else {
3986+
peer->m_wants_dsq = Peer::WantsDSQ::INV;
3987+
}
39443988
return;
39453989
}
39463990

src/net_processing.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class CActiveMasternodeManager;
1717
class AddrMan;
1818
class CTxMemPool;
19+
class CCoinJoinQueue;
1920
class CDeterministicMNManager;
2021
class CMasternodeMetaMan;
2122
class CMasternodeSync;
@@ -93,6 +94,9 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
9394
/** Broadcast inventory message to a specific peer. */
9495
virtual void PushInventory(NodeId nodeid, const CInv& inv) = 0;
9596

97+
/** Relay DSQ based on peer preference */
98+
virtual void RelayDSQ(const CCoinJoinQueue& queue) = 0;
99+
96100
/** Relay inventories to all peers */
97101
virtual void RelayInv(CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION) = 0;
98102
virtual void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx,

0 commit comments

Comments
 (0)