Skip to content

Commit

Permalink
Merge pull request #561 from UdjinM6/v0.12.1.x_pre_enabled
Browse files Browse the repository at this point in the history
V0.12.1.x pre-enabled status from masternodes
  • Loading branch information
evan82 committed Sep 22, 2015
2 parents e29241b + 30ab984 commit ddf71c0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,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;
Expand Down Expand Up @@ -392,7 +396,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,
Expand Down Expand Up @@ -421,8 +425,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);
}
Expand Down Expand Up @@ -582,7 +586,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
Expand Down
31 changes: 19 additions & 12 deletions src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -243,6 +244,11 @@ class CMasternode
return activeState == MASTERNODE_ENABLED;
}

bool IsPreEnabled()
{
return activeState == MASTERNODE_PRE_ENABLED;
}

int GetMasternodeInputAge()
{
if(chainActive.Tip() == NULL) return 0;
Expand All @@ -256,13 +262,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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ddf71c0

Please sign in to comment.