refactor: move CSuperblockManager::IsValid to CGoveranceManager::IsValidSuperblock

This commit is contained in:
Konstantin Akimov 2024-10-06 20:40:10 +07:00
parent de8969f463
commit 3641653174
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
4 changed files with 11 additions and 7 deletions

View File

@ -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;

View File

@ -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);
};
/**

View File

@ -368,6 +368,9 @@ public:
bool GetSuperblockPayments(const CDeterministicMNList& tip_mn_list, int nBlockHeight,
std::vector<CTxOut>& 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);

View File

@ -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 {