From 30ab9849204654cf7603ae830730beda203d33ce Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 5 Aug 2015 06:16:29 +0300 Subject: [PATCH] treat MN as pre-enabled while there is no legit ping that differ from initial one (from mnb) --- src/activemasternode.cpp | 3 ++- src/masternode.cpp | 12 ++++++++---- src/masternode.h | 31 +++++++++++++++++++------------ src/masternodeman.cpp | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 6050a045bbad..43cc0c6bb321 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -32,7 +32,8 @@ void CActiveMasternode::ManageStatus() pmn = mnodeman.Find(pubKeyMasternode); if(pmn != NULL) { pmn->Check(); - if(pmn->IsEnabled() && pmn->protocolVersion == PROTOCOL_VERSION) EnableHotColdMasterNode(pmn->vin, pmn->addr); + if((pmn->IsEnabled() || pmn->IsPreEnabled()) && pmn->protocolVersion == PROTOCOL_VERSION) + EnableHotColdMasterNode(pmn->vin, pmn->addr); } } diff --git a/src/masternode.cpp b/src/masternode.cpp index 859da5131694..58aee2193834 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -189,6 +189,10 @@ void CMasternode::Check(bool forceCheck) //once spent, stop doing the checks if(activeState == MASTERNODE_VIN_SPENT) return; + if(lastPing.sigTime - sigTime < MASTERNODE_MIN_MNP_SECONDS){ + activeState = MASTERNODE_PRE_ENABLED; + return; + } if(!IsPingedWithin(MASTERNODE_REMOVAL_SECONDS)){ activeState = MASTERNODE_REMOVE; @@ -398,7 +402,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) //search existing Masternode list, this is where we update existing Masternodes with new mnb broadcasts CMasternode* pmn = mnodeman.Find(vin); - // no such masternode or it's not enabled already, nothing to update + // no such masternode or it's not enabled yet/already, nothing to update if(pmn == NULL || (pmn != NULL && !pmn->IsEnabled())) return true; // mn.pubkey = pubkey, IsVinAssociatedWithPubkey is validated once below, @@ -427,8 +431,8 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS) CMasternode* pmn = mnodeman.Find(vin); if(pmn != NULL) { - // nothing to do here if we already know about this masternode and it's enabled - if(pmn->IsEnabled()) return true; + // nothing to do here if we already know about this masternode and it's (pre)enabled + if(pmn->IsEnabled() || pmn->IsPreEnabled()) return true; // if it's not enabled, remove old MN first and continue else mnodeman.Remove(pmn->vin); } @@ -586,7 +590,7 @@ bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled) CMasternode* pmn = mnodeman.Find(vin); if(pmn != NULL && pmn->protocolVersion >= masternodePayments.GetMinMasternodePaymentsProto()) { - if (fRequireEnabled && !pmn->IsEnabled()) return false; + if (fRequireEnabled && !pmn->IsEnabled() && !pmn->IsPreEnabled()) return false; // LogPrintf("mnping - Found corresponding mn for vin: %s\n", vin.ToString()); // update only if there is no known ping for this masternode or diff --git a/src/masternode.h b/src/masternode.h index 0bdf396691a4..9cdca762951e 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -111,11 +111,12 @@ class CMasternode int64_t lastTimeChecked; public: enum state { - MASTERNODE_ENABLED = 1, - MASTERNODE_EXPIRED = 2, - MASTERNODE_VIN_SPENT = 3, - MASTERNODE_REMOVE = 4, - MASTERNODE_POS_ERROR = 5 + MASTERNODE_PRE_ENABLED, + MASTERNODE_ENABLED, + MASTERNODE_EXPIRED, + MASTERNODE_VIN_SPENT, + MASTERNODE_REMOVE, + MASTERNODE_POS_ERROR }; CTxIn vin; @@ -246,6 +247,11 @@ class CMasternode return activeState == MASTERNODE_ENABLED; } + bool IsPreEnabled() + { + return activeState == MASTERNODE_PRE_ENABLED; + } + int GetMasternodeInputAge() { if(chainActive.Tip() == NULL) return 0; @@ -259,13 +265,14 @@ class CMasternode } std::string Status() { - std::string strStatus = "ACTIVE"; - - if(activeState == CMasternode::MASTERNODE_ENABLED) strStatus = "ENABLED"; - if(activeState == CMasternode::MASTERNODE_EXPIRED) strStatus = "EXPIRED"; - if(activeState == CMasternode::MASTERNODE_VIN_SPENT) strStatus = "VIN_SPENT"; - if(activeState == CMasternode::MASTERNODE_REMOVE) strStatus = "REMOVE"; - if(activeState == CMasternode::MASTERNODE_POS_ERROR) strStatus = "POS_ERROR"; + std::string strStatus = "unknown"; + + if(activeState == CMasternode::MASTERNODE_PRE_ENABLED) strStatus = "PRE_ENABLED"; + if(activeState == CMasternode::MASTERNODE_ENABLED) strStatus = "ENABLED"; + if(activeState == CMasternode::MASTERNODE_EXPIRED) strStatus = "EXPIRED"; + if(activeState == CMasternode::MASTERNODE_VIN_SPENT) strStatus = "VIN_SPENT"; + if(activeState == CMasternode::MASTERNODE_REMOVE) strStatus = "REMOVE"; + if(activeState == CMasternode::MASTERNODE_POS_ERROR) strStatus = "POS_ERROR"; return strStatus; } diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index ae52184c8c5b..4783dbb2668e 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -210,7 +210,7 @@ bool CMasternodeMan::Add(CMasternode &mn) { LOCK(cs); - if (!mn.IsEnabled()) + if (!mn.IsEnabled() && !mn.IsPreEnabled()) return false; CMasternode *pmn = Find(mn.vin);