diff options
author | fanquake <fanquake@gmail.com> | 2020-10-13 19:04:10 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2020-10-13 20:00:39 +0800 |
commit | ad90dd9f313aa4a2f87675b4392b85c0b06a5a83 (patch) | |
tree | c226854c5dfeaee9fa4648ba8705c5228ed42fbd /src | |
parent | f79a4a895279ba4efa43494270633f94f7d18342 (diff) | |
parent | d1292f25f272401da0c58580521c74b1fa03a9ad (diff) |
Merge #20141: Avoid the use of abs64 in timedata
d1292f25f272401da0c58580521c74b1fa03a9ad Avoid the use of abs64 in timedata (Pieter Wuille)
Pull request description:
Fixes #20135.
ACKs for top commit:
kallewoof:
ACK d1292f25f272401da0c58580521c74b1fa03a9ad
jonatack:
ACK d1292f25f272401da0c58580521c74b1fa03a9ad code/logic review, verified there are no remaining callers of `abs64()`, verified no warnings in a debug build
practicalswift:
ACK d1292f25f272401da0c58580521c74b1fa03a9ad
MarcoFalke:
ACK d1292f25f272401da0c58580521c74b1fa03a9ad 🎹
Tree-SHA512: d17e95c668eb5e02ea546433b3d1b5a0ccbfb2c9cec62fa67dad1844d7e278a2576fbc0b75bddbf4db9af7331e978148c7bef7fce7e6a07e0eb917ef1392f302
Diffstat (limited to 'src')
-rw-r--r-- | src/timedata.cpp | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/timedata.cpp b/src/timedata.cpp index 6b3a79017b..354092752d 100644 --- a/src/timedata.cpp +++ b/src/timedata.cpp @@ -36,11 +36,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) @@ -79,7 +74,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 { nTimeOffset = 0; @@ -89,7 +85,7 @@ 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) fMatch = true; + if (nOffset != 0 && nOffset > -5 * 60 && nOffset < 5 * 60) fMatch = true; } if (!fMatch) { |