Skip to content

Commit 9a5644a

Browse files
Merge #6840: refactor: move CDSTXManager to NodeContext, abstract wallet-only CoinJoin managers behind interface, s/CJContext/CJWalletManager/g
6a20464 refactor: `s/CJContext/CJWalletManager/g` (Kittywhiskers Van Gogh) 4f3da68 refactor: drop `m_is_masternode` from `CoinJoinWalletManager` (Kittywhiskers Van Gogh) 5bd1a6b refactor: drop `m_is_masternode` from `CCoinJoinClientQueueManager` (Kittywhiskers Van Gogh) 1a35a65 refactor: drop `mn_activeman` from `CJContext` (Kittywhiskers Van Gogh) 80c201b refactor: make `CJContext` an interface, move implementation to source (Kittywhiskers Van Gogh) d56879f refactor: restrict access to CoinJoin wallet managers (Kittywhiskers Van Gogh) cd77127 refactor: separate `MisbehavingError` and `MessageProcessingResult` (Kittywhiskers Van Gogh) 9d06491 refactor: allow `MessageProcessingResult` to submit DSQ messages (Kittywhiskers Van Gogh) cebe18b refactor: remove `ENABLE_WALLET` from `dsnotificationinterface.cpp` (Kittywhiskers Van Gogh) 2606d8c refactor: obscure scheduled CoinJoin tasks by moving into context (Kittywhiskers Van Gogh) e786b4c refactor: move CDSTXManager out of CJContext (Kittywhiskers Van Gogh) Pull request description: ## Additional Information * Depends on #6828 * Depends on #6839 * As part of efforts in reducing `ENABLE_WALLET` proliferation in non-wallet code, this pull request isolates wallet-specific logic by abstracting implementation details of CoinJoin wallet managers in a manner similar to `PeerManager` ([source](https://github.com/dashpay/dash/blob/cae0bff3ee3d19628b255f36d17f5f62770cc3c2/src/net_processing.h#L55)). * Additionally, as it is now conditionally initialized (as opposed to current `develop` behavior of unconditional initialization and bailout), we get to reduce the footprint of `CActiveMasternodeManager`, which is part of a larger initiative to isolate masternode-mode logic. * `MisbehavingError` and `MessageProcessingResult` were extracted to `msg_processing.h` as support for relaying DSQ messages requires including `coinjoin/coinjoin.h` which creates a circular dependency issue if left as-is in `protocol.h` (as it is in `develop`), see below. ``` A new circular dependency in the form of "chainparams -> protocol -> coinjoin/coinjoin -> chainparams" appears to have been introduced. ``` Moving the constructor definitions to a source file would not have resolved this as circular dependencies treat the source file and header as one unit. ## How Has This Been Tested? A full CoinJoin session run on 6a20464 ![CoinJoin session run on build 6a20464](https://github.com/user-attachments/assets/6041c1b8-fa23-44dc-a1af-6da32c503a9c) ## Breaking Changes None expected. ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: PastaPastaPasta: utACK 6a20464 UdjinM6: light ACK 6a20464 Tree-SHA512: a713876f03df60933a80e569f0c1153f054daa0d15e1e833c542ccd408f5b391a23a5e857bfda4a99f3e24e544aecbda7e76abae962598e835cebb558c227528
2 parents 88121b0 + 6a20464 commit 9a5644a

39 files changed

+571
-438
lines changed

src/Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ BITCOIN_CORE_H = \
179179
coinjoin/coinjoin.h \
180180
coinjoin/client.h \
181181
coinjoin/common.h \
182-
coinjoin/context.h \
183182
coinjoin/options.h \
184183
coinjoin/server.h \
185184
coinjoin/util.h \
185+
coinjoin/walletman.h \
186186
coins.h \
187187
common/bloom.h \
188188
compat/assumptions.h \
@@ -292,6 +292,7 @@ BITCOIN_CORE_H = \
292292
memusage.h \
293293
merkleblock.h \
294294
messagesigner.h \
295+
msg_result.h \
295296
net.h \
296297
net_permissions.h \
297298
net_processing.h \
@@ -486,8 +487,8 @@ libbitcoin_node_a_SOURCES = \
486487
chainlock/clsig.cpp \
487488
chainlock/signing.cpp \
488489
coinjoin/coinjoin.cpp \
489-
coinjoin/context.cpp \
490490
coinjoin/server.cpp \
491+
coinjoin/walletman.cpp \
491492
consensus/tx_verify.cpp \
492493
dbwrapper.cpp \
493494
deploymentstatus.cpp \

