Give peer time-adjustment data an own lock
Instead of relying on cs_main (defined in a different module) to prevent concurrent access to it.
This commit is contained in:
parent
0d09b3e8b0
commit
a616206865
2 changed files with 7 additions and 3 deletions
|
@ -49,7 +49,7 @@ int64 CTransaction::nMinTxFee = 10000; // Override with -mintxfee
|
||||||
/** Fees smaller than this (in satoshi) are considered zero fee (for relaying) */
|
/** Fees smaller than this (in satoshi) are considered zero fee (for relaying) */
|
||||||
int64 CTransaction::nMinRelayTxFee = 10000;
|
int64 CTransaction::nMinRelayTxFee = 10000;
|
||||||
|
|
||||||
CMedianFilter<int> cPeerBlockCounts(8, 0); // Amount of blocks that other nodes claim to have
|
static CMedianFilter<int> cPeerBlockCounts(8, 0); // Amount of blocks that other nodes claim to have
|
||||||
|
|
||||||
map<uint256, CBlock*> mapOrphanBlocks;
|
map<uint256, CBlock*> mapOrphanBlocks;
|
||||||
multimap<uint256, CBlock*> mapOrphanBlocksByPrev;
|
multimap<uint256, CBlock*> mapOrphanBlocksByPrev;
|
||||||
|
@ -3460,8 +3460,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||||
|
|
||||||
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());
|
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());
|
||||||
|
|
||||||
LOCK(cs_main);
|
|
||||||
AddTimeData(pfrom->addr, nTime);
|
AddTimeData(pfrom->addr, nTime);
|
||||||
|
|
||||||
|
LOCK(cs_main);
|
||||||
cPeerBlockCounts.input(pfrom->nStartingHeight);
|
cPeerBlockCounts.input(pfrom->nStartingHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,6 @@ bool fServer = false;
|
||||||
string strMiscWarning;
|
string strMiscWarning;
|
||||||
bool fNoListen = false;
|
bool fNoListen = false;
|
||||||
bool fLogTimestamps = false;
|
bool fLogTimestamps = false;
|
||||||
CMedianFilter<int64> vTimeOffsets(200,0);
|
|
||||||
volatile bool fReopenDebugLog = false;
|
volatile bool fReopenDebugLog = false;
|
||||||
|
|
||||||
// Init OpenSSL library multithreading support
|
// Init OpenSSL library multithreading support
|
||||||
|
@ -1296,10 +1295,12 @@ void SetMockTime(int64 nMockTimeIn)
|
||||||
nMockTime = nMockTimeIn;
|
nMockTime = nMockTimeIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CCriticalSection cs_nTimeOffset;
|
||||||
static int64 nTimeOffset = 0;
|
static int64 nTimeOffset = 0;
|
||||||
|
|
||||||
int64 GetTimeOffset()
|
int64 GetTimeOffset()
|
||||||
{
|
{
|
||||||
|
LOCK(cs_nTimeOffset);
|
||||||
return nTimeOffset;
|
return nTimeOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1312,12 +1313,14 @@ void AddTimeData(const CNetAddr& ip, int64 nTime)
|
||||||
{
|
{
|
||||||
int64 nOffsetSample = nTime - GetTime();
|
int64 nOffsetSample = nTime - GetTime();
|
||||||
|
|
||||||
|
LOCK(cs_nTimeOffset);
|
||||||
// Ignore duplicates
|
// Ignore duplicates
|
||||||
static set<CNetAddr> setKnown;
|
static set<CNetAddr> setKnown;
|
||||||
if (!setKnown.insert(ip).second)
|
if (!setKnown.insert(ip).second)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Add data
|
// Add data
|
||||||
|
static CMedianFilter<int64> vTimeOffsets(200,0);
|
||||||
vTimeOffsets.input(nOffsetSample);
|
vTimeOffsets.input(nOffsetSample);
|
||||||
LogPrintf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60);
|
LogPrintf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60);
|
||||||
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
|
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
|
||||||
|
|
Loading…
Reference in a new issue