refactor: move GetBestSuperblock to CGovernanceManager

This commit is contained in:
Konstantin Akimov 2024-10-06 20:54:13 +07:00
parent 3641653174
commit b240d08e09
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
3 changed files with 9 additions and 22 deletions

View File

@ -272,14 +272,15 @@ bool CGovernanceManager::IsSuperblockTriggered(const CDeterministicMNList& tip_m
}
bool CSuperblockManager::GetBestSuperblock(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, CSuperblock_sptr& pSuperblockRet, int nBlockHeight)
bool CGovernanceManager::GetBestSuperblock(const CDeterministicMNList& tip_mn_list, CSuperblock_sptr& pSuperblockRet,
int nBlockHeight) const
{
if (!CSuperblock::IsValidBlockHeight(nBlockHeight)) {
return false;
}
AssertLockHeld(govman.cs);
std::vector<CSuperblock_sptr> vecTriggers = govman.GetActiveTriggers();
AssertLockHeld(cs);
std::vector<CSuperblock_sptr> vecTriggers = GetActiveTriggers();
int nYesCount = 0;
for (const auto& pSuperblock : vecTriggers) {
@ -287,7 +288,7 @@ bool CSuperblockManager::GetBestSuperblock(CGovernanceManager& govman, const CDe
continue;
}
const CGovernanceObject* pObj = pSuperblock->GetGovernanceObject(govman);
const CGovernanceObject* pObj = pSuperblock->GetGovernanceObject(*this);
if (!pObj) {
continue;
@ -313,7 +314,7 @@ bool CGovernanceManager::GetSuperblockPayments(const CDeterministicMNList& tip_m
// GET THE BEST SUPERBLOCK FOR THIS BLOCK HEIGHT
CSuperblock_sptr pSuperblock;
if (!CSuperblockManager::GetBestSuperblock(*this, tip_mn_list, pSuperblock, nBlockHeight)) {
if (!GetBestSuperblock(tip_mn_list, pSuperblock, nBlockHeight)) {
LogPrint(BCLog::GOBJECT, "GetSuperblockPayments -- Can't find superblock for height %d\n", nBlockHeight);
return false;
}
@ -359,7 +360,7 @@ bool CGovernanceManager::IsValidSuperblock(const CChain& active_chain, const CDe
LOCK(cs);
CSuperblock_sptr pSuperblock;
if (CSuperblockManager::GetBestSuperblock(*this, tip_mn_list, pSuperblock, nBlockHeight)) {
if (GetBestSuperblock(tip_mn_list, pSuperblock, nBlockHeight)) {
return pSuperblock->IsValid(*this, active_chain, txNew, nBlockHeight, blockReward);
}
@ -371,7 +372,7 @@ void CGovernanceManager::ExecuteBestSuperblock(const CDeterministicMNList& tip_m
LOCK(cs);
CSuperblock_sptr pSuperblock;
if (CSuperblockManager::GetBestSuperblock(*this, tip_mn_list, pSuperblock, nBlockHeight)) {
if (GetBestSuperblock(tip_mn_list, pSuperblock, nBlockHeight)) {
// All checks are done in CSuperblock::IsValid via IsBlockValueValid and IsBlockPayeeValid,
// tip wouldn't be updated if anything was wrong. Mark this trigger as executed.
pSuperblock->SetExecuted();

View File

@ -13,7 +13,6 @@
class CChain;
class CGovernanceManager;
class CSuperblock;
class CSuperblockManager;
class CTxOut;
class CTransaction;
@ -21,20 +20,6 @@ using CSuperblock_sptr = std::shared_ptr<CSuperblock>;
CAmount ParsePaymentAmount(const std::string& strAmount);
/**
* Superblock Manager
*
* Class for querying superblock information
*/
class CSuperblockManager
{
public:
static bool GetBestSuperblock(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, CSuperblock_sptr& pSuperblockRet, int nBlockHeight);
public:
};
/**
* Governance Object Payment
*

View File

@ -373,6 +373,7 @@ public:
private:
void ExecuteBestSuperblock(const CDeterministicMNList& tip_mn_list, int nBlockHeight);
bool GetBestSuperblock(const CDeterministicMNList& tip_mn_list, CSuperblock_sptr& pSuperblockRet, int nBlockHeight);
std::optional<const CSuperblock> CreateSuperblockCandidate(int nHeight) const;
std::optional<const CGovernanceObject> CreateGovernanceTrigger(const std::optional<const CSuperblock>& sb_opt, PeerManager& peerman,