Skip to content

Commit

Permalink
Split sentinel expiration in CMasternode::Check() in two parts (timeo…
Browse files Browse the repository at this point in the history
…ut and version) (bitcoin#2121)

The initial ping is sent with defaults which switch MNs to SENTINEL_PING_EXPIRED state
while they should really be in PRE_ENABLED state. The fix is to split this verification
in two parts - this way sentinel version is only checked after at least one ping is received
from the masternode itself and not from the cold wallet.
  • Loading branch information
UdjinM6 authored and Michael Polzer committed Jul 2, 2018
1 parent 44f0ee7 commit 0548008
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ void CMasternode::Check(bool fForce)
return;
}

// part 1: expire based on dashd ping
bool fSentinelPingActive = masternodeSync.IsSynced() && mnodeman.IsSentinelPingActive();
bool fSentinelPingExpired = fSentinelPingActive && (!lastPing.fSentinelIsCurrent || !IsPingedWithin(MASTERNODE_SENTINEL_PING_MAX_SECONDS));

LogPrint(BCLog::MNODE, "CMasternode::Check -- outpoint=%s, GetAdjustedTime()=%d, fSentinelPingExpired=%d\n",
bool fSentinelPingExpired = fSentinelPingActive && !IsPingedWithin(MASTERNODE_SENTINEL_PING_MAX_SECONDS);
LogPrint(BCLog::MNODE, "CMasternode::Check -- outpoint=%s, GetAdjustedTime()=%d, fSentinelPingExpired=%d\n",
outpoint.ToStringShort(), GetAdjustedTime(), fSentinelPingExpired);

if(fSentinelPingExpired) {
Expand All @@ -234,7 +234,7 @@ void CMasternode::Check(bool fForce)
}
}

// Allow MNs to become ENABLED immediately in regtest/devnet
// Allow MNs to become PRE_ENABLED immediately in regtest/devnet
// On mainnet/testnet, we require them to be in PRE_ENABLED state for some time before they get into ENABLED state
if (Params().NetworkIDString() != CBaseChainParams::REGTEST) {
if (lastPing.sigTime - sigTime < MASTERNODE_MIN_MNP_SECONDS) {
Expand All @@ -246,6 +246,23 @@ void CMasternode::Check(bool fForce)
}
}

if(!fWaitForPing || fOurMasternode) {
// part 2: expire based on sentinel info
bool fSentinelPingActive = masternodeSync.IsSynced() && mnodeman.IsSentinelPingActive();
bool fSentinelPingExpired = fSentinelPingActive && !lastPing.fSentinelIsCurrent;

LogPrint("masternode", "CMasternode::Check -- outpoint=%s, GetAdjustedTime()=%d, fSentinelPingExpired=%d\n",
outpoint.ToStringShort(), GetAdjustedTime(), fSentinelPingExpired);

if(fSentinelPingExpired) {
nActiveState = MASTERNODE_SENTINEL_PING_EXPIRED;
if(nActiveStatePrev != nActiveState) {
LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", outpoint.ToStringShort(), GetStateString());
}
return;
}
}

nActiveState = MASTERNODE_ENABLED; // OK
if(nActiveStatePrev != nActiveState) {
LogPrint(BCLog::MNODE, "CMasternode::Check -- Masternode %s is in %s state now\n", outpoint.ToStringShort(), GetStateString());
Expand Down

0 comments on commit 0548008

Please sign in to comment.