Browse Source

Add compile flag to disable compilation of mining code

pull/4/head
Jack Grigg 8 years ago
parent
commit
2cc0a252ad
No known key found for this signature in database GPG Key ID: 6A6914DAFBEA00DA
  1. 17
      configure.ac
  2. 20
      src/Makefile.am
  3. 14
      src/crypto/equihash.cpp
  4. 4
      src/crypto/equihash.h
  5. 6
      src/gtest/test_equihash.cpp
  6. 4
      src/init.cpp
  7. 8
      src/metrics.cpp
  8. 6
      src/miner.cpp
  9. 2
      src/miner.h
  10. 11
      src/rpcmining.cpp
  11. 2
      src/rpcserver.cpp
  12. 8
      src/test/equihash_tests.cpp
  13. 2
      src/wallet/rpcwallet.cpp
  14. 2
      src/zcbenchmarks.cpp
  15. 15
      zcutil/build.sh

17
configure.ac

@ -82,6 +82,12 @@ AC_ARG_ENABLE([wallet],
[enable_wallet=$enableval],
[enable_wallet=yes])
AC_ARG_ENABLE([mining],
[AS_HELP_STRING([--enable-mining],
[enable mining (default is yes)])],
[enable_mining=$enableval],
[enable_mining=yes])
AC_ARG_WITH([miniupnpc],
[AS_HELP_STRING([--with-miniupnpc],
[enable UPNP (default is yes if libminiupnpc is found)])],
@ -790,6 +796,16 @@ else
AC_MSG_RESULT(no)
fi
dnl enable mining
AC_MSG_CHECKING([if mining should be enabled])
if test x$enable_mining != xno; then
AC_MSG_RESULT(yes)
AC_DEFINE(ENABLE_MINING, 1, [Define to 1 to enable mining functions])
else
AC_MSG_RESULT(no)
fi
dnl enable upnp support
AC_MSG_CHECKING([whether to build with support for UPnP])
if test x$have_miniupnpc = xno; then
@ -881,6 +897,7 @@ AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
AM_CONDITIONAL([ENABLE_MINING],[test x$enable_mining = xyes])
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes])

20
src/Makefile.am

@ -248,13 +248,8 @@ libbitcoin_wallet_a_SOURCES = \
$(BITCOIN_CORE_H) \
$(LIBZCASH_H)
EQUIHASH_TROMP_SOURCES = \
pow/tromp/equi_miner.h \
pow/tromp/equi.h \
pow/tromp/osx_barrier.h
# crypto primitives library
crypto_libbitcoin_crypto_a_CPPFLAGS = $(BITCOIN_CONFIG_INCLUDES) -DEQUIHASH_TROMP_ATOMIC
crypto_libbitcoin_crypto_a_CPPFLAGS = $(BITCOIN_CONFIG_INCLUDES)
crypto_libbitcoin_crypto_a_SOURCES = \
crypto/common.h \
crypto/equihash.cpp \
@ -271,8 +266,19 @@ crypto_libbitcoin_crypto_a_SOURCES = \
crypto/sha256.cpp \
crypto/sha256.h \
crypto/sha512.cpp \
crypto/sha512.h \
crypto/sha512.h
if ENABLE_MINING
EQUIHASH_TROMP_SOURCES = \
pow/tromp/equi_miner.h \
pow/tromp/equi.h \
pow/tromp/osx_barrier.h
crypto_libbitcoin_crypto_a_CPPFLAGS += \
-DEQUIHASH_TROMP_ATOMIC
crypto_libbitcoin_crypto_a_SOURCES += \
${EQUIHASH_TROMP_SOURCES}
endif
# univalue JSON library
univalue_libbitcoin_univalue_a_SOURCES = \

14
src/crypto/equihash.cpp