src/coinjoin/client.cpp

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <masternode/meta.h>
1313
#include <masternode/sync.h>
1414
#include <net.h>
15-
#include <net_processing.h>
1615
#include <netmessagemaker.h>
1716
#include <rpc/evo_util.h>
1817
#include <shutdown.h>
@@ -39,14 +38,12 @@ using wallet::CoinType;
3938
using wallet::CWallet;
4039
using wallet::ReserveDestination;
4140

42-
MessageProcessingResult CCoinJoinClientQueueManager::ProcessMessage(NodeId from, CConnman& connman, PeerManager& peerman,
41+
MessageProcessingResult CCoinJoinClientQueueManager::ProcessMessage(NodeId from, CConnman& connman,
4342
std::string_view msg_type, CDataStream& vRecv)
4443
{
4544
if (msg_type != NetMsgType::DSQUEUE) {
4645
return {};
4746
}
48-
49-
if (m_is_masternode) return {};
5047
if (!m_mn_sync.IsBlockchainSynced()) return {};
5148

5249
assert(m_mn_metaman.IsValid());
@@ -138,13 +135,12 @@ MessageProcessingResult CCoinJoinClientQueueManager::ProcessMessage(NodeId from,
138135
WITH_LOCK(cs_vecqueue, vecCoinJoinQueue.push_back(dsq));
139136
}
140137
} // cs_ProcessDSQueue
141-
peerman.RelayDSQ(dsq);
138+
ret.m_dsq.push_back(dsq);
142139
return ret;
143140
}
144141

