Skip to content

Commit

Permalink
Merge 10282 via timebomb_knots-0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Nov 11, 2017
3 parents 333528e + a268347 + b71f948 commit 647f952
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/bitcoind.cpp
Expand Up @@ -130,6 +130,11 @@ bool AppInit(int argc, char* argv[])
}
}

if (IsThisSoftwareExpired(GetTime())) {
fprintf(stderr, "This software is expired, and may be out of consensus. You must choose to upgrade or override this expiration.\n");
exit(EXIT_FAILURE);
}

// -server defaults to true for bitcoind but not for the GUI so do this here
gArgs.SoftSetBoolArg("-server", true);
// Set this early so that parameter interactions go to console
Expand Down
11 changes: 11 additions & 0 deletions src/clientversion.cpp
Expand Up @@ -5,6 +5,8 @@
#include "clientversion.h"

#include "tinyformat.h"
#include "utiltime.h"
#include "util.h"

#include <string>

Expand Down Expand Up @@ -101,3 +103,12 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const
ss << "/";
return ss.str();
}

bool IsThisSoftwareExpired(int64_t nTime)
{
int64_t nSoftwareExpiry = gArgs.GetArg("-softwareexpiry", DEFAULT_SOFTWARE_EXPIRY);
if (nSoftwareExpiry <= 0) {
nSoftwareExpiry = std::numeric_limits<int64_t>::max();
}
return (nTime > nSoftwareExpiry);
}
6 changes: 6 additions & 0 deletions src/clientversion.h
Expand Up @@ -48,6 +48,12 @@ extern const std::string CLIENT_BUILD;
std::string FormatFullVersion();
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);

static const int64_t SECONDS_PER_YEAR = 31558060;
static const int POSIX_EPOCH_YEAR = 1970;
static const int64_t DEFAULT_SOFTWARE_EXPIRY = ((COPYRIGHT_YEAR - POSIX_EPOCH_YEAR) * SECONDS_PER_YEAR) + (SECONDS_PER_YEAR * 2);

bool IsThisSoftwareExpired(int64_t nTime);

#endif // WINDRES_PREPROC

#endif // BITCOIN_CLIENTVERSION_H
4 changes: 4 additions & 0 deletions src/init.cpp
Expand Up @@ -14,6 +14,7 @@
#include "chain.h"
#include "chainparams.h"
#include "checkpoints.h"
#include "clientversion.h"
#include "compat/sanity.h"
#include "consensus/validation.h"
#include "fs.h"
Expand Down Expand Up @@ -380,6 +381,9 @@ std::string HelpMessage(HelpMessageMode mode)
}
strUsage += HelpMessageOpt("-persistmempool", strprintf(_("Whether to save the mempool on shutdown and load on restart (default: %u)"), DEFAULT_PERSIST_MEMPOOL));
strUsage += HelpMessageOpt("-blockreconstructionextratxn=<n>", strprintf(_("Extra transactions to keep in memory for compact block reconstructions (default: %u)"), DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN));
if (showDebug) {
strUsage += HelpMessageOpt("-softwareexpiry", strprintf("Stop working after this POSIX timestamp (default: %s)", DEFAULT_SOFTWARE_EXPIRY));
}
strUsage += HelpMessageOpt("-par=<n>", strprintf(_("Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)"),
-GetNumCores(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS));
#ifndef WIN32
Expand Down
6 changes: 6 additions & 0 deletions src/qt/bitcoin.cpp
Expand Up @@ -26,6 +26,7 @@
#include "walletmodel.h"
#endif

#include "clientversion.h"
#include "init.h"
#include "rpc/server.h"
#include "scheduler.h"
Expand Down Expand Up @@ -675,6 +676,11 @@ int main(int argc, char *argv[])
// Re-initialize translations after changing application name (language in network-specific settings can be different)
initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);

if (IsThisSoftwareExpired(GetTime())) {
QMessageBox::critical(0, QObject::tr("Software expired"), QObject::tr("This software is expired, and may be out of consensus. You must choose to upgrade or override this expiration."));
return EXIT_FAILURE;
}

#ifdef ENABLE_WALLET
/// 8. URI IPC sending
// - Do this early as we don't want to bother initializing if we are just calling IPC
Expand Down
5 changes: 5 additions & 0 deletions src/validation.cpp
Expand Up @@ -10,6 +10,7 @@
#include "chainparams.h"
#include "checkpoints.h"
#include "checkqueue.h"
#include "clientversion.h"
#include "consensus/consensus.h"
#include "consensus/merkle.h"
#include "consensus/tx_verify.h"
Expand Down Expand Up @@ -2872,6 +2873,10 @@ static bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state,
if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits, consensusParams))
return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed");

if (IsThisSoftwareExpired(block.nTime)) {
return state.DoS(0, false, REJECT_INVALID, "node-expired", true, "node software has expired");
}

return true;
}

Expand Down

0 comments on commit 647f952

Please sign in to comment.