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: @@ -187,3 +187,7 @@ disable-wallet mode with:
./configure --disable-wallet
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 = \ @@ -48,9 +48,11 @@ libbitcoin_server_a_SOURCES = \
keystore.cpp \
leveldbwrapper.cpp \
main.cpp \
miner.cpp \
net.cpp \
noui.cpp \
rpcblockchain.cpp \
rpcmining.cpp \
rpcnet.cpp \
rpcrawtransaction.cpp \
txdb.cpp \
@ -61,9 +63,7 @@ libbitcoin_server_a_SOURCES = \ @@ -61,9 +63,7 @@ libbitcoin_server_a_SOURCES = \
libbitcoin_wallet_a_SOURCES = \
db.cpp \
crypter.cpp \
miner.cpp \
rpcdump.cpp \
rpcmining.cpp \
rpcwallet.cpp \
wallet.cpp \
walletdb.cpp \

4
src/init.cpp

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

9
src/miner.cpp

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

24
src/rpcmining.cpp

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

19
src/rpcserver.cpp

@ -248,12 +248,14 @@ static const CRPCCommand vRPCCommands[] = @@ -248,12 +248,14 @@ static const CRPCCommand vRPCCommands[] =
{ "gettxout", &gettxout, true, false, false },
{ "verifychain", &verifychain, true, false, false },
#ifdef ENABLE_WALLET
/* Mining */
{ "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 },
{ "getblocktemplate", &getblocktemplate, true, false, false },
{ "submitblock", &submitblock, false, false, false },
#ifdef ENABLE_WALLET
/* Wallet */
{ "getnewaddress", &getnewaddress, true, false, true },
{ "getaccountaddress", &getaccountaddress, true, false, true },
{ "getrawchangeaddress", &getrawchangeaddress, true, false, true },
@ -283,10 +285,7 @@ static const CRPCCommand vRPCCommands[] = @@ -283,10 +285,7 @@ static const CRPCCommand vRPCCommands[] =
{ "listaddressgroupings", &listaddressgroupings, false, false, true },
{ "signmessage", &signmessage, false, false, true },
{ "verifymessage", &verifymessage, false, false, false },
{ "getwork", &getwork, true, false, true },
{ "listaccounts", &listaccounts, false, false, true },
{ "getblocktemplate", &getblocktemplate, true, false, false },
{ "submitblock", &submitblock, false, false, false },
{ "listsinceblock", &listsinceblock, false, false, true },
{ "dumpprivkey", &dumpprivkey, true, false, true },
{ "dumpwallet", &dumpwallet, true, false, true },
@ -295,6 +294,12 @@ static const CRPCCommand vRPCCommands[] = @@ -295,6 +294,12 @@ static const CRPCCommand vRPCCommands[] =
{ "listunspent", &listunspent, false, false, true },
{ "lockunspent", &lockunspent, 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
};

Loading…
Cancel
Save