refactor: move IsSuperblockTriggered to CGovernanceManager

This commit is contained in:
Konstantin Akimov 2024-10-06 20:25:57 +07:00
parent 9638fdce6d
commit 7a470c441e
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
5 changed files with 30 additions and 26 deletions

View File

@ -218,46 +218,41 @@ std::vector<CSuperblock_sptr> 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<CSuperblock_sptr> vecTriggers = govman.GetActiveTriggers();
std::vector<CSuperblock_sptr> 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");
}
}

View File

@ -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<CTxOut>& voutSuperblockRet);
static void ExecuteBestSuperblock(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, int nBlockHeight);

View File

@ -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<const CSuperblock> CreateSuperblockCandidate(int nHeight) const;
std::optional<const CGovernanceObject> CreateGovernanceTrigger(const std::optional<const CSuperblock>& sb_opt, PeerManager& peerman,

View File

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

View File

@ -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<CTxOut> voutSuperblock;
if (!CSuperblockManager::GetSuperblockPayments(govman, tip_mn_list, nBlockHeight, voutSuperblock)) {
return strPayments + ", error";