Skip to content

Commit

Permalink
fix mn anounce: (#813)
Browse files Browse the repository at this point in the history
- every node should check for "pre-enabled" status of a newly added mn to relay message further (was "enabled" which is wrong - if node is enabled, that's not the first announce, so no need to relay it because most likely we were the one who asked for that mn directly via dseg)
- we should not add ourselves to mn list if announce message has outdated protocol version (report this in log)
- we should remove ourselves from saved list if we start updated mn for the first time and just loaded old list from mncache.dat
  • Loading branch information
UdjinM6 authored and schinzelh committed May 27, 2016
1 parent 517ffd7 commit c3b950d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
31 changes: 23 additions & 8 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ void CMasternode::Check(bool forceCheck)
//once spent, stop doing the checks
if(activeState == MASTERNODE_VIN_SPENT) return;

if(!IsPingedWithin(MASTERNODE_REMOVAL_SECONDS)){
// If there are no pings for quite a long time ...
if(!IsPingedWithin(MASTERNODE_REMOVAL_SECONDS)
// or doesn't meet payments requirements ...
|| protocolVersion < mnpayments.GetMinMasternodePaymentsProto()
// or it's our own node and we just updated it to the new protocol but we are still waiting for activation -
|| (pubkey2 == activeMasternode.pubKeyMasternode && protocolVersion < PROTOCOL_VERSION)) {
// remove it from the list
activeState = MASTERNODE_REMOVE;
return;
}
Expand Down Expand Up @@ -433,7 +439,8 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
LogPrintf("CMasternodeBroadcast::CheckAndUpdate - Got updated entry for %s\n", addr.ToString());
if(pmn->UpdateFromNewBroadcast((*this))){
pmn->Check();
if(pmn->IsEnabled()) Relay();
// normally masternode should be in pre-enabled status after update, if not - do not relay
if(pmn->IsPreEnabled()) Relay();
}
masternodeSync.AddedMasternodeList(GetHash());
}
Expand All @@ -458,7 +465,7 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDos)
if(pmn != NULL) {
// 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
// if it's not (pre)enabled, remove old MN first and continue
else mnodeman.Remove(pmn->vin);
}

Expand Down Expand Up @@ -525,15 +532,23 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDos)
}
}

// if it matches our Masternode privkey...
if(fMasterNode && pubkey2 == activeMasternode.pubKeyMasternode) {
if(protocolVersion == PROTOCOL_VERSION) {
// ... and PROTOCOL_VERSION, then we've been remotely activated ...
activeMasternode.EnableHotColdMasterNode(vin, addr);
} else {
// ... otherwise we need to reactivate our node, don not add it to the list and do not relay
// but also do not ban the node we get this message from
LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - wrong PROTOCOL_VERSION, announce message: %d MN: %d - re-activate your MN\n", protocolVersion, PROTOCOL_VERSION);
return false;
}
}

LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Got NEW Masternode entry - %s - %s - %s - %lli \n", GetHash().ToString(), addr.ToString(), vin.ToString(), sigTime);
CMasternode mn(*this);
mnodeman.Add(mn);

// if it matches our Masternode privkey, then we've been remotely activated
if(pubkey2 == activeMasternode.pubKeyMasternode && protocolVersion == PROTOCOL_VERSION){
activeMasternode.EnableHotColdMasterNode(vin, addr);
}

bool isLocal = addr.IsRFC1918() || addr.IsLocal();
if(Params().NetworkIDString() == CBaseChainParams::REGTEST) isLocal = false;

Expand Down
3 changes: 1 addition & 2 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ void CMasternodeMan::CheckAndRemove(bool forceExpiredRemoval)
while(it != vMasternodes.end()){
if((*it).activeState == CMasternode::MASTERNODE_REMOVE ||
(*it).activeState == CMasternode::MASTERNODE_VIN_SPENT ||
(forceExpiredRemoval && (*it).activeState == CMasternode::MASTERNODE_EXPIRED) ||
(*it).protocolVersion < mnpayments.GetMinMasternodePaymentsProto()) {
(forceExpiredRemoval && (*it).activeState == CMasternode::MASTERNODE_EXPIRED)) {
LogPrint("masternode", "CMasternodeMan::CheckAndRemove - Removing inactive Masternode %s - %i now\n", (*it).addr.ToString(), size() - 1);

//erase all of the broadcasts we've seen from this vin
Expand Down

0 comments on commit c3b950d

Please sign in to comment.