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),
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,6 +909,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
}
vote_instance_t& voteInstance = it2->second;
int64_t nNow = GetTime();
if(governance.AreRateChecksEnabled()) {
int64_t nTimeDelta = nNow - voteInstance.nTime;
if(nTimeDelta < GOVERNANCE_UPDATE_MIN) {
std::ostringstream ostr;
@ -919,6 +921,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
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)) {
std::ostringstream ostr;

View File

@ -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);

View File

@ -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);