Browse Source

Allow mining RPCs with --disable-wallet

The following mining-related RPC calls don't use the wallet:

- getnetworkhashps
- getmininginfo
- getblocktemplate
- submitblock

Enable them when compiling with --disable-wallet.
0.10
Wladimir J. van der Laan 11 years ago
parent
commit
4a85e06750
  1. 4
      doc/build-unix.md
  2. 4
      src/Makefile.am
  3. 4
      src/init.cpp
  4. 9
      src/miner.cpp
  5. 24
      src/rpcmining.cpp
  6. 19
      src/rpcserver.cpp

4
doc/build-unix.md

@ -187,3 +187,7 @@ disable-wallet mode with:
./configure --disable-wallet ./configure --disable-wallet
In this case there is no dependency on Berkeley DB 4.8. In this case there is no dependency on Berkeley DB 4.8.
Mining is also possible in disable-wallet mode, but only using the `getblocktemplate` RPC
call not `getwork`.

4
src/Makefile.am

@ -48,9 +48,11 @@ libbitcoin_server_a_SOURCES = \
keystore.cpp \ keystore.cpp \
leveldbwrapper.cpp \ leveldbwrapper.cpp \
main.cpp \ main.cpp \
miner.cpp \
net.cpp \ net.cpp \
noui.cpp \ noui.cpp \
rpcblockchain.cpp \ rpcblockchain.cpp \
rpcmining.cpp \
rpcnet.cpp \ rpcnet.cpp \
rpcrawtransaction.cpp \ rpcrawtransaction.cpp \
txdb.cpp \ txdb.cpp \
@ -61,9 +63,7 @@ libbitcoin_server_a_SOURCES = \
libbitcoin_wallet_a_SOURCES = \ libbitcoin_wallet_a_SOURCES = \
db.cpp \ db.cpp \
crypter.cpp \ crypter.cpp \
miner.cpp \
rpcdump.cpp \ rpcdump.cpp \
rpcmining.cpp \
rpcwallet.cpp \ rpcwallet.cpp \
wallet.cpp \ wallet.cpp \
walletdb.cpp \ walletdb.cpp \

4
src/init.cpp

@ -113,8 +113,8 @@ void Shutdown()
RenameThread("bitcoin-shutoff"); RenameThread("bitcoin-shutoff");
mempool.AddTransactionsUpdated(1); mempool.AddTransactionsUpdated(1);
StopRPCThreads(); StopRPCThreads();
#ifdef ENABLE_WALLET
ShutdownRPCMining(); ShutdownRPCMining();
#ifdef ENABLE_WALLET
if (pwalletMain) if (pwalletMain)
bitdb.Flush(false); bitdb.Flush(false);
GenerateBitcoins(false, NULL, 0); GenerateBitcoins(false, NULL, 0);
@ -1041,10 +1041,8 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
#endif #endif
StartNode(threadGroup); StartNode(threadGroup);
#ifdef ENABLE_WALLET
// InitRPCMining is needed here so getwork/getblocktemplate in the GUI debug console works properly. // InitRPCMining is needed here so getwork/getblocktemplate in the GUI debug console works properly.
InitRPCMining(); InitRPCMining();
#endif
if (fServer) if (fServer)
StartRPCThreads(); StartRPCThreads();

9
src/miner.cpp

@ -10,8 +10,11 @@
#include "net.h" #include "net.h"
#include "wallet.h" #include "wallet.h"
#ifdef ENABLE_WALLET
// These globals are only used by the built-in miner
double dHashesPerSec = 0.0; double dHashesPerSec = 0.0;
int64_t nHPSTimerStart = 0; int64_t nHPSTimerStart = 0;
#endif
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
@ -381,6 +384,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
return pblocktemplate.release(); return pblocktemplate.release();
} }
#ifdef ENABLE_WALLET
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
{ {
CPubKey pubkey; CPubKey pubkey;
@ -390,6 +394,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
CScript scriptPubKey = CScript() << pubkey << OP_CHECKSIG; CScript scriptPubKey = CScript() << pubkey << OP_CHECKSIG;
return CreateNewBlock(scriptPubKey); return CreateNewBlock(scriptPubKey);
} }
#endif
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce) void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
{ {
@ -454,7 +459,7 @@ void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash
memcpy(phash1, &tmp.hash1, 64); memcpy(phash1, &tmp.hash1, 64);
} }
#ifdef ENABLE_WALLET
bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey) bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
{ {
uint256 hash = pblock->GetHash(); uint256 hash = pblock->GetHash();
@ -665,5 +670,5 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
} }
#endif

24
src/rpcmining.cpp