@ -12,6 +12,10 @@
// NDSS ’16, 21-24 February 2016, San Diego, CA, USA
// https://www.internetsociety.org/sites/default/files/blogs-media/equihash-asymmetric-proof-of-work-based-generalized-birthday-problem.pdf
#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
#endif
#include "crypto/equihash.h"
#include "util.h"
@ -319,6 +323,7 @@ std::shared_ptr<eh_trunc> TruncatedStepRow<WIDTH>::GetTruncatedIndices(size_t le
return p;
}
#ifdef ENABLE_MINING
template<unsigned int N, unsigned int K>
bool Equihash<N,K>::BasicSolve(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
@ -711,6 +716,7 @@ invalidsolution:
return false;
}
#endif // ENABLE_MINING
template<unsigned int N, unsigned int K>
bool Equihash<N,K>::IsValidSolution(const eh_HashState& base_state, std::vector<unsigned char> soln)
@ -762,40 +768,48 @@ bool Equihash<N,K>::IsValidSolution(const eh_HashState& base_state, std::vector<
// Explicit instantiations for Equihash<96,3>
template int Equihash<96,3>::InitialiseState(eh_HashState& base_state);
#ifdef ENABLE_MINING
template bool Equihash<96,3>::BasicSolve(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
const std::function<bool(EhSolverCancelCheck)> cancelled);
template bool Equihash<96,3>::OptimisedSolve(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
const std::function<bool(EhSolverCancelCheck)> cancelled);
#endif
template bool Equihash<96,3>::IsValidSolution(const eh_HashState& base_state, std::vector<unsigned char> soln);
// Explicit instantiations for Equihash<200,9>
template int Equihash<200,9>::InitialiseState(eh_HashState& base_state);
#ifdef ENABLE_MINING
template bool Equihash<200,9>::BasicSolve(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
const std::function<bool(EhSolverCancelCheck)> cancelled);
template bool Equihash<200,9>::OptimisedSolve(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
const std::function<bool(EhSolverCancelCheck)> cancelled);
#endif
template bool Equihash<200,9>::IsValidSolution(const eh_HashState& base_state, std::vector<unsigned char> soln);
// Explicit instantiations for Equihash<96,5>
template int Equihash<96,5>::InitialiseState(eh_HashState& base_state);
#ifdef ENABLE_MINING
template bool Equihash<96,5>::BasicSolve(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
const std::function<bool(EhSolverCancelCheck)> cancelled);
template bool Equihash<96,5>::OptimisedSolve(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
const std::function<bool(EhSolverCancelCheck)> cancelled);
#endif
template bool Equihash<96,5>::IsValidSolution(const eh_HashState& base_state, std::vector<unsigned char> soln);
// Explicit instantiations for Equihash<48,5>
template int Equihash<48,5>::InitialiseState(eh_HashState& base_state);
#ifdef ENABLE_MINING
template bool Equihash<48,5>::BasicSolve(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
const std::function<bool(EhSolverCancelCheck)> cancelled);
template bool Equihash<48,5>::OptimisedSolve(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
const std::function<bool(EhSolverCancelCheck)> cancelled);
#endif
template bool Equihash<48,5>::IsValidSolution(const eh_HashState& base_state, std::vector<unsigned char> soln);

4
src/crypto/equihash.h

@ -182,12 +182,14 @@ public:
Equihash() { }
int InitialiseState(eh_HashState& base_state);
#ifdef ENABLE_MINING
bool BasicSolve(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
const std::function<bool(EhSolverCancelCheck)> cancelled);
bool OptimisedSolve(const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
const std::function<bool(EhSolverCancelCheck)> cancelled);
#endif
bool IsValidSolution(const eh_HashState& base_state, std::vector<unsigned char> soln);
};
@ -211,6 +213,7 @@ static Equihash<48,5> Eh48_5;
throw std::invalid_argument("Unsupported Equihash parameters"); \
}
#ifdef ENABLE_MINING
inline bool EhBasicSolve(unsigned int n, unsigned int k, const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
const std::function<bool(EhSolverCancelCheck)> cancelled)
@ -258,6 +261,7 @@ inline bool EhOptimisedSolveUncancellable(unsigned int n, unsigned int k, const
return EhOptimisedSolve(n, k, base_state, validBlock,
[](EhSolverCancelCheck pos) { return false; });
}
#endif // ENABLE_MINING
#define EhIsValidSolution(n, k, base_state, soln, ret) \
if (n == 96 && k == 3) { \

6
src/gtest/test_equihash.cpp

@ -1,3 +1,7 @@
#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
#endif
#include <gtest/gtest.h>
#include <gmock/gmock.h>
@ -76,6 +80,7 @@ TEST(equihash_tests, is_probably_duplicate) {
ASSERT_TRUE(IsProbablyDuplicate<4>(p3, 4));
}
#ifdef ENABLE_MINING
TEST(equihash_tests, check_basic_solver_cancelled) {
Equihash<48,5> Eh48_5;
crypto_generichash_blake2b_state state;
@ -283,3 +288,4 @@ TEST(equihash_tests, check_optimised_solver_cancelled) {
}), EhSolverCancelledException);
}
}
#endif // ENABLE_MINING

4
src/init.cpp

@ -163,7 +163,9 @@ void Shutdown()
#ifdef ENABLE_WALLET
if (pwalletMain)
pwalletMain->Flush(false);
#ifdef ENABLE_MINING
GenerateBitcoins(false, NULL, 0);
#endif
#endif
StopNode();
UnregisterNodeSignals(GetNodeSignals());
@ -1500,7 +1502,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
boost::ref(cs_main), boost::cref(pindexBestHeader), nPowTargetSpacing);
scheduler.scheduleEvery(f, nPowTargetSpacing);
#ifdef ENABLE_WALLET
#if defined(ENABLE_WALLET) && defined(ENABLE_MINING)
// Generate coins in the background
if (pwalletMain)
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1));

