Skip to content

Commit cebe18b

Browse files
committed
refactor: remove ENABLE_WALLET from dsnotificationinterface.cpp
Currently a lot of non-wallet code is peppered with `ENABLE_WALLET` due to wallet-only CoinJoin managers, we need to contain them.
1 parent 2606d8c commit cebe18b

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

src/coinjoin/context.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,14 @@ void CJContext::Schedule(CConnman& connman, CScheduler& scheduler)
3636
std::chrono::seconds{1});
3737
#endif // ENABLE_WALLET
3838
}
39+
40+
void CJContext::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload)
41+
{
42+
#ifdef ENABLE_WALLET
43+
if (fInitialDownload || pindexNew == pindexFork) // In IBD or blocks were disconnected without any new ones
44+
return;
45+
46+
walletman->ForEachCJClientMan(
47+
[&pindexNew](std::unique_ptr<CCoinJoinClientManager>& clientman) { clientman->UpdatedBlockTip(pindexNew); });
48+
#endif // ENABLE_WALLET
49+
}

src/coinjoin/context.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
#include <config/bitcoin-config.h>
1010
#endif
1111

12+
#include <validationinterface.h>
13+
1214
#include <memory>
1315

1416
class CActiveMasternodeManager;
17+
class CBlockIndex;
1518
class CConnman;
1619
class CDeterministicMNManager;
1720
class ChainstateManager;
@@ -28,17 +31,21 @@ class CCoinJoinClientQueueManager;
2831
class CoinJoinWalletManager;
2932
#endif // ENABLE_WALLET
3033

31-
struct CJContext {
34+
struct CJContext final : public CValidationInterface {
3235
public:
3336
CJContext() = delete;
3437
CJContext(const CJContext&) = delete;
3538
CJContext(ChainstateManager& chainman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
3639
CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync,
3740
const llmq::CInstantSendManager& isman, bool relay_txes);
38-
~CJContext();
41+
virtual ~CJContext();
3942

4043
void Schedule(CConnman& connman, CScheduler& scheduler);
4144

45+
protected:
46+
// CValidationInterface
47+
void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) override;
48+
4249
#ifdef ENABLE_WALLET
4350
private:
4451
const bool m_relay_txes;

src/dsnotificationinterface.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <chainlock/chainlock.h>
1212
#include <coinjoin/coinjoin.h>
13-
#include <coinjoin/context.h>
1413
#include <evo/deterministicmns.h>
1514
#include <evo/mnauth.h>
1615
#include <governance/governance.h>
@@ -21,26 +20,20 @@
2120
#include <llmq/quorums.h>
2221
#include <masternode/sync.h>
2322

24-
#ifdef ENABLE_WALLET
25-
#include <coinjoin/client.h>
26-
#endif // ENABLE_WALLET
27-
2823
CDSNotificationInterface::CDSNotificationInterface(CConnman& connman,
2924
CDSTXManager& dstxman,
3025
CMasternodeSync& mn_sync,
3126
CGovernanceManager& govman,
3227
const ChainstateManager& chainman,
3328
const std::unique_ptr<CDeterministicMNManager>& dmnman,
34-
const std::unique_ptr<LLMQContext>& llmq_ctx,
35-
const std::unique_ptr<CJContext>& cj_ctx) :
29+
const std::unique_ptr<LLMQContext>& llmq_ctx) :
3630
m_connman(connman),
3731
m_dstxman(dstxman),
3832
m_mn_sync(mn_sync),
3933
m_govman(govman),
4034
m_chainman(chainman),
4135
m_dmnman(dmnman),
42-
m_llmq_ctx(llmq_ctx),
43-
m_cj_ctx(cj_ctx)
36+
m_llmq_ctx(llmq_ctx)
4437
{
4538
}
4639

@@ -80,16 +73,11 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con
8073
return;
8174

8275
m_dstxman.UpdatedBlockTip(pindexNew, *Assert(m_llmq_ctx)->clhandler, m_mn_sync);
83-
#ifdef ENABLE_WALLET
84-
Assert(m_cj_ctx)->walletman->ForEachCJClientMan(
85-
[&pindexNew](std::unique_ptr<CCoinJoinClientManager>& clientman) { clientman->UpdatedBlockTip(pindexNew); });
86-
#endif // ENABLE_WALLET
8776

