@@ -278,25 +278,25 @@ void CGovernanceManager::CheckOrphanVotes(CGovernanceObject& govobj)
278278 AssertLockNotHeld (cs_relay);
279279
280280 uint256 nHash = govobj.GetHash ();
281- std::vector<vote_time_pair_t > vecVotePairs ;
282- cmmapOrphanVotes.GetAll (nHash, vecVotePairs );
281+ std::vector<governance::OrphanVote> orphan_votes ;
282+ cmmapOrphanVotes.GetAll (nHash, orphan_votes );
283283
284284 ScopedLockBool guard (cs_store, fRateChecksEnabled , false );
285285
286- int64_t nNow = GetAdjustedTime ();
286+ const auto now{std::chrono::time_point_cast<std::chrono::seconds>( GetAdjustedTime ())} ;
287287 const auto tip_mn_list = m_dmnman.GetListAtChainTip ();
288- for (const auto & pairVote : vecVotePairs ) {
289- const auto & [ vote, time] = pairVote ;
288+ for (const auto & orphan_vote : orphan_votes ) {
289+ const auto & vote = orphan_vote. vote ;
290290 bool fRemove = false ;
291291 CGovernanceException e;
292- if (time < nNow ) {
292+ if (orphan_vote. expiration < now ) {
293293 fRemove = true ;
294294 } else if (govobj.ProcessVote (m_mn_metaman, fRateChecksEnabled , tip_mn_list, vote, e)) {
295295 RelayVote (vote);
296296 fRemove = true ;
297297 }
298298 if (fRemove ) {
299- cmmapOrphanVotes.Erase (nHash, pairVote );
299+ cmmapOrphanVotes.Erase (nHash, orphan_vote );
300300 }
301301 }
302302}
@@ -733,21 +733,21 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
733733 }
734734
735735 const COutPoint& masternodeOutpoint = govobj.GetMasternodeOutpoint ();
736- int64_t nTimestamp = govobj.GetCreationTime () ;
737- int64_t nNow = GetAdjustedTime ();
738- int64_t nSuperblockCycleSeconds = Params ().GetConsensus ().nSuperblockCycle * Params ().GetConsensus ().nPowTargetSpacing ;
736+ const auto timestamp{ govobj.CreationTime ()} ;
737+ const auto now{std::chrono::time_point_cast<std::chrono::seconds>( GetAdjustedTime ())} ;
738+ const auto superblock_cycle{ Params ().GetConsensus ().nSuperblockCycle * Params ().GetConsensus ().PowTargetSpacing ()} ;
739739
740740 std::string strHash = govobj.GetHash ().ToString ();
741741
742- if (nTimestamp < nNow - 2 * nSuperblockCycleSeconds ) {
742+ if (timestamp < now - 2 * superblock_cycle ) {
743743 LogPrint (BCLog::GOBJECT , " CGovernanceManager::MasternodeRateCheck -- object %s rejected due to too old timestamp, masternode = %s, timestamp = %d, current time = %d\n " ,
744- strHash, masternodeOutpoint.ToStringShort (), nTimestamp, nNow );
744+ strHash, masternodeOutpoint.ToStringShort (), govobj. GetCreationTime (), TicksSinceEpoch<std::chrono::seconds>(now) );
745745 return false ;
746746 }
747747
748- if (nTimestamp > nNow + count_seconds ( MAX_TIME_FUTURE_DEVIATION ) ) {
748+ if (timestamp > now + MAX_TIME_FUTURE_DEVIATION ) {
749749 LogPrint (BCLog::GOBJECT , " CGovernanceManager::MasternodeRateCheck -- object %s rejected due to too new (future) timestamp, masternode = %s, timestamp = %d, current time = %d\n " ,
750- strHash, masternodeOutpoint.ToStringShort (), nTimestamp, nNow );
750+ strHash, masternodeOutpoint.ToStringShort (), govobj. GetCreationTime (), TicksSinceEpoch<std::chrono::seconds>(now) );
751751 return false ;
752752 }
753753
@@ -760,20 +760,20 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
760760 }
761761
762762 // Allow 1 trigger per mn per cycle, with a small fudge factor
763- double dMaxRate = 2 * 1.1 / double (nSuperblockCycleSeconds );
763+ double dMaxRate = 2 * 1.1 / static_cast < double >( count_seconds (superblock_cycle) );
764764
765765 // Temporary copy to check rate after new timestamp is added
766766 CRateCheckBuffer buffer = it->second .triggerBuffer ;
767767
768- buffer.AddTimestamp (nTimestamp );
768+ buffer.AddTimestamp (govobj. GetCreationTime () );
769769 double dRate = buffer.GetRate ();
770770
771771 if (dRate < dMaxRate) {
772772 return true ;
773773 }
774774
775775 LogPrint (BCLog::GOBJECT , " CGovernanceManager::MasternodeRateCheck -- Rate too high: object hash = %s, masternode = %s, object timestamp = %d, rate = %f, max rate = %f\n " ,
776- strHash, masternodeOutpoint.ToStringShort (), nTimestamp , dRate, dMaxRate);
776+ strHash, masternodeOutpoint.ToStringShort (), govobj. GetCreationTime () , dRate, dMaxRate);
777777
778778 if (fUpdateFailStatus ) {
779779 it->second .fStatusOK = false ;
@@ -823,8 +823,7 @@ bool CGovernanceManager::ProcessVote(const CGovernanceVote& vote, CGovernanceExc
823823 std::string msg{strprintf (" CGovernanceManager::%s -- Unknown parent object %s, MN outpoint = %s" , __func__,
824824 nHashGovobj.ToString (), vote.GetMasternodeOutpoint ().ToStringShort ())};
825825 exception = CGovernanceException (msg, GOVERNANCE_EXCEPTION_WARNING );
826- if (cmmapOrphanVotes.Insert (nHashGovobj, vote_time_pair_t (vote, count_seconds (GetTime<std::chrono::seconds>() +
827- GOVERNANCE_ORPHAN_EXPIRATION_TIME )))) {
826+ if (cmmapOrphanVotes.Insert (nHashGovobj, governance::OrphanVote{vote, Now<NodeSeconds>() + GOVERNANCE_ORPHAN_EXPIRATION_TIME })) {
828827 hashToRequest = nHashGovobj; // Caller should request this object
829828 }
830829 LogPrint (BCLog::GOBJECT , " %s\n " , msg);
@@ -883,20 +882,19 @@ void CGovernanceManager::CheckPostponedObjects()
883882
884883
885884 // Perform additional relays for triggers
886- int64_t nNow = GetAdjustedTime ();
887- int64_t nSuperblockCycleSeconds = Params ().GetConsensus ().nSuperblockCycle * Params ().GetConsensus ().nPowTargetSpacing ;
885+ const auto now{std::chrono::time_point_cast<std::chrono::seconds>( GetAdjustedTime ())} ;
886+ const auto superblock_cycle{ Params ().GetConsensus ().nSuperblockCycle * Params ().GetConsensus ().PowTargetSpacing ()} ;
888887
889888 for (auto it = setAdditionalRelayObjects.begin (); it != setAdditionalRelayObjects.end ();) {
890889 auto itObject = mapObjects.find (*it);
891890 if (itObject != mapObjects.end ()) {
892891 const auto & govobj = *Assert (itObject->second );
893892
894- int64_t nTimestamp = govobj.GetCreationTime () ;
893+ const auto timestamp{ govobj.CreationTime ()} ;
895894
896- bool fValid = (nTimestamp <= nNow + count_seconds (MAX_TIME_FUTURE_DEVIATION )) &&
897- (nTimestamp >= nNow - 2 * nSuperblockCycleSeconds);
898- bool fReady = (nTimestamp <=
899- nNow + count_seconds (MAX_TIME_FUTURE_DEVIATION ) - count_seconds (RELIABLE_PROPAGATION_TIME ));
895+ const bool fValid {timestamp <= now + MAX_TIME_FUTURE_DEVIATION &&
896+ timestamp >= now - 2 * superblock_cycle};
897+ const bool fReady {timestamp <= now + MAX_TIME_FUTURE_DEVIATION - RELIABLE_PROPAGATION_TIME };
900898
901899 if (fValid ) {
902900 if (fReady ) {
@@ -1092,15 +1090,14 @@ std::vector<uint256> CGovernanceManager::GetOrphanVoteObjectHashes()
10921090{
10931091 LOCK (cs_store);
10941092
1095- int64_t nNow = GetTime<std::chrono::seconds >(). count () ;
1093+ const auto now{Now<NodeSeconds >()} ;
10961094
10971095 // Clean up expired orphan votes
10981096 const vote_cmm_t ::list_t & items = cmmapOrphanVotes.GetItemList ();
10991097 for (auto it = items.begin (); it != items.end ();) {
11001098 auto prevIt = it;
11011099 ++it;
1102- const auto & [_, time] = prevIt->value ;
1103- if (time < nNow) {
1100+ if (prevIt->value .expiration < now) {
11041101 cmmapOrphanVotes.Erase (prevIt->key , prevIt->value );
11051102 }
11061103 }
0 commit comments