Merge pull request #492 from UdjinM6/v0.12.0.x_mncheck

V0.12.0.x set a cooldown for MN check
This commit is contained in:
evan82 2015-08-08 11:10:38 -07:00
commit 2f479e45db
2 changed files with 13 additions and 4 deletions

View File

@ -72,6 +72,7 @@ CMasternode::CMasternode()
nLastDsq = 0;
nScanningErrorCount = 0;
nLastScanningErrorBlockHeight = 0;
lastTimeChecked = 0;
}
CMasternode::CMasternode(const CMasternode& other)
@ -93,6 +94,7 @@ CMasternode::CMasternode(const CMasternode& other)
nLastDsq = other.nLastDsq;
nScanningErrorCount = other.nScanningErrorCount;
nLastScanningErrorBlockHeight = other.nLastScanningErrorBlockHeight;
lastTimeChecked = 0;
}
CMasternode::CMasternode(const CMasternodeBroadcast& mnb)
@ -114,6 +116,7 @@ CMasternode::CMasternode(const CMasternodeBroadcast& mnb)
nLastDsq = 0;
nScanningErrorCount = 0;
nLastScanningErrorBlockHeight = 0;
lastTimeChecked = 0;
}
//
@ -126,6 +129,7 @@ void CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast& mnb)
sig = mnb.sig;
protocolVersion = mnb.protocolVersion;
addr = mnb.addr;
lastTimeChecked = 0;
int nDoS = 0;
if(mnb.lastPing == CMasternodePing() || (mnb.lastPing != CMasternodePing() && mnb.lastPing.CheckAndUpdate(nDoS, false))) {
lastPing = mnb.lastPing;
@ -164,10 +168,14 @@ uint256 CMasternode::CalculateScore(int mod, int64_t nBlockHeight)
return r;
}
void CMasternode::Check()
void CMasternode::Check(bool forceCheck)
{
if(ShutdownRequested()) return;
if(!forceCheck && (GetTime() - lastTimeChecked < MASTERNODE_CHECK_SECONDS)) return;
lastTimeChecked = GetTime();
//once spent, stop doing the checks
if(activeState == MASTERNODE_VIN_SPENT) return;
@ -605,7 +613,7 @@ bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled)
mnodeman.mapSeenMasternodeBroadcast[hash].lastPing = *this;
}
pmn->Check();
pmn->Check(true);
if(!pmn->IsEnabled()) return false;
LogPrint("masnernode", "CMasternodePing::CheckAndUpdate - Masternode ping accepted, vin: %s\n", vin.ToString());

View File

@ -19,6 +19,7 @@
#define MASTERNODE_PING_SECONDS (5*60)
#define MASTERNODE_EXPIRATION_SECONDS (65*60)
#define MASTERNODE_REMOVAL_SECONDS (75*60)
#define MASTERNODE_CHECK_SECONDS 5
using namespace std;
@ -107,7 +108,7 @@ class CMasternode
private:
// critical section to protect the inner data structures
mutable CCriticalSection cs;
int64_t lastTimeChecked;
public:
enum state {
MASTERNODE_ENABLED = 1,
@ -216,7 +217,7 @@ public:
return n;
}
void Check();
void Check(bool forceCheck = false);
bool IsBroadcastedWithin(int seconds)
{