@ -20,7 +20,8 @@
using namespace json_spirit; using namespace json_spirit;
using namespace std; using namespace std;
// Key used by getwork/getblocktemplate miners. #ifdef ENABLE_WALLET
// Key used by getwork miners.
// Allocated in InitRPCMining, free'd in ShutdownRPCMining // Allocated in InitRPCMining, free'd in ShutdownRPCMining
static CReserveKey* pMiningKey = NULL; static CReserveKey* pMiningKey = NULL;
@ -40,6 +41,14 @@ void ShutdownRPCMining()
delete pMiningKey; pMiningKey = NULL; delete pMiningKey; pMiningKey = NULL;
} }
#else
void InitRPCMining()
{
}
void ShutdownRPCMining()
{
}
#endif
// Return average network hashes per second based on the last 'lookup' blocks, // Return average network hashes per second based on the last 'lookup' blocks,
// or from the last difficulty change if 'lookup' is nonpositive. // or from the last difficulty change if 'lookup' is nonpositive.
@ -99,7 +108,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); return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120, params.size() > 1 ? params[1].get_int() : -1);
} }
#ifdef ENABLE_WALLET
Value getgenerate(const Array& params, bool fHelp) Value getgenerate(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() != 0) if (fHelp || params.size() != 0)
@ -197,7 +206,6 @@ Value setgenerate(const Array& params, bool fHelp)
return Value::null; return Value::null;
} }
Value gethashespersec(const Array& params, bool fHelp) Value gethashespersec(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() != 0) if (fHelp || params.size() != 0)
@ -216,6 +224,7 @@ Value gethashespersec(const Array& params, bool fHelp)
return (boost::int64_t)0; return (boost::int64_t)0;
return (boost::int64_t)dHashesPerSec; return (boost::int64_t)dHashesPerSec;
} }
#endif
Value getmininginfo(const Array& params, bool fHelp) Value getmininginfo(const Array& params, bool fHelp)
@ -248,16 +257,19 @@ Value getmininginfo(const Array& params, bool fHelp)
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx)); obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("errors", GetWarnings("statusbar")));
obj.push_back(Pair("generate", getgenerate(params, false)));
obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1))); obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1)));
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
obj.push_back(Pair("networkhashps", getnetworkhashps(params, false))); obj.push_back(Pair("networkhashps", getnetworkhashps(params, false)));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
obj.push_back(Pair("testnet", TestNet())); obj.push_back(Pair("testnet", TestNet()));
#ifdef ENABLE_WALLET
obj.push_back(Pair("generate", getgenerate(params, false)));
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
#endif
return obj; return obj;
} }
#ifdef ENABLE_WALLET
Value getwork(const Array& params, bool fHelp) Value getwork(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() > 1) if (fHelp || params.size() > 1)
@ -381,7 +393,7 @@ Value getwork(const Array& params, bool fHelp)
return CheckWork(pblock, *pwalletMain, *pMiningKey); return CheckWork(pblock, *pwalletMain, *pMiningKey);
} }
} }
#endif
Value getblocktemplate(const Array& params, bool fHelp) Value getblocktemplate(const Array& params, bool fHelp)
{ {

19
src/rpcserver.cpp

@ -248,12 +248,14 @@ static const CRPCCommand vRPCCommands[] =
{ "gettxout", &gettxout, true, false, false }, { "gettxout", &gettxout, true, false, false },
{ "verifychain", &verifychain, true, false, false }, { "verifychain", &verifychain, true, false, false },
#ifdef ENABLE_WALLET /* Mining */
{ "getnetworkhashps", &getnetworkhashps, true, false, false }, { "getnetworkhashps", &getnetworkhashps, true, false, false },
{ "getgenerate", &getgenerate, true, false, false },
{ "setgenerate", &setgenerate, true, true, false },
{ "gethashespersec", &gethashespersec, true, false, false },
{ "getmininginfo", &getmininginfo, true, false, false }, { "getmininginfo", &getmininginfo, true, false, false },
{ "getblocktemplate", &getblocktemplate, true, false, false },
{ "submitblock", &submitblock, false, false, false },
#ifdef ENABLE_WALLET
/* Wallet */
{ "getnewaddress", &getnewaddress, true, false, true }, { "getnewaddress", &getnewaddress, true, false, true },
{ "getaccountaddress", &getaccountaddress, true, false, true }, { "getaccountaddress", &getaccountaddress, true, false, true },
{ "getrawchangeaddress", &getrawchangeaddress, true, false, true }, { "getrawchangeaddress", &getrawchangeaddress, true, false, true },
@ -283,10 +285,7 @@ static const CRPCCommand vRPCCommands[] =
{ "listaddressgroupings", &listaddressgroupings, false, false, true }, { "listaddressgroupings", &listaddressgroupings, false, false, true },
{ "signmessage", &signmessage, false, false, true }, { "signmessage", &signmessage, false, false, true },
{ "verifymessage", &verifymessage, false, false, false }, { "verifymessage", &verifymessage, false, false, false },
{ "getwork", &getwork, true, false, true },
{ "listaccounts", &listaccounts, false, false, true }, { "listaccounts", &listaccounts, false, false, true },
{ "getblocktemplate", &getblocktemplate, true, false, false },
{ "submitblock", &submitblock, false, false, false },
{ "listsinceblock", &listsinceblock, false, false, true }, { "listsinceblock", &listsinceblock, false, false, true },
{ "dumpprivkey", &dumpprivkey, true, false, true }, { "dumpprivkey", &dumpprivkey, true, false, true },
{ "dumpwallet", &dumpwallet, true, false, true }, { "dumpwallet", &dumpwallet, true, false, true },
@ -295,6 +294,12 @@ static const CRPCCommand vRPCCommands[] =
{ "listunspent", &listunspent, false, false, true }, { "listunspent", &listunspent, false, false, true },
{ "lockunspent", &lockunspent, false, false, true }, { "lockunspent", &lockunspent, false, false, true },
{ "listlockunspent", &listlockunspent, false, false, true }, { "listlockunspent", &listlockunspent, false, false, true },
/* Wallet-enabled mining */
{ "getgenerate", &getgenerate, true, false, false },
{ "setgenerate", &setgenerate, true, true, false },
{ "gethashespersec", &gethashespersec, true, false, false },
{ "getwork", &getwork, true, false, true },
#endif // ENABLE_WALLET #endif // ENABLE_WALLET
}; };

Loading…
Cancel
Save