From 17cebbed15e273e7ca7d9cf3552af97fdb508098 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 30 Nov 2016 05:33:37 +0400 Subject: [PATCH] fix excessive banning, remove some redundant logic (#1172) * Since we send all mnb's now regardless of mn state, ping check for sigTime being too old is obsolete (and wrong). Also removing fRequireEnabled, this logic is deprecated too it seems. * remove (pre-)enabled check in CMasternodeMan::Add --- src/masternode.cpp | 14 +++----------- src/masternode.h | 2 +- src/masternodeman.cpp | 5 +---- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/masternode.cpp b/src/masternode.cpp index 196beaa1b..7f1285405 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -121,7 +121,7 @@ bool CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast& mnb) nTimeLastChecked = 0; nTimeLastWatchdogVote = mnb.sigTime; int nDos = 0; - if(mnb.lastPing == CMasternodePing() || (mnb.lastPing != CMasternodePing() && mnb.lastPing.CheckAndUpdate(nDos, false))) { + if(mnb.lastPing == CMasternodePing() || (mnb.lastPing != CMasternodePing() && mnb.lastPing.CheckAndUpdate(nDos))) { lastPing = mnb.lastPing; mnodeman.mapSeenMasternodePing.insert(std::make_pair(lastPing.GetHash(), lastPing)); } @@ -466,7 +466,7 @@ bool CMasternodeBroadcast::SimpleCheck(int& nDos) } // empty ping or incorrect sigTime/blockhash - if(lastPing == CMasternodePing() || !lastPing.CheckAndUpdate(nDos, false, true)) { + if(lastPing == CMasternodePing() || !lastPing.CheckAndUpdate(nDos, true)) { return false; } @@ -765,7 +765,7 @@ bool CMasternodePing::CheckSignature(CPubKey& pubKeyMasternode, int &nDos) return true; } -bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fSimpleCheck) +bool CMasternodePing::CheckAndUpdate(int& nDos, bool fSimpleCheck) { if (sigTime > GetAdjustedTime() + 60 * 60) { LogPrintf("CMasternodePing::CheckAndUpdate -- Signature rejected, too far into the future, masternode=%s\n", vin.prevout.ToStringShort()); @@ -773,12 +773,6 @@ bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fSimp return false; } - if (sigTime <= GetAdjustedTime() - 60 * 60) { - LogPrintf("CMasternodePing::CheckAndUpdate -- Signature rejected, too far into the past: masternode=%s sigTime=%d GetAdjustedTime()=%d\n", vin.prevout.ToStringShort(), sigTime, GetAdjustedTime()); - nDos = 1; - return false; - } - { LOCK(cs_main); BlockMap::iterator mi = mapBlockIndex.find(blockHash); @@ -811,8 +805,6 @@ bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fSimp return false; } - if (fRequireEnabled && !pmn->IsEnabled() && !pmn->IsPreEnabled() && !pmn->IsWatchdogExpired()) return false; - // LogPrintf("mnping - Found corresponding mn for vin: %s\n", vin.prevout.ToStringShort()); // update only if there is no known ping for this masternode or // last ping was more then MASTERNODE_MIN_MNP_SECONDS-60 ago comparing to this one diff --git a/src/masternode.h b/src/masternode.h index 2b5077bef..bf2458c50 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -78,7 +78,7 @@ public: bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode); bool CheckSignature(CPubKey& pubKeyMasternode, int &nDos); - bool CheckAndUpdate(int& nDos, bool fRequireEnabled = true, bool fSimpleCheck = false); + bool CheckAndUpdate(int& nDos, bool fSimpleCheck = false); void Relay(); CMasternodePing& operator=(CMasternodePing from) diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index b5721a970..5a8ed2916 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -123,9 +123,6 @@ bool CMasternodeMan::Add(CMasternode &mn) { LOCK(cs); - if (!mn.IsEnabled() && !mn.IsPreEnabled()) - return false; - CMasternode *pmn = Find(mn.vin); if (pmn == NULL) { LogPrint("masternode", "CMasternodeMan::Add -- Adding new Masternode: addr=%s, %i now\n", mn.addr.ToString(), size() + 1); @@ -733,7 +730,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s new\n", mnp.vin.prevout.ToStringShort()); int nDos = 0; - if(mnp.CheckAndUpdate(nDos, false)) return; + if(mnp.CheckAndUpdate(nDos)) return; if(nDos > 0) { // if anything significant failed, mark that node