Skip to content

Commit 4f3da68

Browse files
committed
refactor: drop m_is_masternode from CoinJoinWalletManager
1 parent 5bd1a6b commit 4f3da68

File tree

6 files changed

+25
-57
lines changed

6 files changed

+25
-57
lines changed

src/coinjoin/client.cpp

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ MessageProcessingResult CCoinJoinClientQueueManager::ProcessMessage(NodeId from,
141141

142142
void CCoinJoinClientManager::ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
143143
{
144-
if (m_is_masternode) return;
145144
if (!CCoinJoinClientOptions::IsEnabled()) return;
146145
if (!m_mn_sync.IsBlockchainSynced()) return;
147146

@@ -166,21 +165,18 @@ void CCoinJoinClientManager::ProcessMessage(CNode& peer, CChainState& active_cha
166165
CCoinJoinClientSession::CCoinJoinClientSession(const std::shared_ptr<CWallet>& wallet, CCoinJoinClientManager& clientman,
167166
CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
168167
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
169-
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman,
170-
bool is_masternode) :
168+
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman) :
171169
m_wallet(wallet),
172170
m_clientman(clientman),
173171
m_dmnman(dmnman),
174172
m_mn_metaman(mn_metaman),
175173
m_mn_sync(mn_sync),
176174
m_isman{isman},
177-
m_queueman(queueman),
178-
m_is_masternode{is_masternode}
175+
m_queueman(queueman)
179176
{}
180177

181178
void CCoinJoinClientSession::ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
182179
{
183-
if (m_is_masternode) return;
184180
if (!CCoinJoinClientOptions::IsEnabled()) return;
185181
if (!m_mn_sync.IsBlockchainSynced()) return;
186182

@@ -383,8 +379,6 @@ bool CCoinJoinClientManager::GetMixingMasternodesInfo(std::vector<CDeterministic
383379
//
384380
bool CCoinJoinClientSession::CheckTimeout()
385381
{
386-
if (m_is_masternode) return false;
387-
388382
if (nState == POOL_STATE_IDLE) return false;
389383

390384
if (nState == POOL_STATE_ERROR) {
@@ -420,7 +414,6 @@ bool CCoinJoinClientSession::CheckTimeout()
420414
void CCoinJoinClientManager::CheckTimeout()
421415
{
422416
AssertLockNotHeld(cs_deqsessions);
423-
if (m_is_masternode) return;
424417

425418
if (!CCoinJoinClientOptions::IsEnabled() || !IsMixing()) return;
426419

@@ -438,11 +431,6 @@ void CCoinJoinClientManager::CheckTimeout()
438431
//
439432
bool CCoinJoinClientSession::SendDenominate(const std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsIn, CConnman& connman)
440433
{
441-
if (m_is_masternode) {
442-
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::SendDenominate -- CoinJoin from a Masternode is not supported currently.\n");
443-
return false;
444-
}
445-
446434
if (CTransaction(txMyCollateral).IsNull()) {
447435
WalletCJLogPrint(m_wallet, "CCoinJoinClient:SendDenominate -- CoinJoin collateral not set\n");
448436
return false;
@@ -495,8 +483,6 @@ bool CCoinJoinClientSession::SendDenominate(const std::vector<std::pair<CTxDSIn,
495483
// Process incoming messages from Masternode updating the progress of mixing
496484
void CCoinJoinClientSession::ProcessPoolStateUpdate(CCoinJoinStatusUpdate psssup)
497485
{
498-
if (m_is_masternode) return;
499-
500486
// do not update state when mixing client state is one of these
501487
if (nState == POOL_STATE_IDLE || nState == POOL_STATE_ERROR) return;
502488

@@ -549,7 +535,6 @@ bool CCoinJoinClientSession::SignFinalTransaction(CNode& peer, CChainState& acti
549535
{
550536
if (!CCoinJoinClientOptions::IsEnabled()) return false;
551537

552-
if (m_is_masternode) return false;
553538
if (!mixingMasternode) return false;
554539

555540
LOCK(m_wallet->cs_wallet);
@@ -679,8 +664,6 @@ bool CCoinJoinClientSession::SignFinalTransaction(CNode& peer, CChainState& acti
679664
// mixing transaction was completed (failed or successful)
680665
void CCoinJoinClientSession::CompletedTransaction(PoolMessage nMessageID)
681666
{
682-
if (m_is_masternode) return;
683-
684667
if (nMessageID == MSG_SUCCESS) {
685668
m_clientman.UpdatedSuccessBlock();
686669
keyHolderStorage.KeepAll();
@@ -696,7 +679,6 @@ void CCoinJoinClientSession::CompletedTransaction(PoolMessage nMessageID)
696679

697680
void CCoinJoinClientManager::UpdatedSuccessBlock()
698681
{
699-
if (m_is_masternode) return;
700682
nCachedLastSuccessBlock = nCachedBlockHeight;
701683
}
702684

@@ -788,7 +770,6 @@ bool CCoinJoinClientManager::CheckAutomaticBackup()
788770
bool CCoinJoinClientSession::DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman,
789771
const CTxMemPool& mempool, bool fDryRun)
790772
{
791-
if (m_is_masternode) return false; // no client-side mixing on masternodes
792773
if (nState != POOL_STATE_IDLE) return false;
793774

794775
if (!m_mn_sync.IsBlockchainSynced()) {
@@ -969,7 +950,6 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(ChainstateManager& chainman
969950
bool CCoinJoinClientManager::DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman,
970951
const CTxMemPool& mempool, bool fDryRun)
971952
{
972-
if (m_is_masternode) return false; // no client-side mixing on masternodes
973953
if (!CCoinJoinClientOptions::IsEnabled() || !IsMixing()) return false;
974954

975955
if (!m_mn_sync.IsBlockchainSynced()) {
@@ -998,7 +978,7 @@ bool CCoinJoinClientManager::DoAutomaticDenominating(ChainstateManager& chainman
998978
AssertLockNotHeld(cs_deqsessions);
999979
LOCK(cs_deqsessions);
1000980
if (int(deqSessions.size()) < CCoinJoinClientOptions::GetSessions()) {
1001-
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);
1002982
}
1003983
for (auto& session : deqSessions) {
1004984
if (!CheckAutomaticBackup()) return false;
@@ -1845,7 +1825,6 @@ void CCoinJoinClientQueueManager::DoMaintenance()
18451825
void CCoinJoinClientManager::DoMaintenance(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool)
18461826
{
18471827
if (!CCoinJoinClientOptions::IsEnabled()) return;
1848-
if (m_is_masternode) return; // no client-side mixing on masternodes
18491828

18501829
if (!m_mn_sync.IsBlockchainSynced() || ShutdownRequested()) return;
18511830

@@ -1899,7 +1878,7 @@ void CoinJoinWalletManager::Add(const std::shared_ptr<CWallet>& wallet)
18991878
LOCK(cs_wallet_manager_map);
19001879
m_wallet_manager_map.try_emplace(wallet->GetName(),
19011880
std::make_unique<CCoinJoinClientManager>(wallet, m_dmnman, m_mn_metaman, m_mn_sync,
1902-
m_isman, m_queueman, m_is_masternode));
1881+
m_isman, m_queueman));
19031882
}
19041883

19051884
void CoinJoinWalletManager::DoMaintenance(CConnman& connman)

src/coinjoin/client.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -268,9 +262,6 @@ class CCoinJoinClientManager
268262
const llmq::CInstantSendManager& m_isman;
269263
const std::unique_ptr<CCoinJoinClientQueueManager>& m_queueman;
270264

271-
// Track node type
272-
const bool m_is_masternode;
273-
274265
// Keep track of the used Masternodes
275266
std::vector<COutPoint> vecMasternodesUsed;
276267

@@ -303,14 +294,13 @@ class CCoinJoinClientManager
303294
explicit CCoinJoinClientManager(const std::shared_ptr<wallet::CWallet>& wallet, CDeterministicMNManager& dmnman,
304295
CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync,
305296
const llmq::CInstantSendManager& isman,
306-
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman, bool is_masternode) :
297+
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman) :
307298
m_wallet(wallet),
308299
m_dmnman(dmnman),
309300
m_mn_metaman(mn_metaman),
310301
m_mn_sync(mn_sync),
311302
m_isman{isman},
312-
m_queueman(queueman),
313-
m_is_masternode{is_masternode}
303+
m_queueman(queueman)
314304
{
315305
}
316306

src/coinjoin/context.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CJContextImpl final : public CJContext
3939
std::string_view msg_type, CDataStream& vRecv) override;
4040
std::optional<CCoinJoinQueue> getQueueFromHash(const uint256& hash) const override;
4141
std::optional<int> getQueueSize() const override;
42-
std::vector<CDeterministicMNCPtr> getMixingMasternodes() const override;
42+
std::vector<CDeterministicMNCPtr> getMixingMasternodes() override;
4343
void addWallet(const std::shared_ptr<wallet::CWallet>& wallet) override;
4444
void removeWallet(const std::string& name) override;
4545
void flushWallet(const std::string& name) override;
@@ -51,17 +51,16 @@ class CJContextImpl final : public CJContext
5151
private:
5252
const bool m_relay_txes;
5353

54-
const std::unique_ptr<CoinJoinWalletManager> walletman;
54+
CoinJoinWalletManager walletman;
5555
const std::unique_ptr<CCoinJoinClientQueueManager> queueman;
5656
};
5757

5858
CJContextImpl::CJContextImpl(ChainstateManager& chainman, CDeterministicMNManager& dmnman,
5959
CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool, const CMasternodeSync& mn_sync,
6060
const llmq::CInstantSendManager& isman, bool relay_txes) :
6161
m_relay_txes{relay_txes},
62-
walletman{std::make_unique<CoinJoinWalletManager>(chainman, dmnman, mn_metaman, mempool, mn_sync, isman, queueman,
63-
/*is_masternode=*/false)},
64-
queueman{m_relay_txes ? std::make_unique<CCoinJoinClientQueueManager>(*walletman, dmnman, mn_metaman, mn_sync) : nullptr}
62+
walletman{chainman, dmnman, mn_metaman, mempool, mn_sync, isman, queueman},
63+
queueman{m_relay_txes ? std::make_unique<CCoinJoinClientQueueManager>(walletman, dmnman, mn_metaman, mn_sync) : nullptr}
6564
{
6665
}
6766

@@ -70,7 +69,7 @@ void CJContextImpl::Schedule(CConnman& connman, CScheduler& scheduler)
7069
if (!m_relay_txes) return;
7170
scheduler.scheduleEvery(std::bind(&CCoinJoinClientQueueManager::DoMaintenance, std::ref(*queueman)),
7271
std::chrono::seconds{1});
73-
scheduler.scheduleEvery(std::bind(&CoinJoinWalletManager::DoMaintenance, std::ref(*walletman), std::ref(connman)),
72+
scheduler.scheduleEvery(std::bind(&CoinJoinWalletManager::DoMaintenance, std::ref(walletman), std::ref(connman)),
7473
std::chrono::seconds{1});
7574
}
7675

@@ -79,7 +78,7 @@ void CJContextImpl::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIn
7978
if (fInitialDownload || pindexNew == pindexFork) // In IBD or blocks were disconnected without any new ones
8079
return;
8180

82-
walletman->ForEachCJClientMan(
81+
walletman.ForEachCJClientMan(
8382
[&pindexNew](std::unique_ptr<CCoinJoinClientManager>& clientman) { clientman->UpdatedBlockTip(pindexNew); });
8483
}
8584

@@ -93,13 +92,13 @@ bool CJContextImpl::hasQueue(const uint256& hash) const
9392

9493
CCoinJoinClientManager* CJContextImpl::getClient(const std::string& name)
9594
{
96-
return walletman->Get(name);
95+
return walletman.Get(name);
9796
}
9897

9998
MessageProcessingResult CJContextImpl::processMessage(CNode& pfrom, CChainState& chainstate, CConnman& connman,
10099
CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
101100
{
102-
walletman->ForEachCJClientMan([&](std::unique_ptr<CCoinJoinClientManager>& clientman) {
101+
walletman.ForEachCJClientMan([&](std::unique_ptr<CCoinJoinClientManager>& clientman) {
103102
clientman->ProcessMessage(pfrom, chainstate, connman, mempool, msg_type, vRecv);
104103
});
105104
if (queueman) {
@@ -124,27 +123,27 @@ std::optional<int> CJContextImpl::getQueueSize() const
124123
return std::nullopt;
125124
}
126125

127-
std::vector<CDeterministicMNCPtr> CJContextImpl::getMixingMasternodes() const
126+
std::vector<CDeterministicMNCPtr> CJContextImpl::getMixingMasternodes()
128127
{
129128
std::vector<CDeterministicMNCPtr> ret{};
130-
walletman->ForEachCJClientMan(
129+
walletman.ForEachCJClientMan(
131130
[&](const std::unique_ptr<CCoinJoinClientManager>& clientman) { clientman->GetMixingMasternodesInfo(ret); });
132131
return ret;
133132
}
134133

135134
void CJContextImpl::addWallet(const std::shared_ptr<wallet::CWallet>& wallet)
136135
{
137-
walletman->Add(wallet);
136+
walletman.Add(wallet);
138137
}
139138

140139
void CJContextImpl::flushWallet(const std::string& name)
141140
{
142-
walletman->Flush(name);
141+
walletman.Flush(name);
143142
}
144143

145144
void CJContextImpl::removeWallet(const std::string& name)
146145
{
147-
walletman->Remove(name);
146+
walletman.Remove(name);
148147
}
149148
#endif // ENABLE_WALLET
150149

src/coinjoin/context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CJContext : public CValidationInterface
5252
CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) = 0;
5353
virtual std::optional<CCoinJoinQueue> getQueueFromHash(const uint256& hash) const = 0;
5454
virtual std::optional<int> getQueueSize() const = 0;
55-
virtual std::vector<CDeterministicMNCPtr> getMixingMasternodes() const = 0;
55+
virtual std::vector<CDeterministicMNCPtr> getMixingMasternodes() = 0;
5656
virtual void addWallet(const std::shared_ptr<wallet::CWallet>& wallet) = 0;
5757
virtual void removeWallet(const std::string& name) = 0;
5858
virtual void flushWallet(const std::string& name) = 0;

src/masternode/utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#endif
1818

1919
void CMasternodeUtils::DoMaintenance(CConnman& connman, CDeterministicMNManager& dmnman, const CMasternodeSync& mn_sync,
20-
const CJContext* const cj_ctx)
20+
CJContext* const cj_ctx)
2121
{
2222
if (!mn_sync.IsBlockchainSynced()) return;
2323
if (ShutdownRequested()) return;

src/masternode/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CMasternodeUtils
1414
{
1515
public:
1616
static void DoMaintenance(CConnman& connman, CDeterministicMNManager& dmnman, const CMasternodeSync& mn_sync,
17-
const CJContext* const cj_ctx);
17+
CJContext* const cj_ctx);
1818
};
1919

2020
#endif // BITCOIN_MASTERNODE_UTILS_H

0 commit comments

Comments
 (0)