Skip to content

Commit 48a8fdf

Browse files
committed
coinjoin: reduce chain globals use from CCoinJoinServer
1 parent ed190dc commit 48a8fdf

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
@@ -99,6 +99,7 @@ void DashTestSetup(NodeContext& node)
9999
{
100100
CChainState& chainstate = Assert(node.chainman)->ActiveChainstate();
101101

102+
::coinJoinServer = std::make_unique<CCoinJoinServer>(chainstate, *node.connman, *node.mempool, *::masternodeSync);
102103
::deterministicMNManager = std::make_unique<CDeterministicMNManager>(chainstate, *node.connman, *node.evodb);
103104
node.llmq_ctx = std::make_unique<LLMQContext>(chainstate, *node.connman, *node.evodb, *sporkManager, *node.mempool, node.peerman, true, false);
104105
}
@@ -109,6 +110,7 @@ void DashTestSetupClose(NodeContext& node)
109110
node.llmq_ctx->Stop();
110111
node.llmq_ctx.reset();
111112
::deterministicMNManager.reset();
113+
::coinJoinServer.reset();
112114
}
113115

114116
BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args)
@@ -199,7 +201,6 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
199201
::sporkManager = std::make_unique<CSporkManager>();
200202
::governance = std::make_unique<CGovernanceManager>();
201203
::masternodeSync = std::make_unique<CMasternodeSync>(*m_node.connman);
202-
::coinJoinServer = std::make_unique<CCoinJoinServer>(*m_node.mempool, *m_node.connman, *::masternodeSync);
203204
#ifdef ENABLE_WALLET
204205
::coinJoinClientQueueManager = std::make_unique<CCoinJoinClientQueueManager>(*m_node.connman, *::masternodeSync);
205206
#endif // ENABLE_WALLET
@@ -222,7 +223,6 @@ ChainTestingSetup::~ChainTestingSetup()
222223
#ifdef ENABLE_WALLET
223224
::coinJoinClientQueueManager.reset();
224225
#endif // ENABLE_WALLET
225-
::coinJoinServer.reset();
226226
::masternodeSync.reset();
227227
::governance.reset();
228228
::sporkManager.reset();

0 commit comments

Comments
 (0)