Skip to content

Commit

Permalink
Use GetAdjustedTime instead of GetTime when dealing with network-wide…
Browse files Browse the repository at this point in the history
… timestamps (#1590)
  • Loading branch information
UdjinM6 authored Aug 28, 2017
1 parent b5f7be6 commit 4f54550
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/governance-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
return false;
}

int64_t nNow = GetTime();
int64_t nNow = GetAdjustedTime();
int64_t nVoteTimeUpdate = voteInstance.nTime;
if(governance.AreRateChecksEnabled()) {
int64_t nTimeDelta = nNow - voteInstance.nTime;
Expand Down
4 changes: 2 additions & 2 deletions src/governance-vote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ bool CGovernanceVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)

bool CGovernanceVote::IsValid(bool fSignatureCheck) const
{
if(nTime > GetTime() + (60*60)) {
LogPrint("gobject", "CGovernanceVote::IsValid -- vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, GetTime() + (60*60));
if(nTime > GetAdjustedTime() + (60*60)) {
LogPrint("gobject", "CGovernanceVote::IsValid -- vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, GetAdjustedTime() + (60*60));
return false;
}

Expand Down
7 changes: 3 additions & 4 deletions src/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ bool CGovernanceManager::UpdateCurrentWatchdog(CGovernanceObject& watchdogNew)
arith_uint256 nHashCurrent = UintToArith256(nHashWatchdogCurrent);

int64_t nExpirationDelay = GOVERNANCE_WATCHDOG_EXPIRATION_TIME / 2;
int64_t nNow = GetTime();
int64_t nNow = GetAdjustedTime();

if(nHashWatchdogCurrent == uint256() || // no known current OR
((nNow - watchdogNew.GetCreationTime() < nExpirationDelay) && // (new one is NOT expired AND
Expand Down Expand Up @@ -546,7 +546,6 @@ void CGovernanceManager::UpdateCachesAndClean()

// forget about expired deleted objects
hash_time_m_it s_it = mapErasedGovernanceObjects.begin();
nNow = GetTime();
while(s_it != mapErasedGovernanceObjects.end()) {
if(s_it->second < nNow)
mapErasedGovernanceObjects.erase(s_it++);
Expand Down Expand Up @@ -874,7 +873,7 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo

const CTxIn& vin = govobj.GetMasternodeVin();
int64_t nTimestamp = govobj.GetCreationTime();
int64_t nNow = GetTime();
int64_t nNow = GetAdjustedTime();
int64_t nSuperblockCycleSeconds = Params().GetConsensus().nSuperblockCycle * Params().GetConsensus().nPowTargetSpacing;

std::string strHash = govobj.GetHash().ToString();
Expand Down Expand Up @@ -1072,7 +1071,7 @@ void CGovernanceManager::CheckPostponedObjects()


// Perform additional relays for triggers/watchdogs
int64_t nNow = GetTime();
int64_t nNow = GetAdjustedTime();
int64_t nSuperblockCycleSeconds = Params().GetConsensus().nSuperblockCycle * Params().GetConsensus().nPowTargetSpacing;

for(hash_s_it it = setAdditionalRelayObjects.begin(); it != setAdditionalRelayObjects.end();) {
Expand Down
8 changes: 4 additions & 4 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ void CMasternode::Check(bool fForce)
}

bool fWatchdogActive = masternodeSync.IsSynced() && mnodeman.IsWatchdogActive();
bool fWatchdogExpired = (fWatchdogActive && ((GetTime() - nTimeLastWatchdogVote) > MASTERNODE_WATCHDOG_MAX_SECONDS));
bool fWatchdogExpired = (fWatchdogActive && ((GetAdjustedTime() - nTimeLastWatchdogVote) > MASTERNODE_WATCHDOG_MAX_SECONDS));

LogPrint("masternode", "CMasternode::Check -- outpoint=%s, nTimeLastWatchdogVote=%d, GetTime()=%d, fWatchdogExpired=%d\n",
vin.prevout.ToStringShort(), nTimeLastWatchdogVote, GetTime(), fWatchdogExpired);
LogPrint("masternode", "CMasternode::Check -- outpoint=%s, nTimeLastWatchdogVote=%d, GetAdjustedTime()=%d, fWatchdogExpired=%d\n",
vin.prevout.ToStringShort(), nTimeLastWatchdogVote, GetAdjustedTime(), fWatchdogExpired);

if(fWatchdogExpired) {
nActiveState = MASTERNODE_WATCHDOG_EXPIRED;
Expand Down Expand Up @@ -832,7 +832,7 @@ void CMasternode::RemoveGovernanceObject(uint256 nGovernanceObjectHash)
void CMasternode::UpdateWatchdogVoteTime(uint64_t nVoteTime)
{
LOCK(cs);
nTimeLastWatchdogVote = (nVoteTime == 0) ? GetTime() : nVoteTime;
nTimeLastWatchdogVote = (nVoteTime == 0) ? GetAdjustedTime() : nVoteTime;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CMasternodePing
return ss.GetHash();
}

bool IsExpired() const { return GetTime() - sigTime > MASTERNODE_NEW_START_REQUIRED_SECONDS; }
bool IsExpired() const { return GetAdjustedTime() - sigTime > MASTERNODE_NEW_START_REQUIRED_SECONDS; }

bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode);
bool CheckSignature(CPubKey& pubKeyMasternode, int &nDos);
Expand Down
2 changes: 1 addition & 1 deletion src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr
// simulate Check
CMasternode mnTemp = CMasternode(mnb);
mnTemp.Check();
LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- mnb=%s seen request, addr=%s, better lastPing: %d min ago, projected mn state: %s\n", hash.ToString(), pfrom->addr.ToString(), (GetTime() - mnb.lastPing.sigTime)/60, mnTemp.GetStateString());
LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- mnb=%s seen request, addr=%s, better lastPing: %d min ago, projected mn state: %s\n", hash.ToString(), pfrom->addr.ToString(), (GetAdjustedTime() - mnb.lastPing.sigTime)/60, mnTemp.GetStateString());
if(mnTemp.IsValidStateForAutoStart(mnTemp.nActiveState)) {
// this node thinks it's a good one
LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s seen good\n", mnb.vin.prevout.ToStringShort());
Expand Down
2 changes: 1 addition & 1 deletion src/privatesend-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void CPrivateSendClient::ProcessMessage(CNode* pfrom, std::string& strCommand, C

LogPrint("privatesend", "DSQUEUE -- %s new\n", dsq.ToString());

if(dsq.IsExpired() || dsq.nTime > GetTime() + PRIVATESEND_QUEUE_TIMEOUT) return;
if(dsq.IsExpired()) return;

masternode_info_t infoMn = mnodeman.GetMasternodeInfo(dsq.vin);
if(!infoMn.fInfoValid) return;
Expand Down
6 changes: 3 additions & 3 deletions src/privatesend-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, std::string& strCommand, C

LogPrint("privatesend", "DSQUEUE -- %s new\n", dsq.ToString());

if(dsq.IsExpired() || dsq.nTime > GetTime() + PRIVATESEND_QUEUE_TIMEOUT) return;
if(dsq.IsExpired()) return;

CMasternode* pmn = mnodeman.Find(dsq.vin);
if(pmn == NULL) return;
Expand Down Expand Up @@ -537,7 +537,7 @@ void CPrivateSendServer::CheckForCompleteQueue()
if(nState == POOL_STATE_QUEUE && IsSessionReady()) {
SetState(POOL_STATE_ACCEPTING_ENTRIES);

CDarksendQueue dsq(nSessionDenom, activeMasternode.vin, GetTime(), true);
CDarksendQueue dsq(nSessionDenom, activeMasternode.vin, GetAdjustedTime(), true);
LogPrint("privatesend", "CPrivateSendServer::CheckForCompleteQueue -- queue is ready, signing and relaying (%s)\n", dsq.ToString());
dsq.Sign();
dsq.Relay();
Expand Down Expand Up @@ -744,7 +744,7 @@ bool CPrivateSendServer::CreateNewSession(int nDenom, CTransaction txCollateral,

if(!fUnitTest) {
//broadcast that I'm accepting entries, only if it's the first entry through
CDarksendQueue dsq(nDenom, activeMasternode.vin, GetTime(), false);
CDarksendQueue dsq(nDenom, activeMasternode.vin, GetAdjustedTime(), false);
LogPrint("privatesend", "CPrivateSendServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString());
dsq.Sign();
dsq.Relay();
Expand Down
4 changes: 2 additions & 2 deletions src/privatesend.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "pubkey.h"
#include "sync.h"
#include "tinyformat.h"
#include "utiltime.h"
#include "timedata.h"

class CPrivateSend;

Expand Down Expand Up @@ -199,7 +199,7 @@ class CDarksendQueue
bool Relay();

/// Is this queue expired?
bool IsExpired() { return GetTime() - nTime > PRIVATESEND_QUEUE_TIMEOUT; }
bool IsExpired() { return GetAdjustedTime() - nTime > PRIVATESEND_QUEUE_TIMEOUT; }

std::string ToString()
{
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ UniValue gobject(const UniValue& params, bool fHelp)

int nRevision = 1;

int64_t nTime = GetTime();
int64_t nTime = GetAdjustedTime();
std::string strData = params[1].get_str();

CGovernanceObject govobj(hashParent, nRevision, nTime, uint256(), strData);
Expand Down
4 changes: 2 additions & 2 deletions src/sendalert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void ThreadSendAlert(CConnman& connman)
// Nodes never save alerts to disk, they are in-memory-only.
//
CAlert alert;
alert.nRelayUntil = GetTime() + 15 * 60;
alert.nExpiration = GetTime() + 30 * 60 * 60;
alert.nRelayUntil = GetAdjustedTime() + 15 * 60;
alert.nExpiration = GetAdjustedTime() + 30 * 60 * 60;
alert.nID = 1; // keep track of alert IDs somewhere
alert.nCancel = 0; // cancels previous messages up to this ID number

Expand Down
4 changes: 2 additions & 2 deletions src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void CSporkManager::ExecuteSpork(int nSporkID, int nValue)
bool CSporkManager::UpdateSpork(int nSporkID, int64_t nValue)
{

CSporkMessage spork = CSporkMessage(nSporkID, nValue, GetTime());
CSporkMessage spork = CSporkMessage(nSporkID, nValue, GetAdjustedTime());

if(spork.Sign(strMasterPrivKey)) {
spork.Relay();
Expand Down Expand Up @@ -141,7 +141,7 @@ bool CSporkManager::IsSporkActive(int nSporkID)
}
}

return r < GetTime();
return r < GetAdjustedTime();
}

// grab the value of the spork on the network, or the default
Expand Down

0 comments on commit 4f54550

Please sign in to comment.