From 36416531744405eb7288fb4e5f9d0a0cfc4b1a2e Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Sun, 6 Oct 2024 20:40:10 +0700 Subject: [PATCH] refactor: move CSuperblockManager::IsValid to CGoveranceManager::IsValidSuperblock --- src/governance/classes.cpp | 9 +++++---- src/governance/classes.h | 1 - src/governance/governance.h | 3 +++ src/masternode/payments.cpp | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/governance/classes.cpp b/src/governance/classes.cpp index b50bef71c7..9e0e0ba7bc 100644 --- a/src/governance/classes.cpp +++ b/src/governance/classes.cpp @@ -352,14 +352,15 @@ bool CGovernanceManager::GetSuperblockPayments(const CDeterministicMNList& tip_m return true; } -bool CSuperblockManager::IsValid(CGovernanceManager& govman, const CChain& active_chain, const CDeterministicMNList& tip_mn_list, const CTransaction& txNew, int nBlockHeight, CAmount blockReward) +bool CGovernanceManager::IsValidSuperblock(const CChain& active_chain, const CDeterministicMNList& tip_mn_list, + const CTransaction& txNew, int nBlockHeight, CAmount blockReward) { // GET BEST SUPERBLOCK, SHOULD MATCH - LOCK(govman.cs); + LOCK(cs); CSuperblock_sptr pSuperblock; - if (CSuperblockManager::GetBestSuperblock(govman, tip_mn_list, pSuperblock, nBlockHeight)) { - return pSuperblock->IsValid(govman, active_chain, txNew, nBlockHeight, blockReward); + if (CSuperblockManager::GetBestSuperblock(*this, tip_mn_list, pSuperblock, nBlockHeight)) { + return pSuperblock->IsValid(*this, active_chain, txNew, nBlockHeight, blockReward); } return false; diff --git a/src/governance/classes.h b/src/governance/classes.h index f6ea2db7eb..ce19bdbe5d 100644 --- a/src/governance/classes.h +++ b/src/governance/classes.h @@ -33,7 +33,6 @@ public: static bool GetBestSuperblock(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, CSuperblock_sptr& pSuperblockRet, int nBlockHeight); public: - static bool IsValid(CGovernanceManager& govman, const CChain& active_chain, const CDeterministicMNList& tip_mn_list, const CTransaction& txNew, int nBlockHeight, CAmount blockReward); }; /** diff --git a/src/governance/governance.h b/src/governance/governance.h index 25c357c59d..864d9b423d 100644 --- a/src/governance/governance.h +++ b/src/governance/governance.h @@ -368,6 +368,9 @@ public: bool GetSuperblockPayments(const CDeterministicMNList& tip_mn_list, int nBlockHeight, std::vector& voutSuperblockRet); + bool IsValidSuperblock(const CChain& active_chain, const CDeterministicMNList& tip_mn_list, + const CTransaction& txNew, int nBlockHeight, CAmount blockReward); + private: void ExecuteBestSuperblock(const CDeterministicMNList& tip_mn_list, int nBlockHeight); diff --git a/src/masternode/payments.cpp b/src/masternode/payments.cpp index b7d264a7bb..d2c0065394 100644 --- a/src/masternode/payments.cpp +++ b/src/masternode/payments.cpp @@ -257,7 +257,7 @@ bool CMNPaymentsProcessor::IsBlockValueValid(const CBlock& block, const int nBlo } // this actually also checks for correct payees and not only amount - if (!CSuperblockManager::IsValid(m_govman, m_chainman.ActiveChain(), tip_mn_list, *block.vtx[0], nBlockHeight, blockReward)) { + if (!m_govman.IsValidSuperblock(m_chainman.ActiveChain(), tip_mn_list, *block.vtx[0], nBlockHeight, blockReward)) { // triggered but invalid? that's weird LogPrintf("CMNPaymentsProcessor::%s -- ERROR! Invalid superblock detected at height %d: %s", __func__, nBlockHeight, block.vtx[0]->ToString()); /* Continued */ // should NOT allow invalid superblocks, when superblocks are enabled @@ -303,7 +303,8 @@ bool CMNPaymentsProcessor::IsBlockPayeeValid(const CTransaction& txNew, const CB if (!check_superblock) return true; const auto tip_mn_list = m_dmnman.GetListAtChainTip(); if (m_govman.IsSuperblockTriggered(tip_mn_list, nBlockHeight)) { - if (CSuperblockManager::IsValid(m_govman, m_chainman.ActiveChain(), tip_mn_list, txNew, nBlockHeight, blockSubsidy + feeReward)) { + if (m_govman.IsValidSuperblock(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 } else {