From a5de7c91c641151c74ed523edd86aeaf197ccebb Mon Sep 17 00:00:00 2001 From: div72 <60045611+div72@users.noreply.github.com> Date: Mon, 23 Aug 2021 17:03:28 +0300 Subject: [PATCH] refactor: separate clientversion from version --- .gitattributes | 2 +- Makefile.am | 2 +- src/Makefile.am | 5 ++- src/addrdb.cpp | 2 +- src/alert.cpp | 1 + src/clientversion.cpp | 75 ++++++++++++++++++++++++++++++++++ src/clientversion.h | 47 +++++++++++++++++++++ src/dbwrapper.cpp | 3 +- src/dbwrapper.h | 1 + src/gridcoinresearchd-res.rc | 2 +- src/init.cpp | 2 +- src/node/blockstorage.cpp | 1 + src/qt/clientmodel.cpp | 6 +-- src/qt/clientmodel.h | 1 - src/qt/forms/rpcconsole.ui | 23 ----------- src/qt/res/gridcoinresearch.rc | 2 +- src/qt/rpcconsole.cpp | 1 - src/util.cpp | 34 --------------- src/version.cpp | 73 --------------------------------- src/version.h | 37 +---------------- src/wallet/db.h | 2 +- src/wallet/rpcdump.cpp | 3 +- 22 files changed, 140 insertions(+), 185 deletions(-) create mode 100644 src/clientversion.cpp create mode 100644 src/clientversion.h delete mode 100644 src/version.cpp diff --git a/.gitattributes b/.gitattributes index 883d13a97d..8e1e29f804 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ -src/version.cpp export-subst +src/clientversion.cpp export-subst # Auto detect text files and perform LF normalization * text=auto diff --git a/Makefile.am b/Makefile.am index cdc20984c3..a8dbff5f77 100644 --- a/Makefile.am +++ b/Makefile.am @@ -61,7 +61,7 @@ nobase_icons_DATA = $(DIST_ICONS) endif dist-hook: - -$(GIT) archive --format=tar HEAD -- src/version.cpp | $(AMTAR) -C $(top_distdir) -xf - + -$(GIT) archive --format=tar HEAD -- src/clientversion.cpp | $(AMTAR) -C $(top_distdir) -xf - $(BITCOIN_WIN_INSTALLER): all-recursive $(MKDIR_P) $(top_builddir)/release diff --git a/src/Makefile.am b/src/Makefile.am index b6fd5f6c58..4c67f1f427 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -73,6 +73,7 @@ GRIDCOIN_CORE_H = \ chainparams.h \ chainparamsbase.h \ checkpoints.h \ + clientversion.h \ compat.h \ compat/assumptions.h \ compat/byteswap.h \ @@ -203,6 +204,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \ chainparams.cpp \ chainparamsbase.cpp \ checkpoints.cpp \ + clientversion.cpp \ consensus/merkle.cpp \ consensus/tx_verify.cpp \ crypter.cpp \ @@ -282,7 +284,6 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \ util/time.cpp \ util.cpp \ validation.cpp \ - version.cpp \ wallet/db.cpp \ wallet/rpcdump.cpp \ wallet/rpcwallet.cpp \ @@ -294,7 +295,7 @@ obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj @$(top_srcdir)/share/genbuild.sh "$(abs_top_builddir)/src/obj/build.h" \ "$(abs_top_srcdir)" -libgridcoin_util_a-version.$(OBJEXT): obj/build.h +libgridcoin_util_a-clientversion.$(OBJEXT): obj/build.h # util: shared between all executables. # This library *must* be included to make sure that the glibc diff --git a/src/addrdb.cpp b/src/addrdb.cpp index b20e04739b..68d57a9f3c 100644 --- a/src/addrdb.cpp +++ b/src/addrdb.cpp @@ -7,7 +7,7 @@ #include #include -// #include +#include #include // #include // #include diff --git a/src/alert.cpp b/src/alert.cpp index e3c70b476e..ee8abf3844 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -10,6 +10,7 @@ #include "alert.h" #include "chainparams.h" +#include "clientversion.h" #include "key.h" #include "net.h" #include "streams.h" diff --git a/src/clientversion.cpp b/src/clientversion.cpp new file mode 100644 index 0000000000..f5975a9d9e --- /dev/null +++ b/src/clientversion.cpp @@ -0,0 +1,75 @@ +// Copyright (c) 2012-2020 The Bitcoin Core developers +// Copyright (c) 2021 The Gridcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include + + +/** + * Name of client reported in the 'version' message. Report the same name + * for both gridcoinresearchd and gridcoinresearch-qt, to make it harder for attackers to + * target servers or GUI users specifically. + */ +const std::string CLIENT_NAME("Halford"); + + +#ifdef HAVE_BUILD_INFO +#include "build.h" +// The , which is generated by the build environment (share/genbuild.sh), +// could contain only one line of the following: +// - "#define BUILD_GIT_TAG ...", if the top commit is tagged +// - "#define BUILD_GIT_COMMIT ...", if the top commit is not tagged +// - "// No build information available", if proper git information is not available +#endif + +//! git will put "#define GIT_COMMIT_ID ..." on the next line inside archives. $Format:%n#define GIT_COMMIT_ID "%H"$ + +#ifdef BUILD_GIT_TAG + #define BUILD_DESC BUILD_GIT_TAG + #define BUILD_SUFFIX "" +#else + #define BUILD_DESC "v" PACKAGE_VERSION + #if CLIENT_VERSION_IS_RELEASE + #define BUILD_SUFFIX "" + #elif defined(BUILD_GIT_COMMIT) + #define BUILD_SUFFIX "-" BUILD_GIT_COMMIT + #elif defined(GIT_COMMIT_ID) + #define BUILD_SUFFIX "-g" GIT_COMMIT_ID + #else + #define BUILD_SUFFIX "-unk" + #endif +#endif + +static std::string FormatVersion(int nVersion) +{ + return strprintf("%d.%d.%d", nVersion / 10000, (nVersion / 100) % 100, nVersion % 100); +} + +std::string FormatFullVersion() +{ + static const std::string CLIENT_BUILD(BUILD_DESC BUILD_SUFFIX); + return CLIENT_BUILD; +} + +/** + * Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki) + */ +std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector& comments) +{ + std::ostringstream ss; + ss << "/"; + ss << name << ":" << FormatVersion(nClientVersion); + if (!comments.empty()) + { + std::vector::const_iterator it(comments.begin()); + ss << "(" << *it; + for(++it; it != comments.end(); ++it) + ss << "; " << *it; + ss << ")"; + } + ss << "/"; + return ss.str(); +} diff --git a/src/clientversion.h b/src/clientversion.h new file mode 100644 index 0000000000..944853ea39 --- /dev/null +++ b/src/clientversion.h @@ -0,0 +1,47 @@ +// Copyright (c) 2009-2020 The Bitcoin Core developers +// Copyright (c) 2021 The Gridcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or https://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_CLIENTVERSION_H +#define BITCOIN_CLIENTVERSION_H + +#include + +#if defined(HAVE_CONFIG_H) +#include +#endif //HAVE_CONFIG_H + +// Check that required client information is defined +#if !defined(CLIENT_VERSION_MAJOR) || !defined(CLIENT_VERSION_MINOR) || !defined(CLIENT_VERSION_BUILD) || !defined(CLIENT_VERSION_IS_RELEASE) || !defined(COPYRIGHT_YEAR) +#error Client version information missing: version is not defined by gridcoin-config.h or in any other way +#endif + +//! Copyright string used in Windows .rc files +#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " " COPYRIGHT_HOLDERS_FINAL + +/** + * bitcoind-res.rc includes this file, but it cannot cope with real c++ code. + * WINDRES_PREPROC is defined to indicate that its pre-processor is running. + * Anything other than a define should be guarded below. + */ + +#if !defined(WINDRES_PREPROC) + +#include +#include + +static const int CLIENT_VERSION = + 10000 * CLIENT_VERSION_MAJOR + + 100 * CLIENT_VERSION_MINOR + + 1 * CLIENT_VERSION_BUILD; + +extern const std::string CLIENT_NAME; + + +std::string FormatFullVersion(); +std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector& comments); + +#endif // WINDRES_PREPROC + +#endif // BITCOIN_CLIENTVERSION_H diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index c19c4387aa..777006a060 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -5,14 +5,13 @@ #include -#include - #include #include #include #include #include "chainparams.h" +#include "clientversion.h" #include "gridcoin/staking/kernel.h" #include "txdb.h" #include "main.h" diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 8539b2c319..0a801b9708 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -6,6 +6,7 @@ #ifndef BITCOIN_DBWRAPPER_H #define BITCOIN_DBWRAPPER_H +#include "clientversion.h" #include "main.h" #include "streams.h" diff --git a/src/gridcoinresearchd-res.rc b/src/gridcoinresearchd-res.rc index c649dc338f..65981b398a 100644 --- a/src/gridcoinresearchd-res.rc +++ b/src/gridcoinresearchd-res.rc @@ -1,5 +1,5 @@ #include // needed for VERSIONINFO -#include "version.h" // holds the needed client version information +#include "clientversion.h" // holds the needed client version information #define VER_PRODUCTVERSION CLIENT_VERSION_MAJOR,CLIENT_VERSION_MINOR,CLIENT_VERSION_REVISION,CLIENT_VERSION_BUILD #define VER_PRODUCTVERSION_STR STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) "." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD) diff --git a/src/init.cpp b/src/init.cpp index 6591ea268e..b6bc0cc267 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -711,7 +711,7 @@ void InitLogging() #else build_type = "release build"; #endif - LogPrintf(PACKAGE_NAME " version %s (%s - %s)", FormatFullVersion(), build_type, CLIENT_DATE); + LogPrintf(PACKAGE_NAME " version %s (%s)", FormatFullVersion(), build_type); } diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index ded7b6c08d..86cc2e7e57 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -4,6 +4,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "chainparams.h" +#include "clientversion.h" #include "main.h" #include "protocol.h" #include "serialize.h" diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index ae83d4cb3a..4422256fe0 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -7,6 +7,7 @@ #include "transactiontablemodel.h" #include "alert.h" +#include "clientversion.h" #include "main.h" #include "gridcoin/scraper/fwd.h" #include "gridcoin/staking/difficulty.h" @@ -250,11 +251,6 @@ QString ClientModel::formatFullVersion() const return QString::fromStdString(FormatFullVersion()); } -QString ClientModel::formatBuildDate() const -{ - return QString::fromStdString(CLIENT_DATE); -} - QString ClientModel::clientName() const { return QString::fromStdString(CLIENT_NAME); diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index cc86a7ca70..a5b4993e9b 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -55,7 +55,6 @@ class ClientModel : public QObject QString getMinerWarnings() const; QString formatFullVersion() const; - QString formatBuildDate() const; QString clientName() const; QString formatClientStartupTime() const; diff --git a/src/qt/forms/rpcconsole.ui b/src/qt/forms/rpcconsole.ui index 7782bf6a2c..f4f637a714 100755 --- a/src/qt/forms/rpcconsole.ui +++ b/src/qt/forms/rpcconsole.ui @@ -107,13 +107,6 @@ - - - - Build date - - - @@ -166,22 +159,6 @@ - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - - diff --git a/src/qt/res/gridcoinresearch.rc b/src/qt/res/gridcoinresearch.rc index 7469379469..89579f742e 100644 --- a/src/qt/res/gridcoinresearch.rc +++ b/src/qt/res/gridcoinresearch.rc @@ -2,7 +2,7 @@ IDI_ICON1 ICON DISCARDABLE "icons/gridcoin.ico" IDI_ICON2 ICON DISCARDABLE "icons/gridcoin_testnet.ico" #include // needed for VERSIONINFO -#include "../../version.h" // holds the needed client version information +#include "../../clientversion.h" // holds the needed client version information #define VER_PRODUCTVERSION CLIENT_VERSION_MAJOR,CLIENT_VERSION_MINOR,CLIENT_VERSION_REVISION,CLIENT_VERSION_BUILD #define VER_PRODUCTVERSION_STR STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) "." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index b2b51e95bb..edeb08eedc 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -389,7 +389,6 @@ void RPCConsole::setClientModel(ClientModel *model) ui->clientVersion->setText(cvi); ui->clientName->setText(model->clientName()); - ui->buildDate->setText(model->formatBuildDate()); ui->startupTime->setText(model->formatClientStartupTime()); setNumConnections(model->getNumConnections()); diff --git a/src/util.cpp b/src/util.cpp index 898024e969..a9a2907482 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -13,8 +13,6 @@ #include #include -#include -#include // for startswith() and endswith() #include //For day of year #include #include @@ -485,25 +483,6 @@ void seed_insecure_rand(bool fDeterministic) } } -string FormatVersion(int nVersion) -{ - if (nVersion%100 == 0) - return strprintf("%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100); - else - return strprintf("%d.%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100, nVersion%100); -} - -#ifndef UPGRADERFLAG -// avoid including unnecessary files for standalone upgrader - - -string FormatFullVersion() -{ - return CLIENT_BUILD; -} - -#endif - double Round(double d, int place) { const double accuracy = std::pow(10, place); @@ -553,19 +532,6 @@ std::vector split(const std::string& s, const std::string& delim) return elems; } -// Format the subversion field according to BIP 14 spec (https://en.bitcoin.it/wiki/BIP_0014) -std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector& comments) -{ - std::ostringstream ss; - ss << "/"; - ss << name << ":" << FormatVersion(nClientVersion); - - if (!comments.empty()) ss << "(" << boost::algorithm::join(comments, "; ") << ")"; - - ss << "/"; - return ss.str(); -} - void runCommand(std::string strCommand) { int nErr = ::system(strCommand.c_str()); diff --git a/src/version.cpp b/src/version.cpp deleted file mode 100644 index 89e30d9470..0000000000 --- a/src/version.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2012 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or https://opensource.org/licenses/mit-license.php. -#include - -#include "version.h" - -// Name of client reported in the 'version' message. Report the same name -// for both bitcoind and bitcoin-qt, to make it harder for attackers to -// target servers or GUI users specifically. -const std::string CLIENT_NAME("Halford"); - -// Client version number -#define CLIENT_VERSION_SUFFIX "" - - -// The following part of the code determines the CLIENT_BUILD variable. -// Several mechanisms are used for this: -// * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is -// generated by the build environment, possibly containing the output -// of git-describe in a macro called BUILD_DESC -// * secondly, if this is an exported version of the code, GIT_ARCHIVE will -// be defined (automatically using the export-subst git attribute), and -// GIT_COMMIT will contain the commit id. -// * then, three options exist for determining CLIENT_BUILD: -// * if BUILD_DESC is defined, use that literally (output of git-describe) -// * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit] -// * otherwise, use v[maj].[min].[rev].[build]-unk -// finally CLIENT_VERSION_SUFFIX is added - -// First, include build.h if requested -#ifdef HAVE_BUILD_INFO -# include "build.h" -#endif - -// git will put "#define GIT_ARCHIVE 1" on the next line inside archives. -//#define GIT_ARCHIVE 1 -#ifdef GIT_ARCHIVE -# define GIT_COMMIT_ID "-research" -# define GIT_COMMIT_DATE "12/1/2014" -#endif - -#define BUILD_DESC_FROM_COMMIT(maj,min,rev,build,commit) \ - "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit - -#define BUILD_DESC_FROM_UNKNOWN(maj,min,rev,build) \ - "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unk" - -#ifndef BUILD_DESC -# ifdef GIT_COMMIT_ID -# define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID) -# elif defined (BUILD_DESCHASH) -# define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, BUILD_DESCHASH) -# else -# define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD) -# endif -#endif - -#ifndef BUILD_DATE -# ifdef GIT_COMMIT_DATE -# define BUILD_DATE GIT_COMMIT_DATE -# else -# define BUILD_DATE __DATE__ ", " __TIME__ -# endif -#endif - -const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX); -const std::string CLIENT_DATE(BUILD_DATE); - -int MINOR_VERSION = 317; - - - diff --git a/src/version.h b/src/version.h index 581bbf2650..4948ba4a2b 100644 --- a/src/version.h +++ b/src/version.h @@ -1,45 +1,10 @@ // Copyright (c) 2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or https://opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_VERSION_H #define BITCOIN_VERSION_H -#include "config/gridcoin-config.h" - -// Converts the parameter X to a string after macro replacement on X has been performed. -// Don't merge these into one macro! -#define STRINGIZE(X) DO_STRINGIZE(X) -#define DO_STRINGIZE(X) #X - -#define COPYRIGHT_STR "2009-2012" STRINGIZE(COPYRIGHT_YEAR) " The Bitcoin Core Developers" - -/** - * bitcoind-res.rc includes this file, but it cannot cope with real c++ code. - * WINDRES_PREPROC is defined to indicate that its pre-processor is running. - * Anything other than a define should be guarded below. - */ - -#if !defined(WINDRES_PREPROC) - -#include -#include - -static const int CLIENT_VERSION = - 1000000 * CLIENT_VERSION_MAJOR - + 10000 * CLIENT_VERSION_MINOR - + 100 * CLIENT_VERSION_REVISION - + 1 * CLIENT_VERSION_BUILD; - -extern const std::string CLIENT_NAME; -extern const std::string CLIENT_BUILD; -extern const std::string CLIENT_DATE; - - -std::string FormatFullVersion(); -std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector& comments); - -#endif // WINDRES_PREPROC - /////////////////////////////////////////////////////////// // network protocol versioning // // // diff --git a/src/wallet/db.h b/src/wallet/db.h index 67033b7fe1..4a2c8c112e 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -6,10 +6,10 @@ #ifndef BITCOIN_WALLET_DB_H #define BITCOIN_WALLET_DB_H +#include "clientversion.h" #include "fs.h" #include "streams.h" #include "sync.h" -#include "version.h" #include #include diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index d5406eb6e0..3accc4600d 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or https://opensource.org/licenses/mit-license.php. +#include "clientversion.h" #include "fs.h" #include "init.h" // for pwalletMain #include "rpc/server.h" @@ -345,7 +346,7 @@ UniValue dumpwallet(const UniValue& params, bool fHelp) std::sort(vKeyBirth.begin(), vKeyBirth.end()); // produce output - file << strprintf("# Wallet dump created by Gridcoin %s (%s)\n", CLIENT_BUILD, CLIENT_DATE); + file << strprintf("# Wallet dump created by Gridcoin %s\n", FormatFullVersion()); file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime())); file << strprintf("# * Best block at time of backup was %i (%s),\n", nBestHeight, hashBestChain.ToString()); file << strprintf("# mined on %s\n", EncodeDumpTime(pindexBest->nTime));