Implemented missing masternode handling

This commit is contained in:
Tim Flynn 2016-11-11 20:51:45 -05:00
parent 35a45097ed
commit 6deb3a65a3
3 changed files with 46 additions and 1 deletions

View File

@ -35,6 +35,7 @@ CGovernanceManager::CGovernanceManager()
nCachedBlockHeight(0),
mapObjects(),
mapSeenGovernanceObjects(),
mapMasternodeOrphanObjects(),
mapVoteToObject(MAX_CACHE_SIZE),
mapInvalidVotes(MAX_CACHE_SIZE),
mapOrphanVotes(MAX_CACHE_SIZE),
@ -170,7 +171,15 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
std::string strError = "";
// CHECK OBJECT AGAINST LOCAL BLOCKCHAIN
if(!govobj.IsValidLocally(pCurrentBlockIndex, strError, true)) {
bool fMasternodeMissing = false;
bool fIsValid = govobj.IsValidLocally(pCurrentBlockIndex, strError, fMasternodeMissing, true);
if(fMasternodeMissing) {
mapMasternodeOrphanObjects.insert(std::make_pair(govobj.GetHash(), govobj));
LogPrint("gobject", "CGovernanceManager -- Missing masternode for: %s\n", strHash);
// fIsValid must also be false here so we will return early in the next if block
}
if(!fIsValid) {
mapSeenGovernanceObjects.insert(std::make_pair(nHash, SEEN_OBJECT_ERROR_INVALID));
LogPrintf("MNGOVERNANCEOBJECT -- Governance object is invalid - %s\n", strError);
return;
@ -655,6 +664,37 @@ void CGovernanceManager::CheckMasternodeOrphanVotes()
}
}
void CGovernanceManager::CheckMasternodeOrphanObjects()
{
LOCK(cs);
object_m_it it = mapMasternodeOrphanObjects.begin();
while(it != mapMasternodeOrphanObjects.end()) {
CGovernanceObject& govobj = it->second;
string strError;
bool fMasternodeMissing = false;
bool fIsValid = govobj.IsValidLocally(pCurrentBlockIndex, strError, fMasternodeMissing, true);
if(!fIsValid) {
if(!fMasternodeMissing) {
mapMasternodeOrphanObjects.erase(it++);
}
else {
++it;
continue;
}
}
if(AddGovernanceObject(govobj)) {
LogPrintf("CGovernanceManager::CheckMasternodeOrphanObjects -- %s new\n", govobj.GetHash().ToString());
govobj.Relay();
mapMasternodeOrphanObjects.erase(it++);
}
else {
++it;
}
}
}
void CGovernanceManager::RequestGovernanceObject(CNode* pfrom, const uint256& nHash)
{
if(!pfrom) {

View File

@ -120,6 +120,8 @@ private:
count_m_t mapSeenGovernanceObjects;
object_m_t mapMasternodeOrphanObjects;
object_ref_cache_t mapVoteToObject;
vote_cache_t mapInvalidVotes;
@ -252,6 +254,8 @@ public:
void CheckMasternodeOrphanVotes();
void CheckMasternodeOrphanObjects();
private:
void RequestGovernanceObject(CNode* pfrom, const uint256& nHash);

View File

@ -1536,6 +1536,7 @@ void CMasternodeMan::NotifyMasternodeUpdates()
}
if(fMasternodesAddedLocal) {
governance.CheckMasternodeOrphanObjects();
governance.CheckMasternodeOrphanVotes();
}
if(fMasternodesRemovedLocal) {