diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp index d20d5e4a52..af13dda262 100644 --- a/src/coinjoin/client.cpp +++ b/src/coinjoin/client.cpp @@ -31,7 +31,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv) { - if (fMasternodeMode) return {}; + if (m_is_masternode) return {}; if (!m_mn_sync.IsBlockchainSynced()) return {}; if (msg_type == NetMsgType::DSQUEUE) { @@ -133,7 +133,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS void CCoinJoinClientManager::ProcessMessage(CNode& peer, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) { - if (fMasternodeMode) return; + if (m_is_masternode) return; if (!CCoinJoinClientOptions::IsEnabled()) return; if (!m_mn_sync.IsBlockchainSynced()) return; @@ -156,19 +156,20 @@ void CCoinJoinClientManager::ProcessMessage(CNode& peer, CConnman& connman, cons } CCoinJoinClientSession::CCoinJoinClientSession(CWallet& wallet, CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, - const CMasternodeSync& mn_sync, const std::unique_ptr& queueman) : + const CMasternodeSync& mn_sync, const std::unique_ptr& queueman, bool is_masternode) : 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) + m_queueman(queueman), + m_is_masternode{is_masternode} {} void CCoinJoinClientSession::ProcessMessage(CNode& peer, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) { - if (fMasternodeMode) return; + if (m_is_masternode) return; if (!CCoinJoinClientOptions::IsEnabled()) return; if (!m_mn_sync.IsBlockchainSynced()) return; @@ -385,7 +386,7 @@ bool CCoinJoinClientManager::GetMixingMasternodesInfo(std::vector >& vecPSInOutPairsIn, CConnman& connman) { - if (fMasternodeMode) { + if (m_is_masternode) { WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::SendDenominate -- CoinJoin from a Masternode is not supported currently.\n"); return false; } @@ -497,7 +498,7 @@ bool CCoinJoinClientSession::SendDenominate(const std::vector(wallet, *this, m_dmnman, m_mn_metaman, m_mn_sync, m_queueman) + std::make_unique(wallet, *this, m_dmnman, m_mn_metaman, m_mn_sync, m_queueman, m_is_masternode) ); g_wallet_init_interface.InitCoinJoinSettings(*this); } diff --git a/src/coinjoin/client.h b/src/coinjoin/client.h index f07c4b7d06..fb0a257729 100644 --- a/src/coinjoin/client.h +++ b/src/coinjoin/client.h @@ -74,8 +74,10 @@ public: public: 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) {} + const CMasternodeSync& mn_sync, const std::unique_ptr& queueman, bool is_masternode) + : m_connman(connman), m_dmnman(dmnman), m_mn_metaman(mn_metaman), m_mempool(mempool), m_mn_sync(mn_sync), m_queueman(queueman), + m_is_masternode{is_masternode} + {} ~CoinJoinWalletManager() { for (auto& [wallet_name, cj_man] : m_wallet_manager_map) { @@ -101,6 +103,7 @@ private: const CMasternodeSync& m_mn_sync; const std::unique_ptr& m_queueman; + const bool m_is_masternode; wallet_name_cjman_map m_wallet_manager_map; }; @@ -115,6 +118,9 @@ private: const CMasternodeSync& m_mn_sync; const std::unique_ptr& m_queueman; + // Track node type + const bool m_is_masternode; + std::vector vecOutPointLocked; bilingual_str strLastMessage; @@ -162,7 +168,7 @@ private: public: explicit CCoinJoinClientSession(CWallet& wallet, CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, - const CMasternodeSync& mn_sync, const std::unique_ptr& queueman); + const CMasternodeSync& mn_sync, const std::unique_ptr& queueman, bool is_masternode); void ProcessMessage(CNode& peer, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv); @@ -197,12 +203,14 @@ private: CDeterministicMNManager& m_dmnman; CMasternodeMetaMan& m_mn_metaman; const CMasternodeSync& m_mn_sync; + mutable Mutex cs_ProcessDSQueue; + const bool m_is_masternode; public: explicit CCoinJoinClientQueueManager(CConnman& _connman, CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, - 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) {}; + CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync, bool is_masternode) : + connman(_connman), 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) LOCKS_EXCLUDED(cs_vecqueue); PeerMsgRet ProcessDSQueue(const CNode& peer, CDataStream& vRecv); @@ -221,6 +229,9 @@ private: const CMasternodeSync& m_mn_sync; const std::unique_ptr& m_queueman; + // Track node type + const bool m_is_masternode; + // Keep track of the used Masternodes std::vector vecMasternodesUsed; @@ -252,8 +263,9 @@ public: 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_metaman(mn_metaman), m_mn_sync(mn_sync), m_queueman(queueman) {} + const std::unique_ptr& queueman, bool is_masternode) : + m_wallet(wallet), m_walletman(walletman), m_dmnman(dmnman), m_mn_metaman(mn_metaman), m_mn_sync(mn_sync), m_queueman(queueman), + m_is_masternode{is_masternode} {} 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 2b974cdf6c..f8a47466cf 100644 --- a/src/coinjoin/context.cpp +++ b/src/coinjoin/context.cpp @@ -14,8 +14,8 @@ CJContext::CJContext(CChainState& chainstate, CConnman& connman, CDeterministicM const std::unique_ptr& peerman, bool relay_txes) : dstxman{std::make_unique()}, #ifdef ENABLE_WALLET - 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}, + walletman{std::make_unique(connman, dmnman, mn_metaman, mempool, mn_sync, queueman, /* is_masternode = */ mn_activeman != nullptr)}, + queueman {relay_txes ? std::make_unique(connman, *walletman, dmnman, mn_metaman, mn_sync, /* is_masternode = */ mn_activeman != nullptr) : nullptr}, #endif // ENABLE_WALLET server{std::make_unique(chainstate, connman, dmnman, *dstxman, mn_metaman, mempool, mn_activeman, mn_sync, peerman)} {} diff --git a/src/coinjoin/server.cpp b/src/coinjoin/server.cpp index 3c3e312a77..a3b7a8c61e 100644 --- a/src/coinjoin/server.cpp +++ b/src/coinjoin/server.cpp @@ -27,7 +27,7 @@ PeerMsgRet CCoinJoinServer::ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv) { - if (!fMasternodeMode) return {}; + if (!m_mn_activeman) return {}; if (!m_mn_sync.IsBlockchainSynced()) return {}; if (msg_type == NetMsgType::DSACCEPT) { @@ -249,7 +249,7 @@ void CCoinJoinServer::SetNull() // void CCoinJoinServer::CheckPool() { - if (!fMasternodeMode) return; + if (!m_mn_activeman) return; if (int entries = GetEntriesCount(); entries != 0) LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CheckPool -- entries count %lu\n", entries); @@ -312,9 +312,7 @@ void CCoinJoinServer::CreateFinalTransaction() void CCoinJoinServer::CommitFinalTransaction() { AssertLockNotHeld(cs_coinjoin); - if (!fMasternodeMode) return; // check and relay final tx only on masternode - - assert(m_mn_activeman); + if (!m_mn_activeman) return; // check and relay final tx only on masternode CTransactionRef finalTransaction = WITH_LOCK(cs_coinjoin, return MakeTransactionRef(finalMutableTransaction)); uint256 hashTx = finalTransaction->GetHash(); @@ -377,7 +375,7 @@ void CCoinJoinServer::CommitFinalTransaction() void CCoinJoinServer::ChargeFees() const { AssertLockNotHeld(cs_coinjoin); - if (!fMasternodeMode) return; + if (!m_mn_activeman) return; //we don't need to charge collateral for every offence. if (GetRandInt(100) > 33) return; @@ -445,7 +443,7 @@ void CCoinJoinServer::ChargeFees() const */ void CCoinJoinServer::ChargeRandomFees() const { - if (!fMasternodeMode) return; + if (!m_mn_activeman) return; for (const auto& txCollateral : vecSessionCollaterals) { if (GetRandInt(100) > 10) return; @@ -467,7 +465,7 @@ void CCoinJoinServer::ConsumeCollateral(const CTransactionRef& txref) const bool CCoinJoinServer::HasTimedOut() const { - if (!fMasternodeMode) return false; + if (!m_mn_activeman) return false; if (nState == POOL_STATE_IDLE) return false; @@ -481,7 +479,7 @@ bool CCoinJoinServer::HasTimedOut() const // void CCoinJoinServer::CheckTimeout() { - if (!fMasternodeMode) return; + if (!m_mn_activeman) return; CheckQueue(); @@ -501,9 +499,7 @@ void CCoinJoinServer::CheckTimeout() */ void CCoinJoinServer::CheckForCompleteQueue() { - if (!fMasternodeMode) return; - - assert(m_mn_activeman); + if (!m_mn_activeman) return; if (nState == POOL_STATE_QUEUE && IsSessionReady()) { SetState(POOL_STATE_ACCEPTING_ENTRIES); @@ -570,7 +566,7 @@ bool CCoinJoinServer::IsInputScriptSigValid(const CTxIn& txin) const bool CCoinJoinServer::AddEntry(const CCoinJoinEntry& entry, PoolMessage& nMessageIDRet) { AssertLockNotHeld(cs_coinjoin); - if (!fMasternodeMode) return false; + if (!m_mn_activeman) return false; if (size_t(GetEntriesCount()) >= vecSessionCollaterals.size()) { LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- ERROR: entries is full!\n", __func__); @@ -679,7 +675,7 @@ bool CCoinJoinServer::IsSignaturesComplete() const bool CCoinJoinServer::IsAcceptableDSA(const CCoinJoinAccept& dsa, PoolMessage& nMessageIDRet) const { - if (!fMasternodeMode) return false; + if (!m_mn_activeman) return false; // is denom even something legit? if (!CoinJoin::IsValidDenomination(dsa.nDenom)) { @@ -700,9 +696,7 @@ bool CCoinJoinServer::IsAcceptableDSA(const CCoinJoinAccept& dsa, PoolMessage& n bool CCoinJoinServer::CreateNewSession(const CCoinJoinAccept& dsa, PoolMessage& nMessageIDRet) { - if (!fMasternodeMode || nSessionID != 0) return false; - - assert(m_mn_activeman); + if (!m_mn_activeman || nSessionID != 0) return false; // new session can only be started in idle mode if (nState != POOL_STATE_IDLE) { @@ -744,7 +738,7 @@ bool CCoinJoinServer::CreateNewSession(const CCoinJoinAccept& dsa, PoolMessage& bool CCoinJoinServer::AddUserToExistingSession(const CCoinJoinAccept& dsa, PoolMessage& nMessageIDRet) { - if (!fMasternodeMode || nSessionID == 0 || IsSessionReady()) return false; + if (!m_mn_activeman || nSessionID == 0 || IsSessionReady()) return false; if (!IsAcceptableDSA(dsa, nMessageIDRet)) { return false; @@ -880,7 +874,7 @@ void CCoinJoinServer::RelayCompletedTransaction(PoolMessage nMessageID) void CCoinJoinServer::SetState(PoolState nStateNew) { - if (!fMasternodeMode) return; + if (!m_mn_activeman) return; if (nStateNew == POOL_STATE_ERROR) { LogPrint(BCLog::COINJOIN, "CCoinJoinServer::SetState -- Can't set state to ERROR as a Masternode. \n"); @@ -894,7 +888,7 @@ void CCoinJoinServer::SetState(PoolState nStateNew) void CCoinJoinServer::DoMaintenance() { - if (!fMasternodeMode) return; // only run on masternodes + if (!m_mn_activeman) return; // only run on masternodes if (!m_mn_sync.IsBlockchainSynced()) return; if (ShutdownRequested()) return; diff --git a/src/dsnotificationinterface.cpp b/src/dsnotificationinterface.cpp index f540b15114..45931a633b 100644 --- a/src/dsnotificationinterface.cpp +++ b/src/dsnotificationinterface.cpp @@ -97,9 +97,11 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con m_llmq_ctx->qman->UpdatedBlockTip(pindexNew, fInitialDownload); m_llmq_ctx->qdkgsman->UpdatedBlockTip(pindexNew, fInitialDownload); - m_llmq_ctx->ehfSignalsHandler->UpdatedBlockTip(pindexNew); + m_llmq_ctx->ehfSignalsHandler->UpdatedBlockTip(pindexNew, /* is_masternode = */ m_mn_activeman != nullptr); - if (!fDisableGovernance) m_govman.UpdatedBlockTip(pindexNew, m_connman, m_peerman, m_mn_activeman); + if (m_govman.IsValid()) { + m_govman.UpdatedBlockTip(pindexNew, m_connman, m_peerman, m_mn_activeman); + } } void CDSNotificationInterface::TransactionAddedToMempool(const CTransactionRef& ptx, int64_t nAcceptTime) diff --git a/src/evo/mnauth.cpp b/src/evo/mnauth.cpp index 6c61dc5af1..9e9de36f97 100644 --- a/src/evo/mnauth.cpp +++ b/src/evo/mnauth.cpp @@ -22,8 +22,6 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternodeManager& mn_activeman, const CBlockIndex* tip) { - assert(fMasternodeMode); - CMNAuth mnauth; if (mn_activeman.GetProTxHash().IsNull()) { return; @@ -134,9 +132,7 @@ PeerMsgRet CMNAuth::ProcessMessage(CNode& peer, CConnman& connman, CMasternodeMe } } - const uint256 myProTxHash = fMasternodeMode ? - Assert(mn_activeman)->GetProTxHash() : - uint256(); + const uint256 myProTxHash = mn_activeman != nullptr ? mn_activeman->GetProTxHash() : uint256(); connman.ForEachNode([&](CNode* pnode2) { if (peer.fDisconnect) { @@ -145,7 +141,7 @@ PeerMsgRet CMNAuth::ProcessMessage(CNode& peer, CConnman& connman, CMasternodeMe } if (pnode2->GetVerifiedProRegTxHash() == mnauth.proRegTxHash) { - if (fMasternodeMode && !myProTxHash.IsNull()) { + if (mn_activeman != nullptr && !myProTxHash.IsNull()) { const auto deterministicOutbound = llmq::utils::DeterministicOutboundConnection(myProTxHash, mnauth.proRegTxHash); LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- Masternode %s has already verified as peer %d, deterministicOutbound=%s. peer=%d\n", mnauth.proRegTxHash.ToString(), pnode2->GetId(), deterministicOutbound.ToString(), peer.GetId()); diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 7b8ad1532a..19348ba303 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -121,7 +121,7 @@ bool CGovernanceManager::SerializeVoteForHash(const uint256& nHash, CDataStream& PeerMsgRet CGovernanceManager::ProcessMessage(CNode& peer, CConnman& connman, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv) { - if (fDisableGovernance) return {}; + if (!IsValid()) return {}; if (m_mn_sync == nullptr || !m_mn_sync->IsBlockchainSynced()) return {}; const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip(); @@ -565,7 +565,7 @@ struct sortProposalsByVotes { std::optional CGovernanceManager::CreateSuperblockCandidate(int nHeight) const { - if (!fMasternodeMode || fDisableGovernance) return std::nullopt; + if (!IsValid()) return std::nullopt; if (m_mn_sync == nullptr || !m_mn_sync->IsSynced()) return std::nullopt; if (nHeight % Params().GetConsensus().nSuperblockCycle < Params().GetConsensus().nSuperblockCycle - Params().GetConsensus().nSuperblockMaturityWindow) return std::nullopt; if (HasAlreadyVotedFundingTrigger()) return std::nullopt; @@ -673,10 +673,8 @@ std::optional CGovernanceManager::CreateSuperblockCandidate(i } std::optional CGovernanceManager::CreateGovernanceTrigger(const std::optional& sb_opt, PeerManager& peerman, - const CActiveMasternodeManager* const mn_activeman) + const CActiveMasternodeManager& mn_activeman) { - if (!fMasternodeMode) return std::nullopt; - // no sb_opt, no trigger if (!sb_opt.has_value()) return std::nullopt; @@ -700,12 +698,12 @@ std::optional CGovernanceManager::CreateGovernanceTrigg return std::nullopt; } - if (mn_payees.front()->proTxHash != Assert(mn_activeman)->GetProTxHash()) { + if (mn_payees.front()->proTxHash != mn_activeman.GetProTxHash()) { LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s we are not the payee, skipping\n", __func__); return std::nullopt; } - gov_sb.SetMasternodeOutpoint(mn_activeman->GetOutPoint()); - gov_sb.Sign(*mn_activeman); + gov_sb.SetMasternodeOutpoint(mn_activeman.GetOutPoint()); + gov_sb.Sign(mn_activeman); if (std::string strError; !gov_sb.IsValidLocally(m_dmnman->GetListAtChainTip(), strError, true)) { LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s Created trigger is invalid:%s\n", __func__, strError); @@ -723,11 +721,10 @@ std::optional CGovernanceManager::CreateGovernanceTrigg } void CGovernanceManager::VoteGovernanceTriggers(const std::optional& trigger_opt, CConnman& connman, PeerManager& peerman, - const CActiveMasternodeManager* const mn_activeman) + const CActiveMasternodeManager& mn_activeman) { // only active masternodes can vote on triggers - if (!fMasternodeMode) return; - if (Assert(mn_activeman)->GetProTxHash().IsNull()) return; + if (mn_activeman.GetProTxHash().IsNull()) return; LOCK2(cs_main, cs); @@ -769,13 +766,11 @@ void CGovernanceManager::VoteGovernanceTriggers(const std::optionalGetOutPoint(), nHash, VOTE_SIGNAL_FUNDING, outcome); + CGovernanceVote vote(mn_activeman.GetOutPoint(), nHash, VOTE_SIGNAL_FUNDING, outcome); vote.SetTime(GetAdjustedTime()); - vote.Sign(*mn_activeman); + vote.Sign(mn_activeman); CGovernanceException exception; if (!ProcessVoteAndRelay(vote, exception, connman, peerman)) { @@ -798,7 +793,7 @@ void CGovernanceManager::ResetVotedFundingTrigger() void CGovernanceManager::DoMaintenance(CConnman& connman) { - if (fDisableGovernance) return; + if (!IsValid()) return; if (m_mn_sync == nullptr || !m_mn_sync->IsSynced()) return; if (ShutdownRequested()) return; @@ -1485,9 +1480,11 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex* pindex, CConnman& co return; } - const auto sb_opt = CreateSuperblockCandidate(pindex->nHeight); - const auto trigger_opt = CreateGovernanceTrigger(sb_opt, peerman, mn_activeman); - VoteGovernanceTriggers(trigger_opt, connman, peerman, mn_activeman); + if (mn_activeman) { + const auto sb_opt = CreateSuperblockCandidate(pindex->nHeight); + const auto trigger_opt = CreateGovernanceTrigger(sb_opt, peerman, *mn_activeman); + VoteGovernanceTriggers(trigger_opt, connman, peerman, *mn_activeman); + } nCachedBlockHeight = pindex->nHeight; LogPrint(BCLog::GOBJECT, "CGovernanceManager::UpdatedBlockTip -- nCachedBlockHeight: %d\n", nCachedBlockHeight); diff --git a/src/governance/governance.h b/src/governance/governance.h index 9cfe0a0a7c..ddb859603e 100644 --- a/src/governance/governance.h +++ b/src/governance/governance.h @@ -33,6 +33,7 @@ class CNetFulfilledRequestManager; class CSporkManager; static constexpr int RATE_BUFFER_SIZE = 5; +static constexpr bool DEFAULT_GOVERNANCE_ENABLE{true}; class CDeterministicMNList; using CDeterministicMNListPtr = std::shared_ptr; @@ -371,11 +372,11 @@ public: private: std::optional CreateSuperblockCandidate(int nHeight) const; std::optional CreateGovernanceTrigger(const std::optional& sb_opt, PeerManager& peerman, - const CActiveMasternodeManager* const mn_activeman); + const CActiveMasternodeManager& mn_activeman); void VoteGovernanceTriggers(const std::optional& trigger_opt, CConnman& connman, PeerManager& peerman, - const CActiveMasternodeManager* const mn_activeman); + const CActiveMasternodeManager& mn_activeman); bool VoteFundingTrigger(const uint256& nHash, const vote_outcome_enum_t outcome, CConnman& connman, PeerManager& peerman, - const CActiveMasternodeManager* const mn_activeman); + const CActiveMasternodeManager& mn_activeman); bool HasAlreadyVotedFundingTrigger() const; void RequestGovernanceObject(CNode* pfrom, const uint256& nHash, CConnman& connman, bool fUseFilter = false) const; diff --git a/src/init.cpp b/src/init.cpp index 37c5383d49..f57dd4a5e0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -366,7 +366,7 @@ void PrepareShutdown(NodeContext& node) delete pdsNotificationInterface; pdsNotificationInterface = nullptr; } - if (fMasternodeMode) { + if (node.mn_activeman) { UnregisterValidationInterface(node.mn_activeman.get()); node.mn_activeman.reset(); } @@ -1230,7 +1230,7 @@ bool AppInitParameterInteraction(const ArgsManager& args) return InitError(_("Prune mode is incompatible with -txindex.")); if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) return InitError(_("Prune mode is incompatible with -coinstatsindex.")); - if (!args.GetBoolArg("-disablegovernance", false)) { + if (!args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)) { return InitError(_("Prune mode is incompatible with -disablegovernance=false.")); } } @@ -1454,15 +1454,12 @@ bool AppInitParameterInteraction(const ArgsManager& args) if (args.GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS) < DEFAULT_MAX_PEER_CONNECTIONS) { return InitError(strprintf(Untranslated("Masternode must be able to handle at least %d connections, set -maxconnections=%d"), DEFAULT_MAX_PEER_CONNECTIONS, DEFAULT_MAX_PEER_CONNECTIONS)); } - if (args.GetBoolArg("-disablegovernance", false)) { + if (args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)) { return InitError(_("You can not disable governance validation on a masternode.")); } } - fDisableGovernance = args.GetBoolArg("-disablegovernance", false); - LogPrintf("fDisableGovernance %d\n", fDisableGovernance); - - if (fDisableGovernance) { + if (args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)) { InitWarning(_("You are starting with governance validation disabled.") + (fPruneMode ? Untranslated(" ") + _("This is expected because you are running a pruned node.") : @@ -1684,6 +1681,15 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc assert(!node.netfulfilledman); node.netfulfilledman = std::make_unique(); + /** + * The manager needs to be constructed regardless of whether governance + * validation is needed or not. + * + * Instead, we decide whether to initialize its database based on whether we + * need it or not further down and then query if the database is initialized + * to check if validation is enabled. + */ + const bool is_governance_enabled{!args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)}; assert(!node.govman); node.govman = std::make_unique(*node.mn_metaman, *node.netfulfilledman, node.dmnman, node.mn_sync); @@ -1988,7 +1994,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc break; } - if (!fDisableGovernance && !args.GetBoolArg("-txindex", DEFAULT_TXINDEX) && chainparams.NetworkIDString() != CBaseChainParams::REGTEST) { // TODO remove this when pruning is fixed. See https://github.com/dashpay/dash/pull/1817 and https://github.com/dashpay/dash/pull/1743 + if (is_governance_enabled && !args.GetBoolArg("-txindex", DEFAULT_TXINDEX) && chainparams.NetworkIDString() != CBaseChainParams::REGTEST) { // TODO remove this when pruning is fixed. See https://github.com/dashpay/dash/pull/1817 and https://github.com/dashpay/dash/pull/1743 return InitError(_("Transaction index can't be disabled with governance validation enabled. Either start with -disablegovernance command line switch or enable transaction index.")); } @@ -2234,10 +2240,10 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc return InitError(strprintf(_("Failed to clear masternode cache at %s"), file_path)); } - if (!fDisableGovernance) { + if (is_governance_enabled) { if (!node.govman->LoadCache(fLoadCacheFiles)) { auto file_path = (GetDataDir() / "governance.dat").string(); - if (fLoadCacheFiles && !fDisableGovernance) { + if (fLoadCacheFiles) { return InitError(strprintf(_("Failed to load governance cache from %s"), file_path)); } return InitError(strprintf(_("Failed to clear governance cache at %s"), file_path)); @@ -2312,11 +2318,11 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc node.scheduler->scheduleEvery(std::bind(&CMasternodeUtils::DoMaintenance, std::ref(*node.connman), std::ref(*node.dmnman), std::ref(*node.mn_sync), std::ref(*node.cj_ctx)), std::chrono::minutes{1}); node.scheduler->scheduleEvery(std::bind(&CDeterministicMNManager::DoMaintenance, std::ref(*node.dmnman)), std::chrono::seconds{10}); - if (!fDisableGovernance) { + if (node.govman->IsValid()) { node.scheduler->scheduleEvery(std::bind(&CGovernanceManager::DoMaintenance, std::ref(*node.govman), std::ref(*node.connman)), std::chrono::minutes{5}); } - if (fMasternodeMode) { + if (node.mn_activeman) { node.scheduler->scheduleEvery(std::bind(&CCoinJoinServer::DoMaintenance, std::ref(*node.cj_ctx->server)), std::chrono::seconds{1}); node.scheduler->scheduleEvery(std::bind(&llmq::CDKGSessionManager::CleanupOldContributions, std::ref(*node.llmq_ctx->qdkgsman)), std::chrono::hours{1}); #ifdef ENABLE_WALLET diff --git a/src/interfaces/node.h b/src/interfaces/node.h index b7ed607644..374e4d0a95 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -65,6 +65,7 @@ public: virtual void getAllNewerThan(std::vector &objs, int64_t nMoreThanTime) = 0; virtual int32_t getObjAbsYesCount(const CGovernanceObject& obj, vote_signal_enum_t vote_signal) = 0; virtual bool getObjLocalValidity(const CGovernanceObject& obj, std::string& error, bool check_collateral) = 0; + virtual bool isEnabled() = 0; virtual void setContext(NodeContext* context) {} }; @@ -230,6 +231,9 @@ public: //! Is initial block download. virtual bool isInitialBlockDownload() = 0; + //! Is masternode. + virtual bool isMasternode() = 0; + //! Get reindex. virtual bool getReindex() = 0; diff --git a/src/llmq/chainlocks.cpp b/src/llmq/chainlocks.cpp index 72a0771a3a..f8bd76696c 100644 --- a/src/llmq/chainlocks.cpp +++ b/src/llmq/chainlocks.cpp @@ -28,7 +28,8 @@ std::unique_ptr chainLocksHandler; CChainLocksHandler::CChainLocksHandler(CChainState& chainstate, CQuorumManager& _qman, CSigningManager& _sigman, CSigSharesManager& _shareman, CSporkManager& sporkman, CTxMemPool& _mempool, - const CMasternodeSync& mn_sync, const std::unique_ptr& peerman) : + const CMasternodeSync& mn_sync, const std::unique_ptr& peerman, + bool is_masternode) : m_chainstate(chainstate), qman(_qman), sigman(_sigman), @@ -37,6 +38,7 @@ CChainLocksHandler::CChainLocksHandler(CChainState& chainstate, CQuorumManager& mempool(_mempool), m_mn_sync(mn_sync), m_peerman(peerman), + m_is_masternode{is_masternode}, scheduler(std::make_unique()), scheduler_thread(std::make_unique(std::thread(util::TraceThread, "cl-schdlr", [&] { scheduler->serviceQueue(); }))) { @@ -238,7 +240,7 @@ void CChainLocksHandler::TrySignChainTip() { Cleanup(); - if (!fMasternodeMode) { + if (!m_is_masternode) { return; } diff --git a/src/llmq/chainlocks.h b/src/llmq/chainlocks.h index 9ac83669dd..29818ff1c4 100644 --- a/src/llmq/chainlocks.h +++ b/src/llmq/chainlocks.h @@ -54,6 +54,7 @@ private: const CMasternodeSync& m_mn_sync; const std::unique_ptr& m_peerman; + const bool m_is_masternode; std::unique_ptr scheduler; std::unique_ptr scheduler_thread; mutable Mutex cs; @@ -87,7 +88,8 @@ private: public: explicit CChainLocksHandler(CChainState& chainstate, CQuorumManager& _qman, CSigningManager& _sigman, CSigSharesManager& _shareman, CSporkManager& sporkman, CTxMemPool& _mempool, - const CMasternodeSync& mn_sync, const std::unique_ptr& peerman); + const CMasternodeSync& mn_sync, const std::unique_ptr& peerman, + bool is_masternode); ~CChainLocksHandler(); void Start(); diff --git a/src/llmq/context.cpp b/src/llmq/context.cpp index ee1f723d29..919c9dce8c 100644 --- a/src/llmq/context.cpp +++ b/src/llmq/context.cpp @@ -21,6 +21,7 @@ LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CDeterminis 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) : + is_masternode{mn_activeman != nullptr}, bls_worker{std::make_shared()}, dkg_debugman{std::make_unique()}, quorum_block_processor{[&]() -> llmq::CQuorumBlockProcessor* const { @@ -38,12 +39,12 @@ LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CDeterminis shareman{std::make_unique(connman, *sigman, mn_activeman, *llmq::quorumManager, sporkman, peerman)}, clhandler{[&]() -> llmq::CChainLocksHandler* const { assert(llmq::chainLocksHandler == nullptr); - llmq::chainLocksHandler = std::make_unique(chainstate, *llmq::quorumManager, *sigman, *shareman, sporkman, mempool, mn_sync, peerman); + llmq::chainLocksHandler = std::make_unique(chainstate, *llmq::quorumManager, *sigman, *shareman, sporkman, mempool, mn_sync, peerman, is_masternode); return llmq::chainLocksHandler.get(); }()}, isman{[&]() -> llmq::CInstantSendManager* const { assert(llmq::quorumInstantSendManager == nullptr); - llmq::quorumInstantSendManager = std::make_unique(*llmq::chainLocksHandler, chainstate, connman, *llmq::quorumManager, *sigman, *shareman, sporkman, mempool, mn_sync, peerman, unit_tests, wipe); + llmq::quorumInstantSendManager = std::make_unique(*llmq::chainLocksHandler, chainstate, connman, *llmq::quorumManager, *sigman, *shareman, sporkman, mempool, mn_sync, peerman, is_masternode, unit_tests, wipe); return llmq::quorumInstantSendManager.get(); }()}, ehfSignalsHandler{std::make_unique(chainstate, mnhfman, *sigman, *shareman, mempool, *llmq::quorumManager, sporkman, peerman)} @@ -76,7 +77,7 @@ void LLMQContext::Start() { assert(isman == llmq::quorumInstantSendManager.get()); bls_worker->Start(); - if (fMasternodeMode) { + if (is_masternode) { qdkgsman->StartThreads(); } qman->Start(); @@ -101,7 +102,7 @@ void LLMQContext::Stop() { shareman->UnregisterAsRecoveredSigsListener(); sigman->StopWorkerThread(); qman->Stop(); - if (fMasternodeMode) { + if (is_masternode) { qdkgsman->StopThreads(); } bls_worker->Stop(); diff --git a/src/llmq/context.h b/src/llmq/context.h index 531dcb0525..99c73c84cb 100644 --- a/src/llmq/context.h +++ b/src/llmq/context.h @@ -34,6 +34,10 @@ class CSigningManager; } struct LLMQContext { +private: + const bool is_masternode; + +public: LLMQContext() = delete; LLMQContext(const LLMQContext&) = delete; LLMQContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, CEvoDB& evo_db, diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index 43eb04a5fb..7b48885bde 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -532,7 +532,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); + utils::EnsureQuorumConnections(params, connman, m_dmnman, m_sporkman, tip_mn_list, pQuorumBaseBlockIndex, curSession->myProTxHash, /* is_masternode = */ m_mn_activeman != nullptr); if (curSession->AreWeMember()) { utils::AddQuorumProbeConnections(params, connman, m_dmnman, m_mn_metaman, m_sporkman, tip_mn_list, pQuorumBaseBlockIndex, curSession->myProTxHash); } diff --git a/src/llmq/dkgsessionmgr.cpp b/src/llmq/dkgsessionmgr.cpp index 707edf9ec0..9a61844073 100644 --- a/src/llmq/dkgsessionmgr.cpp +++ b/src/llmq/dkgsessionmgr.cpp @@ -36,7 +36,7 @@ CDKGSessionManager::CDKGSessionManager(CBLSWorker& _blsWorker, CChainState& chai quorumBlockProcessor(_quorumBlockProcessor), spork_manager(sporkman) { - if (!fMasternodeMode && !IsWatchQuorumsEnabled()) { + if (mn_activeman == nullptr && !IsWatchQuorumsEnabled()) { // Regular nodes do not care about any DKG internals, bail out return; } @@ -173,7 +173,7 @@ void CDKGSessionManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fIni } } -PeerMsgRet CDKGSessionManager::ProcessMessage(CNode& pfrom, PeerManager* peerman, const std::string& msg_type, CDataStream& vRecv) +PeerMsgRet CDKGSessionManager::ProcessMessage(CNode& pfrom, PeerManager* peerman, bool is_masternode, const std::string& msg_type, CDataStream& vRecv) { static Mutex cs_indexedQuorumsCache; static std::map> indexedQuorumsCache GUARDED_BY(cs_indexedQuorumsCache); @@ -190,7 +190,7 @@ PeerMsgRet CDKGSessionManager::ProcessMessage(CNode& pfrom, PeerManager* peerman } if (msg_type == NetMsgType::QWATCH) { - if (!fMasternodeMode) { + if (!is_masternode) { // non-masternodes should never receive this return tl::unexpected{10}; } @@ -198,7 +198,7 @@ PeerMsgRet CDKGSessionManager::ProcessMessage(CNode& pfrom, PeerManager* peerman return {}; } - if ((!fMasternodeMode && !IsWatchQuorumsEnabled())) { + if ((!is_masternode && !IsWatchQuorumsEnabled())) { // regular non-watching nodes should never receive any of these return tl::unexpected{10}; } diff --git a/src/llmq/dkgsessionmgr.h b/src/llmq/dkgsessionmgr.h index d920b50bfb..6077b8373c 100644 --- a/src/llmq/dkgsessionmgr.h +++ b/src/llmq/dkgsessionmgr.h @@ -77,7 +77,7 @@ public: void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload); - PeerMsgRet ProcessMessage(CNode& pfrom, PeerManager* peerman, const std::string& msg_type, CDataStream& vRecv); + PeerMsgRet ProcessMessage(CNode& pfrom, PeerManager* peerman, bool is_masternode, const std::string& msg_type, CDataStream& vRecv); bool AlreadyHave(const CInv& inv) const; bool GetContribution(const uint256& hash, CDKGContribution& ret) const; bool GetComplaint(const uint256& hash, CDKGComplaint& ret) const; diff --git a/src/llmq/ehf_signals.cpp b/src/llmq/ehf_signals.cpp index 8c69d7fb4c..d4f6d151f8 100644 --- a/src/llmq/ehf_signals.cpp +++ b/src/llmq/ehf_signals.cpp @@ -44,11 +44,11 @@ CEHFSignalsHandler::~CEHFSignalsHandler() sigman.UnregisterRecoveredSigsListener(this); } -void CEHFSignalsHandler::UpdatedBlockTip(const CBlockIndex* const pindexNew) +void CEHFSignalsHandler::UpdatedBlockTip(const CBlockIndex* const pindexNew, bool is_masternode) { if (!DeploymentActiveAfter(pindexNew, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) return; - if (!fMasternodeMode || (Params().IsTestChain() && !sporkman.IsSporkActive(SPORK_24_TEST_EHF))) { + if (!is_masternode || (Params().IsTestChain() && !sporkman.IsSporkActive(SPORK_24_TEST_EHF))) { return; } diff --git a/src/llmq/ehf_signals.h b/src/llmq/ehf_signals.h index b29828ebd2..b93474f2d2 100644 --- a/src/llmq/ehf_signals.h +++ b/src/llmq/ehf_signals.h @@ -49,7 +49,7 @@ public: /** * Since Tip is updated it could be a time to generate EHF Signal */ - void UpdatedBlockTip(const CBlockIndex* const pindexNew); + void UpdatedBlockTip(const CBlockIndex* const pindexNew, bool is_masternode); void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override LOCKS_EXCLUDED(cs); diff --git a/src/llmq/instantsend.cpp b/src/llmq/instantsend.cpp index f558c91515..76d42113cb 100644 --- a/src/llmq/instantsend.cpp +++ b/src/llmq/instantsend.cpp @@ -474,7 +474,7 @@ void CInstantSendManager::Stop() void CInstantSendManager::ProcessTx(const CTransaction& tx, bool fRetroactive, const Consensus::Params& params) { - if (!fMasternodeMode || !IsInstantSendEnabled() || !m_mn_sync.IsBlockchainSynced()) { + if (!m_is_masternode || !IsInstantSendEnabled() || !m_mn_sync.IsBlockchainSynced()) { return; } @@ -1062,7 +1062,7 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, const uint256& has // bump mempool counter to make sure newly locked txes are picked up by getblocktemplate mempool.AddTransactionsUpdated(1); } else { - AskNodesForLockedTx(islock->txid, connman, *m_peerman); + AskNodesForLockedTx(islock->txid, connman, *m_peerman, m_is_masternode); } } @@ -1338,7 +1338,7 @@ void CInstantSendManager::RemoveMempoolConflictsForLock(const uint256& hash, con for (const auto& p : toDelete) { RemoveConflictedTx(*p.second); } - AskNodesForLockedTx(islock.txid, connman, *m_peerman); + AskNodesForLockedTx(islock.txid, connman, *m_peerman, m_is_masternode); } } @@ -1443,7 +1443,7 @@ void CInstantSendManager::RemoveConflictingLock(const uint256& islockHash, const } } -void CInstantSendManager::AskNodesForLockedTx(const uint256& txid, const CConnman& connman, const PeerManager& peerman) +void CInstantSendManager::AskNodesForLockedTx(const uint256& txid, const CConnman& connman, const PeerManager& peerman, bool is_masternode) { std::vector nodesToAskFor; nodesToAskFor.reserve(4); @@ -1476,7 +1476,7 @@ void CInstantSendManager::AskNodesForLockedTx(const uint256& txid, const CConnma txid.ToString(), pnode->GetId()); CInv inv(MSG_TX, txid); - RequestObject(pnode->GetId(), inv, GetTime(), true); + RequestObject(pnode->GetId(), inv, GetTime(), is_masternode, /* fForce = */ true); } } for (CNode* pnode : nodesToAskFor) { diff --git a/src/llmq/instantsend.h b/src/llmq/instantsend.h index 4f4167b7ad..5244e3d64c 100644 --- a/src/llmq/instantsend.h +++ b/src/llmq/instantsend.h @@ -208,6 +208,7 @@ private: const CMasternodeSync& m_mn_sync; const std::unique_ptr& m_peerman; + const bool m_is_masternode; std::atomic fUpgradedDB{false}; std::thread workThread; @@ -257,10 +258,11 @@ public: explicit CInstantSendManager(CChainLocksHandler& _clhandler, CChainState& chainstate, CConnman& _connman, CQuorumManager& _qman, CSigningManager& _sigman, CSigSharesManager& _shareman, CSporkManager& sporkman, CTxMemPool& _mempool, const CMasternodeSync& mn_sync, - const std::unique_ptr& peerman, bool unitTests, bool fWipe) : + const std::unique_ptr& peerman, bool is_masternode, bool unitTests, bool fWipe) : db(unitTests, fWipe), clhandler(_clhandler), m_chainstate(chainstate), connman(_connman), qman(_qman), sigman(_sigman), - shareman(_shareman), spork_manager(sporkman), mempool(_mempool), m_mn_sync(mn_sync), m_peerman(peerman) + shareman(_shareman), spork_manager(sporkman), mempool(_mempool), m_mn_sync(mn_sync), m_peerman(peerman), + m_is_masternode{is_masternode} { workInterrupt.reset(); } @@ -299,7 +301,7 @@ private: void RemoveMempoolConflictsForLock(const uint256& hash, const CInstantSendLock& islock); void ResolveBlockConflicts(const uint256& islockHash, const CInstantSendLock& islock) LOCKS_EXCLUDED(cs_pendingLocks, cs_nonLocked); - static void AskNodesForLockedTx(const uint256& txid, const CConnman& connman, const PeerManager& peerman); + static void AskNodesForLockedTx(const uint256& txid, const CConnman& connman, const PeerManager& peerman, bool is_masternode); void ProcessPendingRetryLockTxs() LOCKS_EXCLUDED(cs_creating, cs_nonLocked, cs_pendingRetry); void WorkThreadMain(); diff --git a/src/llmq/quorums.cpp b/src/llmq/quorums.cpp index 8b8021ae21..fae082f839 100644 --- a/src/llmq/quorums.cpp +++ b/src/llmq/quorums.cpp @@ -240,7 +240,7 @@ void CQuorumManager::Stop() void CQuorumManager::TriggerQuorumDataRecoveryThreads(const CBlockIndex* pIndex) const { - if ((!fMasternodeMode && !IsWatchQuorumsEnabled()) || !QuorumDataRecoveryEnabled() || pIndex == nullptr) { + if ((m_mn_activeman == nullptr && !IsWatchQuorumsEnabled()) || !QuorumDataRecoveryEnabled() || pIndex == nullptr) { return; } @@ -252,11 +252,7 @@ void CQuorumManager::TriggerQuorumDataRecoveryThreads(const CBlockIndex* pIndex) const auto vecQuorums = ScanQuorums(params.type, pIndex, params.keepOldConnections); // First check if we are member of any quorum of this type - const uint256 proTxHash = [this]() { - if (!fMasternodeMode) return uint256(); - assert(m_mn_activeman); - return m_mn_activeman->GetProTxHash(); - }(); + const uint256 proTxHash = m_mn_activeman != nullptr ? m_mn_activeman->GetProTxHash() : uint256(); bool fWeAreQuorumTypeMember = ranges::any_of(vecQuorums, [&proTxHash](const auto& pQuorum) { return pQuorum->IsValidMember(proTxHash); @@ -302,7 +298,7 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial CheckQuorumConnections(params, pindexNew); } - if (fMasternodeMode || IsWatchQuorumsEnabled()) { + if (m_mn_activeman != nullptr || IsWatchQuorumsEnabled()) { // Cleanup expired data requests LOCK(cs_data_requests); auto it = mapQuorumDataRequests.begin(); @@ -321,7 +317,7 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexNew) const { - if (!fMasternodeMode && !IsWatchQuorumsEnabled()) return; + if (m_mn_activeman == nullptr && !IsWatchQuorumsEnabled()) return; auto lastQuorums = ScanQuorums(llmqParams.type, pindexNew, (size_t)llmqParams.keepOldConnections); @@ -348,11 +344,7 @@ void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqPar LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- llmqType[%d] h[%d] keeping mn quorum connections for quorum: [%d:%s]\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight, curDkgHeight, curDkgBlock.ToString()); } - const uint256 myProTxHash = [this]() { - if (!fMasternodeMode) return uint256(); - assert(m_mn_activeman); - return m_mn_activeman->GetProTxHash(); - }(); + const uint256 myProTxHash = m_mn_activeman != nullptr ? m_mn_activeman->GetProTxHash() : uint256(); bool isISType = llmqParams.type == Params().GetConsensus().llmqTypeDIP0024InstantSend; @@ -362,7 +354,7 @@ void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqPar }); for (const auto& quorum : lastQuorums) { - if (utils::EnsureQuorumConnections(llmqParams, connman, m_dmnman, m_sporkman, m_dmnman.GetListAtChainTip(), quorum->m_quorum_base_block_index, myProTxHash)) { + if (utils::EnsureQuorumConnections(llmqParams, connman, m_dmnman, m_sporkman, m_dmnman.GetListAtChainTip(), quorum->m_quorum_base_block_index, myProTxHash, /* is_masternode = */ m_mn_activeman != nullptr)) { if (connmanQuorumsToDelete.erase(quorum->qc->quorumHash) > 0) { LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- llmqType[%d] h[%d] keeping mn quorum connections for quorum: [%d:%s]\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight, quorum->m_quorum_base_block_index->nHeight, quorum->m_quorum_base_block_index->GetBlockHash().ToString()); } @@ -688,7 +680,7 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_t if (msg_type == NetMsgType::QGETDATA) { - if (!fMasternodeMode || (pfrom.GetVerifiedProRegTxHash().IsNull() && !pfrom.qwatch)) { + if (m_mn_activeman == nullptr || (pfrom.GetVerifiedProRegTxHash().IsNull() && !pfrom.qwatch)) { return errorHandler("Not a verified masternode or a qwatch connection"); } @@ -778,7 +770,7 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_t } if (msg_type == NetMsgType::QDATA) { - if ((!fMasternodeMode && !IsWatchQuorumsEnabled()) || pfrom.GetVerifiedProRegTxHash().IsNull()) { + if ((m_mn_activeman == nullptr && !IsWatchQuorumsEnabled()) || pfrom.GetVerifiedProRegTxHash().IsNull()) { return errorHandler("Not a verified masternode and -watchquorums is not enabled"); } @@ -827,7 +819,7 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_t // Check if request has ENCRYPTED_CONTRIBUTIONS data if (request.GetDataMask() & CQuorumDataRequest::ENCRYPTED_CONTRIBUTIONS) { - assert(fMasternodeMode); + assert(m_mn_activeman); if (WITH_LOCK(pQuorum->cs, return pQuorum->quorumVvec->size() != size_t(pQuorum->params.threshold))) { return errorHandler("No valid quorum verification vector available", 0); // Don't bump score because we asked for it @@ -844,7 +836,7 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_t std::vector vecSecretKeys; vecSecretKeys.resize(vecEncrypted.size()); for (const auto i : irange::range(vecEncrypted.size())) { - if (!Assert(m_mn_activeman)->Decrypt(vecEncrypted[i], memberIdx, vecSecretKeys[i], PROTOCOL_VERSION)) { + if (!m_mn_activeman->Decrypt(vecEncrypted[i], memberIdx, vecSecretKeys[i], PROTOCOL_VERSION)) { return errorHandler("Failed to decrypt"); } } @@ -1069,7 +1061,7 @@ void CQuorumManager::StartCleanupOldQuorumDataThread(const CBlockIndex* pIndex) // window and it's better to have more room so we pick next cycle. // dkgMiningWindowStart for small quorums is 10 i.e. a safe block to start // these calculations is at height 576 + 24 * 2 + 10 = 576 + 58. - if ((!fMasternodeMode && !IsWatchQuorumsEnabled()) || pIndex == nullptr || (pIndex->nHeight % 576 != 58)) { + if ((m_mn_activeman == nullptr && !IsWatchQuorumsEnabled()) || pIndex == nullptr || (pIndex->nHeight % 576 != 58)) { return; } diff --git a/src/llmq/signing.cpp b/src/llmq/signing.cpp index 98bf59d96d..4e4590c4de 100644 --- a/src/llmq/signing.cpp +++ b/src/llmq/signing.cpp @@ -838,7 +838,7 @@ void CSigningManager::ProcessRecoveredSig(const std::shared_ptrGetHash()); } - if (fMasternodeMode) { + if (m_mn_activeman != nullptr) { CInv inv(MSG_QUORUM_RECOVERED_SIG, recoveredSig->GetHash()); connman.ForEachNode([&](CNode* pnode) { if (pnode->fSendRecSigs) { @@ -895,9 +895,7 @@ void CSigningManager::UnregisterRecoveredSigsListener(CRecoveredSigsListener* l) bool CSigningManager::AsyncSignIfMember(Consensus::LLMQType llmqType, CSigSharesManager& shareman, const uint256& id, const uint256& msgHash, const uint256& quorumHash, bool allowReSign) { - if (!fMasternodeMode) return false; - - assert(m_mn_activeman); + if (m_mn_activeman == nullptr) return false; if (m_mn_activeman->GetProTxHash().IsNull()) return false; const CQuorumCPtr quorum = [&]() { diff --git a/src/llmq/signing_shares.cpp b/src/llmq/signing_shares.cpp index fb8541fd32..548602e622 100644 --- a/src/llmq/signing_shares.cpp +++ b/src/llmq/signing_shares.cpp @@ -218,9 +218,7 @@ void CSigSharesManager::InterruptWorkerThread() void CSigSharesManager::ProcessMessage(const CNode& pfrom, const CSporkManager& sporkman, const std::string& msg_type, CDataStream& vRecv) { // non-masternodes are not interested in sigshares - if (!fMasternodeMode) return; - - assert(m_mn_activeman); + if (m_mn_activeman == nullptr) return; if (m_mn_activeman->GetProTxHash().IsNull()) return; if (sporkman.IsSporkActive(SPORK_21_QUORUM_ALL_CONNECTED) && msg_type == NetMsgType::QSIGSHARE) { diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index 9fc63deb47..d6416f0c2c 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -755,9 +755,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) + const uint256& myProTxHash, bool is_masternode) { - if (!fMasternodeMode && !IsWatchQuorumsEnabled()) { + if (!is_masternode && !IsWatchQuorumsEnabled()) { return false; } diff --git a/src/llmq/utils.h b/src/llmq/utils.h index 9e219b507a..2b5dc3a88e 100644 --- a/src/llmq/utils.h +++ b/src/llmq/utils.h @@ -40,7 +40,7 @@ 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); + const uint256& myProTxHash, bool is_masternode); 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); diff --git a/src/masternode/node.cpp b/src/masternode/node.cpp index 23bfce2d47..3964c8d195 100644 --- a/src/masternode/node.cpp +++ b/src/masternode/node.cpp @@ -75,8 +75,6 @@ void CActiveMasternodeManager::InitInternal(const CBlockIndex* pindex) { AssertLockHeld(cs); - if (!fMasternodeMode) return; - if (!DeploymentDIP0003Enforced(pindex->nHeight, Params().GetConsensus())) return; // Check that our local network configuration is correct @@ -146,8 +144,6 @@ void CActiveMasternodeManager::InitInternal(const CBlockIndex* pindex) void CActiveMasternodeManager::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) { - if (!fMasternodeMode) return; - if (!DeploymentDIP0003Enforced(pindexNew->nHeight, Params().GetConsensus())) return; const auto [cur_state, cur_protx_hash] = WITH_READ_LOCK(cs, return std::make_pair(m_state, m_info.proTxHash)); diff --git a/src/masternode/payments.cpp b/src/masternode/payments.cpp index 7d1482ec96..05b907339d 100644 --- a/src/masternode/payments.cpp +++ b/src/masternode/payments.cpp @@ -18,7 +18,6 @@ #include