Skip to content

Commit

Permalink
Disable time offset (#30)
Browse files Browse the repository at this point in the history
* Disable time offsets for now

* Change function name to uppercase

* Minor change in time offset check + warning update
  • Loading branch information
aistrych authored and JRedinger committed Mar 20, 2019
1 parent 2d05810 commit 5baebc8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3209,8 +3209,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,

pfrom->fClient = !(pfrom->nServices & NODE_NETWORK);

if (GetBoolArg("-synctime", true))
AddTimeData(pfrom->addr, nTime);
AddTimeData(pfrom->addr, nTime, GetBoolArg("-synctime", false));

// Change version
pfrom->PushMessage("verack");
Expand Down
4 changes: 2 additions & 2 deletions src/qt/bitcoinstrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ QT_TRANSLATE_NOOP("bitcoin-core", ""
QT_TRANSLATE_NOOP("bitcoin-core", "Invalid amount"),
QT_TRANSLATE_NOOP("bitcoin-core", "Insufficient funds"),
QT_TRANSLATE_NOOP("bitcoin-core", ""
"Warning: Please check that your computer's date and time are correct! If "
"your clock is wrong Pinkcoin will not work properly."),
"Warning: Please check that your computer's date and time are correct! "
"If your clock is wrong Pinkcoin will not work properly."),
QT_TRANSLATE_NOOP("bitcoin-core", "Warning: This version is obsolete, upgrade required!"),
QT_TRANSLATE_NOOP("bitcoin-core", "WARNING: syncronized checkpoint violation detected, but skipped!"),
QT_TRANSLATE_NOOP("bitcoin-core", "Warning: Disk space is low!"),
Expand Down
63 changes: 41 additions & 22 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,36 @@ int64_t GetAdjustedTime()
return GetTime() + GetTimeOffset();
}

void AddTimeData(const CNetAddr& ip, int64_t nTime)
void CompareTimeWithPeers(const std::vector<int64_t>& vSorted)
{
static bool fDone;
if (!fDone)
{
// If nobody has a time different than ours but within 30 seconds of ours, give a warning
bool fMatch = false;
BOOST_FOREACH(int64_t nOffset, vSorted)
if (nOffset != 0 && abs64(nOffset) < 30)
fMatch = true;

if (!fMatch)
{
fDone = true;
string strMessage = _(
"Warning: Please check that your computer's date and time are correct! "
"If your clock is wrong Pinkcoin will not work properly."
);
strMiscWarning = strMessage;
printf("*** %s\n", strMessage.c_str());
uiInterface.ThreadSafeMessageBox(
strMessage+" ",
string("Pinkcoin"),
CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION
);
}
}
}

void AddTimeData(const CNetAddr& ip, int64_t nTime, bool fSyncTime)
{
int64_t nOffsetSample = nTime - GetTime();

Expand Down Expand Up @@ -1214,37 +1243,27 @@ void AddTimeData(const CNetAddr& ip, int64_t nTime)
// So we should hold off on fixing this and clean it up as part of
// a timing cleanup that strengthens it in a number of other ways.
//
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
// No time offset adjustment. Just Compare node
// local time with peers and displays warning if offset it to big.
if (!fSyncTime)
{
if (vTimeOffsets.size() >= 5)
CompareTimeWithPeers(vTimeOffsets.sorted());
}
else if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
{
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) < 70 * 60)
if (abs64(nMedian) < 30)
{
nTimeOffset = nMedian;
}
else
{
nTimeOffset = 0;

static bool fDone;
if (!fDone)
{
// If nobody has a time different than ours but within 5 minutes of ours, give a warning
bool fMatch = false;
BOOST_FOREACH(int64_t nOffset, vSorted)
if (nOffset != 0 && abs64(nOffset) < 5 * 60)
fMatch = true;

if (!fMatch)
{
fDone = true;
string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong Pinkcoin will not work properly.");
strMiscWarning = strMessage;
printf("*** %s\n", strMessage.c_str());
uiInterface.ThreadSafeMessageBox(strMessage+" ", string("Pinkcoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION);
}
}
CompareTimeWithPeers(vSorted);
}
if (fDebug) {
BOOST_FOREACH(int64_t n, vSorted)
Expand Down
3 changes: 2 additions & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ int64_t GetAdjustedTime();
int64_t GetTimeOffset();
std::string FormatFullVersion();
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
void AddTimeData(const CNetAddr& ip, int64_t nTime);
void CompareTimeWithPeers(const std::vector<int64_t>& vSorted);
void AddTimeData(const CNetAddr& ip, int64_t nTime, bool fSyncTime = false);
void runCommand(std::string strCommand);


Expand Down

0 comments on commit 5baebc8

Please sign in to comment.