Masternode syncing changes (#1149)

* Modified DSEG to send mnb regardless of state

* Removed unused function

* Deactivate rate check when processing masternode orphan objects
This commit is contained in:
Tim Flynn 2016-11-18 09:17:22 -05:00 committed by UdjinM6
parent 90bd7cb62b
commit e59bee8114
3 changed files with 28 additions and 21 deletions

View File

@ -41,6 +41,7 @@ CGovernanceManager::CGovernanceManager()
mapOrphanVotes(MAX_CACHE_SIZE), mapOrphanVotes(MAX_CACHE_SIZE),
mapLastMasternodeTrigger(), mapLastMasternodeTrigger(),
setRequestedObjects(), setRequestedObjects(),
fRateChecksEnabled(true),
cs() cs()
{} {}
@ -578,18 +579,14 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp)
LogPrintf("CGovernanceManager::Sync -- sent %d items, peer=%d\n", nInvCount, pfrom->id); 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) bool CGovernanceManager::MasternodeRateCheck(const CTxIn& vin, int nObjectType)
{ {
LOCK(cs); LOCK(cs);
if(!fRateChecksEnabled) {
return true;
}
int mindiff = 0; int mindiff = 0;
switch(nObjectType) { switch(nObjectType) {
case GOVERNANCE_OBJECT_TRIGGER: case GOVERNANCE_OBJECT_TRIGGER:
@ -665,14 +662,17 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
void CGovernanceManager::CheckMasternodeOrphanVotes() void CGovernanceManager::CheckMasternodeOrphanVotes()
{ {
LOCK(cs); LOCK(cs);
fRateChecksEnabled = false;
for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) { for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) {
it->second.CheckOrphanVotes(); it->second.CheckOrphanVotes();
} }
fRateChecksEnabled = true;
} }
void CGovernanceManager::CheckMasternodeOrphanObjects() void CGovernanceManager::CheckMasternodeOrphanObjects()
{ {
LOCK(cs); LOCK(cs);
fRateChecksEnabled = false;
object_m_it it = mapMasternodeOrphanObjects.begin(); object_m_it it = mapMasternodeOrphanObjects.begin();
while(it != mapMasternodeOrphanObjects.end()) { while(it != mapMasternodeOrphanObjects.end()) {
CGovernanceObject& govobj = it->second; CGovernanceObject& govobj = it->second;
@ -699,6 +699,7 @@ void CGovernanceManager::CheckMasternodeOrphanObjects()
++it; ++it;
} }
} }
fRateChecksEnabled = true;
} }
void CGovernanceManager::RequestGovernanceObject(CNode* pfrom, const uint256& nHash) void CGovernanceManager::RequestGovernanceObject(CNode* pfrom, const uint256& nHash)
@ -908,6 +909,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
} }
vote_instance_t& voteInstance = it2->second; vote_instance_t& voteInstance = it2->second;
int64_t nNow = GetTime(); int64_t nNow = GetTime();
if(governance.AreRateChecksEnabled()) {
int64_t nTimeDelta = nNow - voteInstance.nTime; int64_t nTimeDelta = nNow - voteInstance.nTime;
if(nTimeDelta < GOVERNANCE_UPDATE_MIN) { if(nTimeDelta < GOVERNANCE_UPDATE_MIN) {
std::ostringstream ostr; std::ostringstream ostr;
@ -919,6 +921,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_TEMPORARY_ERROR); exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_TEMPORARY_ERROR);
return false; return false;
} }
}
// Finally check that the vote is actually valid (done last because of cost of signature verification) // Finally check that the vote is actually valid (done last because of cost of signature verification)
if(!vote.IsValid(true)) { if(!vote.IsValid(true)) {
std::ostringstream ostr; std::ostringstream ostr;

View File

@ -136,6 +136,8 @@ private:
hash_s_t setRequestedVotes; hash_s_t setRequestedVotes;
bool fRateChecksEnabled;
public: public:
// critical section to protect the inner data structures // critical section to protect the inner data structures
mutable CCriticalSection cs; mutable CCriticalSection cs;
@ -166,8 +168,6 @@ public:
void Sync(CNode* node, uint256 nProp); void Sync(CNode* node, uint256 nProp);
void SyncParentObjectByVote(CNode* pfrom, const CGovernanceVote& vote);
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
void NewBlock(); void NewBlock();
@ -258,6 +258,11 @@ public:
void CheckMasternodeOrphanObjects(); void CheckMasternodeOrphanObjects();
bool AreRateChecksEnabled() const {
LOCK(cs);
return fRateChecksEnabled;
}
private: private:
void RequestGovernanceObject(CNode* pfrom, const uint256& nHash); void RequestGovernanceObject(CNode* pfrom, const uint256& nHash);

View File

@ -783,7 +783,6 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
BOOST_FOREACH(CMasternode& mn, vMasternodes) { BOOST_FOREACH(CMasternode& mn, vMasternodes) {
if (vin != CTxIn() && vin != mn.vin) continue; // asked for specific vin but we are not there yet 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.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()); LogPrint("masternode", "DSEG -- Sending Masternode entry: masternode=%s addr=%s\n", mn.vin.prevout.ToStringShort(), mn.addr.ToString());
CMasternodeBroadcast mnb = CMasternodeBroadcast(mn); CMasternodeBroadcast mnb = CMasternodeBroadcast(mn);