29
29
#include < validation.h>
30
30
31
31
const std::string GovernanceStore::SERIALIZATION_VERSION_STRING = " CGovernanceManager-Version-16" ;
32
- const int CGovernanceManager::MAX_TIME_FUTURE_DEVIATION = 60 * 60 ;
33
- const int CGovernanceManager::RELIABLE_PROPAGATION_TIME = 60 ;
34
32
35
33
namespace {
34
+ constexpr std::chrono::seconds GOVERNANCE_DELETION_DELAY{10min};
35
+ constexpr std::chrono::seconds GOVERNANCE_ORPHAN_EXPIRATION_TIME{10min};
36
+ constexpr std::chrono::seconds MAX_TIME_FUTURE_DEVIATION{1h};
37
+ constexpr std::chrono::seconds RELIABLE_PROPAGATION_TIME{1min};
38
+
36
39
class ScopedLockBool
37
40
{
38
41
bool & ref;
@@ -485,7 +488,7 @@ void CGovernanceManager::CheckAndRemove()
485
488
strHash, pObj->GetDeletionTime (), nTimeSinceDeletion, pObj->IsSetCachedDelete (), pObj->IsSetExpired ());
486
489
487
490
if ((pObj->IsSetCachedDelete () || pObj->IsSetExpired ()) &&
488
- (nTimeSinceDeletion >= GOVERNANCE_DELETION_DELAY)) {
491
+ (nTimeSinceDeletion >= count_seconds ( GOVERNANCE_DELETION_DELAY) )) {
489
492
LogPrint (BCLog::GOBJECT, " CGovernanceManager::UpdateCachesAndClean -- erase obj %s\n " , (*it).first .ToString ());
490
493
m_mn_metaman.RemoveGovernanceObject (pObj->GetHash ());
491
494
@@ -509,7 +512,7 @@ void CGovernanceManager::CheckAndRemove()
509
512
nTimeExpired = std::numeric_limits<int64_t >::max ();
510
513
} else {
511
514
int64_t nSuperblockCycleSeconds = Params ().GetConsensus ().nSuperblockCycle * Params ().GetConsensus ().nPowTargetSpacing ;
512
- nTimeExpired = pObj->GetCreationTime () + 2 * nSuperblockCycleSeconds + GOVERNANCE_DELETION_DELAY;
515
+ nTimeExpired = pObj->GetCreationTime () + 2 * nSuperblockCycleSeconds + count_seconds ( GOVERNANCE_DELETION_DELAY) ;
513
516
}
514
517
515
518
mapErasedGovernanceObjects.insert (std::make_pair (nHash, nTimeExpired));
@@ -678,7 +681,7 @@ bool CGovernanceManager::ConfirmInventoryRequest(const CInv& inv)
678
681
return false ;
679
682
}
680
683
681
- const auto valid_until = GetTime<std::chrono::seconds>() + std::chrono::seconds ( RELIABLE_PROPAGATION_TIME) ;
684
+ const auto valid_until = GetTime<std::chrono::seconds>() + RELIABLE_PROPAGATION_TIME;
682
685
const auto & [_itr, inserted] = m_requested_hash_time.emplace (inv.hash , valid_until);
683
686
684
687
if (inserted) {
@@ -804,7 +807,7 @@ void CGovernanceManager::MasternodeRateUpdate(const CGovernanceObject& govobj)
804
807
int64_t nTimestamp = govobj.GetCreationTime ();
805
808
it->second .triggerBuffer .AddTimestamp (nTimestamp);
806
809
807
- if (nTimestamp > GetTime () + MAX_TIME_FUTURE_DEVIATION - RELIABLE_PROPAGATION_TIME) {
810
+ if (nTimestamp > GetTime () + count_seconds ( MAX_TIME_FUTURE_DEVIATION) - count_seconds ( RELIABLE_PROPAGATION_TIME) ) {
808
811
// schedule additional relay for the object
809
812
setAdditionalRelayObjects.insert (govobj.GetHash ());
810
813
}
@@ -845,7 +848,7 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
845
848
return false ;
846
849
}
847
850
848
- if (nTimestamp > nNow + MAX_TIME_FUTURE_DEVIATION) {
851
+ if (nTimestamp > nNow + count_seconds ( MAX_TIME_FUTURE_DEVIATION) ) {
849
852
LogPrint (BCLog::GOBJECT, " CGovernanceManager::MasternodeRateCheck -- object %s rejected due to too new (future) timestamp, masternode = %s, timestamp = %d, current time = %d\n " ,
850
853
strHash, masternodeOutpoint.ToStringShort (), nTimestamp, nNow);
851
854
return false ;
@@ -919,7 +922,7 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
919
922
std::string msg{strprintf (" CGovernanceManager::%s -- Unknown parent object %s, MN outpoint = %s" , __func__,
920
923
nHashGovobj.ToString (), vote.GetMasternodeOutpoint ().ToStringShort ())};
921
924
exception = CGovernanceException (msg, GOVERNANCE_EXCEPTION_WARNING);
922
- if (cmmapOrphanVotes.Insert (nHashGovobj, vote_time_pair_t (vote, GetTime<std::chrono::seconds>(). count () + GOVERNANCE_ORPHAN_EXPIRATION_TIME))) {
925
+ if (cmmapOrphanVotes.Insert (nHashGovobj, vote_time_pair_t (vote, count_seconds ( GetTime<std::chrono::seconds>() + GOVERNANCE_ORPHAN_EXPIRATION_TIME) ))) {
923
926
LEAVE_CRITICAL_SECTION (cs);
924
927
RequestGovernanceObject (pfrom, nHashGovobj, connman);
925
928
LogPrint (BCLog::GOBJECT, " %s\n " , msg);
@@ -990,8 +993,8 @@ void CGovernanceManager::CheckPostponedObjects()
990
993
991
994
int64_t nTimestamp = govobj.GetCreationTime ();
992
995
993
- bool fValid = (nTimestamp <= nNow + MAX_TIME_FUTURE_DEVIATION) && (nTimestamp >= nNow - 2 * nSuperblockCycleSeconds);
994
- bool fReady = (nTimestamp <= nNow + MAX_TIME_FUTURE_DEVIATION - RELIABLE_PROPAGATION_TIME);
996
+ bool fValid = (nTimestamp <= nNow + count_seconds ( MAX_TIME_FUTURE_DEVIATION) ) && (nTimestamp >= nNow - 2 * nSuperblockCycleSeconds);
997
+ bool fReady = (nTimestamp <= nNow + count_seconds ( MAX_TIME_FUTURE_DEVIATION) - count_seconds ( RELIABLE_PROPAGATION_TIME) );
995
998
996
999
if (fValid ) {
997
1000
if (fReady ) {
0 commit comments