Skip to content

Commit 5be7da7

Browse files
committed
refactor: s/CJContext/CJWalletManager/g
CJContext is no longer just a context class, it's a lot more involved now and serves triple duty as also a notification interface and a layer of abstraction. Name reflects that it's the wallet-specific components of CoinJoin.
1 parent f5620ad commit 5be7da7

19 files changed

+103
-102
lines changed

src/Makefile.am

Lines changed: 2 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 \
@@ -485,8 +485,8 @@ libbitcoin_node_a_SOURCES = \
485485
chainlock/clsig.cpp \
486486
chainlock/signing.cpp \
487487
coinjoin/coinjoin.cpp \
488-
coinjoin/context.cpp \
489488
coinjoin/server.cpp \
489+
coinjoin/walletman.cpp \
490490
consensus/tx_verify.cpp \
491491
dbwrapper.cpp \
492492
deploymentstatus.cpp \

src/coinjoin/interfaces.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include <interfaces/coinjoin.h>
66

77
#include <coinjoin/client.h>
8-
#include <coinjoin/context.h>
98
#include <coinjoin/options.h>
9+
#include <coinjoin/walletman.h>
1010
#include <node/context.h>
1111
#include <util/check.h>
1212
#include <walletinitinterface.h>
@@ -77,9 +77,9 @@ class CoinJoinClientImpl : public interfaces::CoinJoin::Client
7777
class CoinJoinLoaderImpl : public interfaces::CoinJoin::Loader
7878
{
7979
private:
80-
CJContext& manager()
80+
CJWalletManager& manager()
8181
{
82-
return *Assert(m_node.cj_ctx);
82+
return *Assert(m_node.cj_walletman);
8383
}
8484

8585
interfaces::WalletLoader& wallet_loader()
Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <config/bitcoin-config.h>
77
#endif
88

9-
#include <coinjoin/context.h>
9+
#include <coinjoin/walletman.h>
1010

1111
#include <net.h>
1212
#include <scheduler.h>
@@ -21,13 +21,13 @@
2121
#include <memory>
2222

2323
#ifdef ENABLE_WALLET
24-
class CJContextImpl final : public CJContext
24+
class CJWalletManagerImpl final : public CJWalletManager
2525
{
2626
public:
27-
CJContextImpl(ChainstateManager& chainman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
28-
CTxMemPool& mempool, const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
29-
bool relay_txes);
30-
virtual ~CJContextImpl() = default;
27+
CJWalletManagerImpl(ChainstateManager& chainman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
28+
CTxMemPool& mempool, const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
29+
bool relay_txes);
30+
virtual ~CJWalletManagerImpl() = default;
3131

3232
public:
3333
void Schedule(CConnman& connman, CScheduler& scheduler) override;
@@ -55,16 +55,17 @@ class CJContextImpl final : public CJContext
5555
const std::unique_ptr<CCoinJoinClientQueueManager> queueman;
5656
};
5757

58-
CJContextImpl::CJContextImpl(ChainstateManager& chainman, CDeterministicMNManager& dmnman,
59-
CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool, const CMasternodeSync& mn_sync,
60-
const llmq::CInstantSendManager& isman, bool relay_txes) :
58+
CJWalletManagerImpl::CJWalletManagerImpl(ChainstateManager& chainman, CDeterministicMNManager& dmnman,
59+
CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool,
60+
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
61+
bool relay_txes) :
6162
m_relay_txes{relay_txes},
6263
walletman{chainman, dmnman, mn_metaman, mempool, mn_sync, isman, queueman},
6364
queueman{m_relay_txes ? std::make_unique<CCoinJoinClientQueueManager>(walletman, dmnman, mn_metaman, mn_sync) : nullptr}
6465
{
6566
}
6667

67-
void CJContextImpl::Schedule(CConnman& connman, CScheduler& scheduler)
68+
void CJWalletManagerImpl::Schedule(CConnman& connman, CScheduler& scheduler)
6869
{
6970
if (!m_relay_txes) return;
7071
scheduler.scheduleEvery(std::bind(&CCoinJoinClientQueueManager::DoMaintenance, std::ref(*queueman)),
@@ -73,7 +74,7 @@ void CJContextImpl::Schedule(CConnman& connman, CScheduler& scheduler)
7374
std::chrono::seconds{1});
7475
}
7576

76-
void CJContextImpl::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload)
77+
void CJWalletManagerImpl::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload)
7778
{
7879
if (fInitialDownload || pindexNew == pindexFork) // In IBD or blocks were disconnected without any new ones
7980
return;
@@ -82,21 +83,22 @@ void CJContextImpl::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIn
8283
[&pindexNew](std::unique_ptr<CCoinJoinClientManager>& clientman) { clientman->UpdatedBlockTip(pindexNew); });
8384
}
8485

