Skip to content

Commit

Permalink
merge bitcoin#22107: rename GetSystemTimeInSeconds to GetTimeSeconds
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Mar 28, 2024
1 parent 07306dd commit 561d4e8
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
"See this help\n"
"> dash-cli -netinfo help\n"};
}
const int64_t m_time_now{GetSystemTimeInSeconds()};
const int64_t m_time_now{GetTimeSeconds()};

public:
static constexpr int ID_PEERINFO = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/masternode/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void CMasternodeUtils::DoMaintenance(CConnman& connman, const CMasternodeSync& m
connman.ForEachNode(CConnman::AllNodes, [&](CNode* pnode) {
if (pnode->m_masternode_probe_connection) {
// we're not disconnecting masternode probes for at least PROBE_WAIT_INTERVAL seconds
if (GetSystemTimeInSeconds() - pnode->nTimeConnected < PROBE_WAIT_INTERVAL) return;
if (GetTimeSeconds() - pnode->nTimeConnected < PROBE_WAIT_INTERVAL) return;
} else {
// we're only disconnecting m_masternode_connection connections
if (!pnode->m_masternode_connection) return;
Expand All @@ -65,7 +65,7 @@ void CMasternodeUtils::DoMaintenance(CConnman& connman, const CMasternodeSync& m
if (pnode->IsInboundConn()) {
return;
}
} else if (GetSystemTimeInSeconds() - pnode->nTimeConnected < 5) {
} else if (GetTimeSeconds() - pnode->nTimeConnected < 5) {
// non-verified, give it some time to verify itself
return;
} else if (pnode->qwatch) {
Expand Down
12 changes: 6 additions & 6 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ size_t CConnman::SocketSendData(CNode& node)
nBytes = send(node.hSocket, reinterpret_cast<const char*>(data.data()) + node.nSendOffset, data.size() - node.nSendOffset, MSG_NOSIGNAL | MSG_DONTWAIT);
}
if (nBytes > 0) {
node.nLastSend = GetSystemTimeInSeconds();
node.nLastSend = GetTimeSeconds();
node.nSendBytes += nBytes;
node.nSendOffset += nBytes;
nSentSize += nBytes;
Expand Down Expand Up @@ -1072,7 +1072,7 @@ bool CConnman::AttemptToEvictConnection()
// was accepted. This short time is meant for the VERSION/VERACK exchange and the possible MNAUTH that might
// follow when the incoming connection is from another masternode. When a message other than MNAUTH
// is received after VERSION/VERACK, the protection is lifted immediately.
bool isProtected = GetSystemTimeInSeconds() - node->nTimeConnected < INBOUND_EVICTION_PROTECTION_TIME;
bool isProtected = GetTimeSeconds() - node->nTimeConnected < INBOUND_EVICTION_PROTECTION_TIME;
if (node->nTimeFirstMessageReceived != 0 && !node->fFirstMessageIsMNAUTH) {
isProtected = false;
}
Expand Down Expand Up @@ -1492,15 +1492,15 @@ void CConnman::CalculateNumConnectionsChangedStats()

bool CConnman::ShouldRunInactivityChecks(const CNode& node, std::optional<int64_t> now_in) const
{
const int64_t now = now_in ? now_in.value() : GetSystemTimeInSeconds();
const int64_t now = now_in ? now_in.value() : GetTimeSeconds();
return node.nTimeConnected + m_peer_connect_timeout < now;
}

bool CConnman::InactivityCheck(const CNode& node) const
{
// Use non-mockable system time (otherwise these timers will pop when we
// use setmocktime in the tests).
int64_t now = GetSystemTimeInSeconds();
int64_t now = GetTimeSeconds();

if (!ShouldRunInactivityChecks(node, now)) return false;

Expand Down Expand Up @@ -2720,7 +2720,7 @@ void CConnman::ThreadOpenMasternodeConnections()
// we probably connected to it before it became a masternode
// or maybe we are still waiting for mnauth
(void)ForNode(addr2, [&](CNode* pnode) {
if (pnode->nTimeFirstMessageReceived != 0 && GetSystemTimeInSeconds() - pnode->nTimeFirstMessageReceived > 5) {
if (pnode->nTimeFirstMessageReceived != 0 && GetTimeSeconds() - pnode->nTimeFirstMessageReceived > 5) {
// clearly not expecting mnauth to take that long even if it wasn't the first message
// we received (as it should normally), disconnect
LogPrint(BCLog::NET_NETCONN, "CConnman::%s -- dropping non-mnauth connection to %s, service=%s\n", _func_, proRegTxHash.ToString(), addr2.ToString(false));
Expand Down Expand Up @@ -4035,7 +4035,7 @@ ServiceFlags CConnman::GetLocalServices() const
unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; }

CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion)
: nTimeConnected(GetSystemTimeInSeconds()),
: nTimeConnected(GetTimeSeconds()),
addr(addrIn),
addrBind(addrBindIn),
nKeyedNetGroup(nKeyedNetGroupIn),
Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3342,7 +3342,7 @@ void PeerManagerImpl::ProcessMessage(

if (pfrom.nTimeFirstMessageReceived == 0) {
// First message after VERSION/VERACK
pfrom.nTimeFirstMessageReceived = GetSystemTimeInSeconds();
pfrom.nTimeFirstMessageReceived = GetTimeSeconds();
pfrom.fFirstMessageIsMNAUTH = msg_type == NetMsgType::MNAUTH;
// Note: do not break the flow here

Expand Down
2 changes: 1 addition & 1 deletion src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ void RPCConsole::updateNodeDetail(const CNodeCombinedStats *stats)
ui->peerHeading->setText(peerAddrDetails);
ui->peerServices->setText(GUIUtil::formatServicesStr(stats->nodeStats.nServices));
ui->peerRelayTxes->setText(stats->nodeStats.fRelayTxes ? "Yes" : "No");
const int64_t time_now{GetSystemTimeInSeconds()};
const int64_t time_now{GetTimeSeconds()};
ui->peerConnTime->setText(GUIUtil::formatDurationStr(time_now - stats->nodeStats.nTimeConnected));
ui->peerLastBlock->setText(TimeDurationField(time_now, stats->nodeStats.nLastBlockTime));
ui->peerLastTx->setText(TimeDurationField(time_now, stats->nodeStats.nLastTXTime));
Expand Down
2 changes: 1 addition & 1 deletion src/test/util_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ BOOST_AUTO_TEST_CASE(util_FormatParseISO8601DateTime)
BOOST_CHECK_EQUAL(ParseISO8601DateTime("1960-01-01T00:00:00Z"), 0);
BOOST_CHECK_EQUAL(ParseISO8601DateTime("2011-09-30T23:36:17Z"), 1317425777);

auto time = GetSystemTimeInSeconds();
auto time = GetTimeSeconds();
BOOST_CHECK_EQUAL(ParseISO8601DateTime(FormatISO8601DateTime(time)), time);
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int64_t GetTimeMicros()
return int64_t{GetSystemTime<std::chrono::microseconds>().count()};
}

int64_t GetSystemTimeInSeconds()
int64_t GetTimeSeconds()
{
return int64_t{GetSystemTime<std::chrono::seconds>().count()};
}
Expand Down
4 changes: 2 additions & 2 deletions src/util/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ inline double CountSecondsDouble(SecondsDouble t) { return t.count(); }

/**
* DEPRECATED
* Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
* Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
*/
int64_t GetTime();

Expand All @@ -53,7 +53,7 @@ int64_t GetTimeMillis();
/** Returns the system time (not mockable) */
int64_t GetTimeMicros();
/** Returns the system time (not mockable) */
int64_t GetSystemTimeInSeconds(); // Like GetTime(), but not mockable
int64_t GetTimeSeconds(); // Like GetTime(), but not mockable

/**
* DEPRECATED
Expand Down

0 comments on commit 561d4e8

Please sign in to comment.