From 3e8c0062a0a319c59527dcf584cb4717cd245cd2 Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Wed, 23 Nov 2016 10:30:36 -0500 Subject: [PATCH] Implement SPORK_14_REQUIRE_SENTINEL (#1163) --- src/masternode-payments.cpp | 4 ++-- src/masternode.h | 14 ++++++++++++++ src/masternodeman.cpp | 7 +++++-- src/spork.cpp | 4 ++++ src/spork.h | 4 +++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 8f551e762..6436eb7c6 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -620,7 +620,7 @@ bool CMasternodePaymentVote::IsValid(CNode* pnode, int nValidationHeight, std::s return false; } - int nRank = mnodeman.GetMasternodeRank(vinMasternode, nBlockHeight - 101, nMinRequiredProtocol); + int nRank = mnodeman.GetMasternodeRank(vinMasternode, nBlockHeight - 101, nMinRequiredProtocol, false); if(nRank > MNPAYMENTS_SIGNATURES_TOTAL) { // It's common to have masternodes mistakenly think they are in the top 10 @@ -650,7 +650,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) // if we have not enough data about masternodes. if(!masternodeSync.IsMasternodeListSynced()) return false; - int nRank = mnodeman.GetMasternodeRank(activeMasternode.vin, nBlockHeight - 101, GetMinMasternodePaymentsProto()); + int nRank = mnodeman.GetMasternodeRank(activeMasternode.vin, nBlockHeight - 101, GetMinMasternodePaymentsProto(), false); if (nRank == -1) { LogPrint("mnpayments", "CMasternodePayments::ProcessBlock -- Unknown Masternode\n"); diff --git a/src/masternode.h b/src/masternode.h index 7762ac5a9..2b5077bef 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -8,6 +8,7 @@ #include "key.h" #include "main.h" #include "net.h" +#include "spork.h" #include "timedata.h" class CMasternode; @@ -258,6 +259,19 @@ public: bool IsWatchdogExpired() { return nActiveState == MASTERNODE_WATCHDOG_EXPIRED; } + bool IsValidForPayment() + { + if(nActiveState == MASTERNODE_ENABLED) { + return true; + } + if(!sporkManager.IsSporkActive(SPORK_14_REQUIRE_SENTINEL_FLAG) && + (nActiveState == MASTERNODE_WATCHDOG_EXPIRED)) { + return true; + } + + return false; + } + bool IsValidNetAddr(); void IncreasePoSeBanScore() { if(nPoSeBanScore < MASTERNODE_POSE_BAN_MAX_SCORE) nPoSeBanScore++; } diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 8abc31658..c5f3d4af0 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -476,7 +476,7 @@ CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight BOOST_FOREACH(CMasternode &mn, vMasternodes) { mn.Check(); - if(!mn.IsEnabled()) continue; + if(!mn.IsValidForPayment()) continue; // //check protocol version if(mn.nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto()) continue; @@ -581,10 +581,13 @@ int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int nBlockHeight, int nM // scan for winner BOOST_FOREACH(CMasternode& mn, vMasternodes) { if(mn.nProtocolVersion < nMinProtocol) continue; + mn.Check(); if(fOnlyActive) { - mn.Check(); if(!mn.IsEnabled()) continue; } + else { + if(!mn.IsValidForPayment()) continue; + } int64_t nScore = mn.CalculateScore(blockHash).GetCompact(false); vecMasternodeScores.push_back(std::make_pair(nScore, &mn)); diff --git a/src/spork.cpp b/src/spork.cpp index 97926e4a2..130e935a9 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -112,6 +112,7 @@ bool CSporkManager::IsSporkActive(int nSporkID) case SPORK_10_MASTERNODE_PAY_UPDATED_NODES: r = SPORK_10_MASTERNODE_PAY_UPDATED_NODES_DEFAULT; break; case SPORK_12_RECONSIDER_BLOCKS: r = SPORK_12_RECONSIDER_BLOCKS_DEFAULT; break; case SPORK_13_OLD_SUPERBLOCK_FLAG: r = SPORK_13_OLD_SUPERBLOCK_FLAG_DEFAULT; break; + case SPORK_14_REQUIRE_SENTINEL_FLAG: r = SPORK_14_REQUIRE_SENTINEL_FLAG_DEFAULT; break; default: LogPrint("spork", "CSporkManager::IsSporkActive -- Unknown Spork ID %d\n", nSporkID); r = 4070908800; // 2099-1-1 i.e. off by default @@ -137,6 +138,7 @@ int64_t CSporkManager::GetSporkValue(int nSporkID) case SPORK_10_MASTERNODE_PAY_UPDATED_NODES: return SPORK_10_MASTERNODE_PAY_UPDATED_NODES_DEFAULT; case SPORK_12_RECONSIDER_BLOCKS: return SPORK_12_RECONSIDER_BLOCKS_DEFAULT; case SPORK_13_OLD_SUPERBLOCK_FLAG: return SPORK_13_OLD_SUPERBLOCK_FLAG_DEFAULT; + case SPORK_14_REQUIRE_SENTINEL_FLAG: return SPORK_14_REQUIRE_SENTINEL_FLAG_DEFAULT; default: LogPrint("spork", "CSporkManager::GetSporkValue -- Unknown Spork ID %d\n", nSporkID); return -1; @@ -154,6 +156,7 @@ int CSporkManager::GetSporkIDByName(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_13_OLD_SUPERBLOCK_FLAG") return SPORK_13_OLD_SUPERBLOCK_FLAG; + if (strName == "SPORK_14_REQUIRE_SENTINEL_FLAG") return SPORK_14_REQUIRE_SENTINEL_FLAG; LogPrint("spork", "CSporkManager::GetSporkIDByName -- Unknown Spork name '%s'\n", strName); return -1; @@ -170,6 +173,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_13_OLD_SUPERBLOCK_FLAG: return "SPORK_13_OLD_SUPERBLOCK_FLAG"; + case SPORK_14_REQUIRE_SENTINEL_FLAG: return "SPORK_14_REQUIRE_SENTINEL_FLAG"; default: LogPrint("spork", "CSporkManager::GetSporkNameByID -- Unknown Spork ID %d\n", nSporkID); return "Unknown"; diff --git a/src/spork.h b/src/spork.h index 63cf60e59..d586d3220 100644 --- a/src/spork.h +++ b/src/spork.h @@ -17,7 +17,7 @@ class CSporkManager; - This would result in old clients getting confused about which spork is for what */ static const int SPORK_START = 10001; -static const int SPORK_END = 10012; +static const int SPORK_END = 10013; static const int SPORK_2_INSTANTSEND_ENABLED = 10001; static const int SPORK_3_INSTANTSEND_BLOCK_FILTERING = 10002; @@ -27,6 +27,7 @@ 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_13_OLD_SUPERBLOCK_FLAG = 10012; +static const int SPORK_14_REQUIRE_SENTINEL_FLAG = 10013; static const int64_t SPORK_2_INSTANTSEND_ENABLED_DEFAULT = 0; // ON static const int64_t SPORK_3_INSTANTSEND_BLOCK_FILTERING_DEFAULT = 0; // ON @@ -36,6 +37,7 @@ static const int64_t SPORK_9_SUPERBLOCKS_ENABLED_DEFAULT = 407090 static const int64_t SPORK_10_MASTERNODE_PAY_UPDATED_NODES_DEFAULT = 4070908800; // OFF static const int64_t SPORK_12_RECONSIDER_BLOCKS_DEFAULT = 0; // 0 BLOCKS static const int64_t SPORK_13_OLD_SUPERBLOCK_FLAG_DEFAULT = 4070908800; // OFF +static const int64_t SPORK_14_REQUIRE_SENTINEL_FLAG_DEFAULT = 4070908800; // OFF extern std::map mapSporks; extern CSporkManager sporkManager;