From 68a7f92cfdad30ddc32bab1f9863fd3e12e952f5 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:07:34 +0000 Subject: [PATCH] refactor: move `CConnman`, `PeerManager` out of `CCoinJoinClientQueueManager` ctor --- src/coinjoin/client.cpp | 14 +++++++------- src/coinjoin/client.h | 11 +++-------- src/coinjoin/context.cpp | 4 ++-- src/net_processing.cpp | 2 +- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp index 7b240c65966865..21f61ef4767292 100644 --- a/src/coinjoin/client.cpp +++ b/src/coinjoin/client.cpp @@ -30,18 +30,18 @@ #include #include -PeerMsgRet CCoinJoinClientQueueManager::ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv) +PeerMsgRet CCoinJoinClientQueueManager::ProcessMessage(const CNode& peer, CConnman& connman, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv) { if (m_is_masternode) return {}; if (!m_mn_sync.IsBlockchainSynced()) return {}; if (msg_type == NetMsgType::DSQUEUE) { - return CCoinJoinClientQueueManager::ProcessDSQueue(peer, vRecv); + return CCoinJoinClientQueueManager::ProcessDSQueue(peer, connman, peerman, vRecv); } return {}; } -PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataStream& vRecv) +PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CConnman& connman, PeerManager& peerman, CDataStream& vRecv) { assert(m_mn_metaman.IsValid()); @@ -50,7 +50,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS { LOCK(cs_main); - Assert(peerman)->EraseObjectRequest(peer.GetId(), CInv(MSG_DSQ, dsq.GetHash())); + peerman.EraseObjectRequest(peer.GetId(), CInv(MSG_DSQ, dsq.GetHash())); } if (dsq.masternodeOutpoint.IsNull() && dsq.m_protxHash.IsNull()) { @@ -102,8 +102,8 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS } // if the queue is ready, submit if we can - if (dsq.fReady && m_walletman.ForAnyCJClientMan([this, &dmn](std::unique_ptr& clientman) { - return clientman->TrySubmitDenominate(dmn->pdmnState->addr, this->connman); + if (dsq.fReady && m_walletman.ForAnyCJClientMan([this, &connman, &dmn](std::unique_ptr& clientman) { + return clientman->TrySubmitDenominate(dmn->pdmnState->addr, connman); })) { LogPrint(BCLog::COINJOIN, "DSQUEUE -- CoinJoin queue (%s) is ready on masternode %s\n", dsq.ToString(), dmn->pdmnState->addr.ToStringAddrPort()); @@ -132,7 +132,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS WITH_LOCK(cs_vecqueue, vecCoinJoinQueue.push_back(dsq)); } } // cs_ProcessDSQueue - peerman->RelayDSQ(dsq); + peerman.RelayDSQ(dsq); return {}; } diff --git a/src/coinjoin/client.h b/src/coinjoin/client.h index 412a940fe69afd..9ffa176f493c62 100644 --- a/src/coinjoin/client.h +++ b/src/coinjoin/client.h @@ -232,8 +232,6 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession class CCoinJoinClientQueueManager : public CCoinJoinBaseManager { private: - CConnman& connman; - std::unique_ptr& peerman; CoinJoinWalletManager& m_walletman; CDeterministicMNManager& m_dmnman; CMasternodeMetaMan& m_mn_metaman; @@ -243,20 +241,17 @@ class CCoinJoinClientQueueManager : public CCoinJoinBaseManager const bool m_is_masternode; public: - explicit CCoinJoinClientQueueManager(CConnman& _connman, std::unique_ptr& _peerman, - CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, + explicit CCoinJoinClientQueueManager(CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync, bool is_masternode) : - connman(_connman), - peerman(_peerman), m_walletman(walletman), m_dmnman(dmnman), m_mn_metaman(mn_metaman), m_mn_sync(mn_sync), m_is_masternode{is_masternode} {}; - PeerMsgRet ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv) EXCLUSIVE_LOCKS_REQUIRED(!cs_vecqueue); - PeerMsgRet ProcessDSQueue(const CNode& peer, CDataStream& vRecv); + PeerMsgRet ProcessMessage(const CNode& peer, CConnman& connman, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv) EXCLUSIVE_LOCKS_REQUIRED(!cs_vecqueue); + PeerMsgRet ProcessDSQueue(const CNode& peer, CConnman& connman, PeerManager& peerman, CDataStream& vRecv); void DoMaintenance(); }; diff --git a/src/coinjoin/context.cpp b/src/coinjoin/context.cpp index cbf8a2b13ac550..fac18fde055b1c 100644 --- a/src/coinjoin/context.cpp +++ b/src/coinjoin/context.cpp @@ -18,8 +18,8 @@ CJContext::CJContext(ChainstateManager& chainman, CConnman& connman, CDeterminis walletman{std::make_unique(chainman, dmnman, mn_metaman, mempool, mn_sync, queueman, /*is_masternode=*/mn_activeman != nullptr)}, queueman{relay_txes - ? std::make_unique(connman, peerman, *walletman, dmnman, mn_metaman, - mn_sync, /* is_masternode = */ mn_activeman != nullptr) + ? std::make_unique(*walletman, dmnman, mn_metaman, mn_sync, + /*is_masternode=*/mn_activeman != nullptr) : nullptr}, #endif // ENABLE_WALLET server{std::make_unique(chainman, connman, dmnman, *dstxman, mn_metaman, mempool, mn_activeman, diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 47f27e77c2f937..4fc702a822ec34 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -5251,7 +5251,7 @@ void PeerManagerImpl::ProcessMessage( { //probably one the extensions #ifdef ENABLE_WALLET - ProcessPeerMsgRet(m_cj_ctx->queueman->ProcessMessage(pfrom, msg_type, vRecv), pfrom); + ProcessPeerMsgRet(m_cj_ctx->queueman->ProcessMessage(pfrom, m_connman, *this, msg_type, vRecv), pfrom); m_cj_ctx->walletman->ForEachCJClientMan([this, &pfrom, &msg_type, &vRecv](std::unique_ptr& clientman) { clientman->ProcessMessage(pfrom, m_chainman.ActiveChainstate(), m_connman, m_mempool, msg_type, vRecv); });