diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp index d8e0d51ef1..d20d5e4a52 100644 --- a/src/coinjoin/client.cpp +++ b/src/coinjoin/client.cpp @@ -42,7 +42,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessMessage(const CNode& peer, std::s PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataStream& vRecv) { - assert(::mmetaman->IsValid()); + assert(m_mn_metaman.IsValid()); CCoinJoinQueue dsq; vRecv >> dsq; @@ -105,18 +105,18 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS dmn->pdmnState->addr.ToString()); return {}; } else { - int64_t nLastDsq = mmetaman->GetMetaInfo(dmn->proTxHash)->GetLastDsq(); - int64_t nDsqThreshold = mmetaman->GetDsqThreshold(dmn->proTxHash, tip_mn_list.GetValidMNsCount()); + int64_t nLastDsq = m_mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastDsq(); + int64_t nDsqThreshold = m_mn_metaman.GetDsqThreshold(dmn->proTxHash, tip_mn_list.GetValidMNsCount()); LogPrint(BCLog::COINJOIN, "DSQUEUE -- nLastDsq: %d nDsqThreshold: %d nDsqCount: %d\n", nLastDsq, - nDsqThreshold, mmetaman->GetDsqCount()); + nDsqThreshold, m_mn_metaman.GetDsqCount()); // don't allow a few nodes to dominate the queuing process - if (nLastDsq != 0 && nDsqThreshold > mmetaman->GetDsqCount()) { + if (nLastDsq != 0 && nDsqThreshold > m_mn_metaman.GetDsqCount()) { LogPrint(BCLog::COINJOIN, "DSQUEUE -- Masternode %s is sending too many dsq messages\n", dmn->proTxHash.ToString()); return {}; } - mmetaman->AllowMixing(dmn->proTxHash); + m_mn_metaman.AllowMixing(dmn->proTxHash); LogPrint(BCLog::COINJOIN, "DSQUEUE -- new CoinJoin queue (%s) from masternode %s\n", dsq.ToString(), dmn->pdmnState->addr.ToString()); @@ -155,12 +155,13 @@ void CCoinJoinClientManager::ProcessMessage(CNode& peer, CConnman& connman, cons } } -CCoinJoinClientSession::CCoinJoinClientSession(CWallet& wallet, CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, const CMasternodeSync& mn_sync, - const std::unique_ptr& queueman) : +CCoinJoinClientSession::CCoinJoinClientSession(CWallet& wallet, CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, + const CMasternodeSync& mn_sync, const std::unique_ptr& queueman) : m_wallet(wallet), m_walletman(walletman), m_manager(*Assert(walletman.Get(wallet.GetName()))), m_dmnman(dmnman), + m_mn_metaman(mn_metaman), m_mn_sync(mn_sync), m_queueman(queueman) {} @@ -990,7 +991,7 @@ bool CCoinJoinClientManager::DoAutomaticDenominating(CConnman& connman, CTxMemPo AssertLockNotHeld(cs_deqsessions); LOCK(cs_deqsessions); if (int(deqSessions.size()) < CCoinJoinClientOptions::GetSessions()) { - deqSessions.emplace_back(m_wallet, m_walletman, m_dmnman, m_mn_sync, m_queueman); + deqSessions.emplace_back(m_wallet, m_walletman, m_dmnman, m_mn_metaman, m_mn_sync, m_queueman); } for (auto& session : deqSessions) { if (!CheckAutomaticBackup()) return false; @@ -1119,7 +1120,7 @@ bool CCoinJoinClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, bool CCoinJoinClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman) { - assert(::mmetaman->IsValid()); + assert(m_mn_metaman.IsValid()); if (!CCoinJoinClientOptions::IsEnabled()) return false; if (nBalanceNeedsAnonymized <= 0) return false; @@ -1156,13 +1157,13 @@ bool CCoinJoinClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CCon continue; } - int64_t nLastDsq = mmetaman->GetMetaInfo(dmn->proTxHash)->GetLastDsq(); - int64_t nDsqThreshold = mmetaman->GetDsqThreshold(dmn->proTxHash, nMnCount); - if (nLastDsq != 0 && nDsqThreshold > mmetaman->GetDsqCount()) { + int64_t nLastDsq = m_mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastDsq(); + int64_t nDsqThreshold = m_mn_metaman.GetDsqThreshold(dmn->proTxHash, nMnCount); + if (nLastDsq != 0 && nDsqThreshold > m_mn_metaman.GetDsqCount()) { WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::StartNewQueue -- Too early to mix on this masternode!" /* Continued */ " masternode=%s addr=%s nLastDsq=%d nDsqThreshold=%d nDsqCount=%d\n", dmn->proTxHash.ToString(), dmn->pdmnState->addr.ToString(), nLastDsq, - nDsqThreshold, mmetaman->GetDsqCount()); + nDsqThreshold, m_mn_metaman.GetDsqCount()); nTries++; continue; } @@ -1892,7 +1893,7 @@ void CCoinJoinClientManager::GetJsonInfo(UniValue& obj) const void CoinJoinWalletManager::Add(CWallet& wallet) { m_wallet_manager_map.try_emplace( wallet.GetName(), - std::make_unique(wallet, *this, m_dmnman, m_mn_sync, m_queueman) + std::make_unique(wallet, *this, m_dmnman, m_mn_metaman, m_mn_sync, m_queueman) ); g_wallet_init_interface.InitCoinJoinSettings(*this); } diff --git a/src/coinjoin/client.h b/src/coinjoin/client.h index 99564414a9..f07c4b7d06 100644 --- a/src/coinjoin/client.h +++ b/src/coinjoin/client.h @@ -21,9 +21,10 @@ class CCoinJoinClientQueueManager; class CConnman; class CDeterministicMN; class CDeterministicMNManager; -class CoinJoinWalletManager; class CNode; +class CMasternodeMetaMan; class CMasternodeSync; +class CoinJoinWalletManager; class CTxMemPool; class UniValue; @@ -72,9 +73,10 @@ public: using wallet_name_cjman_map = std::map>; public: - CoinJoinWalletManager(CConnman& connman, CDeterministicMNManager& dmnman, CTxMemPool& mempool, const CMasternodeSync& mn_sync, - const std::unique_ptr& queueman) - : m_connman(connman), m_dmnman(dmnman), m_mempool(mempool), m_mn_sync(mn_sync), m_queueman(queueman) {} + CoinJoinWalletManager(CConnman& connman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool, + const CMasternodeSync& mn_sync, const std::unique_ptr& queueman) + : m_connman(connman), m_dmnman(dmnman), m_mn_metaman(mn_metaman), m_mempool(mempool), m_mn_sync(mn_sync), m_queueman(queueman) {} + ~CoinJoinWalletManager() { for (auto& [wallet_name, cj_man] : m_wallet_manager_map) { cj_man.reset(); @@ -94,6 +96,7 @@ public: private: CConnman& m_connman; CDeterministicMNManager& m_dmnman; + CMasternodeMetaMan& m_mn_metaman; CTxMemPool& m_mempool; const CMasternodeSync& m_mn_sync; const std::unique_ptr& m_queueman; @@ -108,6 +111,7 @@ private: CoinJoinWalletManager& m_walletman; CCoinJoinClientManager& m_manager; CDeterministicMNManager& m_dmnman; + CMasternodeMetaMan& m_mn_metaman; const CMasternodeSync& m_mn_sync; const std::unique_ptr& m_queueman; @@ -157,8 +161,8 @@ private: void SetNull() override EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin); public: - explicit CCoinJoinClientSession(CWallet& wallet, CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, const CMasternodeSync& mn_sync, - const std::unique_ptr& queueman); + explicit CCoinJoinClientSession(CWallet& wallet, CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, + const CMasternodeSync& mn_sync, const std::unique_ptr& queueman); void ProcessMessage(CNode& peer, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv); @@ -191,13 +195,14 @@ private: CConnman& connman; CoinJoinWalletManager& m_walletman; CDeterministicMNManager& m_dmnman; + CMasternodeMetaMan& m_mn_metaman; const CMasternodeSync& m_mn_sync; mutable Mutex cs_ProcessDSQueue; public: explicit CCoinJoinClientQueueManager(CConnman& _connman, CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, - const CMasternodeSync& mn_sync) : - connman(_connman), m_walletman(walletman), m_dmnman(dmnman), m_mn_sync(mn_sync) {}; + CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync) : + connman(_connman), m_walletman(walletman), m_dmnman(dmnman), m_mn_metaman(mn_metaman), m_mn_sync(mn_sync) {}; PeerMsgRet ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv) LOCKS_EXCLUDED(cs_vecqueue); PeerMsgRet ProcessDSQueue(const CNode& peer, CDataStream& vRecv); @@ -212,6 +217,7 @@ private: CWallet& m_wallet; CoinJoinWalletManager& m_walletman; CDeterministicMNManager& m_dmnman; + CMasternodeMetaMan& m_mn_metaman; const CMasternodeSync& m_mn_sync; const std::unique_ptr& m_queueman; @@ -244,9 +250,10 @@ public: CCoinJoinClientManager(CCoinJoinClientManager const&) = delete; CCoinJoinClientManager& operator=(CCoinJoinClientManager const&) = delete; - explicit CCoinJoinClientManager(CWallet& wallet, CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, const CMasternodeSync& mn_sync, + explicit CCoinJoinClientManager(CWallet& wallet, CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, + CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync, const std::unique_ptr& queueman) : - m_wallet(wallet), m_walletman(walletman), m_dmnman(dmnman), m_mn_sync(mn_sync), m_queueman(queueman) {} + m_wallet(wallet), m_walletman(walletman), m_dmnman(dmnman), m_mn_metaman(mn_metaman), m_mn_sync(mn_sync), m_queueman(queueman) {} void ProcessMessage(CNode& peer, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) LOCKS_EXCLUDED(cs_deqsessions); diff --git a/src/coinjoin/context.cpp b/src/coinjoin/context.cpp index 286a5928ca..46ec89a156 100644 --- a/src/coinjoin/context.cpp +++ b/src/coinjoin/context.cpp @@ -13,14 +13,15 @@ #endif // ENABLE_WALLET #include -CJContext::CJContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, CTxMemPool& mempool, - const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, bool relay_txes) : +CJContext::CJContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, + CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, + bool relay_txes) : dstxman{std::make_unique()}, #ifdef ENABLE_WALLET - walletman{std::make_unique(connman, dmnman, mempool, mn_sync, queueman)}, - queueman {relay_txes ? std::make_unique(connman, *walletman, dmnman, mn_sync) : nullptr}, + walletman{std::make_unique(connman, dmnman, mn_metaman, mempool, mn_sync, queueman)}, + queueman {relay_txes ? std::make_unique(connman, *walletman, dmnman, mn_metaman, mn_sync) : nullptr}, #endif // ENABLE_WALLET - server{std::make_unique(chainstate, connman, dmnman, *dstxman, mempool, mn_activeman, mn_sync)} + server{std::make_unique(chainstate, connman, dmnman, *dstxman, mn_metaman, mempool, mn_activeman, mn_sync)} {} CJContext::~CJContext() {} diff --git a/src/coinjoin/context.h b/src/coinjoin/context.h index c3257447c6..881daed6d0 100644 --- a/src/coinjoin/context.h +++ b/src/coinjoin/context.h @@ -18,6 +18,7 @@ class CCoinJoinServer; class CConnman; class CDeterministicMNManager; class CDSTXManager; +class CMasternodeMetaMan; class CMasternodeSync; class CTxMemPool; @@ -29,8 +30,9 @@ class CoinJoinWalletManager; struct CJContext { CJContext() = delete; CJContext(const CJContext&) = delete; - CJContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, CTxMemPool& mempool, - const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, bool relay_txes); + CJContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, + CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, + bool relay_txes); ~CJContext(); const std::unique_ptr dstxman; diff --git a/src/coinjoin/server.cpp b/src/coinjoin/server.cpp index d1d279a570..250e965c61 100644 --- a/src/coinjoin/server.cpp +++ b/src/coinjoin/server.cpp @@ -44,7 +44,7 @@ PeerMsgRet CCoinJoinServer::ProcessMessage(CNode& peer, std::string_view msg_typ void CCoinJoinServer::ProcessDSACCEPT(CNode& peer, CDataStream& vRecv) { assert(m_mn_activeman); - assert(::mmetaman->IsValid()); + assert(m_mn_metaman.IsValid()); if (IsSessionReady()) { // too many users in this session already, reject new ones @@ -81,9 +81,9 @@ void CCoinJoinServer::ProcessDSACCEPT(CNode& peer, CDataStream& vRecv) } } - int64_t nLastDsq = mmetaman->GetMetaInfo(dmn->proTxHash)->GetLastDsq(); - int64_t nDsqThreshold = mmetaman->GetDsqThreshold(dmn->proTxHash, mnList.GetValidMNsCount()); - if (nLastDsq != 0 && nDsqThreshold > mmetaman->GetDsqCount()) { + int64_t nLastDsq = m_mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastDsq(); + int64_t nDsqThreshold = m_mn_metaman.GetDsqThreshold(dmn->proTxHash, mnList.GetValidMNsCount()); + if (nLastDsq != 0 && nDsqThreshold > m_mn_metaman.GetDsqCount()) { if (fLogIPs) { LogPrint(BCLog::COINJOIN, "DSACCEPT -- last dsq too recent, must wait: peer=%d, addr=%s\n", peer.GetId(), peer.addr.ToString()); } else { @@ -111,7 +111,7 @@ void CCoinJoinServer::ProcessDSACCEPT(CNode& peer, CDataStream& vRecv) PeerMsgRet CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv) { - assert(::mmetaman->IsValid()); + assert(m_mn_metaman.IsValid()); CCoinJoinQueue dsq; vRecv >> dsq; @@ -162,15 +162,15 @@ PeerMsgRet CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv } if (!dsq.fReady) { - int64_t nLastDsq = mmetaman->GetMetaInfo(dmn->proTxHash)->GetLastDsq(); - int64_t nDsqThreshold = mmetaman->GetDsqThreshold(dmn->proTxHash, tip_mn_list.GetValidMNsCount()); - LogPrint(BCLog::COINJOIN, "DSQUEUE -- nLastDsq: %d nDsqThreshold: %d nDsqCount: %d\n", nLastDsq, nDsqThreshold, mmetaman->GetDsqCount()); + int64_t nLastDsq = m_mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastDsq(); + int64_t nDsqThreshold = m_mn_metaman.GetDsqThreshold(dmn->proTxHash, tip_mn_list.GetValidMNsCount()); + LogPrint(BCLog::COINJOIN, "DSQUEUE -- nLastDsq: %d nDsqThreshold: %d nDsqCount: %d\n", nLastDsq, nDsqThreshold, m_mn_metaman.GetDsqCount()); //don't allow a few nodes to dominate the queuing process - if (nLastDsq != 0 && nDsqThreshold > mmetaman->GetDsqCount()) { + if (nLastDsq != 0 && nDsqThreshold > m_mn_metaman.GetDsqCount()) { LogPrint(BCLog::COINJOIN, "DSQUEUE -- Masternode %s is sending too many dsq messages\n", dmn->pdmnState->addr.ToString()); return {}; } - mmetaman->AllowMixing(dmn->proTxHash); + m_mn_metaman.AllowMixing(dmn->proTxHash); LogPrint(BCLog::COINJOIN, "DSQUEUE -- new CoinJoin queue (%s) from masternode %s\n", dsq.ToString(), dmn->pdmnState->addr.ToString()); diff --git a/src/coinjoin/server.h b/src/coinjoin/server.h index 3f0df14543..9913224c28 100644 --- a/src/coinjoin/server.h +++ b/src/coinjoin/server.h @@ -15,6 +15,7 @@ class CCoinJoinServer; class CDataStream; class CDeterministicMNManager; class CDSTXManager; +class CMasternodeMetaMan; class CNode; class CTxMemPool; @@ -29,6 +30,7 @@ private: CConnman& connman; CDeterministicMNManager& m_dmnman; CDSTXManager& m_dstxman; + CMasternodeMetaMan& m_mn_metaman; CTxMemPool& mempool; const CActiveMasternodeManager* const m_mn_activeman; const CMasternodeSync& m_mn_sync; @@ -87,11 +89,13 @@ private: public: explicit CCoinJoinServer(CChainState& chainstate, CConnman& _connman, CDeterministicMNManager& dmnman, CDSTXManager& dstxman, - CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync) : + CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, + const CMasternodeSync& mn_sync) : m_chainstate(chainstate), connman(_connman), m_dmnman(dmnman), m_dstxman(dstxman), + m_mn_metaman(mn_metaman), mempool(mempool), m_mn_activeman(mn_activeman), m_mn_sync(mn_sync), diff --git a/src/evo/mnauth.cpp b/src/evo/mnauth.cpp index ff733cfe42..6c61dc5af1 100644 --- a/src/evo/mnauth.cpp +++ b/src/evo/mnauth.cpp @@ -62,10 +62,10 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternode connman.PushMessage(&peer, CNetMsgMaker(peer.GetCommonVersion()).Make(NetMsgType::MNAUTH, mnauth)); } -PeerMsgRet CMNAuth::ProcessMessage(CNode& peer, CConnman& connman, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, - const CDeterministicMNList& tip_mn_list, std::string_view msg_type, CDataStream& vRecv) +PeerMsgRet CMNAuth::ProcessMessage(CNode& peer, CConnman& connman, CMasternodeMetaMan& mn_metaman, const CActiveMasternodeManager* const mn_activeman, + const CMasternodeSync& mn_sync, const CDeterministicMNList& tip_mn_list, std::string_view msg_type, CDataStream& vRecv) { - assert(::mmetaman->IsValid()); + assert(mn_metaman.IsValid()); if (msg_type != NetMsgType::MNAUTH || !mn_sync.IsBlockchainSynced()) { // we can't verify MNAUTH messages when we don't have the latest MN list @@ -125,7 +125,7 @@ PeerMsgRet CMNAuth::ProcessMessage(CNode& peer, CConnman& connman, const CActive } if (!peer.IsInboundConn()) { - mmetaman->GetMetaInfo(mnauth.proRegTxHash)->SetLastOutboundSuccess(GetTime().count()); + mn_metaman.GetMetaInfo(mnauth.proRegTxHash)->SetLastOutboundSuccess(GetTime().count()); if (peer.m_masternode_probe_connection) { LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- Masternode probe successful for %s, disconnecting. peer=%d\n", mnauth.proRegTxHash.ToString(), peer.GetId()); diff --git a/src/evo/mnauth.h b/src/evo/mnauth.h index 1212efbb20..211dae0cf2 100644 --- a/src/evo/mnauth.h +++ b/src/evo/mnauth.h @@ -17,6 +17,7 @@ class CDeterministicMN; class CDeterministicMNList; class CDeterministicMNListDiff; class CDeterministicMNManager; +class CMasternodeMetaMan; class CMasternodeSync; class CNode; @@ -57,8 +58,8 @@ public: * @pre CMasternodeMetaMan's database must be successfully loaded before * attempting to call this function regardless of sync state */ - static PeerMsgRet ProcessMessage(CNode& peer, CConnman& connman, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, - const CDeterministicMNList& tip_mn_list, std::string_view msg_type, CDataStream& vRecv); + static PeerMsgRet ProcessMessage(CNode& peer, CConnman& connman, CMasternodeMetaMan& mn_metaman, const CActiveMasternodeManager* const mn_activeman, + const CMasternodeSync& mn_sync, const CDeterministicMNList& tip_mn_list, std::string_view msg_type, CDataStream& vRecv); static void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff, CConnman& connman); }; diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 31dbe42a39..0214111127 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -43,10 +43,11 @@ GovernanceStore::GovernanceStore() : { } -CGovernanceManager::CGovernanceManager(CNetFulfilledRequestManager& netfulfilledman, +CGovernanceManager::CGovernanceManager(CMasternodeMetaMan& mn_metaman, CNetFulfilledRequestManager& netfulfilledman, const std::unique_ptr& dmnman, const std::unique_ptr& mn_sync) : m_db{std::make_unique("governance.dat", "magicGovernanceCache")}, + m_mn_metaman{mn_metaman}, m_netfulfilledman{netfulfilledman}, m_dmnman{dmnman}, m_mn_sync{mn_sync}, @@ -275,7 +276,7 @@ void CGovernanceManager::CheckOrphanVotes(CGovernanceObject& govobj, CConnman& c CGovernanceException e; if (pairVote.second < nNow) { fRemove = true; - } else if (govobj.ProcessVote(*this, tip_mn_list, vote, e)) { + } else if (govobj.ProcessVote(m_mn_metaman, *this, tip_mn_list, vote, e)) { vote.Relay(connman, *Assert(m_mn_sync), tip_mn_list); fRemove = true; } @@ -347,14 +348,14 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman void CGovernanceManager::CheckAndRemove() { - assert(::mmetaman->IsValid()); + assert(m_mn_metaman.IsValid()); // Return on initial sync, spammed the debug.log and provided no use if (m_mn_sync == nullptr || !m_mn_sync->IsBlockchainSynced()) return; LogPrint(BCLog::GOBJECT, "CGovernanceManager::UpdateCachesAndClean\n"); - std::vector vecDirtyHashes = mmetaman->GetAndClearDirtyGovernanceObjectHashes(); + std::vector vecDirtyHashes = m_mn_metaman.GetAndClearDirtyGovernanceObjectHashes(); const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip(); @@ -401,7 +402,7 @@ void CGovernanceManager::CheckAndRemove() if ((pObj->IsSetCachedDelete() || pObj->IsSetExpired()) && (nTimeSinceDeletion >= GOVERNANCE_DELETION_DELAY)) { LogPrint(BCLog::GOBJECT, "CGovernanceManager::UpdateCachesAndClean -- erase obj %s\n", (*it).first.ToString()); - mmetaman->RemoveGovernanceObject(pObj->GetHash()); + m_mn_metaman.RemoveGovernanceObject(pObj->GetHash()); // Remove vote references const object_ref_cm_t::list_t& listItems = cmapVoteToObject.GetItemList(); @@ -1123,7 +1124,7 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote, return false; } - bool fOk = govobj.ProcessVote(*this, Assert(m_dmnman)->GetListAtChainTip(), vote, exception) && cmapVoteToObject.Insert(nHashVote, &govobj); + bool fOk = govobj.ProcessVote(m_mn_metaman, *this, Assert(m_dmnman)->GetListAtChainTip(), vote, exception) && cmapVoteToObject.Insert(nHashVote, &govobj); LEAVE_CRITICAL_SECTION(cs); return fOk; } diff --git a/src/governance/governance.h b/src/governance/governance.h index 58e070ce5f..cad15d52aa 100644 --- a/src/governance/governance.h +++ b/src/governance/governance.h @@ -25,6 +25,7 @@ class CDeterministicMNManager; class CGovernanceManager; class CGovernanceObject; class CGovernanceVote; +class CMasternodeMetaMan; class CMasternodeSync; class CNetFulfilledRequestManager; class CSporkManager; @@ -255,6 +256,7 @@ private: const std::unique_ptr m_db; bool is_valid{false}; + CMasternodeMetaMan& m_mn_metaman; CNetFulfilledRequestManager& m_netfulfilledman; const std::unique_ptr& m_dmnman; const std::unique_ptr& m_mn_sync; @@ -271,7 +273,7 @@ private: std::map> mapTrigger; public: - explicit CGovernanceManager(CNetFulfilledRequestManager& netfulfilledman, + explicit CGovernanceManager(CMasternodeMetaMan& mn_metaman, CNetFulfilledRequestManager& netfulfilledman, const std::unique_ptr& dmnman, const std::unique_ptr& mn_sync); ~CGovernanceManager(); diff --git a/src/governance/object.cpp b/src/governance/object.cpp index 3217b3703b..dfd28b3879 100644 --- a/src/governance/object.cpp +++ b/src/governance/object.cpp @@ -80,9 +80,10 @@ CGovernanceObject::CGovernanceObject(const CGovernanceObject& other) : { } -bool CGovernanceObject::ProcessVote(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, const CGovernanceVote& vote, CGovernanceException& exception) +bool CGovernanceObject::ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, + const CGovernanceVote& vote, CGovernanceException& exception) { - assert(::mmetaman->IsValid()); + assert(mn_metaman.IsValid()); LOCK(cs); @@ -180,7 +181,7 @@ bool CGovernanceObject::ProcessVote(CGovernanceManager& govman, const CDetermini return false; } - if (!mmetaman->AddGovernanceVote(dmn->proTxHash, vote.GetParentHash())) { + if (!mn_metaman.AddGovernanceVote(dmn->proTxHash, vote.GetParentHash())) { std::ostringstream ostr; ostr << "CGovernanceObject::ProcessVote -- Unable to add governance vote" << ", MN outpoint = " << vote.GetMasternodeOutpoint().ToStringShort() diff --git a/src/governance/object.h b/src/governance/object.h index 5ee5e3f79f..d7f22bad9b 100644 --- a/src/governance/object.h +++ b/src/governance/object.h @@ -19,6 +19,7 @@ class CDeterministicMNList; class CGovernanceManager; class CGovernanceObject; class CGovernanceVote; +class CMasternodeMetaMan; class CMasternodeSync; class CNode; @@ -290,7 +291,8 @@ public: void LoadData(); void GetData(UniValue& objResult) const; - bool ProcessVote(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, const CGovernanceVote& vote, CGovernanceException& exception); + bool ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, + const CGovernanceVote& vote, CGovernanceException& exception); /// Called when MN's which have voted on this object have been removed void ClearMasternodeVotes(const CDeterministicMNList& tip_mn_list); diff --git a/src/init.cpp b/src/init.cpp index 4f3dfc430d..02154bf686 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -309,8 +309,7 @@ void PrepareShutdown(NodeContext& node) node.sporkman.reset(); node.govman.reset(); node.netfulfilledman.reset(); - node.mn_metaman = nullptr; - ::mmetaman.reset(); + node.mn_metaman.reset(); // Stop and delete all indexes only after flushing background callbacks. if (g_txindex) { @@ -1677,15 +1676,14 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc node.chainman = &g_chainman; ChainstateManager& chainman = *Assert(node.chainman); - assert(!::mmetaman); - ::mmetaman = std::make_unique(); - node.mn_metaman = ::mmetaman.get(); + assert(!node.mn_metaman); + node.mn_metaman = std::make_unique(); assert(!node.netfulfilledman); node.netfulfilledman = std::make_unique(); assert(!node.govman); - node.govman = std::make_unique(*node.netfulfilledman, ::deterministicMNManager, node.mn_sync); + node.govman = std::make_unique(*node.mn_metaman, *node.netfulfilledman, ::deterministicMNManager, node.mn_sync); assert(!node.sporkman); node.sporkman = std::make_unique(); @@ -1958,7 +1956,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc node.llmq_ctx->Stop(); } node.llmq_ctx.reset(); - node.llmq_ctx = std::make_unique(chainman.ActiveChainstate(), *node.connman, *node.dmnman, *node.evodb, *node.mnhf_manager, *node.sporkman, + node.llmq_ctx = std::make_unique(chainman.ActiveChainstate(), *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool, node.mn_activeman.get(), *node.mn_sync, node.peerman, /* unit_tests = */ false, /* wipe = */ fReset || fReindexChainState); // Have to start it early to let VerifyDB check ChainLock signatures in coinbase node.llmq_ctx->Start(); @@ -2204,8 +2202,8 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc // ********************************************************* Step 7c: Setup CoinJoin - node.cj_ctx = std::make_unique(chainman.ActiveChainstate(), *node.connman, *node.dmnman, *node.mempool, node.mn_activeman.get(), - *node.mn_sync, !ignores_incoming_txs); + node.cj_ctx = std::make_unique(chainman.ActiveChainstate(), *node.connman, *node.dmnman, *node.mn_metaman, *node.mempool, + node.mn_activeman.get(), *node.mn_sync, !ignores_incoming_txs); #ifdef ENABLE_WALLET node.coinjoin_loader = interfaces::MakeCoinJoinLoader(*node.cj_ctx->walletman); diff --git a/src/llmq/context.cpp b/src/llmq/context.cpp index 5228d358d6..cc32e7a0dd 100644 --- a/src/llmq/context.cpp +++ b/src/llmq/context.cpp @@ -20,8 +20,9 @@ #include LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, CEvoDB& evo_db, - CMNHFManager& mnhfman, CSporkManager& sporkman, CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, - const CMasternodeSync& mn_sync, const std::unique_ptr& peerman, bool unit_tests, bool wipe) : + CMasternodeMetaMan& mn_metaman, CMNHFManager& mnhfman, CSporkManager& sporkman, CTxMemPool& mempool, + const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, + const std::unique_ptr& peerman, bool unit_tests, bool wipe) : bls_worker{std::make_shared()}, dkg_debugman{std::make_unique()}, quorum_block_processor{[&]() -> llmq::CQuorumBlockProcessor* const { @@ -29,7 +30,7 @@ LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CDeterminis llmq::quorumBlockProcessor = std::make_unique(chainstate, connman, dmnman, evo_db); return llmq::quorumBlockProcessor.get(); }()}, - qdkgsman{std::make_unique(*bls_worker, chainstate, connman, dmnman, *dkg_debugman, *quorum_block_processor, mn_activeman, sporkman, unit_tests, wipe)}, + qdkgsman{std::make_unique(*bls_worker, chainstate, connman, dmnman, *dkg_debugman, mn_metaman, *quorum_block_processor, mn_activeman, sporkman, unit_tests, wipe)}, qman{[&]() -> llmq::CQuorumManager* const { assert(llmq::quorumManager == nullptr); llmq::quorumManager = std::make_unique(*bls_worker, chainstate, connman, dmnman, *qdkgsman, evo_db, *quorum_block_processor, mn_activeman, mn_sync, sporkman); diff --git a/src/llmq/context.h b/src/llmq/context.h index b3723fc973..531dcb0525 100644 --- a/src/llmq/context.h +++ b/src/llmq/context.h @@ -14,6 +14,7 @@ class CConnman; class CDeterministicMNManager; class CDBWrapper; class CEvoDB; +class CMasternodeMetaMan; class CMasternodeSync; class CMNHFManager; class CSporkManager; @@ -36,8 +37,9 @@ struct LLMQContext { LLMQContext() = delete; LLMQContext(const LLMQContext&) = delete; LLMQContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, CEvoDB& evo_db, - CMNHFManager& mnhfman, CSporkManager& sporkman, CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman, - const CMasternodeSync& mn_sync, const std::unique_ptr& peerman, bool unit_tests, bool wipe); + CMasternodeMetaMan& mn_metaman, CMNHFManager& mnhfman, CSporkManager& sporkman, CTxMemPool& mempool, + const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, + const std::unique_ptr& peerman, bool unit_tests, bool wipe); ~LLMQContext(); void Interrupt(); diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp index cb0c9bb1bb..ead2adab8f 100644 --- a/src/llmq/dkgsession.cpp +++ b/src/llmq/dkgsession.cpp @@ -450,7 +450,7 @@ void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages) void CDKGSession::VerifyConnectionAndMinProtoVersions() const { - assert(::mmetaman->IsValid()); + assert(m_mn_metaman.IsValid()); if (!IsQuorumPoseEnabled(params.type, m_sporkman)) { return; @@ -482,7 +482,7 @@ void CDKGSession::VerifyConnectionAndMinProtoVersions() const logger.Batch("%s does not have min proto version %d (has %d)", m->dmn->proTxHash.ToString(), MIN_MASTERNODE_PROTO_VERSION, it->second); } - if (mmetaman->GetMetaInfo(m->dmn->proTxHash)->OutboundFailedTooManyTimes()) { + if (m_mn_metaman.GetMetaInfo(m->dmn->proTxHash)->OutboundFailedTooManyTimes()) { m->badConnection = true; logger.Batch("%s failed to connect to it too many times", m->dmn->proTxHash.ToString()); } diff --git a/src/llmq/dkgsession.h b/src/llmq/dkgsession.h index 16da61894b..5b19d6a097 100644 --- a/src/llmq/dkgsession.h +++ b/src/llmq/dkgsession.h @@ -19,6 +19,7 @@ class CActiveMasternodeManager; class CInv; class CConnman; class CDeterministicMN; +class CMasternodeMetaMan; class CSporkManager; class UniValue; @@ -272,9 +273,11 @@ private: CBLSWorker& blsWorker; CBLSWorkerCache cache; + CConnman& connman; CDeterministicMNManager& m_dmnman; CDKGSessionManager& dkgManager; CDKGDebugManager& dkgDebugManager; + CMasternodeMetaMan& m_mn_metaman; const CActiveMasternodeManager* const m_mn_activeman; const CSporkManager& m_sporkman; @@ -297,7 +300,6 @@ private: uint256 myProTxHash; CBLSId myId; - CConnman& connman; std::optional myIdx; // all indexed by msg hash @@ -317,11 +319,12 @@ private: std::set validCommitments GUARDED_BY(invCs); public: - CDKGSession(const Consensus::LLMQParams& _params, CBLSWorker& _blsWorker, CDeterministicMNManager& dmnman, - CDKGSessionManager& _dkgManager, CDKGDebugManager& _dkgDebugManager, CConnman& _connman, - const CActiveMasternodeManager* const mn_activeman, const CSporkManager& sporkman) : - params(_params), blsWorker(_blsWorker), cache(_blsWorker), m_dmnman(dmnman), dkgManager(_dkgManager), - dkgDebugManager(_dkgDebugManager), m_mn_activeman(mn_activeman), m_sporkman(sporkman), connman(_connman) {} + CDKGSession(const Consensus::LLMQParams& _params, CBLSWorker& _blsWorker, CConnman& _connman, + CDeterministicMNManager& dmnman, CDKGSessionManager& _dkgManager, CDKGDebugManager& _dkgDebugManager, + CMasternodeMetaMan& mn_metaman, const CActiveMasternodeManager* const mn_activeman, + const CSporkManager& sporkman) : + params(_params), blsWorker(_blsWorker), cache(_blsWorker), connman(_connman), m_dmnman(dmnman), dkgManager(_dkgManager), + dkgDebugManager(_dkgDebugManager), m_mn_metaman(mn_metaman), m_mn_activeman(mn_activeman), m_sporkman(sporkman) {} bool Init(gsl::not_null pQuorumBaseBlockIndex, Span mns, const uint256& _myProTxHash, int _quorumIndex); diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index 429b2b2c47..43eb04a5fb 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -25,21 +25,22 @@ namespace llmq { CDKGSessionHandler::CDKGSessionHandler(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman, CDeterministicMNManager& dmnman, - CDKGDebugManager& _dkgDebugManager, CDKGSessionManager& _dkgManager, CQuorumBlockProcessor& _quorumBlockProcessor, - const CActiveMasternodeManager* const mn_activeman, const CSporkManager& sporkman, const Consensus::LLMQParams& _params, - int _quorumIndex) : + CDKGDebugManager& _dkgDebugManager, CDKGSessionManager& _dkgManager, CMasternodeMetaMan& mn_metaman, + CQuorumBlockProcessor& _quorumBlockProcessor, const CActiveMasternodeManager* const mn_activeman, + const CSporkManager& sporkman, const Consensus::LLMQParams& _params, int _quorumIndex) : blsWorker(_blsWorker), m_chainstate(chainstate), connman(_connman), m_dmnman(dmnman), dkgDebugManager(_dkgDebugManager), dkgManager(_dkgManager), + m_mn_metaman(mn_metaman), quorumBlockProcessor(_quorumBlockProcessor), m_mn_activeman(mn_activeman), m_sporkman(sporkman), params(_params), quorumIndex(_quorumIndex), - curSession(std::make_unique(_params, _blsWorker, dmnman, _dkgManager, _dkgDebugManager, _connman, m_mn_activeman, sporkman)), + curSession(std::make_unique(_params, _blsWorker, _connman, dmnman, _dkgManager, _dkgDebugManager, m_mn_metaman, m_mn_activeman, sporkman)), pendingContributions((size_t)_params.size * 2, MSG_QUORUM_CONTRIB), // we allow size*2 messages as we need to make sure we see bad behavior (double messages) pendingComplaints((size_t)_params.size * 2, MSG_QUORUM_COMPLAINT), pendingJustifications((size_t)_params.size * 2, MSG_QUORUM_JUSTIFICATION), @@ -187,7 +188,7 @@ void CDKGSessionHandler::StopThread() bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex) { - curSession = std::make_unique(params, blsWorker, m_dmnman, dkgManager, dkgDebugManager, connman, m_mn_activeman, m_sporkman); + curSession = std::make_unique(params, blsWorker, connman, m_dmnman, dkgManager, dkgDebugManager, m_mn_metaman, m_mn_activeman, m_sporkman); if (!DeploymentDIP0003Enforced(pQuorumBaseBlockIndex->nHeight, Params().GetConsensus())) { return false; @@ -533,7 +534,7 @@ void CDKGSessionHandler::HandleDKGRound() const auto tip_mn_list = m_dmnman.GetListAtChainTip(); utils::EnsureQuorumConnections(params, connman, m_dmnman, m_sporkman, tip_mn_list, pQuorumBaseBlockIndex, curSession->myProTxHash); if (curSession->AreWeMember()) { - utils::AddQuorumProbeConnections(params, connman, m_dmnman, m_sporkman, tip_mn_list, pQuorumBaseBlockIndex, curSession->myProTxHash); + utils::AddQuorumProbeConnections(params, connman, m_dmnman, m_mn_metaman, m_sporkman, tip_mn_list, pQuorumBaseBlockIndex, curSession->myProTxHash); } WaitForNextPhase(QuorumPhase::Initialized, QuorumPhase::Contribute, curQuorumHash); diff --git a/src/llmq/dkgsessionhandler.h b/src/llmq/dkgsessionhandler.h index c8121edcf1..fb509be8ec 100644 --- a/src/llmq/dkgsessionhandler.h +++ b/src/llmq/dkgsessionhandler.h @@ -19,6 +19,7 @@ class CBlockIndex; class CBLSWorker; class CChainState; class CDeterministicMNManager; +class CMasternodeMetaMan; class CSporkManager; class PeerManager; @@ -125,6 +126,7 @@ private: CDeterministicMNManager& m_dmnman; CDKGDebugManager& dkgDebugManager; CDKGSessionManager& dkgManager; + CMasternodeMetaMan& m_mn_metaman; CQuorumBlockProcessor& quorumBlockProcessor; const CActiveMasternodeManager* const m_mn_activeman; const CSporkManager& m_sporkman; @@ -147,9 +149,9 @@ private: public: CDKGSessionHandler(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman, CDeterministicMNManager& dmnman, - CDKGDebugManager& _dkgDebugManager, CDKGSessionManager& _dkgManager, CQuorumBlockProcessor& _quorumBlockProcessor, - const CActiveMasternodeManager* const mn_activeman, const CSporkManager& sporkman, const Consensus::LLMQParams& _params, - int _quorumIndex); + CDKGDebugManager& _dkgDebugManager, CDKGSessionManager& _dkgManager, CMasternodeMetaMan& mn_metaman, + CQuorumBlockProcessor& _quorumBlockProcessor, const CActiveMasternodeManager* const mn_activeman, + const CSporkManager& sporkman, const Consensus::LLMQParams& _params, int _quorumIndex); ~CDKGSessionHandler() = default; void UpdatedBlockTip(const CBlockIndex *pindexNew); diff --git a/src/llmq/dkgsessionmgr.cpp b/src/llmq/dkgsessionmgr.cpp index 9715368f6c..707edf9ec0 100644 --- a/src/llmq/dkgsessionmgr.cpp +++ b/src/llmq/dkgsessionmgr.cpp @@ -25,8 +25,8 @@ static const std::string DB_SKCONTRIB = "qdkg_S"; static const std::string DB_ENC_CONTRIB = "qdkg_E"; CDKGSessionManager::CDKGSessionManager(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman, CDeterministicMNManager& dmnman, - CDKGDebugManager& _dkgDebugManager, CQuorumBlockProcessor& _quorumBlockProcessor, const CActiveMasternodeManager* const mn_activeman, - const CSporkManager& sporkman, bool unitTests, bool fWipe) : + CDKGDebugManager& _dkgDebugManager, CMasternodeMetaMan& mn_metaman, CQuorumBlockProcessor& _quorumBlockProcessor, + const CActiveMasternodeManager* const mn_activeman, const CSporkManager& sporkman, bool unitTests, bool fWipe) : db(std::make_unique(unitTests ? "" : (GetDataDir() / "llmq/dkgdb"), 1 << 20, unitTests, fWipe)), blsWorker(_blsWorker), m_chainstate(chainstate), @@ -49,7 +49,7 @@ CDKGSessionManager::CDKGSessionManager(CBLSWorker& _blsWorker, CChainState& chai for (const auto i : irange::range(session_count)) { dkgSessionHandlers.emplace(std::piecewise_construct, std::forward_as_tuple(params.type, i), - std::forward_as_tuple(blsWorker, m_chainstate, connman, dmnman, dkgDebugManager, *this, quorumBlockProcessor, mn_activeman, spork_manager, params, i)); + std::forward_as_tuple(blsWorker, m_chainstate, connman, dmnman, dkgDebugManager, *this, mn_metaman, quorumBlockProcessor, mn_activeman, spork_manager, params, i)); } } } diff --git a/src/llmq/dkgsessionmgr.h b/src/llmq/dkgsessionmgr.h index d237f77eaa..d920b50bfb 100644 --- a/src/llmq/dkgsessionmgr.h +++ b/src/llmq/dkgsessionmgr.h @@ -20,6 +20,7 @@ class CChainState; class CDBWrapper; class CDeterministicMNManager; class CDKGDebugManager; +class CMasternodeMetaMan; class CSporkManager; class PeerManager; @@ -67,8 +68,8 @@ private: public: CDKGSessionManager(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman, CDeterministicMNManager& dmnman, - CDKGDebugManager& _dkgDebugManager, CQuorumBlockProcessor& _quorumBlockProcessor, const CActiveMasternodeManager* const mn_activeman, - const CSporkManager& sporkman, bool unitTests, bool fWipe); + CDKGDebugManager& _dkgDebugManager, CMasternodeMetaMan& mn_metaman, CQuorumBlockProcessor& _quorumBlockProcessor, + const CActiveMasternodeManager* const mn_activeman, const CSporkManager& sporkman, bool unitTests, bool fWipe); ~CDKGSessionManager() = default; void StartThreads(); diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index 2f2ed213c4..9fc63deb47 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -808,11 +808,11 @@ bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, CConnman& return true; } -void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman& connman, CDeterministicMNManager& dmnman, const CSporkManager& sporkman, - const CDeterministicMNList& tip_mn_list, gsl::not_null pQuorumBaseBlockIndex, - const uint256 &myProTxHash) +void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman& connman, CDeterministicMNManager& dmnman, + CMasternodeMetaMan& mn_metaman, const CSporkManager& sporkman, const CDeterministicMNList& tip_mn_list, + gsl::not_null pQuorumBaseBlockIndex, const uint256 &myProTxHash) { - assert(::mmetaman->IsValid()); + assert(mn_metaman.IsValid()); if (!IsQuorumPoseEnabled(llmqParams.type, sporkman)) { return; @@ -826,7 +826,7 @@ void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman if (dmn->proTxHash == myProTxHash) { continue; } - auto lastOutbound = mmetaman->GetMetaInfo(dmn->proTxHash)->GetLastOutboundSuccess(); + auto lastOutbound = mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastOutboundSuccess(); if (curTime - lastOutbound < 10 * 60) { // avoid re-probing nodes too often continue; diff --git a/src/llmq/utils.h b/src/llmq/utils.h index e9e1275be8..9e219b507a 100644 --- a/src/llmq/utils.h +++ b/src/llmq/utils.h @@ -19,9 +19,11 @@ class CBlockIndex; class CDeterministicMN; class CDeterministicMNList; class CDeterministicMNManager; -using CDeterministicMNCPtr = std::shared_ptr; +class CMasternodeMetaMan; class CSporkManager; +using CDeterministicMNCPtr = std::shared_ptr; + namespace llmq { @@ -39,9 +41,9 @@ std::set CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, CConnman& connman, CDeterministicMNManager& dmnman, const CSporkManager& sporkman, const CDeterministicMNList& tip_mn_list, gsl::not_null pQuorumBaseBlockIndex, const uint256& myProTxHash); -void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman& connman, CDeterministicMNManager& dmnman, const CSporkManager& sporkman, - const CDeterministicMNList& tip_mn_list, gsl::not_null pQuorumBaseBlockIndex, - const uint256& myProTxHash); +void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman& connman, CDeterministicMNManager& dmnman, + CMasternodeMetaMan& mn_metaman, const CSporkManager& sporkman, const CDeterministicMNList& tip_mn_list, + gsl::not_null pQuorumBaseBlockIndex, const uint256& myProTxHash); template void InitQuorumsCache(CacheType& cache, bool limit_by_connections = true); diff --git a/src/masternode/meta.cpp b/src/masternode/meta.cpp index 7c7861640c..3160e280ad 100644 --- a/src/masternode/meta.cpp +++ b/src/masternode/meta.cpp @@ -9,8 +9,6 @@ #include -std::unique_ptr mmetaman; - const std::string MasternodeMetaStore::SERIALIZATION_VERSION_STRING = "CMasternodeMetaMan-Version-3"; CMasternodeMetaMan::CMasternodeMetaMan() : diff --git a/src/masternode/meta.h b/src/masternode/meta.h index b2c4dfc371..d6177a8ca1 100644 --- a/src/masternode/meta.h +++ b/src/masternode/meta.h @@ -176,6 +176,4 @@ public: std::vector GetAndClearDirtyGovernanceObjectHashes(); }; -extern std::unique_ptr mmetaman; - #endif // BITCOIN_MASTERNODE_META_H diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 24d1c0ff81..96c3766fda 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -4630,7 +4630,7 @@ void PeerManagerImpl::ProcessMessage( ProcessPeerMsgRet(m_sporkman.ProcessMessage(pfrom, m_connman, msg_type, vRecv), pfrom); m_mn_sync.ProcessMessage(pfrom, msg_type, vRecv); ProcessPeerMsgRet(m_govman.ProcessMessage(pfrom, m_connman, msg_type, vRecv), pfrom); - ProcessPeerMsgRet(CMNAuth::ProcessMessage(pfrom, m_connman, m_mn_activeman, m_mn_sync, m_dmnman->GetListAtChainTip(), msg_type, vRecv), pfrom); + ProcessPeerMsgRet(CMNAuth::ProcessMessage(pfrom, m_connman, m_mn_metaman, m_mn_activeman, m_mn_sync, m_dmnman->GetListAtChainTip(), msg_type, vRecv), pfrom); ProcessPeerMsgRet(m_llmq_ctx->quorum_block_processor->ProcessMessage(pfrom, msg_type, vRecv), pfrom); ProcessPeerMsgRet(m_llmq_ctx->qdkgsman->ProcessMessage(pfrom, this, msg_type, vRecv), pfrom); ProcessPeerMsgRet(m_llmq_ctx->qman->ProcessMessage(pfrom, msg_type, vRecv), pfrom); diff --git a/src/node/context.cpp b/src/node/context.cpp index 7592fbe95f..7aa05d0288 100644 --- a/src/node/context.cpp +++ b/src/node/context.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/src/node/context.h b/src/node/context.h index 09e3c07826..604227ff7a 100644 --- a/src/node/context.h +++ b/src/node/context.h @@ -77,13 +77,13 @@ struct NodeContext { std::unique_ptr chain_helper; std::unique_ptr govman; std::unique_ptr cj_ctx; + std::unique_ptr mn_metaman; std::unique_ptr mn_sync; std::unique_ptr mnhf_manager; std::unique_ptr netfulfilledman; std::unique_ptr sporkman; std::unique_ptr llmq_ctx; CDeterministicMNManager* dmnman{nullptr}; - CMasternodeMetaMan* mn_metaman{nullptr}; //! Declare default constructor and destructor that are not inline, so code //! instantiating the NodeContext struct doesn't need to #include class diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index b10f7f4e09..3ab291a777 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -111,11 +111,12 @@ void DashTestSetup(NodeContext& node, const CChainParams& chainparams) ::deterministicMNManager = std::make_unique(chainstate, *node.connman, *node.evodb); node.dmnman = ::deterministicMNManager.get(); - node.cj_ctx = std::make_unique(chainstate, *node.connman, *node.dmnman, *node.mempool, /* mn_activeman = */ nullptr, *node.mn_sync, /* relay_txes = */ true); + node.cj_ctx = std::make_unique(chainstate, *node.connman, *node.dmnman, *node.mn_metaman, *node.mempool, + /* mn_activeman = */ nullptr, *node.mn_sync, /* relay_txes = */ true); #ifdef ENABLE_WALLET node.coinjoin_loader = interfaces::MakeCoinJoinLoader(*node.cj_ctx->walletman); #endif // ENABLE_WALLET - node.llmq_ctx = std::make_unique(chainstate, *node.connman, *node.dmnman, *node.evodb, *node.mnhf_manager, *node.sporkman, *node.mempool, + node.llmq_ctx = std::make_unique(chainstate, *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool, /* mn_activeman = */ nullptr, *node.mn_sync, node.peerman, /* unit_tests = */ true, /* wipe = */ false); node.chain_helper = std::make_unique(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor), chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler)); @@ -227,11 +228,10 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve m_node.connman = std::make_unique(0x1337, 0x1337, *m_node.addrman); // Deterministic randomness for tests. - ::mmetaman = std::make_unique(); - m_node.mn_metaman = ::mmetaman.get(); + m_node.mn_metaman = std::make_unique(); m_node.netfulfilledman = std::make_unique(); m_node.sporkman = std::make_unique(); - m_node.govman = std::make_unique(*m_node.netfulfilledman, ::deterministicMNManager, m_node.mn_sync); + m_node.govman = std::make_unique(*m_node.mn_metaman, *m_node.netfulfilledman, ::deterministicMNManager, m_node.mn_sync); m_node.mn_sync = std::make_unique(*m_node.connman, *m_node.netfulfilledman, *m_node.govman); // Start script-checking threads. Set g_parallel_script_checks to true so they are used. @@ -250,8 +250,7 @@ ChainTestingSetup::~ChainTestingSetup() m_node.govman.reset(); m_node.sporkman.reset(); m_node.netfulfilledman.reset(); - m_node.mn_metaman = nullptr; - ::mmetaman.reset(); + m_node.mn_metaman.reset(); m_node.connman.reset(); m_node.addrman.reset(); m_node.args = nullptr;