Skip to content

Commit

Permalink
[Refactoring] Add IsDIP3Enforced/LegacyMNObsolete funcs to DMNManager
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Apr 22, 2021
1 parent c013bf1 commit 41869ec
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/evo/deterministicmns.cpp
Expand Up @@ -12,6 +12,7 @@
#include "guiinterface.h"
#include "masternode.h" // for MN_COLL_AMT, MasternodeCollateralMinConf
#include "script/standard.h"
#include "spork.h"
#include "sync.h"
#include "validation.h"
#include "validationinterface.h"
Expand Down Expand Up @@ -503,7 +504,10 @@ CDeterministicMNManager::CDeterministicMNManager(CEvoDB& _evoDb) :
bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& _state, bool fJustCheck)
{
int nHeight = pindex->nHeight;
// !TODO: exit early if enforcement not active
if (!IsDIP3Enforced(nHeight)) {
// nothing to do
return true;
}

CDeterministicMNList oldList, newList;
CDeterministicMNListDiff diff;
Expand Down Expand Up @@ -558,8 +562,12 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde

bool CDeterministicMNManager::UndoBlock(const CBlock& block, const CBlockIndex* pindex)
{
// !TODO: exit early if enforcement not active
uint256 blockHash = block.GetHash();
if (!IsDIP3Enforced(pindex->nHeight)) {
// nothing to do
return true;
}

const uint256& blockHash = block.GetHash();

CDeterministicMNList curList;
CDeterministicMNList prevList;
Expand Down Expand Up @@ -812,6 +820,28 @@ CDeterministicMNList CDeterministicMNManager::GetListAtChainTip()
return GetListForBlock(tipIndex);
}

bool CDeterministicMNManager::IsDIP3Enforced(int nHeight) const
{
return Params().GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V6_0);
}

bool CDeterministicMNManager::IsDIP3Enforced() const
{
int tipHeight = WITH_LOCK(cs, return tipIndex ? tipIndex->nHeight : -1;);
return IsDIP3Enforced(tipHeight);
}

bool CDeterministicMNManager::LegacyMNObsolete(int nHeight) const
{
return nHeight > sporkManager.GetSporkValue(SPORK_21_LEGACY_MNS_MAX_HEIGHT);
}

bool CDeterministicMNManager::LegacyMNObsolete() const
{
int tipHeight = WITH_LOCK(cs, return tipIndex ? tipIndex->nHeight : -1;);
return LegacyMNObsolete(tipHeight);
}

void CDeterministicMNManager::CleanupCache(int nHeight)
{
AssertLockHeld(cs);
Expand Down
8 changes: 8 additions & 0 deletions src/evo/deterministicmns.h
Expand Up @@ -589,6 +589,14 @@ class CDeterministicMNManager
CDeterministicMNList GetListForBlock(const CBlockIndex* pindex);
CDeterministicMNList GetListAtChainTip();

// Whether DMNs are enforced at provided height, or at the chain-tip
bool IsDIP3Enforced(int nHeight) const;
bool IsDIP3Enforced() const;

// Whether Legacy MNs are disabled at provided height, or at the chain-tip
bool LegacyMNObsolete(int nHeight) const;
bool LegacyMNObsolete() const;

private:
void CleanupCache(int nHeight);
};
Expand Down

0 comments on commit 41869ec

Please sign in to comment.