8
src/metrics.cpp

@ -128,6 +128,7 @@ int printNetworkStats()
int printMiningStatus(bool mining)
{
#ifdef ENABLE_MINING
// Number of lines that are always displayed
int lines = 1;
@ -151,6 +152,9 @@ int printMiningStatus(bool mining)
std::cout << std::endl;
return lines;
#else // ENABLE_MINING
return 0;
#endif // !ENABLE_MINING
}
int printMetrics(size_t cols, bool mining)
@ -342,7 +346,11 @@ void ThreadShowMetricsScreen()
}
// Miner status
#ifdef ENABLE_MINING
bool mining = GetBoolArg("-gen", false);
#else
bool mining = false;
#endif
if (loaded) {
lines += printNetworkStats();

6
src/miner.cpp

@ -4,7 +4,9 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "miner.h"
#if defined(ENABLE_WALLET) && defined(ENABLE_MINING)
#include "pow/tromp/equi_miner.h"
#endif
#include "amount.h"
#include "chainparams.h"
@ -21,7 +23,9 @@
#include "util.h"
#include "utilmoneystr.h"
#ifdef ENABLE_WALLET
#ifdef ENABLE_MINING
#include "crypto/equihash.h"
#endif
#include "wallet/wallet.h"
#include <functional>
#endif
@ -414,6 +418,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
return CreateNewBlock(scriptPubKey);
}
#ifdef ENABLE_MINING
static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
{
LogPrintf("%s\n", pblock->ToString());
@ -687,4 +692,5 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
}
#endif // ENABLE_MINING
#endif // ENABLE_WALLET

2
src/miner.h

@ -23,8 +23,10 @@ struct CBlockTemplate
std::vector<int64_t> vTxSigOps;
};
#ifdef ENABLE_MINING
/** Run the miner threads */
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads);
#endif
/** Generate a new block, without valid proof-of-work */
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn);
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey);

11
src/rpcmining.cpp

@ -137,7 +137,7 @@ Value getnetworkhashps(const Array& params, bool fHelp)
return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120, params.size() > 1 ? params[1].get_int() : -1);
}
#ifdef ENABLE_WALLET
#if defined(ENABLE_WALLET) && defined(ENABLE_MINING)
Value getgenerate(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
@ -343,7 +343,7 @@ Value getmininginfo(const Array& params, bool fHelp)
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC()));
obj.push_back(Pair("chain", Params().NetworkIDString()));
#ifdef ENABLE_WALLET
#if defined(ENABLE_WALLET) && defined(ENABLE_MINING)
obj.push_back(Pair("generate", getgenerate(params, false)));
#endif
return obj;
@ -466,9 +466,10 @@ Value getblocktemplate(const Array& params, bool fHelp)
LOCK(cs_main);
#ifdef ENABLE_WALLET
// Wallet is required because we support coinbasetxn
if (pwalletMain == NULL) {
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)");
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (wallet disabled)");
}
std::string strMode = "template";
@ -694,6 +695,10 @@ Value getblocktemplate(const Array& params, bool fHelp)
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
return result;
#else // ENABLE_WALLET
// Wallet is required because we support coinbasetxn
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (wallet support not built)");
#endif // !ENABLE_WALLET
}
#endif

2
src/rpcserver.cpp

@ -313,7 +313,7 @@ static const CRPCCommand vRPCCommands[] =
{ "mining", "submitblock", &submitblock, true },
{ "mining", "getblocksubsidy", &getblocksubsidy, true },
#ifdef ENABLE_WALLET
#if defined(ENABLE_WALLET) && defined(ENABLE_MINING)
/* Coin generation */
{ "generating", "getgenerate", &getgenerate, true },
{ "generating", "setgenerate", &setgenerate, true },

8
src/test/equihash_tests.cpp

