From 7a470c441e3101c78b535c94839e5369ab03330d Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Sun, 6 Oct 2024 20:25:57 +0700 Subject: [PATCH] refactor: move IsSuperblockTriggered to CGovernanceManager --- src/governance/classes.cpp | 35 +++++++++++++++-------------------- src/governance/classes.h | 2 -- src/governance/governance.h | 11 +++++++++++ src/masternode/payments.cpp | 6 +++--- src/rpc/masternode.cpp | 2 +- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/governance/classes.cpp b/src/governance/classes.cpp index 7d410a790f..fec30027ea 100644 --- a/src/governance/classes.cpp +++ b/src/governance/classes.cpp @@ -218,46 +218,41 @@ std::vector CGovernanceManager::GetActiveTriggers() return vecResults; } -/** -* Is Superblock Triggered -* -* - Does this block have a non-executed and activated trigger? -*/ - -bool CSuperblockManager::IsSuperblockTriggered(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, int nBlockHeight) +bool CGovernanceManager::IsSuperblockTriggered(const CDeterministicMNList& tip_mn_list, int nBlockHeight) { - LogPrint(BCLog::GOBJECT, "CSuperblockManager::IsSuperblockTriggered -- Start nBlockHeight = %d\n", nBlockHeight); + LogPrint(BCLog::GOBJECT, "IsSuperblockTriggered -- Start nBlockHeight = %d\n", nBlockHeight); if (!CSuperblock::IsValidBlockHeight(nBlockHeight)) { return false; } - LOCK(govman.cs); + LOCK(cs); // GET ALL ACTIVE TRIGGERS - std::vector vecTriggers = govman.GetActiveTriggers(); + std::vector vecTriggers = GetActiveTriggers(); - LogPrint(BCLog::GOBJECT, "CSuperblockManager::IsSuperblockTriggered -- vecTriggers.size() = %d\n", vecTriggers.size()); + LogPrint(BCLog::GOBJECT, "IsSuperblockTriggered -- vecTriggers.size() = %d\n", vecTriggers.size()); for (const auto& pSuperblock : vecTriggers) { if (!pSuperblock) { - LogPrintf("CSuperblockManager::IsSuperblockTriggered -- Non-superblock found, continuing\n"); + LogPrintf("IsSuperblockTriggered -- Non-superblock found, continuing\n"); continue; } - CGovernanceObject* pObj = pSuperblock->GetGovernanceObject(govman); + CGovernanceObject* pObj = pSuperblock->GetGovernanceObject(*this); if (!pObj) { - LogPrintf("CSuperblockManager::IsSuperblockTriggered -- pObj == nullptr, continuing\n"); + LogPrintf("IsSuperblockTriggered -- pObj == nullptr, continuing\n"); continue; } - LogPrint(BCLog::GOBJECT, "CSuperblockManager::IsSuperblockTriggered -- data = %s\n", pObj->GetDataAsPlainString()); + LogPrint(BCLog::GOBJECT, "IsSuperblockTriggered -- data = %s\n", pObj->GetDataAsPlainString()); // note : 12.1 - is epoch calculation correct? if (nBlockHeight != pSuperblock->GetBlockHeight()) { - LogPrint(BCLog::GOBJECT, "CSuperblockManager::IsSuperblockTriggered -- block height doesn't match nBlockHeight = %d, blockStart = %d, continuing\n", - nBlockHeight, - pSuperblock->GetBlockHeight()); + LogPrint(BCLog::GOBJECT, + "IsSuperblockTriggered -- block height doesn't match nBlockHeight = %d, blockStart = %d, " + "continuing\n", + nBlockHeight, pSuperblock->GetBlockHeight()); continue; } @@ -266,10 +261,10 @@ bool CSuperblockManager::IsSuperblockTriggered(CGovernanceManager& govman, const pObj->UpdateSentinelVariables(tip_mn_list); if (pObj->IsSetCachedFunding()) { - LogPrint(BCLog::GOBJECT, "CSuperblockManager::IsSuperblockTriggered -- fCacheFunding = true, returning true\n"); + LogPrint(BCLog::GOBJECT, "IsSuperblockTriggered -- fCacheFunding = true, returning true\n"); return true; } else { - LogPrint(BCLog::GOBJECT, "CSuperblockManager::IsSuperblockTriggered -- fCacheFunding = false, continuing\n"); + LogPrint(BCLog::GOBJECT, "IsSuperblockTriggered -- fCacheFunding = false, continuing\n"); } } diff --git a/src/governance/classes.h b/src/governance/classes.h index 7ff8eff2e4..759325ed0f 100644 --- a/src/governance/classes.h +++ b/src/governance/classes.h @@ -33,8 +33,6 @@ private: static bool GetBestSuperblock(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, CSuperblock_sptr& pSuperblockRet, int nBlockHeight); public: - static bool IsSuperblockTriggered(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, int nBlockHeight); - static bool GetSuperblockPayments(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, int nBlockHeight, std::vector& voutSuperblockRet); static void ExecuteBestSuperblock(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, int nBlockHeight); diff --git a/src/governance/governance.h b/src/governance/governance.h index 0ee80d9afb..3166c39c4a 100644 --- a/src/governance/governance.h +++ b/src/governance/governance.h @@ -350,6 +350,17 @@ public: bool AddNewTrigger(uint256 nHash); void CleanAndRemoveTriggers(); + // Superblocks related: + + /** + * Is Superblock Triggered + * + * - Does this block have a non-executed and activated trigger? + */ + + bool IsSuperblockTriggered(const CDeterministicMNList& tip_mn_list, int nBlockHeight); + + private: std::optional CreateSuperblockCandidate(int nHeight) const; std::optional CreateGovernanceTrigger(const std::optional& sb_opt, PeerManager& peerman, diff --git a/src/masternode/payments.cpp b/src/masternode/payments.cpp index cdb5f4c56c..853b587024 100644 --- a/src/masternode/payments.cpp +++ b/src/masternode/payments.cpp @@ -246,7 +246,7 @@ bool CMNPaymentsProcessor::IsBlockValueValid(const CBlock& block, const int nBlo const auto tip_mn_list = m_dmnman.GetListAtChainTip(); - if (!CSuperblockManager::IsSuperblockTriggered(m_govman, tip_mn_list, nBlockHeight)) { + if (!m_govman.IsSuperblockTriggered(tip_mn_list, nBlockHeight)) { // we are on a valid superblock height but a superblock was not triggered // revert to block reward limits in this case if(!isBlockRewardValueMet) { @@ -302,7 +302,7 @@ bool CMNPaymentsProcessor::IsBlockPayeeValid(const CTransaction& txNew, const CB if (AreSuperblocksEnabled(m_sporkman)) { if (!check_superblock) return true; const auto tip_mn_list = m_dmnman.GetListAtChainTip(); - if (CSuperblockManager::IsSuperblockTriggered(m_govman, tip_mn_list, nBlockHeight)) { + if (m_govman.IsSuperblockTriggered(tip_mn_list, nBlockHeight)) { if (CSuperblockManager::IsValid(m_govman, m_chainman.ActiveChain(), tip_mn_list, txNew, nBlockHeight, blockSubsidy + feeReward)) { LogPrint(BCLog::GOBJECT, "CMNPaymentsProcessor::%s -- Valid superblock at height %d: %s", __func__, nBlockHeight, txNew.ToString()); /* Continued */ // continue validation, should also pay MN @@ -330,7 +330,7 @@ void CMNPaymentsProcessor::FillBlockPayments(CMutableTransaction& txNew, const C // only create superblocks if spork is enabled AND if superblock is actually triggered // (height should be validated inside) const auto tip_mn_list = m_dmnman.GetListAtChainTip(); - if(AreSuperblocksEnabled(m_sporkman) && CSuperblockManager::IsSuperblockTriggered(m_govman, tip_mn_list, nBlockHeight)) { + if (AreSuperblocksEnabled(m_sporkman) && m_govman.IsSuperblockTriggered(tip_mn_list, nBlockHeight)) { LogPrint(BCLog::GOBJECT, "CMNPaymentsProcessor::%s -- Triggered superblock creation at height %d\n", __func__, nBlockHeight); CSuperblockManager::GetSuperblockPayments(m_govman, tip_mn_list, nBlockHeight, voutSuperblockPaymentsRet); } diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 88819f5dbd..8f86534ad3 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -253,7 +253,7 @@ static std::string GetRequiredPaymentsString(CGovernanceManager& govman, const C strPayments += ", " + EncodeDestination(dest); } } - if (CSuperblockManager::IsSuperblockTriggered(govman, tip_mn_list, nBlockHeight)) { + if (govman.IsSuperblockTriggered(tip_mn_list, nBlockHeight)) { std::vector voutSuperblock; if (!CSuperblockManager::GetSuperblockPayments(govman, tip_mn_list, nBlockHeight, voutSuperblock)) { return strPayments + ", error";