diff --git a/src/governance.cpp b/src/governance.cpp index 191a025b7..5979daa4e 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -41,6 +41,7 @@ CGovernanceManager::CGovernanceManager() mapOrphanVotes(MAX_CACHE_SIZE), mapLastMasternodeTrigger(), setRequestedObjects(), + fRateChecksEnabled(true), cs() {} @@ -578,18 +579,14 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp) LogPrintf("CGovernanceManager::Sync -- sent %d items, peer=%d\n", nInvCount, pfrom->id); } -void CGovernanceManager::SyncParentObjectByVote(CNode* pfrom, const CGovernanceVote& vote) -{ - if(!mapAskedForGovernanceObject.count(vote.GetParentHash())){ - pfrom->PushMessage(NetMsgType::MNGOVERNANCESYNC, vote.GetParentHash()); - mapAskedForGovernanceObject[vote.GetParentHash()] = GetTime(); - } -} - bool CGovernanceManager::MasternodeRateCheck(const CTxIn& vin, int nObjectType) { LOCK(cs); + if(!fRateChecksEnabled) { + return true; + } + int mindiff = 0; switch(nObjectType) { case GOVERNANCE_OBJECT_TRIGGER: @@ -665,14 +662,17 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote, void CGovernanceManager::CheckMasternodeOrphanVotes() { LOCK(cs); + fRateChecksEnabled = false; for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) { it->second.CheckOrphanVotes(); } + fRateChecksEnabled = true; } void CGovernanceManager::CheckMasternodeOrphanObjects() { LOCK(cs); + fRateChecksEnabled = false; object_m_it it = mapMasternodeOrphanObjects.begin(); while(it != mapMasternodeOrphanObjects.end()) { CGovernanceObject& govobj = it->second; @@ -699,6 +699,7 @@ void CGovernanceManager::CheckMasternodeOrphanObjects() ++it; } } + fRateChecksEnabled = true; } void CGovernanceManager::RequestGovernanceObject(CNode* pfrom, const uint256& nHash) @@ -908,16 +909,18 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom, } vote_instance_t& voteInstance = it2->second; int64_t nNow = GetTime(); - int64_t nTimeDelta = nNow - voteInstance.nTime; - if(nTimeDelta < GOVERNANCE_UPDATE_MIN) { - std::ostringstream ostr; - ostr << "CGovernanceObject::ProcessVote -- Masternode voting too often " - << ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort() - << ", governance object hash = " << GetHash().ToString() - << ", time delta = " << nTimeDelta << "\n"; - LogPrint("gobject", ostr.str().c_str()); - exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_TEMPORARY_ERROR); - return false; + if(governance.AreRateChecksEnabled()) { + int64_t nTimeDelta = nNow - voteInstance.nTime; + if(nTimeDelta < GOVERNANCE_UPDATE_MIN) { + std::ostringstream ostr; + ostr << "CGovernanceObject::ProcessVote -- Masternode voting too often " + << ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort() + << ", governance object hash = " << GetHash().ToString() + << ", time delta = " << nTimeDelta << "\n"; + LogPrint("gobject", ostr.str().c_str()); + exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_TEMPORARY_ERROR); + return false; + } } // Finally check that the vote is actually valid (done last because of cost of signature verification) if(!vote.IsValid(true)) { diff --git a/src/governance.h b/src/governance.h index 38a75b899..98a805ca9 100644 --- a/src/governance.h +++ b/src/governance.h @@ -136,6 +136,8 @@ private: hash_s_t setRequestedVotes; + bool fRateChecksEnabled; + public: // critical section to protect the inner data structures mutable CCriticalSection cs; @@ -166,8 +168,6 @@ public: void Sync(CNode* node, uint256 nProp); - void SyncParentObjectByVote(CNode* pfrom, const CGovernanceVote& vote); - void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); void NewBlock(); @@ -258,6 +258,11 @@ public: void CheckMasternodeOrphanObjects(); + bool AreRateChecksEnabled() const { + LOCK(cs); + return fRateChecksEnabled; + } + private: void RequestGovernanceObject(CNode* pfrom, const uint256& nHash); diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index ecca9bfb4..8c496ca55 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -783,7 +783,6 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData BOOST_FOREACH(CMasternode& mn, vMasternodes) { if (vin != CTxIn() && vin != mn.vin) continue; // asked for specific vin but we are not there yet if (mn.addr.IsRFC1918() || mn.addr.IsLocal()) continue; // do not send local network masternode - if (!mn.IsEnabled()) continue; LogPrint("masternode", "DSEG -- Sending Masternode entry: masternode=%s addr=%s\n", mn.vin.prevout.ToStringShort(), mn.addr.ToString()); CMasternodeBroadcast mnb = CMasternodeBroadcast(mn);