@ -3,6 +3,10 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
#endif
#include "arith_uint256.h"
#include "crypto/sha256.h"
#include "crypto/equihash.h"
@ -40,6 +44,7 @@ void PrintSolutions(std::stringstream &strm, std::set<std::vector<uint32_t>> sol
strm << "\n}";
}
#ifdef ENABLE_MINING
void TestEquihashSolvers(unsigned int n, unsigned int k, const std::string &I, const arith_uint256 &nonce, const std::set<std::vector<uint32_t>> &solns) {
size_t cBitLen { n/(k+1) };
crypto_generichash_blake2b_state state;
@ -78,6 +83,7 @@ void TestEquihashSolvers(unsigned int n, unsigned int k, const std::string &I, c
BOOST_CHECK(retOpt == solns);
BOOST_CHECK(retOpt == ret);
}
#endif
void TestEquihashValidator(unsigned int n, unsigned int k, const std::string &I, const arith_uint256 &nonce, std::vector<uint32_t> soln, bool expected) {
size_t cBitLen { n/(k+1) };
@ -95,6 +101,7 @@ void TestEquihashValidator(unsigned int n, unsigned int k, const std::string &I,
BOOST_CHECK(isValid == expected);
}
#ifdef ENABLE_MINING
BOOST_AUTO_TEST_CASE(solver_testvectors) {
TestEquihashSolvers(96, 5, "block header", 0, {
{976, 126621, 100174, 123328, 38477, 105390, 38834, 90500, 6411, 116489, 51107, 129167, 25557, 92292, 38525, 56514, 1110, 98024, 15426, 74455, 3185, 84007, 24328, 36473, 17427, 129451, 27556, 119967, 31704, 62448, 110460, 117894},
@ -147,6 +154,7 @@ BOOST_AUTO_TEST_CASE(solver_testvectors) {
{8144, 33053, 33933, 77498, 21356, 110495, 42805, 116575, 27360, 48574, 100682, 102629, 50754, 64608, 96899, 120978, 11924, 74422, 49240, 106822, 12787, 68290, 44314, 50005, 38056, 49716, 83299, 95307, 41798, 82309, 94504, 96161}
});
}
#endif
BOOST_AUTO_TEST_CASE(validator_testvectors) {
// Original valid solution

2
src/wallet/rpcwallet.cpp

@ -2498,6 +2498,7 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp)
}
} else if (benchmarktype == "verifyjoinsplit") {
sample_times.push_back(benchmark_verify_joinsplit(samplejoinsplit));
#ifdef ENABLE_MINING
} else if (benchmarktype == "solveequihash") {
if (params.size() < 3) {
sample_times.push_back(benchmark_solve_equihash());
@ -2506,6 +2507,7 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp)
std::vector<double> vals = benchmark_solve_equihash_threaded(nThreads);
sample_times.insert(sample_times.end(), vals.begin(), vals.end());
}
#endif
} else if (benchmarktype == "verifyequihash") {
sample_times.push_back(benchmark_verify_equihash());
} else if (benchmarktype == "validatelargetx") {

2
src/zcbenchmarks.cpp

@ -126,6 +126,7 @@ double benchmark_verify_joinsplit(const JSDescription &joinsplit)
return timer_stop(tv_start);
}
#ifdef ENABLE_MINING
double benchmark_solve_equihash()
{
CBlock pblock;
@ -173,6 +174,7 @@ std::vector<double> benchmark_solve_equihash_threaded(int nThreads)
}
return ret;
}
#endif // ENABLE_MINING
double benchmark_verify_equihash()
{

15
zcutil/build.sh

@ -33,13 +33,16 @@ Usage:
$0 --help
Show this help message and exit.
$0 [ --enable-lcov || --disable-tests ] [ MAKEARGS... ]
$0 [ --enable-lcov || --disable-tests ] [ --disable-mining ] [ MAKEARGS... ]
Build Zcash and most of its transitive dependencies from
source. MAKEARGS are applied to both dependencies and Zcash itself.
If --enable-lcov is passed, Zcash is configured to add coverage
instrumentation, thus enabling "make cov" to work.
If --disable-tests is passed instead, the Zcash tests are not built.
If --disable-mining is passed, Zcash is configured to not build any mining
code. It must be passed after the test arguments, if present.
EOF
exit 0
fi
@ -62,9 +65,17 @@ then
shift
fi
# If --disable-mining is the next argument, disable mining code:
MINING_ARG=''
if [ "x${1:-}" = 'x--disable-mining' ]
then
MINING_ARG='--enable-mining=no'
shift
fi
PREFIX="$(pwd)/depends/$BUILD/"
HOST="$HOST" BUILD="$BUILD" "$MAKE" "$@" -C ./depends/ V=1 NO_QT=1
./autogen.sh
CC="$CC" CXX="$CXX" ./configure --prefix="${PREFIX}" --host="$HOST" --build="$BUILD" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" "$TEST_ARG" CXXFLAGS='-fwrapv -fno-strict-aliasing -Werror -g'
CC="$CC" CXX="$CXX" ./configure --prefix="${PREFIX}" --host="$HOST" --build="$BUILD" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" "$TEST_ARG" "$MINING_ARG" CXXFLAGS='-fwrapv -fno-strict-aliasing -Werror -g'
"$MAKE" "$@" V=1

Loading…
Cancel
Save