mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Avoid the use of abs64 in timedata
This commit is contained in:
parent
af22322dab
commit
d1292f25f2
1 changed files with 3 additions and 7 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue