Skip to content

Commit

Permalink
refactor: use GetTime<T> instead
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Oct 20, 2023
1 parent d83054f commit 62a82f5
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/evo/mnauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
}

if (!peer.fInbound) {
mmetaman->GetMetaInfo(mnauth.proRegTxHash)->SetLastOutboundSuccess(GetTime());
mmetaman->GetMetaInfo(mnauth.proRegTxHash)->SetLastOutboundSuccess(count_seconds(GetTime<std::chrono::seconds>()));
if (peer.m_masternode_probe_connection) {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- Masternode probe successful for %s, disconnecting. peer=%d\n",
mnauth.proRegTxHash.ToString(), peer.GetId());
Expand Down
2 changes: 1 addition & 1 deletion src/governance/classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void CGovernanceTriggerManager::CleanAndRemove()
if (pObj) {
strDataAsPlainString = pObj->GetDataAsPlainString();
// mark corresponding object for deletion
pObj->PrepareDeletion(GetTime());
pObj->PrepareDeletion(count_seconds(GetTime<std::chrono::seconds>()));
}
LogPrint(BCLog::GOBJECT, "CGovernanceTriggerManager::CleanAndRemove -- Removing trigger object %s\n", strDataAsPlainString);
// delete the trigger
Expand Down
10 changes: 5 additions & 5 deletions src/governance/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman

if (govobj.GetObjectType() == GovernanceObject::TRIGGER && !triggerman.AddNewTrigger(nHash)) {
LogPrint(BCLog::GOBJECT, "CGovernanceManager::AddGovernanceObject -- undo adding invalid trigger object: hash = %s\n", nHash.ToString());
objpair.first->second.PrepareDeletion(GetTime());
objpair.first->second.PrepareDeletion(count_seconds(GetTime<std::chrono::seconds>()));
return;
}

Expand Down Expand Up @@ -360,7 +360,7 @@ void CGovernanceManager::UpdateCachesAndClean()
triggerman.CleanAndRemove();

auto it = mapObjects.begin();
int64_t nNow = GetTime();
int64_t nNow = count_seconds(GetTime<std::chrono::seconds>());

while (it != mapObjects.end()) {
CGovernanceObject* pObj = &((*it).second);
Expand Down Expand Up @@ -1047,7 +1047,7 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
ostr << "CGovernanceManager::ProcessVote -- Unknown parent object " << nHashGovobj.ToString()
<< ", MN outpoint = " << vote.GetMasternodeOutpoint().ToStringShort();
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
if (cmmapOrphanVotes.Insert(nHashGovobj, vote_time_pair_t(vote, GetTime() + GOVERNANCE_ORPHAN_EXPIRATION_TIME))) {
if (cmmapOrphanVotes.Insert(nHashGovobj, vote_time_pair_t(vote, count_seconds(GetTime<std::chrono::seconds>()) + GOVERNANCE_ORPHAN_EXPIRATION_TIME))) {
LEAVE_CRITICAL_SECTION(cs)
RequestGovernanceObject(pfrom, nHashGovobj, connman);
LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
Expand Down Expand Up @@ -1318,7 +1318,7 @@ void CGovernanceManager::AddCachedTriggers()
{
LOCK(cs);

int64_t nNow = GetTime();
int64_t nNow = count_seconds(GetTime<std::chrono::seconds>());

for (auto& objpair : mapObjects) {
CGovernanceObject& govobj = objpair.second;
Expand Down Expand Up @@ -1466,7 +1466,7 @@ void CGovernanceManager::CleanOrphanObjects()
LOCK(cs);
const vote_cmm_t::list_t& items = cmmapOrphanVotes.GetItemList();

int64_t nNow = GetTime();
int64_t nNow = count_seconds(GetTime<std::chrono::seconds>());

auto it = items.begin();
while (it != items.end()) {
Expand Down
2 changes: 1 addition & 1 deletion src/governance/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ void CGovernanceObject::UpdateSentinelVariables()
if ((GetAbsoluteYesCount(VOTE_SIGNAL_DELETE) >= nAbsDeleteReq) && !fCachedDelete) {
fCachedDelete = true;
if (nDeletionTime == 0) {
nDeletionTime = GetTime();
nDeletionTime = count_seconds(GetTime<std::chrono::seconds>());
}
}
if (GetAbsoluteYesCount(VOTE_SIGNAL_ENDORSED) >= nAbsVoteReq) fCachedEndorsed = true;
Expand Down
6 changes: 3 additions & 3 deletions src/llmq/chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void CChainLocksHandler::TrySignChainTip()
LOCK(cs);
auto it = txFirstSeenTime.find(txid);
if (it != txFirstSeenTime.end()) {
txAge = GetTime() - it->second;
txAge = count_seconds(GetTime<std::chrono::seconds>()) - it->second;
}
}

Expand Down Expand Up @@ -382,7 +382,7 @@ void CChainLocksHandler::BlockConnected(const std::shared_ptr<const CBlock>& pbl
}
auto& txids = *it->second;

int64_t curTime = GetTime();
int64_t curTime = count_seconds(GetTime<std::chrono::seconds>());

for (const auto& tx : pblock->vtx) {
if (tx->IsCoinBase() || tx->vin.empty()) {
Expand Down Expand Up @@ -457,7 +457,7 @@ bool CChainLocksHandler::IsTxSafeForMining(const uint256& txid) const
LOCK(cs);
auto it = txFirstSeenTime.find(txid);
if (it != txFirstSeenTime.end()) {
txAge = GetTime() - it->second;
txAge = count_seconds(GetTime<std::chrono::seconds>()) - it->second;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
break;
}

if ((GetTime() - nTimeLastSuccess) > nRequestTimeout) {
if ((count_seconds(GetTime<std::chrono::seconds>()) - nTimeLastSuccess) > nRequestTimeout) {
if (nTries >= vecMemberHashes.size()) {
printLog("All tried but failed");
break;
Expand All @@ -918,7 +918,7 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
}
// Sleep a bit depending on the start offset to balance out multiple requests to same masternode
quorumThreadInterrupt.sleep_for(std::chrono::milliseconds(nMyStartOffset * 100));
nTimeLastSuccess = GetTime();
nTimeLastSuccess = count_seconds(GetTime<std::chrono::seconds>());
connman.AddPendingMasternode(*pCurrentMemberHash);
printLog("Connect");
}
Expand All @@ -931,7 +931,7 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
}

if (RequestQuorumData(pNode, pQuorum->qc->llmqType, pQuorum->m_quorum_base_block_index, nDataMask, proTxHash)) {
nTimeLastSuccess = GetTime();
nTimeLastSuccess = count_seconds(GetTime<std::chrono::seconds>());
printLog("Requested");
} else {
LOCK(cs_data_requests);
Expand Down
8 changes: 4 additions & 4 deletions src/llmq/signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void CRecoveredSigsDb::WriteRecoveredSig(const llmq::CRecoveredSig& recSig)
{
CDBBatch batch(*db);

uint32_t curTime = GetTime();
uint32_t curTime = count_seconds(GetTime<std::chrono::seconds>());

// we put these close to each other to leverage leveldb's key compaction
// this way, the second key can be used for fast HasRecoveredSig checks while the first key stores the recSig
Expand Down Expand Up @@ -411,7 +411,7 @@ void CRecoveredSigsDb::CleanupOldRecoveredSigs(int64_t maxAge)
std::unique_ptr<CDBIterator> pcursor(db->NewIterator());

auto start = std::make_tuple(std::string("rs_t"), (uint32_t)0, (Consensus::LLMQType)0, uint256());
uint32_t endTime = (uint32_t)(GetTime() - maxAge);
uint32_t endTime = (uint32_t)(count_seconds(GetTime<std::chrono::seconds>()) - maxAge);
pcursor->Seek(start);

std::vector<std::pair<Consensus::LLMQType, uint256>> toDelete;
Expand Down Expand Up @@ -475,7 +475,7 @@ bool CRecoveredSigsDb::GetVoteForId(Consensus::LLMQType llmqType, const uint256&
void CRecoveredSigsDb::WriteVoteForId(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash)
{
auto k1 = std::make_tuple(std::string("rs_v"), llmqType, id);
auto k2 = std::make_tuple(std::string("rs_vt"), (uint32_t)htobe32(GetTime()), llmqType, id);
auto k2 = std::make_tuple(std::string("rs_vt"), (uint32_t)htobe32(count_seconds(GetTime<std::chrono::seconds>())), llmqType, id);

CDBBatch batch(*db);
batch.Write(k1, msgHash);
Expand All @@ -489,7 +489,7 @@ void CRecoveredSigsDb::CleanupOldVotes(int64_t maxAge)
std::unique_ptr<CDBIterator> pcursor(db->NewIterator());

auto start = std::make_tuple(std::string("rs_vt"), (uint32_t)0, (Consensus::LLMQType)0, uint256());
uint32_t endTime = (uint32_t)(GetTime() - maxAge);
uint32_t endTime = (uint32_t)(count_seconds(GetTime<std::chrono::seconds>()) - maxAge);
pcursor->Seek(start);

CDBBatch batch(*db);
Expand Down
8 changes: 4 additions & 4 deletions src/llmq/signing_shares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ void CSigSharesManager::ProcessSigShare(const CSigShare& sigShare, const CConnma
}

// Update the time we've seen the last sigShare
timeSeenForSessions[sigShare.GetSignHash()] = GetTime();
timeSeenForSessions[sigShare.GetSignHash()] = count_seconds(GetTime<std::chrono::seconds>());

if (!quorumNodes.empty()) {
// don't announce and wait for other nodes to request this share and directly send it to them
Expand Down Expand Up @@ -823,7 +823,7 @@ void CSigSharesManager::CollectSigSharesToRequest(std::unordered_map<NodeId, std
{
AssertLockHeld(cs);

int64_t now = GetTime();
int64_t now = count_seconds(GetTime<std::chrono::seconds>());
const size_t maxRequestsForNode = 32;

// avoid requesting from same nodes all the time
Expand Down Expand Up @@ -1241,7 +1241,7 @@ CSigShare CSigSharesManager::RebuildSigShare(const CSigSharesNodeState::SessionI

void CSigSharesManager::Cleanup()
{
int64_t now = GetTime();
int64_t now = count_seconds(GetTime<std::chrono::seconds>());
if (now - lastCleanupTime < 5) {
return;
}
Expand Down Expand Up @@ -1365,7 +1365,7 @@ void CSigSharesManager::Cleanup()
nodeStates.erase(nodeId);
}

lastCleanupTime = GetTime();
lastCleanupTime = count_seconds(GetTime<std::chrono::seconds>());
}

void CSigSharesManager::RemoveSigSharesForSession(const uint256& signHash)
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, const CB
}

auto members = GetAllQuorumMembers(llmqParams.type, pQuorumBaseBlockIndex);
auto curTime = GetTime();
auto curTime = count_seconds(GetTime<std::chrono::seconds>());

std::set<uint256> probeConnections;
for (const auto& dmn : members) {
Expand Down
2 changes: 1 addition & 1 deletion src/masternode/meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ UniValue CMasternodeMetaInfo::ToJson() const
{
UniValue ret(UniValue::VOBJ);

auto now = GetTime();
auto now = count_seconds(GetTime<std::chrono::seconds>());

ret.pushKV("lastDSQ", nLastDsq);
ret.pushKV("mixingTxCount", nMixingTxCount);
Expand Down
2 changes: 1 addition & 1 deletion src/masternode/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void CMasternodeSync::NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitia
void CMasternodeSync::UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload)
{
LogPrint(BCLog::MNSYNC, "CMasternodeSync::UpdatedBlockTip -- pindexNew->nHeight: %d fInitialDownload=%d\n", pindexNew->nHeight, fInitialDownload);
nTimeLastUpdateBlockTip = GetTime();
nTimeLastUpdateBlockTip = count_seconds(GetTime<std::chrono::seconds>());

CBlockIndex* pindexTip = WITH_LOCK(cs_main, return pindexBestHeader);

Expand Down
2 changes: 1 addition & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2568,7 +2568,7 @@ void CConnman::ThreadOpenMasternodeConnections()
if (interruptNet)
return;

int64_t nANow = GetTime();
int64_t nANow = count_seconds(GetTime<std::chrono::seconds>());
constexpr const auto &_func_ = __func__;

// NOTE: Process only one pending masternode at a time
Expand Down

0 comments on commit 62a82f5

Please sign in to comment.