Skip to content

Commit 1dffbf0

Browse files
committed
Merge pull request #3114
a616206 Give peer time-adjustment data an own lock (Pieter Wuille)
2 parents ede3ee3 + a616206 commit 1dffbf0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int64 CTransaction::nMinTxFee = 10000; // Override with -mintxfee
4949
/** Fees smaller than this (in satoshi) are considered zero fee (for relaying) */
5050
int64 CTransaction::nMinRelayTxFee = 10000;
5151

52-
CMedianFilter<int> cPeerBlockCounts(8, 0); // Amount of blocks that other nodes claim to have
52+
static CMedianFilter<int> cPeerBlockCounts(8, 0); // Amount of blocks that other nodes claim to have
5353

5454
map<uint256, CBlock*> mapOrphanBlocks;
5555
multimap<uint256, CBlock*> mapOrphanBlocksByPrev;
@@ -3396,8 +3396,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
33963396

33973397
LogPrintf("receive version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString().c_str(), addrFrom.ToString().c_str(), pfrom->addr.ToString().c_str());
33983398

3399-
LOCK(cs_main);
34003399
AddTimeData(pfrom->addr, nTime);
3400+
3401+
LOCK(cs_main);
34013402
cPeerBlockCounts.input(pfrom->nStartingHeight);
34023403
}
34033404

src/util.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ bool fServer = false;
8080
string strMiscWarning;
8181
bool fNoListen = false;
8282
bool fLogTimestamps = false;
83-
CMedianFilter<int64> vTimeOffsets(200,0);
8483
volatile bool fReopenDebugLog = false;
8584

8685
// Init OpenSSL library multithreading support
@@ -1305,10 +1304,12 @@ void SetMockTime(int64 nMockTimeIn)
13051304
nMockTime = nMockTimeIn;
13061305
}
13071306

1307+
static CCriticalSection cs_nTimeOffset;
13081308
static int64 nTimeOffset = 0;
13091309

13101310
int64 GetTimeOffset()
13111311
{
1312+
LOCK(cs_nTimeOffset);
13121313
return nTimeOffset;
13131314
}
13141315

@@ -1321,12 +1322,14 @@ void AddTimeData(const CNetAddr& ip, int64 nTime)
13211322
{
13221323
int64 nOffsetSample = nTime - GetTime();
13231324

1325+
LOCK(cs_nTimeOffset);
13241326
// Ignore duplicates
13251327
static set<CNetAddr> setKnown;
13261328
if (!setKnown.insert(ip).second)
13271329
return;
13281330

13291331
// Add data
1332+
static CMedianFilter<int64> vTimeOffsets(200,0);
13301333
vTimeOffsets.input(nOffsetSample);
13311334
LogPrintf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60);
13321335
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)

0 commit comments

Comments
 (0)