Skip to content

Commit 1d6d97a

Browse files
committed
coinjoin: reduce chain globals use from CCoinJoinServer
1 parent b7aa576 commit 1d6d97a

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/coinjoin/server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void CCoinJoinServer::CommitFinalTransaction()
322322
TRY_LOCK(cs_main, lockMain);
323323
TxValidationState validationState;
324324
mempool.PrioritiseTransaction(hashTx, 0.1 * COIN);
325-
if (!lockMain || !AcceptToMemoryPool(::ChainstateActive(), mempool, validationState, finalTransaction, false /* bypass_limits */, DEFAULT_MAX_RAW_TX_FEE /* nAbsurdFee */)) {
325+
if (!lockMain || !AcceptToMemoryPool(m_chainstate, mempool, validationState, finalTransaction, false /* bypass_limits */, DEFAULT_MAX_RAW_TX_FEE /* nAbsurdFee */)) {
326326
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CommitFinalTransaction -- AcceptToMemoryPool() error: Transaction not valid\n");
327327
WITH_LOCK(cs_coinjoin, SetNull());
328328
// not much we can do in this case, just notify clients
@@ -455,7 +455,7 @@ void CCoinJoinServer::ConsumeCollateral(const CTransactionRef& txref) const
455455
{
456456
LOCK(cs_main);
457457
TxValidationState validationState;
458-
if (!AcceptToMemoryPool(::ChainstateActive(), mempool, validationState, txref, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
458+
if (!AcceptToMemoryPool(m_chainstate, mempool, validationState, txref, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
459459
LogPrint(BCLog::COINJOIN, "%s -- AcceptToMemoryPool failed\n", __func__);
460460
} else {
461461
connman.RelayTransaction(*txref);

src/coinjoin/server.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <coinjoin/coinjoin.h>
99
#include <net.h>
1010

11+
class CChainState;
1112
class CCoinJoinServer;
1213
class CTxMemPool;
1314
class PeerManager;
@@ -22,8 +23,9 @@ extern std::unique_ptr<CCoinJoinServer> coinJoinServer;
2223
class CCoinJoinServer : public CCoinJoinBaseSession, public CCoinJoinBaseManager
2324
{
2425
private:
25-
CTxMemPool& mempool;
26+
CChainState& m_chainstate;
2627
CConnman& connman;
28+
CTxMemPool& mempool;
2729
const CMasternodeSync& m_mn_sync;
2830

2931
// Mixing uses collateral transactions to trust parties entering the pool
@@ -79,9 +81,10 @@ class CCoinJoinServer : public CCoinJoinBaseSession, public CCoinJoinBaseManager
7981
void SetNull() EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin);
8082

8183
public:
82-
explicit CCoinJoinServer(CTxMemPool& mempool, CConnman& _connman, const CMasternodeSync& mn_sync) :
83-
mempool(mempool),
84+
explicit CCoinJoinServer(CChainState& chainstate, CConnman& _connman, CTxMemPool& mempool, const CMasternodeSync& mn_sync) :
85+
m_chainstate(chainstate),
8486
connman(_connman),
87+
mempool(mempool),
8588
m_mn_sync(mn_sync),
8689
vecSessionCollaterals(),
8790
fUnitTest(false)

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
22492249

22502250
// ********************************************************* Step 10a: Setup CoinJoin
22512251

2252-
::coinJoinServer = std::make_unique<CCoinJoinServer>(*node.mempool, *node.connman, *::masternodeSync);
2252+
::coinJoinServer = std::make_unique<CCoinJoinServer>(chainman.ActiveChainstate(), *node.connman, *node.mempool, *::masternodeSync);
22532253
#ifdef ENABLE_WALLET
22542254
if (!ignores_incoming_txs) {
22552255
::coinJoinClientQueueManager = std::make_unique<CCoinJoinClientQueueManager>(*node.connman, *::masternodeSync);

src/test/util/setup_common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void InitComponents(NodeContext& node)
100100
{
101101
CChainState& chainstate = Assert(node.chainman)->ActiveChainstate();
102102

103+
::coinJoinServer = std::make_unique<CCoinJoinServer>(chainstate, *node.connman, *node.mempool, *::masternodeSync);
103104
::deterministicMNManager = std::make_unique<CDeterministicMNManager>(chainstate, *node.connman, *node.evodb);
104105
node.llmq_ctx = std::make_unique<LLMQContext>(chainstate, *node.connman, *node.evodb, *sporkManager, *node.mempool, node.peerman, true, false);
105106
}
@@ -110,6 +111,7 @@ void DestroyComponents(NodeContext& node)
110111
node.llmq_ctx->Stop();
111112
node.llmq_ctx.reset();
112113
::deterministicMNManager.reset();
114+
::coinJoinServer.reset();
113115
}
114116
} /* namespace dash */
115117

@@ -201,7 +203,6 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
201203
::sporkManager = std::make_unique<CSporkManager>();
202204
::governance = std::make_unique<CGovernanceManager>();
203205
::masternodeSync = std::make_unique<CMasternodeSync>(*m_node.connman);
204-
::coinJoinServer = std::make_unique<CCoinJoinServer>(*m_node.mempool, *m_node.connman, *::masternodeSync);
205206
#ifdef ENABLE_WALLET
206207
::coinJoinClientQueueManager = std::make_unique<CCoinJoinClientQueueManager>(*m_node.connman, *::masternodeSync);
207208
#endif // ENABLE_WALLET
@@ -224,7 +225,6 @@ ChainTestingSetup::~ChainTestingSetup()
224225
#ifdef ENABLE_WALLET
225226
::coinJoinClientQueueManager.reset();
226227
#endif // ENABLE_WALLET
227-
::coinJoinServer.reset();
228228
::masternodeSync.reset();
229229
::governance.reset();
230230
::sporkManager.reset();

0 commit comments

Comments
 (0)