Skip to content

Commit 43868ba

Browse files
committed
timedata: rename variables to match the coding style
Rename the local variables in `src/timedata.cpp`: `setKnown` -> `g_sources` `vTimeOffsets` -> `g_time_offsets` `fDone` -> `g_warning_emitted`
1 parent 60da1ea commit 43868ba

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/timedata.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,31 @@ int64_t GetAdjustedTime()
3939

4040
#define BITCOIN_TIMEDATA_MAX_SAMPLES 200
4141

42-
static std::set<CNetAddr> setKnown;
43-
static CMedianFilter<int64_t> vTimeOffsets(BITCOIN_TIMEDATA_MAX_SAMPLES, 0);
44-
static bool fDone;
42+
static std::set<CNetAddr> g_sources;
43+
static CMedianFilter<int64_t> g_time_offsets{BITCOIN_TIMEDATA_MAX_SAMPLES, 0};
44+
static bool g_warning_emitted;
4545

4646
void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
4747
{
4848
LOCK(g_timeoffset_mutex);
4949
// Ignore duplicates
50-
if (setKnown.size() == BITCOIN_TIMEDATA_MAX_SAMPLES)
50+
if (g_sources.size() == BITCOIN_TIMEDATA_MAX_SAMPLES)
5151
return;
52-
if (!setKnown.insert(ip).second)
52+
if (!g_sources.insert(ip).second)
5353
return;
5454

5555
// Add data
56-
vTimeOffsets.input(nOffsetSample);
57-
LogPrint(BCLog::NET, "added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample / 60);
56+
g_time_offsets.input(nOffsetSample);
57+
LogPrint(BCLog::NET, "added time data, samples %d, offset %+d (%+d minutes)\n", g_time_offsets.size(), nOffsetSample, nOffsetSample / 60);
5858

5959
// There is a known issue here (see issue #4521):
6060
//
61-
// - The structure vTimeOffsets contains up to 200 elements, after which
61+
// - The structure g_time_offsets contains up to 200 elements, after which
6262
// any new element added to it will not increase its size, replacing the
6363
// oldest element.
6464
//
6565
// - The condition to update nTimeOffset includes checking whether the
66-
// number of elements in vTimeOffsets is odd, which will never happen after
66+
// number of elements in g_time_offsets is odd, which will never happen after
6767
// there are 200 elements.
6868
//
6969
// But in this case the 'bug' is protective against some attacks, and may
@@ -73,25 +73,25 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
7373
// So we should hold off on fixing this and clean it up as part of
7474
// a timing cleanup that strengthens it in a number of other ways.
7575
//
76-
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) {
77-
int64_t nMedian = vTimeOffsets.median();
78-
std::vector<int64_t> vSorted = vTimeOffsets.sorted();
76+
if (g_time_offsets.size() >= 5 && g_time_offsets.size() % 2 == 1) {
77+
int64_t nMedian = g_time_offsets.median();
78+
std::vector<int64_t> vSorted = g_time_offsets.sorted();
7979
// Only let other nodes change our time by so much
8080
int64_t max_adjustment = std::max<int64_t>(0, gArgs.GetIntArg("-maxtimeadjustment", DEFAULT_MAX_TIME_ADJUSTMENT));
8181
if (nMedian >= -max_adjustment && nMedian <= max_adjustment) {
8282
nTimeOffset = nMedian;
8383
} else {
8484
nTimeOffset = 0;
8585

86-
if (!fDone) {
86+
if (!g_warning_emitted) {
8787
// If nobody has a time different than ours but within 5 minutes of ours, give a warning
8888
bool fMatch = false;
8989
for (const int64_t nOffset : vSorted) {
9090
if (nOffset != 0 && nOffset > -5 * 60 && nOffset < 5 * 60) fMatch = true;
9191
}
9292

9393
if (!fMatch) {
94-
fDone = true;
94+
g_warning_emitted = true;
9595
bilingual_str strMessage = strprintf(_("Please check that your computer's date and time are correct! If your clock is wrong, %s will not work properly."), PACKAGE_NAME);
9696
SetMiscWarning(strMessage);
9797
uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_WARNING);
@@ -114,7 +114,7 @@ void TestOnlyResetTimeData()
114114
{
115115
LOCK(g_timeoffset_mutex);
116116
nTimeOffset = 0;
117-
setKnown.clear();
118-
vTimeOffsets = CMedianFilter<int64_t>(BITCOIN_TIMEDATA_MAX_SAMPLES, 0);
119-
fDone = false;
117+
g_sources.clear();
118+
g_time_offsets = CMedianFilter<int64_t>{BITCOIN_TIMEDATA_MAX_SAMPLES, 0};
119+
g_warning_emitted = false;
120120
}

0 commit comments

Comments
 (0)