fix watchdogs (#1346)

* fix watchdogs:
- do not accept if CreationTime is out of bounds (using CreationTime, not local time now)
- do not sync expired
- fix disk serialization

* drop watchdogs early, avoid adding//removing

* clean mapWatchdogObjects when object is deleted via votes
This commit is contained in:
UdjinM6 2017-02-17 04:48:42 +04:00 committed by GitHub
parent f774daf47f
commit 57fd9e9e2a
2 changed files with 24 additions and 10 deletions

View File

@ -316,6 +316,8 @@ public:
if(nType & SER_DISK) {
// Only include these for the disk file format
LogPrint("gobject", "CGovernanceObject::SerializationOp Reading/writing votes from/to disk\n");
READWRITE(nDeletionTime);
READWRITE(fExpired);
READWRITE(mapCurrentMNVotes);
READWRITE(fileVotes);
LogPrint("gobject", "CGovernanceObject::SerializationOp hash = %s, vote count = %d\n", GetHash().ToString(), fileVotes.GetVoteCount());

View File

@ -20,7 +20,7 @@ std::map<uint256, int64_t> mapAskedForGovernanceObject;
int nSubmittedFinalBudget;
const std::string CGovernanceManager::SERIALIZATION_VERSION_STRING = "CGovernanceManager-Version-8";
const std::string CGovernanceManager::SERIALIZATION_VERSION_STRING = "CGovernanceManager-Version-9";
CGovernanceManager::CGovernanceManager()
: pCurrentBlockIndex(NULL),
@ -324,6 +324,16 @@ bool CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj)
LogPrint("gobject", "CGovernanceManager::AddGovernanceObject -- Adding object: hash = %s, type = %d\n", nHash.ToString(), govobj.GetObjectType());
// If it's a watchdog, make sure it fits required time bounds
if(govobj.nObjectType == GOVERNANCE_OBJECT_WATCHDOG &&
(govobj.GetCreationTime() < GetAdjustedTime() - GOVERNANCE_WATCHDOG_EXPIRATION_TIME ||
govobj.GetCreationTime() > GetAdjustedTime() + GOVERNANCE_WATCHDOG_EXPIRATION_TIME)
) {
// drop it
LogPrint("gobject", "CGovernanceManager::AddGovernanceObject -- CreationTime is out of bounds: hash = %s\n", nHash.ToString());
return false;
}
// INSERT INTO OUR GOVERNANCE OBJECT MEMORY
mapObjects.insert(std::make_pair(nHash, govobj));
@ -341,8 +351,8 @@ bool CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj)
DBG( cout << "CGovernanceManager::AddGovernanceObject After AddNewTrigger" << endl; );
break;
case GOVERNANCE_OBJECT_WATCHDOG:
mapWatchdogObjects[nHash] = GetAdjustedTime() + GOVERNANCE_WATCHDOG_EXPIRATION_TIME;
LogPrint("gobject", "CGovernanceManager::AddGovernanceObject -- Added watchdog to map: hash = %s\n", nHash.ToString());
mapWatchdogObjects[nHash] = govobj.GetCreationTime() + GOVERNANCE_WATCHDOG_EXPIRATION_TIME;
LogPrint("gobject", "CGovernanceManager::AddGovernanceObject -- Added watchdog to map: hash = %s\n", nHash.ToString());
break;
default:
break;
@ -455,7 +465,9 @@ void CGovernanceManager::UpdateCachesAndClean()
++lit;
}
}
if(pObj->nObjectType == GOVERNANCE_OBJECT_WATCHDOG && pObj->IsSetCachedDelete()) {
mapWatchdogObjects.erase(it->first);
}
mapObjects.erase(it++);
} else {
++it;
@ -686,8 +698,8 @@ void CGovernanceManager::Sync(CNode* pfrom, const uint256& nProp, const CBloomFi
LogPrint("gobject", "CGovernanceManager::Sync -- attempting to sync govobj: %s, peer=%d\n", strHash, pfrom->id);
if(govobj.IsSetCachedDelete()) {
LogPrintf("CGovernanceManager::Sync -- not syncing deleted govobj: %s, peer=%d\n",
if(govobj.IsSetCachedDelete() || govobj.IsSetExpired()) {
LogPrintf("CGovernanceManager::Sync -- not syncing deleted/expired govobj: %s, peer=%d\n",
strHash, pfrom->id);
continue;
}
@ -709,8 +721,8 @@ void CGovernanceManager::Sync(CNode* pfrom, const uint256& nProp, const CBloomFi
LogPrint("gobject", "CGovernanceManager::Sync -- attempting to sync govobj: %s, peer=%d\n", strHash, pfrom->id);
if(govobj.IsSetCachedDelete()) {
LogPrintf("CGovernanceManager::Sync -- not syncing deleted govobj: %s, peer=%d\n",
if(govobj.IsSetCachedDelete() || govobj.IsSetExpired()) {
LogPrintf("CGovernanceManager::Sync -- not syncing deleted/expired govobj: %s, peer=%d\n",
strHash, pfrom->id);
return;
}
@ -1193,9 +1205,9 @@ std::string CGovernanceManager::ToString() const
++it;
}
return strprintf("Governance Objects: %d (Proposals: %d, Triggers: %d, Watchdogs: %d, Other: %d; Seen: %d), Votes: %d",
return strprintf("Governance Objects: %d (Proposals: %d, Triggers: %d, Watchdogs: %d/%d, Other: %d; Seen: %d), Votes: %d",
(int)mapObjects.size(),
nProposalCount, nTriggerCount, nWatchdogCount, nOtherCount, (int)mapSeenGovernanceObjects.size(),
nProposalCount, nTriggerCount, nWatchdogCount, mapWatchdogObjects.size(), nOtherCount, (int)mapSeenGovernanceObjects.size(),
(int)mapVoteToObject.GetSize());
}