Skip to content

Commit

Permalink
Add spork to control deterministic MN lists activation
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Aug 30, 2018
1 parent 9e8a867 commit 5461e92
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "script/standard.h"
#include "base58.h"
#include "core_io.h"
#include "spork.h"

#include <univalue.h>

Expand Down Expand Up @@ -312,6 +313,10 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde
__func__, nHeight, newList.size());
}

if (nHeight == GetSpork15Value()) {
LogPrintf("CDeterministicMNManager::%s -- spork15 is active now. nHeight=%d\n", __func__, nHeight);
}

CleanupCache(nHeight);

return true;
Expand All @@ -326,6 +331,10 @@ bool CDeterministicMNManager::UndoBlock(const CBlock& block, const CBlockIndex*
evoDb.Erase(std::make_pair(DB_LIST_DIFF, block.GetHash()));
evoDb.Erase(std::make_pair(DB_LIST_SNAPSHOT, block.GetHash()));

if (nHeight == GetSpork15Value()) {
LogPrintf("CDeterministicMNManager::%s -- spork15 is not active anymore. nHeight=%d\n", __func__, nHeight);
}

return true;
}

Expand Down Expand Up @@ -473,6 +482,23 @@ bool CDeterministicMNManager::HasValidMNAtChainTip(const uint256& proTxHash)
return GetListAtChainTip().IsMNValid(proTxHash);
}

int64_t CDeterministicMNManager::GetSpork15Value()
{
return sporkManager.GetSporkValue(SPORK_15_DETERMINISTIC_MNS_ENABLED);
}

bool CDeterministicMNManager::IsDeterministicMNsSporkActive(int nHeight)
{
LOCK(cs);

if (nHeight == -1) {
nHeight = tipHeight;
}

int64_t spork15Value = GetSpork15Value();
return nHeight >= spork15Value;
}

void CDeterministicMNManager::CleanupCache(int nHeight)
{
AssertLockHeld(cs);
Expand Down
4 changes: 4 additions & 0 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ class CDeterministicMNManager
bool HasValidMNAtBlock(const uint256& blockHash, const uint256& proTxHash);
bool HasValidMNAtChainTip(const uint256& proTxHash);

bool IsDeterministicMNsSporkActive(int nHeight = -1);

private:
void UpdateSpork15Value();
int64_t GetSpork15Value();
void CleanupCache(int nHeight);
};

Expand Down
3 changes: 3 additions & 0 deletions src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ std::map<int, int64_t> mapSporkDefaults = {
{SPORK_10_MASTERNODE_PAY_UPDATED_NODES, 4070908800ULL}, // OFF
{SPORK_12_RECONSIDER_BLOCKS, 0}, // 0 BLOCKS
{SPORK_14_REQUIRE_SENTINEL_FLAG, 4070908800ULL}, // OFF
{SPORK_15_DETERMINISTIC_MNS_ENABLED, 4070908800ULL}, // OFF
};

void CSporkManager::Clear()
Expand Down Expand Up @@ -182,6 +183,7 @@ int CSporkManager::GetSporkIDByName(const std::string& strName)
if (strName == "SPORK_10_MASTERNODE_PAY_UPDATED_NODES") return SPORK_10_MASTERNODE_PAY_UPDATED_NODES;
if (strName == "SPORK_12_RECONSIDER_BLOCKS") return SPORK_12_RECONSIDER_BLOCKS;
if (strName == "SPORK_14_REQUIRE_SENTINEL_FLAG") return SPORK_14_REQUIRE_SENTINEL_FLAG;
if (strName == "SPORK_15_DETERMINISTIC_MNS_ENABLED") return SPORK_15_DETERMINISTIC_MNS_ENABLED;

LogPrint("spork", "CSporkManager::GetSporkIDByName -- Unknown Spork name '%s'\n", strName);
return -1;
Expand All @@ -199,6 +201,7 @@ std::string CSporkManager::GetSporkNameByID(int nSporkID)
case SPORK_10_MASTERNODE_PAY_UPDATED_NODES: return "SPORK_10_MASTERNODE_PAY_UPDATED_NODES";
case SPORK_12_RECONSIDER_BLOCKS: return "SPORK_12_RECONSIDER_BLOCKS";
case SPORK_14_REQUIRE_SENTINEL_FLAG: return "SPORK_14_REQUIRE_SENTINEL_FLAG";
case SPORK_15_DETERMINISTIC_MNS_ENABLED: return "SPORK_15_DETERMINISTIC_MNS_ENABLED";
default:
LogPrint("spork", "CSporkManager::GetSporkNameByID -- Unknown Spork ID %d\n", nSporkID);
return "Unknown";
Expand Down
3 changes: 2 additions & 1 deletion src/spork.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ static const int SPORK_9_SUPERBLOCKS_ENABLED = 10008;
static const int SPORK_10_MASTERNODE_PAY_UPDATED_NODES = 10009;
static const int SPORK_12_RECONSIDER_BLOCKS = 10011;
static const int SPORK_14_REQUIRE_SENTINEL_FLAG = 10013;
static const int SPORK_15_DETERMINISTIC_MNS_ENABLED = 10014;

static const int SPORK_START = SPORK_2_INSTANTSEND_ENABLED;
static const int SPORK_END = SPORK_14_REQUIRE_SENTINEL_FLAG;
static const int SPORK_END = SPORK_15_DETERMINISTIC_MNS_ENABLED;

extern std::map<int, int64_t> mapSporkDefaults;
extern CSporkManager sporkManager;
Expand Down

0 comments on commit 5461e92

Please sign in to comment.