Slightly refactor masternode statuses:

- better names (MASTERNODE_INITIAL was defined twice before that)
- move to proper header
This commit is contained in:
UdjinM6 2015-07-17 13:26:24 +03:00
parent b6001065ae
commit 33ee068d6a
6 changed files with 35 additions and 35 deletions

View File

@ -19,12 +19,12 @@ void CActiveMasternode::ManageStatus()
//need correct blocks to send ping
if(IsInitialBlockDownload()) {
status = MASTERNODE_SYNC_IN_PROCESS;
status = ACTIVE_MASTERNODE_SYNC_IN_PROCESS;
LogPrintf("CActiveMasternode::ManageStatus() - Sync in progress. Must wait until sync is complete to start Masternode.\n");
return;
}
if(status == MASTERNODE_INITIAL || status == MASTERNODE_SYNC_IN_PROCESS) {
if(status == ACTIVE_MASTERNODE_INITIAL || status == ACTIVE_MASTERNODE_SYNC_IN_PROCESS) {
CMasternode *pmn;
pmn = mnodeman.Find(pubKeyMasternode);
if(pmn != NULL) {
@ -33,10 +33,10 @@ void CActiveMasternode::ManageStatus()
}
}
if(status != MASTERNODE_STARTED) {
if(status != ACTIVE_MASTERNODE_STARTED) {
// Set defaults
status = MASTERNODE_NOT_CAPABLE;
status = ACTIVE_MASTERNODE_NOT_CAPABLE;
notCapableReason = "";
if(strMasterNodeAddr.empty()) {
@ -86,7 +86,7 @@ void CActiveMasternode::ManageStatus()
notCapableReason = "Input must have least " + boost::lexical_cast<string>(MASTERNODE_MIN_CONFIRMATIONS) +
" confirmations - " + boost::lexical_cast<string>(GetInputAge(vin)) + " confirmations";
LogPrintf("CActiveMasternode::ManageStatus() - %s\n", notCapableReason);
status = MASTERNODE_INPUT_TOO_NEW;
status = ACTIVE_MASTERNODE_INPUT_TOO_NEW;
return;
}
@ -110,7 +110,7 @@ void CActiveMasternode::ManageStatus()
}
LogPrintf("CActiveMasternode::ManageStatus() - Is capable master node!\n");
status = MASTERNODE_STARTED;
status = ACTIVE_MASTERNODE_STARTED;
return;
} else {
@ -128,17 +128,17 @@ void CActiveMasternode::ManageStatus()
std::string CActiveMasternode::GetStatus() {
switch (status) {
case MASTERNODE_INITIAL: return "node just started, not yet activated";
case MASTERNODE_SYNC_IN_PROCESS: return "sync in process. Must wait until client is synced to start";
case MASTERNODE_INPUT_TOO_NEW: return "masternode input must have at least 15 confirmations";
case MASTERNODE_NOT_CAPABLE: return "not capable masternode: " + notCapableReason;
case MASTERNODE_STARTED: return "masternode successfully started";
case ACTIVE_MASTERNODE_INITIAL: return "node just started, not yet activated";
case ACTIVE_MASTERNODE_SYNC_IN_PROCESS: return "sync in process. Must wait until client is synced to start";
case ACTIVE_MASTERNODE_INPUT_TOO_NEW: return "masternode input must have at least 15 confirmations";
case ACTIVE_MASTERNODE_NOT_CAPABLE: return "not capable masternode: " + notCapableReason;
case ACTIVE_MASTERNODE_STARTED: return "masternode successfully started";
default: return "unknown";
}
}
bool CActiveMasternode::SendMasternodePing(std::string& errorMessage) {
if(status != MASTERNODE_STARTED) {
if(status != ACTIVE_MASTERNODE_STARTED) {
errorMessage = "Masternode is not in a running status";
return false;
}
@ -179,7 +179,7 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage) {
{
// Seems like we are trying to send a ping while the Masternode is not registered in the network
errorMessage = "Darksend Masternode List doesn't include our Masternode, shutting down Masternode pinging service! " + vin.ToString();
status = MASTERNODE_NOT_CAPABLE;
status = ACTIVE_MASTERNODE_NOT_CAPABLE;
notCapableReason = errorMessage;
return false;
}
@ -353,7 +353,7 @@ bool CActiveMasternode::EnableHotColdMasterNode(CTxIn& newVin, CService& newServ
{
if(!fMasterNode) return false;
status = MASTERNODE_STARTED;
status = ACTIVE_MASTERNODE_STARTED;
//The values below are needed for signing mnping messages going forward
this->vin = newVin;

View File

@ -13,6 +13,12 @@
#include "darksend.h"
#include "masternode.h"
#define ACTIVE_MASTERNODE_INITIAL 0 // initial state
#define ACTIVE_MASTERNODE_SYNC_IN_PROCESS 1
#define ACTIVE_MASTERNODE_INPUT_TOO_NEW 2
#define ACTIVE_MASTERNODE_NOT_CAPABLE 3
#define ACTIVE_MASTERNODE_STARTED 4
// Responsible for activating the Masternode and pinging the network
class CActiveMasternode
{
@ -44,7 +50,7 @@ public:
CActiveMasternode()
{
status = MASTERNODE_INITIAL;
status = ACTIVE_MASTERNODE_INITIAL;
}
/// Manage status of main Masternode

View File

@ -17,13 +17,13 @@ CMasternodeSync::CMasternodeSync()
lastMasternodeList = 0;
lastMasternodeWinner = 0;
lastBudgetItem = 0;
RequestedMasternodeAssets = MASTERNODE_INITIAL;
RequestedMasternodeAssets = MASTERNODE_SYNC_INITIAL;
RequestedMasternodeAttempt = 0;
}
bool CMasternodeSync::IsSynced()
{
return (RequestedMasternodeAssets == MASTERNODE_LIST_SYNCED);
return (RequestedMasternodeAssets == MASTERNODE_SYNC_FINISHED);
}
void CMasternodeSync::AddedMasternodeList()
@ -45,10 +45,10 @@ void CMasternodeSync::GetNextAsset()
{
switch(RequestedMasternodeAssets)
{
case(MASTERNODE_INITIAL):
RequestedMasternodeAssets = MASTERNODE_SPORK_SETTINGS;
case(MASTERNODE_SYNC_INITIAL):
RequestedMasternodeAssets = MASTERNODE_SYNC_SPORKS;
break;
case(MASTERNODE_SPORK_SETTINGS):
case(MASTERNODE_SYNC_SPORKS):
RequestedMasternodeAssets = MASTERNODE_SYNC_LIST;
break;
case(MASTERNODE_SYNC_LIST):
@ -58,7 +58,7 @@ void CMasternodeSync::GetNextAsset()
RequestedMasternodeAssets = MASTERNODE_SYNC_BUDGET;
break;
case(MASTERNODE_SYNC_BUDGET):
RequestedMasternodeAssets = MASTERNODE_LIST_SYNCED;
RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED;
break;
}
RequestedMasternodeAttempt = 0;
@ -75,7 +75,7 @@ void CMasternodeSync::Process()
if(fDebug) LogPrintf("CMasternodeSync::Process() - RequestedMasternodeAssets %d c %d\n", RequestedMasternodeAssets, c);
//request full mn list only if Masternodes.dat was updated quite a long time ago
if(RequestedMasternodeAssets == MASTERNODE_INITIAL) GetNextAsset();
if(RequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL) GetNextAsset();
CBlockIndex* pindexPrev = chainActive.Tip();
if(pindexPrev == NULL) return;
@ -86,7 +86,7 @@ void CMasternodeSync::Process()
if (pnode->nVersion >= MIN_POOL_PEER_PROTO_VERSION)
{
if(RequestedMasternodeAssets == MASTERNODE_SPORK_SETTINGS){
if(RequestedMasternodeAssets == MASTERNODE_SYNC_SPORKS){
if(pnode->HasFulfilledRequest("getspork")) continue;
pnode->FulfilledRequest("getspork");

View File

@ -5,12 +5,12 @@
#ifndef MASTERNODE_SYNC_H
#define MASTERNODE_SYNC_H
#define MASTERNODE_INITIAL 0
#define MASTERNODE_SPORK_SETTINGS 1
#define MASTERNODE_SYNC_INITIAL 0
#define MASTERNODE_SYNC_SPORKS 1
#define MASTERNODE_SYNC_LIST 2
#define MASTERNODE_SYNC_MNW 3
#define MASTERNODE_SYNC_BUDGET 4
#define MASTERNODE_LIST_SYNCED 999
#define MASTERNODE_SYNC_FINISHED 999
#define MASTERNODE_SYNC_TIMEOUT 5

View File

@ -13,12 +13,6 @@
#include "main.h"
#include "timedata.h"
#define MASTERNODE_INITIAL 0 // initial state
#define MASTERNODE_SYNC_IN_PROCESS 1
#define MASTERNODE_INPUT_TOO_NEW 2
#define MASTERNODE_NOT_CAPABLE 3
#define MASTERNODE_STARTED 4
#define MASTERNODE_MIN_CONFIRMATIONS 15
#define MASTERNODE_MIN_MNP_SECONDS (30*60)
#define MASTERNODE_MIN_MNB_SECONDS (5*60)

View File

@ -199,8 +199,8 @@ Value masternode(const Array& params, bool fHelp)
}
}
if(activeMasternode.status != MASTERNODE_STARTED){
activeMasternode.status = MASTERNODE_INITIAL; // TODO: consider better way
if(activeMasternode.status != ACTIVE_MASTERNODE_STARTED){
activeMasternode.status = ACTIVE_MASTERNODE_INITIAL; // TODO: consider better way
activeMasternode.ManageStatus();
pwalletMain->Lock();
}
@ -322,7 +322,7 @@ Value masternode(const Array& params, bool fHelp)
if (strCommand == "debug")
{
if(activeMasternode.status != MASTERNODE_INITIAL) return activeMasternode.GetStatus();
if(activeMasternode.status != ACTIVE_MASTERNODE_INITIAL) return activeMasternode.GetStatus();
CTxIn vin = CTxIn();
CPubKey pubkey = CScript();