diff --git a/src/timedata.cpp b/src/timedata.cpp --- a/src/timedata.cpp +++ b/src/timedata.cpp @@ -35,11 +35,6 @@ return GetTime() + GetTimeOffset(); } -static uint64_t abs64(int64_t n) { - const uint64_t un = n; - return (n >= 0) ? un : -un; -} - #define BITCOIN_TIMEDATA_MAX_SAMPLES 200 void AddTimeData(const CNetAddr &ip, int64_t nOffsetSample) { @@ -81,10 +76,10 @@ int64_t nMedian = vTimeOffsets.median(); std::vector vSorted = vTimeOffsets.sorted(); // Only let other nodes change our time by so much - if (abs64(nMedian) <= - uint64_t(std::max( - 0, gArgs.GetArg("-maxtimeadjustment", - DEFAULT_MAX_TIME_ADJUSTMENT)))) { + + int64_t max_adjustment = std::max( + 0, gArgs.GetArg("-maxtimeadjustment", DEFAULT_MAX_TIME_ADJUSTMENT)); + if (nMedian >= -max_adjustment && nMedian <= max_adjustment) { nTimeOffset = nMedian; } else { nTimeOffset = 0; @@ -95,7 +90,7 @@ // of ours, give a warning bool fMatch = false; for (const int64_t nOffset : vSorted) { - if (nOffset != 0 && abs64(nOffset) < 5 * 60) { + if (nOffset != 0 && nOffset > -5 * 60 && nOffset < 5 * 60) { fMatch = true; } }