diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index f1717382a7..5300b26401 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -11,6 +11,7 @@ #include "script/standard.h" #include "base58.h" #include "core_io.h" +#include "spork.h" #include @@ -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; @@ -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; } @@ -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); diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index cfea510be1..5a84095807 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -401,7 +401,11 @@ public: 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); }; diff --git a/src/spork.cpp b/src/spork.cpp index adf3f315e1..1d096fa935 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -25,6 +25,7 @@ std::map 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() @@ -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; @@ -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"; diff --git a/src/spork.h b/src/spork.h index 60153efc06..4ccd619d12 100644 --- a/src/spork.h +++ b/src/spork.h @@ -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 mapSporkDefaults; extern CSporkManager sporkManager;