145142
void CCoinJoinClientManager::ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
146143
{
147-
if (m_is_masternode) return;
148144
if (!CCoinJoinClientOptions::IsEnabled()) return;
149145
if (!m_mn_sync.IsBlockchainSynced()) return;
150146

@@ -169,21 +165,18 @@ void CCoinJoinClientManager::ProcessMessage(CNode& peer, CChainState& active_cha
169165
CCoinJoinClientSession::CCoinJoinClientSession(const std::shared_ptr<CWallet>& wallet, CCoinJoinClientManager& clientman,
170166
CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
171167
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
172-
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman,
173-
bool is_masternode) :
168+
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman) :
174169
m_wallet(wallet),
175170
m_clientman(clientman),
176171
m_dmnman(dmnman),
177172
m_mn_metaman(mn_metaman),
178173
m_mn_sync(mn_sync),
179174
m_isman{isman},
180-
m_queueman(queueman),
181-
m_is_masternode{is_masternode}
175+
m_queueman(queueman)
182176
{}
183177

184178
void CCoinJoinClientSession::ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
185179
{
186-
if (m_is_masternode) return;
187180
if (!CCoinJoinClientOptions::IsEnabled()) return;
188181
if (!m_mn_sync.IsBlockchainSynced()) return;
189182

@@ -386,8 +379,6 @@ bool CCoinJoinClientManager::GetMixingMasternodesInfo(std::vector<CDeterministic
386379
//
387380
bool CCoinJoinClientSession::CheckTimeout()
388381
{
389-
if (m_is_masternode) return false;
390-
391382
if (nState == POOL_STATE_IDLE) return false;
392383

393384
if (nState == POOL_STATE_ERROR) {
@@ -423,7 +414,6 @@ bool CCoinJoinClientSession::CheckTimeout()
423414
void CCoinJoinClientManager::CheckTimeout()
424415
{
425416
AssertLockNotHeld(cs_deqsessions);
426-
if (m_is_masternode) return;
427417

428418
if (!CCoinJoinClientOptions::IsEnabled() || !IsMixing()) return;
429419

@@ -441,11 +431,6 @@ void CCoinJoinClientManager::CheckTimeout()
441431
//
442432
bool CCoinJoinClientSession::SendDenominate(const std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsIn, CConnman& connman)
443433
{
444-
if (m_is_masternode) {
445-
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::SendDenominate -- CoinJoin from a Masternode is not supported currently.\n");
446-
return false;
447-
}
448-
449434
if (CTransaction(txMyCollateral).IsNull()) {
450435
WalletCJLogPrint(m_wallet, "CCoinJoinClient:SendDenominate -- CoinJoin collateral not set\n");
451436
return false;
@@ -498,8 +483,6 @@ bool CCoinJoinClientSession::SendDenominate(const std::vector<std::pair<CTxDSIn,
498483
// Process incoming messages from Masternode updating the progress of mixing
499484
void CCoinJoinClientSession::ProcessPoolStateUpdate(CCoinJoinStatusUpdate psssup)
500485
{
501-
if (m_is_masternode) return;
502-
503486
// do not update state when mixing client state is one of these
504487
if (nState == POOL_STATE_IDLE || nState == POOL_STATE_ERROR) return;
505488

@@ -552,7 +535,6 @@ bool CCoinJoinClientSession::SignFinalTransaction(CNode& peer, CChainState& acti
552535
{
553536
if (!CCoinJoinClientOptions::IsEnabled()) return false;
554537

555-
if (m_is_masternode) return false;
556538
if (!mixingMasternode) return false;
557539

558540
LOCK(m_wallet->cs_wallet);
@@ -682,8 +664,6 @@ bool CCoinJoinClientSession::SignFinalTransaction(CNode& peer, CChainState& acti
682664
// mixing transaction was completed (failed or successful)
683665
void CCoinJoinClientSession::CompletedTransaction(PoolMessage nMessageID)
684666
{
685-
if (m_is_masternode) return;
686-
687667
if (nMessageID == MSG_SUCCESS) {
688668
m_clientman.UpdatedSuccessBlock();
689669
keyHolderStorage.KeepAll();
@@ -699,7 +679,6 @@ void CCoinJoinClientSession::CompletedTransaction(PoolMessage nMessageID)
699679

700680
void CCoinJoinClientManager::UpdatedSuccessBlock()
701681
{
702-
if (m_is_masternode) return;
703682
nCachedLastSuccessBlock = nCachedBlockHeight;
704683
}
705684

@@ -791,7 +770,6 @@ bool CCoinJoinClientManager::CheckAutomaticBackup()
791770
bool CCoinJoinClientSession::DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman,
792771
const CTxMemPool& mempool, bool fDryRun)
793772
{
794-
if (m_is_masternode) return false; // no client-side mixing on masternodes
795773
if (nState != POOL_STATE_IDLE) return false;
796774

797775
if (!m_mn_sync.IsBlockchainSynced()) {
@@ -972,7 +950,6 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(ChainstateManager& chainman
972950
bool CCoinJoinClientManager::DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman,
973951
const CTxMemPool& mempool, bool fDryRun)
974952
{
975-
if (m_is_masternode) return false; // no client-side mixing on masternodes
976953
if (!CCoinJoinClientOptions::IsEnabled() || !IsMixing()) return false;
977954

978955
if (!m_mn_sync.IsBlockchainSynced()) {
@@ -1001,7 +978,7 @@ bool CCoinJoinClientManager::DoAutomaticDenominating(ChainstateManager& chainman
1001978
AssertLockNotHeld(cs_deqsessions);
1002979
LOCK(cs_deqsessions);
1003980
if (int(deqSessions.size()) < CCoinJoinClientOptions::GetSessions()) {
1004-
deqSessions.emplace_back(m_wallet, *this, m_dmnman, m_mn_metaman, m_mn_sync, m_isman, m_queueman, m_is_masternode);
981+
deqSessions.emplace_back(m_wallet, *this, m_dmnman, m_mn_metaman, m_mn_sync, m_isman, m_queueman);
1005982
}
1006983
for (auto& session : deqSessions) {
1007984
if (!CheckAutomaticBackup()) return false;
@@ -1840,8 +1817,6 @@ void CCoinJoinClientManager::UpdatedBlockTip(const CBlockIndex* pindex)
18401817

18411818
void CCoinJoinClientQueueManager::DoMaintenance()
18421819
{
1843-
if (m_is_masternode) return; // no client-side mixing on masternodes
1844-
18451820
if (!m_mn_sync.IsBlockchainSynced() || ShutdownRequested()) return;
18461821

18471822
CheckQueue();
@@ -1850,7 +1825,6 @@ void CCoinJoinClientQueueManager::DoMaintenance()
18501825
void CCoinJoinClientManager::DoMaintenance(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool)
18511826
{
18521827
if (!CCoinJoinClientOptions::IsEnabled()) return;
1853-
if (m_is_masternode) return; // no client-side mixing on masternodes
18541828

18551829
if (!m_mn_sync.IsBlockchainSynced() || ShutdownRequested()) return;
18561830

@@ -1904,7 +1878,7 @@ void CoinJoinWalletManager::Add(const std::shared_ptr<CWallet>& wallet)
19041878
LOCK(cs_wallet_manager_map);
19051879
m_wallet_manager_map.try_emplace(wallet->GetName(),
19061880
std::make_unique<CCoinJoinClientManager>(wallet, m_dmnman, m_mn_metaman, m_mn_sync,
1907-
m_isman, m_queueman, m_is_masternode));
1881+
m_isman, m_queueman));
19081882
}
19091883

19101884
void CoinJoinWalletManager::DoMaintenance(CConnman& connman)

src/coinjoin/client.h

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <coinjoin/coinjoin.h>
99
#include <coinjoin/util.h>
1010
#include <evo/types.h>
11+
#include <msg_result.h>
1112

1213
#include <net_types.h>
1314
#include <protocol.h>
@@ -29,7 +30,6 @@ class CMasternodeSync;
2930
class CNode;
3031
class CoinJoinWalletManager;
3132
class CTxMemPool;
32-
class PeerManager;
3333

3434
class UniValue;
3535

@@ -77,15 +77,14 @@ class CoinJoinWalletManager {
7777
public:
7878
CoinJoinWalletManager(ChainstateManager& chainman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
7979
const CTxMemPool& mempool, const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
80-
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman, bool is_masternode) :
80+
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman) :
8181
m_chainman(chainman),
8282
m_dmnman(dmnman),
8383
m_mn_metaman(mn_metaman),
8484
m_mempool(mempool),
8585
m_mn_sync(mn_sync),
8686
m_isman{isman},
87-
m_queueman(queueman),
88-
m_is_masternode{is_masternode}
87+
m_queueman(queueman)
8988
{}
9089

9190
~CoinJoinWalletManager() {
@@ -128,8 +127,6 @@ class CoinJoinWalletManager {
128127
const llmq::CInstantSendManager& m_isman;
129128
const std::unique_ptr<CCoinJoinClientQueueManager>& m_queueman;
130129

131-
const bool m_is_masternode;
132-
133130
mutable Mutex cs_wallet_manager_map;
134131
wallet_name_cjman_map m_wallet_manager_map GUARDED_BY(cs_wallet_manager_map);
135132
};
@@ -145,9 +142,6 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession
145142
const llmq::CInstantSendManager& m_isman;
146143
const std::unique_ptr<CCoinJoinClientQueueManager>& m_queueman;
147144

148-
// Track node type
149-
const bool m_is_masternode;
150-
151145
std::vector<COutPoint> vecOutPointLocked;
152146

153147
bilingual_str strLastMessage;
@@ -202,7 +196,7 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession
202196
explicit CCoinJoinClientSession(const std::shared_ptr<wallet::CWallet>& wallet, CCoinJoinClientManager& clientman,
203197
CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
204198
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
205-
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman, bool is_masternode);
199+
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman);
206200

207201
void ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv);
208202

@@ -239,20 +233,19 @@ class CCoinJoinClientQueueManager : public CCoinJoinBaseManager
239233
const CMasternodeSync& m_mn_sync;
240234

241235
mutable Mutex cs_ProcessDSQueue;
242-
const bool m_is_masternode;
243236

244237
public:
245238
explicit CCoinJoinClientQueueManager(CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman,
246-
CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync,
247-
bool is_masternode) :
239+
CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync) :
248240
m_walletman(walletman),
249241
m_dmnman(dmnman),
250242
m_mn_metaman(mn_metaman),
251-
m_mn_sync(mn_sync),
252-
m_is_masternode{is_masternode} {};
243+
m_mn_sync(mn_sync)
244+
{
245+
}
253246

254-
[[nodiscard]] MessageProcessingResult ProcessMessage(NodeId from, CConnman& connman, PeerManager& peerman,
255-
std::string_view msg_type, CDataStream& vRecv)
247+
[[nodiscard]] MessageProcessingResult ProcessMessage(NodeId from, CConnman& connman, std::string_view msg_type,
248+
CDataStream& vRecv)
256249
EXCLUSIVE_LOCKS_REQUIRED(!cs_vecqueue, !cs_ProcessDSQueue);
257250
void DoMaintenance();
258251
};
@@ -269,9 +262,6 @@ class CCoinJoinClientManager
269262
const llmq::CInstantSendManager& m_isman;
270263
const std::unique_ptr<CCoinJoinClientQueueManager>& m_queueman;
271264

272-
// Track node type
273-
const bool m_is_masternode;
274-
275265
// Keep track of the used Masternodes
276266
std::vector<COutPoint> vecMasternodesUsed;
277267

@@ -304,14 +294,13 @@ class CCoinJoinClientManager
304294
explicit CCoinJoinClientManager(const std::shared_ptr<wallet::CWallet>& wallet, CDeterministicMNManager& dmnman,
305295
CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync,
306296
const llmq::CInstantSendManager& isman,
307-
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman, bool is_masternode) :
297+
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman) :
308298
m_wallet(wallet),
309299
m_dmnman(dmnman),
310300
m_mn_metaman(mn_metaman),
311301
m_mn_sync(mn_sync),
312302
m_isman{isman},
313-
m_queueman(queueman),
314-
m_is_masternode{is_masternode}
303+
m_queueman(queueman)
315304
{
316305
}
317306

src/coinjoin/context.cpp

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/coinjoin/context.h

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)