8877
m_llmq_ctx->isman->UpdatedBlockTip(pindexNew);
8978
m_llmq_ctx->clhandler->UpdatedBlockTip(*m_llmq_ctx->isman);
90-
91-
m_llmq_ctx->qman->UpdatedBlockTip(pindexNew, m_connman, fInitialDownload);
9279
m_llmq_ctx->qdkgsman->UpdatedBlockTip(pindexNew, fInitialDownload);
80+
m_llmq_ctx->qman->UpdatedBlockTip(pindexNew, m_connman, fInitialDownload);
9381

9482
if (m_govman.IsValid()) {
9583
m_govman.UpdatedBlockTip(pindexNew);

src/dsnotificationinterface.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class CDeterministicMNManager;
1313
class CGovernanceManager;
1414
class ChainstateManager;
1515
class CMasternodeSync;
16-
struct CJContext;
1716
struct LLMQContext;
1817

1918
class CDSNotificationInterface : public CValidationInterface
@@ -25,8 +24,7 @@ class CDSNotificationInterface : public CValidationInterface
2524
CGovernanceManager& govman,
2625
const ChainstateManager& chainman,
2726
const std::unique_ptr<CDeterministicMNManager>& dmnman,
28-
const std::unique_ptr<LLMQContext>& llmq_ctx,
29-
const std::unique_ptr<CJContext>& cj_ctx);
27+
const std::unique_ptr<LLMQContext>& llmq_ctx);
3028
virtual ~CDSNotificationInterface() = default;
3129

3230
// a small helper to initialize current block height in sub-modules on startup
@@ -54,7 +52,6 @@ class CDSNotificationInterface : public CValidationInterface
5452
const ChainstateManager& m_chainman;
5553
const std::unique_ptr<CDeterministicMNManager>& m_dmnman;
5654
const std::unique_ptr<LLMQContext>& m_llmq_ctx;
57-
const std::unique_ptr<CJContext>& m_cj_ctx;
5855
};
5956

6057
extern std::unique_ptr<CDSNotificationInterface> g_ds_notification_interface;

src/init.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ void PrepareShutdown(NodeContext& node)
325325
g_active_notification_interface.reset();
326326
}
327327

328+
if (node.cj_ctx) {
329+
UnregisterValidationInterface(node.cj_ctx.get());
330+
}
331+
332+
if (g_ds_notification_interface) {
333+
UnregisterValidationInterface(g_ds_notification_interface.get());
334+
g_ds_notification_interface.reset();
335+
}
336+
328337
// After all scheduled tasks have been flushed, destroy pointers
329338
// and reset all to nullptr.
330339
node.active_ctx.reset();
@@ -376,11 +385,6 @@ void PrepareShutdown(NodeContext& node)
376385
}
377386
#endif
378387

379-
if (g_ds_notification_interface) {
380-
UnregisterValidationInterface(g_ds_notification_interface.get());
381-
g_ds_notification_interface.reset();
382-
}
383-
384388
node.mn_activeman.reset();
385389

386390
node.chain_clients.clear();
@@ -2136,6 +2140,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
21362140
node.cj_ctx = std::make_unique<CJContext>(chainman, *node.dmnman, *node.mn_metaman, *node.mempool,
21372141
node.mn_activeman.get(), *node.mn_sync, *node.llmq_ctx->isman,
21382142
!ignores_incoming_txs);
2143+
RegisterValidationInterface(node.cj_ctx.get());
21392144

21402145
assert(!node.peerman);
21412146
node.peerman = PeerManager::make(chainparams, *node.connman, *node.addrman, node.banman.get(), *node.dstxman,
@@ -2145,7 +2150,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
21452150
RegisterValidationInterface(node.peerman.get());
21462151

21472152
g_ds_notification_interface = std::make_unique<CDSNotificationInterface>(
2148-
*node.connman, *node.dstxman, *node.mn_sync, *node.govman, chainman, node.dmnman, node.llmq_ctx, node.cj_ctx
2153+
*node.connman, *node.dstxman, *node.mn_sync, *node.govman, chainman, node.dmnman, node.llmq_ctx
21492154
);
21502155
RegisterValidationInterface(g_ds_notification_interface.get());
21512156

0 commit comments

Comments
 (0)