From 7d26061170d2d95dc9c0d39375d6e5017fc2859d Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Wed, 4 Dec 2024 18:20:10 +0000 Subject: [PATCH] refactor: move `CConnman`, `PeerManager` out of `CCoinJoinClientQueueManager` ctor --- src/coinjoin/client.cpp | 17 ++++++++++------- src/coinjoin/client.h | 12 ++++-------- src/coinjoin/context.cpp | 7 +++---- src/net_processing.cpp | 2 +- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp index 7b240c6596..85c35bc8a7 100644 --- a/src/coinjoin/client.cpp +++ b/src/coinjoin/client.cpp @@ -30,18 +30,20 @@ #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 +52,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 +104,9 @@ 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 +135,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 69db7d1e73..2eccc1cfc2 100644 --- a/src/coinjoin/client.h +++ b/src/coinjoin/client.h @@ -232,8 +232,6 @@ public: class CCoinJoinClientQueueManager : public CCoinJoinBaseManager { private: - CConnman& connman; - std::unique_ptr& peerman; CoinJoinWalletManager& m_walletman; CDeterministicMNManager& m_dmnman; CMasternodeMetaMan& m_mn_metaman; @@ -243,20 +241,18 @@ private: 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 cbf8a2b13a..8ab6f9e636 100644 --- a/src/coinjoin/context.cpp +++ b/src/coinjoin/context.cpp @@ -17,10 +17,9 @@ CJContext::CJContext(ChainstateManager& chainman, CConnman& connman, CDeterminis #ifdef ENABLE_WALLET 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) - : nullptr}, + queueman{relay_txes ? 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, mn_sync, peerman)} diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 47f27e77c2..4fc702a822 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); });