85-
bool CJContextImpl::hasQueue(const uint256& hash) const
86+
bool CJWalletManagerImpl::hasQueue(const uint256& hash) const
8687
{
8788
if (queueman) {
8889
return queueman->HasQueue(hash);
8990
}
9091
return false;
9192
}
9293

93-
CCoinJoinClientManager* CJContextImpl::getClient(const std::string& name)
94+
CCoinJoinClientManager* CJWalletManagerImpl::getClient(const std::string& name)
9495
{
9596
return walletman.Get(name);
9697
}
9798

98-
MessageProcessingResult CJContextImpl::processMessage(CNode& pfrom, CChainState& chainstate, CConnman& connman,
99-
CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
99+
MessageProcessingResult CJWalletManagerImpl::processMessage(CNode& pfrom, CChainState& chainstate, CConnman& connman,
100+
CTxMemPool& mempool, std::string_view msg_type,
101+
CDataStream& vRecv)
100102
{
101103
walletman.ForEachCJClientMan([&](std::unique_ptr<CCoinJoinClientManager>& clientman) {
102104
clientman->ProcessMessage(pfrom, chainstate, connman, mempool, msg_type, vRecv);
@@ -107,53 +109,53 @@ MessageProcessingResult CJContextImpl::processMessage(CNode& pfrom, CChainState&
107109
return {};
108110
}
109111

110-
std::optional<CCoinJoinQueue> CJContextImpl::getQueueFromHash(const uint256& hash) const
112+
std::optional<CCoinJoinQueue> CJWalletManagerImpl::getQueueFromHash(const uint256& hash) const
111113
{
112114
if (queueman) {
113115
return queueman->GetQueueFromHash(hash);
114116
}
115117
return std::nullopt;
116118
}
117119

118-
std::optional<int> CJContextImpl::getQueueSize() const
120+
std::optional<int> CJWalletManagerImpl::getQueueSize() const
119121
{
120122
if (queueman) {
121123
return queueman->GetQueueSize();
122124
}
123125
return std::nullopt;
124126
}
125127

126-
std::vector<CDeterministicMNCPtr> CJContextImpl::getMixingMasternodes()
128+
std::vector<CDeterministicMNCPtr> CJWalletManagerImpl::getMixingMasternodes()
127129
{
128130
std::vector<CDeterministicMNCPtr> ret{};
129131
walletman.ForEachCJClientMan(
130132
[&](const std::unique_ptr<CCoinJoinClientManager>& clientman) { clientman->GetMixingMasternodesInfo(ret); });
131133
return ret;
132134
}
133135

134-
void CJContextImpl::addWallet(const std::shared_ptr<wallet::CWallet>& wallet)
136+
void CJWalletManagerImpl::addWallet(const std::shared_ptr<wallet::CWallet>& wallet)
135137
{
136138
walletman.Add(wallet);
137139
}
138140

139-
void CJContextImpl::flushWallet(const std::string& name)
141+
void CJWalletManagerImpl::flushWallet(const std::string& name)
140142
{
141143
walletman.Flush(name);
142144
}
143145

144-
void CJContextImpl::removeWallet(const std::string& name)
146+
void CJWalletManagerImpl::removeWallet(const std::string& name)
145147
{
146148
walletman.Remove(name);
147149
}
148150
#endif // ENABLE_WALLET
149151

150-
std::unique_ptr<CJContext> CJContext::make(ChainstateManager& chainman, CDeterministicMNManager& dmnman,
151-
CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool,
152-
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
153-
bool relay_txes)
152+
std::unique_ptr<CJWalletManager> CJWalletManager::make(ChainstateManager& chainman, CDeterministicMNManager& dmnman,
153+
CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool,
154+
const CMasternodeSync& mn_sync,
155+
const llmq::CInstantSendManager& isman, bool relay_txes)
154156
{
155157
#ifdef ENABLE_WALLET
156-
return std::make_unique<CJContextImpl>(chainman, dmnman, mn_metaman, mempool, mn_sync, isman, relay_txes);
158+
return std::make_unique<CJWalletManagerImpl>(chainman, dmnman, mn_metaman, mempool, mn_sync, isman, relay_txes);
157159
#else
158160
// Cannot be constructed if wallet support isn't built
159161
return nullptr;
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Distributed under the MIT/X11 software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#ifndef BITCOIN_COINJOIN_CONTEXT_H
6-
#define BITCOIN_COINJOIN_CONTEXT_H
5+
#ifndef BITCOIN_COINJOIN_WALLETMAN_H
6+
#define BITCOIN_COINJOIN_WALLETMAN_H
77

88
#include <evo/types.h>
99
#include <msg_result.h>
@@ -33,14 +33,14 @@ namespace wallet {
3333
class CWallet;
3434
} // namespace wallet
3535

36-
class CJContext : public CValidationInterface
36+
class CJWalletManager : public CValidationInterface
3737
{
3838
public:
39-
static std::unique_ptr<CJContext> make(ChainstateManager& chainman, CDeterministicMNManager& dmnman,
40-
CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool,
41-
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
42-
bool relay_txes);
43-
virtual ~CJContext() = default;
39+
static std::unique_ptr<CJWalletManager> make(ChainstateManager& chainman, CDeterministicMNManager& dmnman,
40+
CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool,
41+
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
42+
bool relay_txes);
43+
virtual ~CJWalletManager() = default;
4444

4545
public:
4646
virtual void Schedule(CConnman& connman, CScheduler& scheduler) = 0;
@@ -63,4 +63,4 @@ class CJContext : public CValidationInterface
6363
bool fInitialDownload) override = 0;
6464
};
6565

66-
#endif // BITCOIN_COINJOIN_CONTEXT_H
66+
#endif // BITCOIN_COINJOIN_WALLETMAN_H

src/init.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878

7979
#include <bls/bls.h>
8080
#include <coinjoin/coinjoin.h>
81-
#include <coinjoin/context.h>
8281
#include <coinjoin/server.h>
82+
#include <coinjoin/walletman.h>
8383
#include <dsnotificationinterface.h>
8484
#include <evo/deterministicmns.h>
8585
#include <evo/evodb.h>
@@ -326,8 +326,8 @@ void PrepareShutdown(NodeContext& node)
326326
g_active_notification_interface.reset();
327327
}
328328

329-
if (node.cj_ctx) {
330-
UnregisterValidationInterface(node.cj_ctx.get());
329+
if (node.cj_walletman) {
330+
UnregisterValidationInterface(node.cj_walletman.get());
331331
}
332332

333333
if (g_ds_notification_interface) {
@@ -392,7 +392,7 @@ void PrepareShutdown(NodeContext& node)
392392

393393
// After all wallets are removed, destroy all CoinJoin objects
394394
// and reset them to nullptr
395-
node.cj_ctx.reset();
395+
node.cj_walletman.reset();
396396
node.dstxman.reset();
397397

398398
UnregisterAllValidationInterfaces();
@@ -2134,20 +2134,20 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
21342134
assert(!node.dstxman);
21352135
node.dstxman = std::make_unique<CDSTXManager>();
21362136

2137-
assert(!node.cj_ctx);
2137+
assert(!node.cj_walletman);
21382138
if (!node.mn_activeman) {
2139-
node.cj_ctx = CJContext::make(chainman, *node.dmnman, *node.mn_metaman, *node.mempool, *node.mn_sync,
2140-
*node.llmq_ctx->isman, !ignores_incoming_txs);
2139+
node.cj_walletman = CJWalletManager::make(chainman, *node.dmnman, *node.mn_metaman, *node.mempool, *node.mn_sync,
2140+
*node.llmq_ctx->isman, !ignores_incoming_txs);
21412141
}
2142-
if (node.cj_ctx) {
2143-
RegisterValidationInterface(node.cj_ctx.get());
2142+
if (node.cj_walletman) {
2143+
RegisterValidationInterface(node.cj_walletman.get());
21442144
}
21452145

21462146
assert(!node.peerman);
21472147
node.peerman = PeerManager::make(chainparams, *node.connman, *node.addrman, node.banman.get(), *node.dstxman,
21482148
chainman, *node.mempool, *node.mn_metaman, *node.mn_sync,
21492149
*node.govman, *node.sporkman, node.mn_activeman.get(), node.dmnman,
2150-
node.active_ctx, node.cj_ctx.get(), node.llmq_ctx, ignores_incoming_txs);
2150+
node.active_ctx, node.cj_walletman.get(), node.llmq_ctx, ignores_incoming_txs);
21512151
RegisterValidationInterface(node.peerman.get());
21522152

21532153
g_ds_notification_interface = std::make_unique<CDSNotificationInterface>(
@@ -2267,7 +2267,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
22672267

22682268
node.scheduler->scheduleEvery(std::bind(&CNetFulfilledRequestManager::DoMaintenance, std::ref(*node.netfulfilledman)), std::chrono::minutes{1});
22692269
node.scheduler->scheduleEvery(std::bind(&CMasternodeSync::DoMaintenance, std::ref(*node.mn_sync), std::cref(*node.peerman), std::cref(*node.govman)), std::chrono::seconds{1});
2270-
node.scheduler->scheduleEvery(std::bind(&CMasternodeUtils::DoMaintenance, std::ref(*node.connman), std::ref(*node.dmnman), std::ref(*node.mn_sync), node.cj_ctx.get()), std::chrono::minutes{1});
2270+
node.scheduler->scheduleEvery(std::bind(&CMasternodeUtils::DoMaintenance, std::ref(*node.connman), std::ref(*node.dmnman), std::ref(*node.mn_sync), node.cj_walletman.get()), std::chrono::minutes{1});
22712271
node.scheduler->scheduleEvery(std::bind(&CDeterministicMNManager::DoMaintenance, std::ref(*node.dmnman)), std::chrono::seconds{10});
22722272

22732273
if (node.govman->IsValid()) {
@@ -2279,8 +2279,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
22792279
node.scheduler->scheduleEvery(std::bind(&llmq::CDKGSessionManager::CleanupOldContributions, std::ref(*node.llmq_ctx->qdkgsman)), std::chrono::hours{1});
22802280
}
22812281

2282-
if (node.cj_ctx) {
2283-
node.cj_ctx->Schedule(*node.connman, *node.scheduler);
2282+
if (node.cj_walletman) {
2283+
node.cj_walletman->Schedule(*node.connman, *node.scheduler);
22842284
}
22852285

22862286
if (::g_stats_client->active()) {

src/masternode/utils.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88
#include <shutdown.h>
99
#include <util/ranges.h>
1010

11-
#include <coinjoin/context.h>
11+
#include <coinjoin/walletman.h>
1212
#include <evo/deterministicmns.h>
1313
#include <masternode/sync.h>
1414

15-
#ifdef ENABLE_WALLET
16-
#include <coinjoin/client.h>
17-
#endif
18-
1915
void CMasternodeUtils::DoMaintenance(CConnman& connman, CDeterministicMNManager& dmnman, const CMasternodeSync& mn_sync,
20-
CJContext* const cj_ctx)
16+
CJWalletManager* const cj_walletman)
2117
{
2218
if (!mn_sync.IsBlockchainSynced()) return;
2319
if (ShutdownRequested()) return;
@@ -40,7 +36,7 @@ void CMasternodeUtils::DoMaintenance(CConnman& connman, CDeterministicMNManager&
4036
return;
4137
}
4238

43-
auto mixing_masternodes = cj_ctx ? cj_ctx->getMixingMasternodes() : std::vector<CDeterministicMNCPtr>{};
39+
auto mixing_masternodes = cj_walletman ? cj_walletman->getMixingMasternodes() : std::vector<CDeterministicMNCPtr>{};
4440
connman.ForEachNode(CConnman::AllNodes, [&](CNode* pnode) {
4541
if (pnode->m_masternode_probe_connection) {
4642
// we're not disconnecting masternode probes for at least PROBE_WAIT_INTERVAL seconds

src/masternode/utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
class CConnman;
99
class CDeterministicMNManager;
1010
class CMasternodeSync;
11-
class CJContext;
11+
class CJWalletManager;
1212

1313
class CMasternodeUtils
1414
{
1515
public:
1616
static void DoMaintenance(CConnman& connman, CDeterministicMNManager& dmnman, const CMasternodeSync& mn_sync,
17-
CJContext* const cj_ctx);
17+
CJWalletManager* const cj_walletman);
1818
};
1919

2020
#endif // BITCOIN_MASTERNODE_UTILS_H

0 commit comments

Comments
 (0)