@@ -29,9 +29,6 @@ CGovernanceManager::CGovernanceManager()
2929 mapObjects(),
3030 mapErasedGovernanceObjects(),
3131 mapMasternodeOrphanObjects(),
32- mapWatchdogObjects(),
33- nHashWatchdogCurrent(),
34- nTimeWatchdogCurrent(0 ),
3532 cmapVoteToObject(MAX_CACHE_SIZE),
3633 cmapInvalidVotes(MAX_CACHE_SIZE),
3734 cmmapOrphanVotes(MAX_CACHE_SIZE),
@@ -321,26 +318,6 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman
321318
322319 LogPrint (" gobject" , " CGovernanceManager::AddGovernanceObject -- Adding object: hash = %s, type = %d\n " , nHash.ToString (), govobj.GetObjectType ());
323320
324- if (govobj.nObjectType == GOVERNANCE_OBJECT_WATCHDOG) {
325- // If it's a watchdog, make sure it fits required time bounds
326- if ((govobj.GetCreationTime () < GetAdjustedTime () - GOVERNANCE_WATCHDOG_EXPIRATION_TIME ||
327- govobj.GetCreationTime () > GetAdjustedTime () + GOVERNANCE_WATCHDOG_EXPIRATION_TIME)
328- ) {
329- // drop it
330- LogPrint (" gobject" , " CGovernanceManager::AddGovernanceObject -- CreationTime is out of bounds: hash = %s\n " , nHash.ToString ());
331- return ;
332- }
333-
334- if (!UpdateCurrentWatchdog (govobj)) {
335- // Allow wd's which are not current to be reprocessed
336- if (pfrom && (nHashWatchdogCurrent != uint256 ())) {
337- pfrom->PushInventory (CInv (MSG_GOVERNANCE_OBJECT, nHashWatchdogCurrent));
338- }
339- LogPrint (" gobject" , " CGovernanceManager::AddGovernanceObject -- Watchdog not better than current: hash = %s\n " , nHash.ToString ());
340- return ;
341- }
342- }
343-
344321 // INSERT INTO OUR GOVERNANCE OBJECT MEMORY
345322 mapObjects.insert (std::make_pair (nHash, govobj));
346323
@@ -351,18 +328,10 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman
351328 << " , nObjectType = " << govobj.nObjectType
352329 << std::endl; );
353330
354- switch (govobj.nObjectType ) {
355- case GOVERNANCE_OBJECT_TRIGGER:
331+ if (govobj.nObjectType == GOVERNANCE_OBJECT_TRIGGER) {
356332 DBG ( std::cout << " CGovernanceManager::AddGovernanceObject Before AddNewTrigger" << std::endl; );
357333 triggerman.AddNewTrigger (nHash);
358334 DBG ( std::cout << " CGovernanceManager::AddGovernanceObject After AddNewTrigger" << std::endl; );
359- break ;
360- case GOVERNANCE_OBJECT_WATCHDOG:
361- mapWatchdogObjects[nHash] = govobj.GetCreationTime () + GOVERNANCE_WATCHDOG_EXPIRATION_TIME;
362- LogPrint (" gobject" , " CGovernanceManager::AddGovernanceObject -- Added watchdog to map: hash = %s\n " , nHash.ToString ());
363- break ;
364- default :
365- break ;
366335 }
367336
368337 LogPrintf (" AddGovernanceObject -- %s new, received form %s\n " , strHash, pfrom? pfrom->GetAddrName () : " NULL" );
@@ -381,40 +350,6 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman
381350 DBG ( std::cout << " CGovernanceManager::AddGovernanceObject END" << std::endl; );
382351}
383352
384- bool CGovernanceManager::UpdateCurrentWatchdog (CGovernanceObject& watchdogNew)
385- {
386- bool fAccept = false ;
387-
388- arith_uint256 nHashNew = UintToArith256 (watchdogNew.GetHash ());
389- arith_uint256 nHashCurrent = UintToArith256 (nHashWatchdogCurrent);
390-
391- int64_t nExpirationDelay = GOVERNANCE_WATCHDOG_EXPIRATION_TIME / 2 ;
392- int64_t nNow = GetAdjustedTime ();
393-
394- if (nHashWatchdogCurrent == uint256 () || // no known current OR
395- ((nNow - watchdogNew.GetCreationTime () < nExpirationDelay) && // (new one is NOT expired AND
396- ((nNow - nTimeWatchdogCurrent > nExpirationDelay) || (nHashNew > nHashCurrent)))// (current is expired OR
397- // its hash is lower))
398- ) {
399- LOCK (cs);
400- object_m_it it = mapObjects.find (nHashWatchdogCurrent);
401- if (it != mapObjects.end ()) {
402- LogPrint (" gobject" , " CGovernanceManager::UpdateCurrentWatchdog -- Expiring previous current watchdog, hash = %s\n " , nHashWatchdogCurrent.ToString ());
403- it->second .fExpired = true ;
404- if (it->second .nDeletionTime == 0 ) {
405- it->second .nDeletionTime = nNow;
406- }
407- }
408- nHashWatchdogCurrent = watchdogNew.GetHash ();
409- nTimeWatchdogCurrent = watchdogNew.GetCreationTime ();
410- fAccept = true ;
411- LogPrint (" gobject" , " CGovernanceManager::UpdateCurrentWatchdog -- Current watchdog updated to: hash = %s\n " ,
412- ArithToUint256 (nHashNew).ToString ());
413- }
414-
415- return fAccept ;
416- }
417-
418353void CGovernanceManager::UpdateCachesAndClean ()
419354{
420355 LogPrint (" gobject" , " CGovernanceManager::UpdateCachesAndClean\n " );
@@ -423,34 +358,6 @@ void CGovernanceManager::UpdateCachesAndClean()
423358
424359 LOCK2 (cs_main, cs);
425360
426- // Flag expired watchdogs for removal
427- int64_t nNow = GetAdjustedTime ();
428- LogPrint (" gobject" , " CGovernanceManager::UpdateCachesAndClean -- Number watchdogs in map: %d, current time = %d\n " , mapWatchdogObjects.size (), nNow);
429- if (mapWatchdogObjects.size () > 1 ) {
430- hash_time_m_it it = mapWatchdogObjects.begin ();
431- while (it != mapWatchdogObjects.end ()) {
432- LogPrint (" gobject" , " CGovernanceManager::UpdateCachesAndClean -- Checking watchdog: %s, expiration time = %d\n " , it->first .ToString (), it->second );
433- if (it->second < nNow) {
434- LogPrint (" gobject" , " CGovernanceManager::UpdateCachesAndClean -- Attempting to expire watchdog: %s, expiration time = %d\n " , it->first .ToString (), it->second );
435- object_m_it it2 = mapObjects.find (it->first );
436- if (it2 != mapObjects.end ()) {
437- LogPrint (" gobject" , " CGovernanceManager::UpdateCachesAndClean -- Expiring watchdog: %s, expiration time = %d\n " , it->first .ToString (), it->second );
438- it2->second .fExpired = true ;
439- if (it2->second .nDeletionTime == 0 ) {
440- it2->second .nDeletionTime = nNow;
441- }
442- }
443- if (it->first == nHashWatchdogCurrent) {
444- nHashWatchdogCurrent = uint256 ();
445- }
446- mapWatchdogObjects.erase (it++);
447- }
448- else {
449- ++it;
450- }
451- }
452- }
453-
454361 for (size_t i = 0 ; i < vecDirtyHashes.size (); ++i) {
455362 object_m_it it = mapObjects.find (vecDirtyHashes[i]);
456363 if (it == mapObjects.end ()) {
@@ -469,6 +376,8 @@ void CGovernanceManager::UpdateCachesAndClean()
469376 // Clean up any expired or invalid triggers
470377 triggerman.CleanAndRemove ();
471378
379+ int64_t nNow = GetAdjustedTime ();
380+
472381 while (it != mapObjects.end ())
473382 {
474383 CGovernanceObject* pObj = &((*it).second );
@@ -490,13 +399,9 @@ void CGovernanceManager::UpdateCachesAndClean()
490399 pObj->UpdateSentinelVariables ();
491400 }
492401
493- if (pObj->IsSetCachedDelete () && (nHash == nHashWatchdogCurrent)) {
494- nHashWatchdogCurrent = uint256 ();
495- }
496-
497402 // IF DELETE=TRUE, THEN CLEAN THE MESS UP!
498403
499- int64_t nTimeSinceDeletion = GetAdjustedTime () - pObj->GetDeletionTime ();
404+ int64_t nTimeSinceDeletion = nNow - pObj->GetDeletionTime ();
500405
501406 LogPrint (" gobject" , " CGovernanceManager::UpdateCachesAndClean -- Checking object for deletion: %s, deletion time = %d, time since deletion = %d, delete flag = %d, expired flag = %d\n " ,
502407 strHash, pObj->GetDeletionTime (), nTimeSinceDeletion, pObj->IsSetCachedDelete (), pObj->IsSetExpired ());
@@ -520,14 +425,14 @@ void CGovernanceManager::UpdateCachesAndClean()
520425 }
521426 }
522427
523- int64_t nSuperblockCycleSeconds = Params ().GetConsensus ().nSuperblockCycle * Params ().GetConsensus ().nPowTargetSpacing ;
524- int64_t nTimeExpired = pObj->GetCreationTime () + 2 * nSuperblockCycleSeconds + GOVERNANCE_DELETION_DELAY;
428+ int64_t nTimeExpired{0 };
525429
526- if (pObj->GetObjectType () == GOVERNANCE_OBJECT_WATCHDOG) {
527- mapWatchdogObjects.erase (nHash);
528- } else if (pObj->GetObjectType () != GOVERNANCE_OBJECT_TRIGGER) {
430+ if (pObj->GetObjectType () == GOVERNANCE_OBJECT_PROPOSAL) {
529431 // keep hashes of deleted proposals forever
530432 nTimeExpired = std::numeric_limits<int64_t >::max ();
433+ } else {
434+ int64_t nSuperblockCycleSeconds = Params ().GetConsensus ().nSuperblockCycle * Params ().GetConsensus ().nPowTargetSpacing ;
435+ nTimeExpired = pObj->GetCreationTime () + 2 * nSuperblockCycleSeconds + GOVERNANCE_DELETION_DELAY;
531436 }
532437
533438 mapErasedGovernanceObjects.insert (std::make_pair (nHash, nTimeExpired));
@@ -824,8 +729,7 @@ void CGovernanceManager::SyncAll(CNode* pnode, CConnman& connman)
824729
825730void CGovernanceManager::MasternodeRateUpdate (const CGovernanceObject& govobj)
826731{
827- int nObjectType = govobj.GetObjectType ();
828- if ((nObjectType != GOVERNANCE_OBJECT_TRIGGER) && (nObjectType != GOVERNANCE_OBJECT_WATCHDOG))
732+ if (govobj.GetObjectType () != GOVERNANCE_OBJECT_TRIGGER)
829733 return ;
830734
831735 const COutPoint& masternodeOutpoint = govobj.GetMasternodeOutpoint ();
@@ -835,10 +739,7 @@ void CGovernanceManager::MasternodeRateUpdate(const CGovernanceObject& govobj)
835739 it = mapLastMasternodeObject.insert (txout_m_t::value_type (masternodeOutpoint, last_object_rec (true ))).first ;
836740
837741 int64_t nTimestamp = govobj.GetCreationTime ();
838- if (GOVERNANCE_OBJECT_TRIGGER == nObjectType)
839- it->second .triggerBuffer .AddTimestamp (nTimestamp);
840- else if (GOVERNANCE_OBJECT_WATCHDOG == nObjectType)
841- it->second .watchdogBuffer .AddTimestamp (nTimestamp);
742+ it->second .triggerBuffer .AddTimestamp (nTimestamp);
842743
843744 if (nTimestamp > GetTime () + MAX_TIME_FUTURE_DEVIATION - RELIABLE_PROPAGATION_TIME) {
844745 // schedule additional relay for the object
@@ -868,8 +769,7 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
868769 return true ;
869770 }
870771
871- int nObjectType = govobj.GetObjectType ();
872- if ((nObjectType != GOVERNANCE_OBJECT_TRIGGER) && (nObjectType != GOVERNANCE_OBJECT_WATCHDOG)) {
772+ if (govobj.GetObjectType () != GOVERNANCE_OBJECT_TRIGGER) {
873773 return true ;
874774 }
875775
@@ -901,38 +801,26 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
901801 return true ;
902802 }
903803
904- double dMaxRate = 1.1 / nSuperblockCycleSeconds;
905- double dRate = 0.0 ;
906- CRateCheckBuffer buffer;
907- switch (nObjectType) {
908- case GOVERNANCE_OBJECT_TRIGGER:
909- // Allow 1 trigger per mn per cycle, with a small fudge factor
910- buffer = it->second .triggerBuffer ;
911- dMaxRate = 2 * 1.1 / double (nSuperblockCycleSeconds);
912- break ;
913- case GOVERNANCE_OBJECT_WATCHDOG:
914- buffer = it->second .watchdogBuffer ;
915- dMaxRate = 2 * 1.1 / 3600 .;
916- break ;
917- default :
918- break ;
919- }
804+ // Allow 1 trigger per mn per cycle, with a small fudge factor
805+ double dMaxRate = 2 * 1.1 / double (nSuperblockCycleSeconds);
806+
807+ // Temporary copy to check rate after new timestamp is added
808+ CRateCheckBuffer buffer = it->second .triggerBuffer ;
920809
921810 buffer.AddTimestamp (nTimestamp);
922- dRate = buffer.GetRate ();
811+ double dRate = buffer.GetRate ();
923812
924- bool fRateOK = ( dRate < dMaxRate );
813+ if (dRate < dMaxRate) {
814+ return true ;
815+ }
925816
926- if (!fRateOK )
927- {
928- LogPrintf (" CGovernanceManager::MasternodeRateCheck -- Rate too high: object hash = %s, masternode = %s, object timestamp = %d, rate = %f, max rate = %f\n " ,
929- strHash, masternodeOutpoint.ToStringShort (), nTimestamp, dRate, dMaxRate);
817+ LogPrintf (" CGovernanceManager::MasternodeRateCheck -- Rate too high: object hash = %s, masternode = %s, object timestamp = %d, rate = %f, max rate = %f\n " ,
818+ strHash, masternodeOutpoint.ToStringShort (), nTimestamp, dRate, dMaxRate);
930819
931- if (fUpdateFailStatus )
932- it->second .fStatusOK = false ;
933- }
820+ if (fUpdateFailStatus )
821+ it->second .fStatusOK = false ;
934822
935- return fRateOK ;
823+ return false ;
936824}
937825
938826bool CGovernanceManager::ProcessVote (CNode* pfrom, const CGovernanceVote& vote, CGovernanceException& exception, CConnman& connman)
@@ -985,10 +873,6 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
985873 }
986874
987875 bool fOk = govobj.ProcessVote (pfrom, vote, exception, connman) && cmapVoteToObject.Insert (nHashVote, &govobj);
988- if (fOk && govobj.GetObjectType () == GOVERNANCE_OBJECT_WATCHDOG) {
989- mnodeman.UpdateWatchdogVoteTime (vote.GetMasternodeOutpoint ());
990- LogPrint (" gobject" , " CGovernanceObject::ProcessVote -- GOVERNANCE_OBJECT_WATCHDOG vote %s for %s\n " , nHashVote.ToString (), nHashGovobj.ToString ());
991- }
992876 LEAVE_CRITICAL_SECTION (cs);
993877 return fOk ;
994878}
@@ -1051,8 +935,7 @@ void CGovernanceManager::CheckPostponedObjects(CConnman& connman)
1051935 const uint256& nHash = it->first ;
1052936 CGovernanceObject& govobj = it->second ;
1053937
1054- assert (govobj.GetObjectType () != GOVERNANCE_OBJECT_WATCHDOG &&
1055- govobj.GetObjectType () != GOVERNANCE_OBJECT_TRIGGER);
938+ assert (govobj.GetObjectType () != GOVERNANCE_OBJECT_TRIGGER);
1056939
1057940 std::string strError;
1058941 bool fMissingConfirmations ;
@@ -1074,7 +957,7 @@ void CGovernanceManager::CheckPostponedObjects(CConnman& connman)
1074957 }
1075958
1076959
1077- // Perform additional relays for triggers/watchdogs
960+ // Perform additional relays for triggers
1078961 int64_t nNow = GetAdjustedTime ();
1079962 int64_t nSuperblockCycleSeconds = Params ().GetConsensus ().nSuperblockCycle * Params ().GetConsensus ().nPowTargetSpacing ;
1080963
@@ -1323,7 +1206,6 @@ std::string CGovernanceManager::ToString() const
13231206
13241207 int nProposalCount = 0 ;
13251208 int nTriggerCount = 0 ;
1326- int nWatchdogCount = 0 ;
13271209 int nOtherCount = 0 ;
13281210
13291211 object_m_cit it = mapObjects.begin ();
@@ -1336,19 +1218,16 @@ std::string CGovernanceManager::ToString() const
13361218 case GOVERNANCE_OBJECT_TRIGGER:
13371219 nTriggerCount++;
13381220 break ;
1339- case GOVERNANCE_OBJECT_WATCHDOG:
1340- nWatchdogCount++;
1341- break ;
13421221 default :
13431222 nOtherCount++;
13441223 break ;
13451224 }
13461225 ++it;
13471226 }
13481227
1349- return strprintf (" Governance Objects: %d (Proposals: %d, Triggers: %d, Watchdogs: %d/%d, Other: %d; Erased: %d), Votes: %d" ,
1228+ return strprintf (" Governance Objects: %d (Proposals: %d, Triggers: %d, Other: %d; Erased: %d), Votes: %d" ,
13501229 (int )mapObjects.size (),
1351- nProposalCount, nTriggerCount, nWatchdogCount, mapWatchdogObjects. size (), nOtherCount, (int )mapErasedGovernanceObjects.size (),
1230+ nProposalCount, nTriggerCount, nOtherCount, (int )mapErasedGovernanceObjects.size (),
13521231 (int )cmapVoteToObject.GetSize ());
13531232}
13541233
0 commit comments