aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2020-10-12 17:36:51 -0700
committerfanquake <fanquake@gmail.com>2020-10-16 11:42:27 +0800
commitee0082b886264fcddd73c5bb7c41ba8316527b9c (patch)
treeb70989098f712f3809c68534d331c99cea1054cb /src
parent05bd0c220aa0f4cb6202dd19d3164ba2e7cb015e (diff)
Avoid the use of abs64 in timedata
Github-Pull: #20141 Rebased-From: d1292f25f272401da0c58580521c74b1fa03a9ad
Diffstat (limited to 'src')
-rw-r--r--src/timedata.cpp14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/timedata.cpp b/src/timedata.cpp
index 942b3cb919..2a584e3f02 100644
--- a/src/timedata.cpp
+++ b/src/timedata.cpp
@@ -37,11 +37,6 @@ int64_t GetAdjustedTime()
return GetTime() + GetTimeOffset();
}
-static int64_t abs64(int64_t n)
-{
- return (n >= 0 ? n : -n);
-}
-
#define BITCOIN_TIMEDATA_MAX_SAMPLES 200
void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
@@ -81,8 +76,8 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
int64_t nMedian = vTimeOffsets.median();
std::vector<int64_t> vSorted = vTimeOffsets.sorted();
// Only let other nodes change our time by so much
- if (abs64(nMedian) <= std::max<int64_t>(0, gArgs.GetArg("-maxtimeadjustment", DEFAULT_MAX_TIME_ADJUSTMENT)))
- {
+ int64_t max_adjustment = std::max<int64_t>(0, gArgs.GetArg("-maxtimeadjustment", DEFAULT_MAX_TIME_ADJUSTMENT));
+ if (nMedian >= -max_adjustment && nMedian <= max_adjustment) {
nTimeOffset = nMedian;
}
else
@@ -94,9 +89,10 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
{
// If nobody has a time different than ours but within 5 minutes of ours, give a warning
bool fMatch = false;
- for (const int64_t nOffset : vSorted)
- if (nOffset != 0 && abs64(nOffset) < 5 * 60)
+ for (const int64_t nOffset : vSorted) {
+ if (nOffset != 0 && nOffset > -5 * 60 && nOffset < 5 * 60)
fMatch = true;
+ }
if (!fMatch)
{