Skip to content

Commit

Permalink
[P2P] Do not store more than 200 timedata samples.
Browse files Browse the repository at this point in the history
Backport of bitcoin/bitcoin#6545
# Conflicts:
#	src/timedata.cpp
  • Loading branch information
random-zebra authored and wqking committed Feb 10, 2021
1 parent 79a5bc5 commit 84da44e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/timedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,20 @@ 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)
{
LOCK(cs_nTimeOffset);
// Ignore duplicates
static set<CNetAddr> setKnown;
static std::set<CNetAddr> setKnown;
if (setKnown.size() == BITCOIN_TIMEDATA_MAX_SAMPLES)
return;
if (!setKnown.insert(ip).second)
return;

// Add data
static CMedianFilter<int64_t> vTimeOffsets(200, 0);
static CMedianFilter<int64_t> vTimeOffsets(BITCOIN_TIMEDATA_MAX_SAMPLES, 0);
vTimeOffsets.input(nOffsetSample);
LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample / 60);

Expand Down

0 comments on commit 84da44e

Please sign in to comment.